<template>
  <div class="app-container">

    <el-card class="card-layout">
      <div class="detail-info">
        <el-row>
          <el-col :span="12">优惠券标题：{{ detail.couponTitle }}</el-col>
        </el-row>
        <el-row>
          <el-col :span="12">优惠券分类：{{ detail.categoryName }}</el-col>
        </el-row>
        <el-row>
          <el-col :span="12">优惠券类型：<dict-tag style="display: inline-block;" :options="dict.type.coupon_type" :value="detail.couponType" /></el-col>
        </el-row>
        <el-row>
          <el-col :span="12">有效期：{{detail.validityType === '1' ? `${detail.validityStartDate} ~ ${detail.validityEndDate}` : `领取后${detail.validityNum}天内`}}</el-col>
        </el-row>
        <el-row>
          <el-col :span="12">库存：{{ detail.issued }}</el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <div class="detail-label">领券限制：</div>
            <div class="detail-value">
              <div>每人总共可领取 {{detail.receiveTotal === -1 ? '不限制' : `${detail.receiveTotal}张`}} </div>
              <div>每人每日可领取 {{detail.receiveDay === -1 ? '不限制' : `${detail.receiveDay}张`}} </div>
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">适用门店：{{ detail.storeName }}</el-col>
        </el-row>
        <el-row>
          <el-col :span="12">优惠券照片：<ImagePreview :src="detail.url || ''" :src-list="[detail.url]" /></el-col>
        </el-row>
        <el-row>
          <el-col :span="12">使用须知：{{ detail.remarks }}</el-col>
        </el-row>
        <el-row v-if="detail.couponType === 'team'">
          <el-col :span="12">套餐名称：{{ detail.mealTitle }}</el-col>
        </el-row>
        <el-row v-if="detail.couponType === 'team'">
          <el-col :span="12">套餐原价：{{ detail.originalPrice }}元</el-col>
        </el-row>
        <el-row v-if="detail.couponType === 'team'">
          <el-col :span="12">折扣价：{{ detail.presentPrice }}元</el-col>
        </el-row>
        <el-row v-if="detail.couponType === 'team'">
          <el-col :span="12">备注：{{ detail.mealRemarks }}</el-col>
        </el-row>
        <template v-if="detail.couponType === 'team'">
          <el-row v-for="(item, index) in detail.couponDetailList" :key="index">
            <el-col :span="12">
              <div style="width: 100%;">
                <div>{{item.category}}</div>
                <el-table :data="item.list" style="width: 100%;" size="small">
                  <el-table-column label="菜品" prop="foodName">
                  </el-table-column>
                  <el-table-column label="份数" prop="foodNum">
                  </el-table-column>
                  <el-table-column label="价格" prop="foodPrice">
                  </el-table-column>
                </el-table>
              </div>

            </el-col>
          </el-row>
        </template>

        <el-row>
          <el-col :span="12">每日发放限制：{{ detail.grant === -1 ? '不限制' : `${detail.grant}张` }}</el-col>
        </el-row>

        <!-- <el-row>
          <el-col :span="12">
            <div class="detail-label">默认决策：</div>
            <div class="detail-value">
              <div v-for="(item, index) in detail.defaultPolicy" :key="index">
                {{ item.groupName }}
                {{ item.fieldZhName }}
                等于
                {{ item.fieldValue }}
              </div>
            </div>
          </el-col>
          <el-col :span="12">创建人：{{ detail.createBy }}</el-col>
        </el-row> -->
      </div>
    </el-card>

    <el-card class="card-layout" style="margin-top: 20px;">
      <el-form ref="formRef" label-width="auto" :model="form">
        <el-form-item prop="examineReason" label="审核意见">
          <el-input type="textarea" v-model="form.examineReason" />
        </el-form-item>
      </el-form>
    </el-card>

    <div class="form-bottom-btn">
      <el-button type="primary" @click="handlePass">审核通过</el-button>
      <el-button type="danger" @click="handleUnPass">审核不通过</el-button>
    </div>
  </div>
</template>

<script>
import { auditDetail, auditCoupon } from '@/api/coupon/audit.js'

export default {
  name: 'CouponAuditAudit',
  dicts: ['coupon_type', 'examine_status'],
  data() {
    return {
      detail: {},
      form: {
        examineReason: undefined
      }
    }
  },
  mounted() {
    this.getDetail()
  },
  methods: {
    getDetail() {
      auditDetail(this.$route.query.id).then(res => {
        this.detail = res.data
      })
    },
    handlePass() {
      auditCoupon(
        {
          id: this.detail.id,
          examineStatus: '1'
        }
      ).then(res => {
        this.$message.success("审核完成");
        this.$tab.closeOpenPage();
        this.$router.push({
          name: "CouponAudit",
          params: {
            refreshTable: true,
          },
        });
      })
    },
    handleUnPass() {
      if (!this.form.examineReason) {
        this.$modal.msgError('审核不通过需输入原因')
        return
      }

      auditCoupon(
        {
          id: this.detail.id,
          examineStatus: '2',
          examineReason: this.form.examineReason
        }
      ).then(res => {
        this.$message.success("审核完成");
        this.$tab.closeOpenPage();
        this.$router.push({
          name: "CouponAudit",
          params: {
            refreshTable: true,
          },
        });
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.detail-info {
  width: 90%;
  margin-top: 26px;
  font-size: 14px;
  line-height: 3;

  &:first-child {
    margin-top: 0;
  }

  .el-col {
    display: flex;
  }
}

.form-bottom-btn {
  margin-top: 20px;
  text-align: right;
}
</style>
