<template>
  <a-modal
    centered
    class="getcode-modal"
    :footer="null"
    :maskClosable="false"
    title="获取充值码"
    v-model="isShow"
    @cancle="isShow=false"
    :width="600">
    <div v-if="detailsData">
      <a-row :gutter="35">
        <a-col :span="24" class="item-cont">
          <p class="item-label">创建时间：</p>
          <p class="item-main">{{ detailsData.createDate }}</p>
        </a-col>
        <a-col :span="24" class="item-cont">
          <p class="item-label">创建人：</p>
          <p class="item-main">{{ detailsData.name }}  {{ detailsData.phone }}</p>
        </a-col>
        <a-col :span="24" class="item-cont">
          <p class="item-label">礼品卡内容：</p>
          <p class="item-main">{{ detailsData.content }}</p>
        </a-col>
        <a-col :span="24" class="item-cont">
          <p class="item-label">充值码：</p>
          <div class="item-main">
            <span style="margin-right: 15px;">{{ detailsData.sequence }}</span>
            <a-button id="gift-card-copy" size="small" v-clipboard:copy="detailsData.sequence" v-clipboard:success="onCopy">复制</a-button>
          </div>
        </a-col>
      </a-row>
    </div>
    <div class="btn-cont"><a-button id="network-detail-modal-back" @click="isShow=false">返回列表</a-button></div>
  </a-modal>
</template>

<script>
import { giftCardDetail } from '@/api/giftCard'
export default {
  name: 'GetCodeModal',
  props: {
    openModal: { //  弹框显示状态
      type: Boolean,
      default: false
    },
    cardId: {
      type: [Number, String],
      default: ''
    }
  },
  data () {
    return {
      isShow: this.openModal, //  是否打开弹框
      detailsData: null //  详情
    }
  },
  methods: {
    //  获取详情
    getDetails () {
      giftCardDetail({ id: this.cardId }).then(res => {
        if (res.status == 200) {
          this.detailsData = res.data
        } else {
          this.detailsData = null
        }
      })
    },
    //  复制
    onCopy () {
      this.$message.success('复制成功')
    }
  },
  watch: {
    //  父页面传过来的弹框状态
    openModal (newValue, oldValue) {
      this.isShow = newValue
    },
    //  重定义的弹框状态
    isShow (newValue, oldValue) {
      if (!newValue) {
        this.$emit('close')
      }
    },
    cardId (newValue, oldValue) {
      if (this.isShow && newValue) {
        this.getDetails()
      }
    }
  }
}
</script>

<style lang="less">
  .getcode-modal{
    .ant-modal-body {
      padding: 40px 40px 24px;
    }
    .item-cont {
      margin-bottom: 15px;
      display: flex;
      .item-label {
        width: 115px;
        font-size: 14px;
        color: rgba(0, 0, 0, 0.85);
        flex-shrink: 0;
      }
      .item-main {
        flex-grow: 1;
        word-break: break-all;
        .wd-icon {
          display: block;
        }
      }
    }
    .btn-cont {
      text-align: center;
      margin: 35px 0 10px;
    }
  }
</style>
