<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="id">
        {{ formData.id || '--' }}
      </el-form-item>
      <el-form-item label="充值订单编号" prop="orderFormid">
        {{ formData.orderFormid || '--' }}
      </el-form-item>
      <el-form-item label="购买者ID" prop="shopId">
        {{ formData.shopId || '--' }}
      </el-form-item>
      <el-form-item label="购买的代金券ID" prop="voucherId">
        {{ formData.voucherId || '--' }}
      </el-form-item>
      <el-form-item label="购买数量" prop="number">
        {{ formData.number || '--' }}
      </el-form-item>
      <el-form-item label="充值类型" prop="status">
        <span v-if="formData.status === 0">未付款</span>
        <span v-else-if="formData.status === 1">取消</span>
        <span v-else-if="formData.status === 2">已付款</span>
        <span v-else-if="formData.status === 3">代金券未发放</span>
        <span v-else-if="formData.status === 4">代金券已发放</span>
        <span v-else-if="formData.status === 5">支付失败</span>
        <span v-else>--</span>
      </el-form-item>
      <el-form-item label="消费金额" prop="payGrade">
        {{ formData.payGrade || '--' }}
      </el-form-item>
      <el-form-item label="第三方支付ID" prop="trxId">
        {{ formData.trxId || '--' }}
      </el-form-item>
      <el-form-item label="支付时间" prop="payTime">
        {{ formData.payTime || '--' }}
      </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: {
        id: '',
        orderFormid: '',
        shopId: '',
        voucherId: '',
        number: '',
        status: '',
        payGrade: '',
        trxId: '',
        payTime: '',
        createTime: ''
      }
    }
  },
  methods: {
    handleClose() {
      this.visible = false
    },
    handleOpen(params = {}) {
      this.formData = Object.assign(this.$options.data().formData, params)
      if (params.id) {
        // this.getInfo(params.id)
      }
      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, {
          id: res.data.id || ''
        })
      } finally {
        loading.close()
      }
    }
  }
}
</script>

