<template>
  <a-modal
    centered
    class="productBrandDetail-modal"
    :footer="null"
    :maskClosable="false"
    title="产品详情"
    v-model="isShow"
    @cancel="isShow=false"
    :width="960">
    <div class="modalContext">
      <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
            id="productBrandDetail-imageUrl"
            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>
    <div class="btn-cont"><a-button id="productBrandDetail-modal-back" @click="isShow = false">返回列表</a-button></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: {// 当前产品品牌sn
      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{
    .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;
    }
    .modalContext{
      padding: 0 40px;
      max-height:630px;
      overflow-y: scroll;
    }
  }
</style>
