<template>
  <a-modal
    centered
    class="customerManagementDetail-modal"
    :footer="null"
    :maskClosable="false"
    title="客户详情"
    v-model="isShow"
    @cancle="isShow=false"
    :width="960">
    <!-- 客户详情 -->
    <div>
      <a-spin :spinning="!detailData" tip="Loading...">
        <a-descriptions :column="3" bordered size="small">
          <a-descriptions-item label="客户名称：">{{ detailData&&detailData.customerName || '--' }}</a-descriptions-item>
          <a-descriptions-item label="联系人：">{{ detailData&&detailData.contactName || '--' }}</a-descriptions-item>
          <a-descriptions-item label="联系电话：">{{ detailData&&detailData.contactTel || '--' }}</a-descriptions-item>
          <a-descriptions-item label="联系手机：">{{ detailData&&detailData.contactMobile || '--' }}</a-descriptions-item>
          <a-descriptions-item label="客户地址：" :span="3">{{ addressStr }}</a-descriptions-item>
          <a-descriptions-item label="客户传真：">{{ detailData&&detailData.fax || '--' }}</a-descriptions-item>
          <a-descriptions-item label="配送方式：">{{ detailData&&detailData.dispatchTypeDictValue || '--' }}</a-descriptions-item>
          <a-descriptions-item label="是否卫星仓客户：">{{ detailData&&detailData.satelliteFlagDictValue || '--' }}</a-descriptions-item>
          <a-descriptions-item label="价格类型：">{{ detailData&&detailData.priceTypeDictValue || '--' }}</a-descriptions-item>
          <a-descriptions-item label="收款方式：">{{ detailData&&detailData.settleStyleName || '--' }}</a-descriptions-item>
          <a-descriptions-item label="客户类型：">{{ detailData&&detailData.customerTypeName || '--' }}</a-descriptions-item>
        </a-descriptions>
      </a-spin>
      <div class="btn-cont"><a-button id="customer-management-detail-modal-back" @click="isShow = false">返回列表</a-button></div>
    </div>
  </a-modal>
</template>

<script>
import { STable } from '@/components'
import { custFindById } from '@/api/customer'
export default {
  name: 'CustomerManagementDetailModal',
  components: { STable },
  props: {
    openModal: { //  弹框显示状态
      type: Boolean,
      default: false
    },
    itemId: {
      type: [Number, String],
      default: ''
    }
  },
  computed: {
    // 地址处理
    addressStr () {
      const provinceName = this.detailData && this.detailData.provinceName ? this.detailData.provinceName : ''
      const cityName = this.detailData && this.detailData.cityName ? this.detailData.cityName : ''
      const countyName = this.detailData && this.detailData.countyName ? this.detailData.countyName : ''
      const customerAddr = this.detailData && this.detailData.customerAddr ? this.detailData.customerAddr : ''
      const str = (provinceName || cityName || countyName || customerAddr) ? (provinceName + cityName + countyName + customerAddr) : '--'
      return str
    }
  },
  data () {
    return {
      isShow: this.openModal, //  是否打开弹框
      detailData: null //  网点数据
    }
  },
  methods: {
    //  获取详情
    getDetail () {
      custFindById({ id: this.itemId }).then(res => {
        if (res.status == 200) {
          this.detailData = res.data
        } else {
          this.detailData = null
        }
      })
    }
  },
  watch: {
    //  父页面传过来的弹框状态
    openModal (newValue, oldValue) {
      this.isShow = newValue
    },
    //  重定义的弹框状态
    isShow (newValue, oldValue) {
      if (!newValue) {
        this.detailData = null
        this.$emit('close')
      }
    },
    itemId (newValue, oldValue) {
      if (this.isShow && newValue) {
        this.getDetail()
      }
    }
  }
}
</script>

<style lang="less">
  .customerManagementDetail-modal{
    .ant-modal-body {
      padding: 40px 40px 24px;
    }
    .ant-descriptions-item-label.ant-descriptions-item-colon{
      width: 145px;
    }
    .item-cont {
      margin-bottom: 10px;
      display: flex;
      .item-label {
        width: 115px;
        font-size: 14px;
        color: rgba(0, 0, 0);
        flex-shrink: 0;
      }
      .item-main {
        flex-grow: 1;
        word-break: break-all;
      }
    }
    .btn-cont {
      text-align: center;
      margin: 35px 0 10px;
    }
  }
</style>
