<template>
  <a-modal
    centered
    class="productInfoDetail-modal"
    :footer="null"
    :maskClosable="false"
    title="产品详情"
    v-model="isShow"
    @cancle="isShow=false"
    width="80%">
    <!-- 产品详情 -->
    <div>
      <a-descriptions bordered size="default">
        <a-descriptions-item label="产品图片：">
          <img
            v-for="(item,index) in fileList"
            :key="index"
            :src="item.url"
            title="点击查看大图"
            class="productPic"
            @click="getPreview(item.url)" />
        </a-descriptions-item>
        <!-- <a-descriptions-item label="产品名称：">{{ detailsData.productName || '--' }}</a-descriptions-item>
        <a-descriptions-item label="产品编码：">{{ detailsData.productCode || '--' }}</a-descriptions-item>
        <a-descriptions-item label="原厂编码：">{{ detailsData.origCode || '--' }}</a-descriptions-item>
        <a-descriptions-item label="其他编码：">{{ detailsData.origCode || '--' }}</a-descriptions-item>
        <a-descriptions-item label="包装规格：">{{ detailsData.origCode || '--' }}</a-descriptions-item>
        <a-descriptions-item label="箭冠产品：">{{ detailsData.origCode || '--' }}</a-descriptions-item>
        <a-descriptions-item label="单位：">{{ detailsData.unit || '--' }}</a-descriptions-item>
        <a-descriptions-item label="产品品牌：">{{ detailsData.productBrandName || '--' }}</a-descriptions-item>
        <a-descriptions-item label="产品类别：">{{ productTypeName || '--' }}</a-descriptions-item>
        <a-descriptions-item label="产品尺寸：">{{ (detailsData.wholesalePrice || detailsData.wholesalePrice==0) ? detailsData.wholesalePrice : '--' }}</a-descriptions-item>
        <a-descriptions-item label="产品重量：">{{ (detailsData.terminalPrice || detailsData.terminalPrice==0) ? detailsData.terminalPrice : '--' }}</a-descriptions-item>
        <a-descriptions-item label="颜色：">{{ detailsData.productBrandName || '--' }}</a-descriptions-item>
        <a-descriptions-item label="产品说明：">{{ detailsData.productBrandName || '--' }}</a-descriptions-item>
        <a-descriptions-item label="其他说明：">{{ detailsData.productBrandName || '--' }}</a-descriptions-item> -->
      </a-descriptions>
      <div class="btn-cont"><a-button id="product-management-detail-modal-back" @click="isShow = false">返回列表</a-button></div>
    </div>
    <a-modal :visible="previewVisible" :footer="null" @cancel="previewVisible=false">
      <img alt="example" style="width: 100%" :src="previewImage" />
    </a-modal>
  </a-modal>
</template>

<script>
// import { dealerProductDetail } from '@/api/dealerProduct'
export default {
  name: 'ProductInfoDetailModal',
  props: {
    openModal: { //  弹框显示状态
      type: Boolean,
      default: false
    },
    itemId: {
      type: [Number, String],
      default: ''
    }
  },
  computed: {
    productTypeName () {
      const productTypeName1 = this.detailsData.productTypeName1 ? this.detailsData.productTypeName1 : ''
      const productTypeName2 = this.detailsData.productTypeName2 ? ' > ' + this.detailsData.productTypeName2 : ''
      const productTypeName3 = this.detailsData.productTypeName3 ? ' > ' + this.detailsData.productTypeName3 : ''
      return productTypeName1 + productTypeName2 + productTypeName3
    }
  },
  data () {
    return {
      isShow: this.openModal, //  是否打开弹框
      detailsData: null, //  详情数据
      previewVisible: false,
      previewImage: '',
      fileList: [
        {
          uid: '-1',
          name: 'image.png',
          status: 'done',
          url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png'
        },
        {
          uid: '-2',
          name: 'image.png',
          status: 'done',
          url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png'
        },
        {
          uid: '-3',
          name: 'image.png',
          status: 'done',
          url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png'
        }
      ]
    }
  },
  methods: {
    //  获取详情
    getDetail () {
      // dealerProductDetail({ id: this.itemId }).then(res => {
      //   if (res.status == 200) {
      //     this.detailsData = res.data
      //   } else {
      //     this.detailsData = null
      //   }
      // })
    },
    // 查看大图
    getPreview (url) {
      this.previewImage = url
      this.previewVisible = true
    }
  },
  watch: {
    //  父页面传过来的弹框状态
    openModal (newValue, oldValue) {
      this.isShow = newValue
    },
    //  重定义的弹框状态
    isShow (newValue, oldValue) {
      if (!newValue) {
        this.$emit('close')
      }
    },
    itemId (newValue, oldValue) {
      if (this.isShow && newValue) {
        this.getDetail()
      }
    }
  }
}
</script>

<style lang="less">
  .productInfoDetail-modal{
    .ant-modal-body {
      padding: 40px 40px 24px;
    }
    .productPic{
      cursor: pointer;
      width: 100px;
      margin-right: 10px;
    }
    .btn-cont {
      text-align: center;
      margin: 35px 0 10px;
    }
  }
</style>
