<template>
  <a-modal
    centered
    class="productInfoDetail-modal"
    :footer="null"
    :maskClosable="false"
    title="产品详情"
    v-model="isShow"
    @cancle="isShow=false"
    :width="800">
    <!-- 产品详情 -->
    <div>
      <a-descriptions bordered :column="2" size="small">
        <a-descriptions-item label="产品名称：">{{ detailsData&&detailsData.name || '--' }}</a-descriptions-item>
        <a-descriptions-item label="产品编码：">{{ detailsData&&detailsData.code || '--' }}</a-descriptions-item>
        <a-descriptions-item label="原厂编码：">{{ detailsData&&detailsData.origCode || '--' }}</a-descriptions-item>
        <a-descriptions-item label="基本单位：">{{ detailsData&&detailsData.unit || '--' }}</a-descriptions-item>
        <a-descriptions-item label="产品品牌：">{{ detailsData&&detailsData.productBrandName || '--' }}</a-descriptions-item>
        <a-descriptions-item label="产品分类：">{{ productTypeName || '--' }}</a-descriptions-item>
        <a-descriptions-item label="经销批发价：">{{ detailsData&&(detailsData.specialPrice || detailsData.specialPrice==0) ? detailsData.specialPrice : '--' }}</a-descriptions-item>
        <a-descriptions-item label="终端价：">{{ detailsData&&(detailsData.terminalPrice || detailsData.terminalPrice==0) ? detailsData.terminalPrice : '--' }}</a-descriptions-item>
        <a-descriptions-item label="车主价：">{{ detailsData&&(detailsData.carOwnersPrice || detailsData.carOwnersPrice==0) ? detailsData.carOwnersPrice : '--' }}</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>
</template>

<script>
import { commonMixin } from '@/utils/mixin'
import { dealerProductDetail } from '@/api/dealerProduct'
export default {
  name: 'ProductInfoDetailModal',
  mixins: [commonMixin],
  props: {
    openModal: { //  弹框显示状态
      type: Boolean,
      default: false
    },
    itemId: {
      type: [Number, String],
      default: ''
    }
  },
  computed: {
    productTypeName () {
      const productTypeName1 = this.detailsData && this.detailsData.productTypeName1 ? this.detailsData.productTypeName1 : ''
      const productTypeName2 = this.detailsData && this.detailsData.productTypeName2 ? ' > ' + this.detailsData.productTypeName2 : ''
      const productTypeName3 = this.detailsData && this.detailsData.productTypeName3 ? ' > ' + this.detailsData.productTypeName3 : ''
      return productTypeName1 + productTypeName2 + productTypeName3
    }
  },
  data () {
    return {
      isShow: this.openModal, //  是否打开弹框
      detailsData: null //  详情数据
    }
  },
  methods: {
    //  获取详情
    getDetail () {
      dealerProductDetail({ id: this.itemId }).then(res => {
        if (res.status == 200) {
          this.detailsData = res.data
        } else {
          this.detailsData = null
        }
      })
    }
  },
  watch: {
    //  父页面传过来的弹框状态
    openModal (newValue, oldValue) {
      this.isShow = newValue
    },
    //  重定义的弹框状态
    isShow (newValue, oldValue) {
      if (!newValue) {
        this.$emit('close')
        this.detailsData = null
      }
    },
    itemId (newValue, oldValue) {
      if (this.isShow && newValue) {
        this.getDetail()
      }
    }
  }
}
</script>

<style lang="less">
  .productInfoDetail-modal{
    .ant-modal-body {
      padding: 40px 40px 24px;
    }
    .ant-descriptions-item-label.ant-descriptions-item-colon{
      width: 120px;
    }
    .btn-cont {
      text-align: center;
      margin: 35px 0 10px;
    }
  }
</style>
