<template>
  <el-dialog
    :visible.sync="visible"
    v-bind="modalOptions"
  >
    <el-form
      ref="formData"
      :model="formData"
      size="mini"
      label-position="left"
      label-suffix=":"
      label-width="200px"
    >
      <!-- 代金券信息 -->
      <el-form-item label="ID" prop="platformVoucherId">
        {{ formData.platformVoucherId || '--' }}
      </el-form-item>
      <el-form-item label="代金券代码" prop="voucherCode">
        {{ formData.voucherCode || '--' }}
      </el-form-item>
      <el-form-item label="代金券名称" prop="voucherName">
        {{ formData.voucherName || '--' }}
      </el-form-item>
      <el-form-item label="代金券购买比例" prop="purchaseRatio">
        {{ formData.purchaseRatio || '--' }}：1
      </el-form-item>
      <el-form-item label="代金券抵扣比例" prop="paymentRatio">
        {{ formData.paymentRatio || '--' }}：1
      </el-form-item>
      <el-form-item label="状态" prop="enabled">
        <span v-if="formData.enabled === 0">正常</span>
        <span v-else-if="formData.enabled === 1">暂停</span>
        <span v-else>--</span>
      </el-form-item>
      <el-form-item label="平台操作者ID" prop="operatorId">
        {{ formData.operatorId || '--' }}
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        {{ formData.createTime || '--' }}
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script>

export default {
  name: 'DetailModal',
  data() {
    return {
      modalOptions: {
        closeOnClickModal: false,
        width: '800px',
        title: '查看代金券详情'
      },
      visible: false,
      formData: {
        platformVoucherId: '',
        voucherCode: '', // 代金券代码（唯一）
        voucherName: '', // 代金券名称
        desc: '', // 代金券描述
        purchaseRatio: '', // 代金券购买比例(与现金比例)
        paymentRatio: '', // 代金券抵扣比例(与现金比例)
        enabled: '', // 启停：0-为启用  1-为停用
        operatorId: '', // 平台操作者ID
        createTime: '',
        updateTime: ''
      }
    }
  },
  methods: {
    handleClose() {
      this.visible = false
    },
    handleOpen(params = {}) {
      this.formData = Object.assign(this.$options.data().formData, params)
      if (params.platformVoucherId) {
        // this.getInfo(params.platformVoucherId)
      }
      this.visible = true
    },
    async getInfo(id) {
      const loading = this.$loading({ text: '加载中' })
      try {
        const res = await xxx({ id })
        this.formData = Object.assign(this.$options.data().formData, res.data, {
          platformVoucherId: res.data.platformVoucherId || ''
        })
      } finally {
        loading.close()
      }
    }
  }
}
</script>

