<template>
  <a-modal
    centered
    class="productBrandDetail-modal"
    :footer="null"
    :maskClosable="false"
    title="产品详情"
    v-model="isShow"
    @cancle="isShow=false"
    :width="960">
    <div>
      <a-descriptions bordered size="small" :column="1">
        <a-descriptions-item label="品牌名称：">{{ detailsData&&detailsData.brandName || '--' }}</a-descriptions-item>
        <a-descriptions-item label="品牌分类：">{{ detailsData&&detailsData.brandTypeDictValue || '--' }}</a-descriptions-item>
        <a-descriptions-item label="排序字母：">{{ detailsData&&detailsData.sortChar || '--' }}</a-descriptions-item>
        <a-descriptions-item label="品牌图片：">
          <img v-if="detailsData&&detailsData.imageUrl" :src="detailsData.imageUrl" title="点击查看大图" class="productPic" @click="getPreview(detailsData.imageUrl)" />
          <span v-else>--</span>
        </a-descriptions-item>
        <a-descriptions-item label="品牌介绍：">
          <div v-if="detailsData&&detailsData.brandIntroduce" v-html="detailsData.brandIntroduce"></div>
          <span v-else>--</span>
        </a-descriptions-item>
      </a-descriptions>
      <div class="btn-cont"><a-button id="productBrandDetail-modal-back" @click="isShow = false">返回列表</a-button></div>
    </div>
    <a-modal :visible="previewVisible" :footer="null" centered :maskClosable="false" @cancel="previewVisible=false">
      <img alt="example" style="width: 100%;" :src="previewImage" />
    </a-modal>
  </a-modal>
</template>

<script>
import { productBrandSnDetail } from '@/api/productBrand'
export default {
  name: 'ProductBrandDetailModal',
  props: {
    openModal: { //  弹框显示状态
      type: Boolean,
      default: false
    },
    itemSn: {
      type: [Number, String],
      default: ''
    }
  },
  data () {
    return {
      isShow: this.openModal, //  是否打开弹框
      detailsData: null, //  详情数据
      previewVisible: false,
      previewImage: ''
    }
  },
  methods: {
    //  获取详情
    getDetail () {
      productBrandSnDetail({ sn: this.itemSn }).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')
        this.detailsData = null
      }
    },
    itemSn (newValue, oldValue) {
      if (this.isShow && newValue) {
        this.getDetail()
      }
    }
  }
}
</script>

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