<template>
  <a-modal
    centered
    class="viewLogistics-modal"
    :footer="null"
    :maskClosable="false"
    title="物流单号"
    v-model="isShow"
    @cancel="isShow=false"
    :width="360">
    <div class="viewLogistics-con">
      <div class="viewLogistics-main">
        物流单号：{{ itemNo||'--' }}
      </div>
      <!-- 按钮 -->
      <div class="btn-con">
        <a-button v-if="itemNo" id="viewLogistics-cancel" class="button-cancel" @click="handleCopy">复制</a-button>
        <a-button v-else id="viewLogistics-cancel" class="button-cancel" @click="isShow=false">关闭</a-button>
      </div>
    </div>
  </a-modal>
</template>

<script>
import { Upload } from '@/components'
export default {
  name: 'ViewLogisticsModal',
  components: { Upload },
  props: {
    openModal: { //  弹框显示状态
      type: Boolean,
      default: false
    },
    itemNo: {
      type: String,
      default: ''
    }
  },
  data () {
    return {
      isShow: this.openModal //  是否打开弹框
    }
  },
  methods: {
    // 复制物流单号
    async handleCopy () {
      const _this = this
      try {
        await navigator.clipboard.writeText(_this.itemNo)
        _this.$message.success('内容已复制到剪贴板')
      } catch (err) {
        _this.$message.error('复制到剪贴板失败', err)
      }
    }
  },
  watch: {
    //  父页面传过来的弹框状态
    openModal (newValue, oldValue) {
      this.isShow = newValue
    },
    //  重定义的弹框状态
    isShow (newValue, oldValue) {
      if (!newValue) {
        this.$emit('close')
      }
    }
  }
}
</script>

<style lang="less" scoped>
  .viewLogistics-modal{
    .viewLogistics-con{
      .viewLogistics-main{
        padding:10px 20px 20px;
      }
     .btn-con{
       margin: 10px 0 20px;
       text-align: center;
       .button-cancel{
         font-size: 12px;
       }
     }

    }
  }
</style>
