<template>
  <div>
    <el-row type="flex" style="margin-top: 15px;margin-bottom: 15px" justify="center">
      <el-col :xs="24" :sm="24" :md="24" :lg="20" :xl="16">
        <div style="display: flex;justify-content: space-between;align-items: flex-end;">
          <h2>查看</h2>
          <div>
            <el-button type="primary" size="small">添加优惠</el-button>
            <el-button type="primary" size="small" @click="$router.push('/customer/edit/' + id)">编辑</el-button>
            <el-button type="primary" size="small">报价</el-button>
            <el-button type="primary" size="small" @click="$refs['customerFollow'].customerFollow.dialogVisible = true">跟进</el-button>
            <el-button type="primary" size="small" @click="$refs['customerComplaint'].handleAdd()">客诉</el-button>
            <el-button type="danger" size="small">删除</el-button>
          </div>
        </div>
        <el-card style="margin-top: 15px;">
          <el-descriptions :column="4" border>
            <el-descriptions-item label="客户编号">{{ customer.number }}</el-descriptions-item>
            <el-descriptions-item label="客户名称">{{ customer.name }}</el-descriptions-item>
            <el-descriptions-item label="结算方式">{{ getDictDataLabel(DICT_TYPE.CUSTOMER_BALANCE, customer.balance) }}</el-descriptions-item>
            <el-descriptions-item label="客户生日">{{ parseTime(customer.birthday, '{y}-{m}-{d}') }}</el-descriptions-item>
            <el-descriptions-item label="客户等级">{{ getDictDataLabel(DICT_TYPE.CUSTOMER_LEVEL, customer.level) }}</el-descriptions-item>
            <el-descriptions-item label="国家">{{ getDictDataLabel(DICT_TYPE.COUNTRY, customer.country) }}</el-descriptions-item>
<!--            <el-descriptions-item label="业务员">{{ customer }}</el-descriptions-item>-->
            <el-descriptions-item label="客户来源">{{ getDictDataLabel(DICT_TYPE.CUSTOMER_SOURCE, customer.source) }}</el-descriptions-item>
            <el-descriptions-item label="客户类别">{{ getDictDataLabel(DICT_TYPE.CUSTOMER_TYPE, customer.type) }}</el-descriptions-item>
<!--            <el-descriptions-item label="联系方式">{{ customer }}</el-descriptions-item>-->
            <el-descriptions-item label="推介人">{{ promoter  }}</el-descriptions-item>
            <el-descriptions-item label="客户经理">{{ customerService }}</el-descriptions-item>
            <el-descriptions-item label="公司名称">{{ customer.company }}</el-descriptions-item>
            <el-descriptions-item label="联系地址">{{ customer.address }}</el-descriptions-item>
            <el-descriptions-item label="创建时间">{{ parseTime(customer.createTime) }}</el-descriptions-item>
            <el-descriptions-item label="状态">{{ getDictDataLabel(DICT_TYPE.CUSTOMER_STATUS, customer.status) }}</el-descriptions-item>
            <el-descriptions-item label="主营类别">{{ productType }}</el-descriptions-item>
            <el-descriptions-item label="常提货网点">{{ pickupPoint }}</el-descriptions-item>
            <el-descriptions-item label="图片">
              <el-image v-show="!!customer.picture" :src="customer.picture" style="width: 100px;height: 100px"></el-image>
            </el-descriptions-item>
            <el-descriptions-item label="备注">{{ customer.remarks }}</el-descriptions-item>
<!--            <el-descriptions-item label="信用等级">{{ customer }}</el-descriptions-item>-->
          </el-descriptions>
        </el-card>

        <el-card style="margin-top: 15px">
          <h3>联系人</h3>

          <el-table
            :data="customerContacts"
            style="width: 100%"
            border
          >
            <el-table-column
              prop="department"
              label="部门"
            >
            </el-table-column>
            <el-table-column
              prop="position"
              label="职位"
            >
            </el-table-column>
            <el-table-column
              prop="name"
              label="联系人"
            >
            </el-table-column>
            <el-table-column
              prop="phoneNew"
              label="联系方式"
            >
              <template v-slot="{row}">
                {{ row.areaCode + row.phoneNew }}
              </template>
            </el-table-column>
            <el-table-column
              prop="username"
              label="关联账号"
            >
            </el-table-column>
            <el-table-column
              prop="social"
              label="社交软件"
            >
            </el-table-column>
            <el-table-column
              prop="socialNumber"
              label="社交软件号码"
            >
            </el-table-column>
            <el-table-column
              prop="email"
              label="邮箱"
            >
            </el-table-column>
          </el-table>
        </el-card>

        <el-tabs style="margin-top: 15px" type="border-card">
          <el-tab-pane label="订单">
            订单
          </el-tab-pane>
          <el-tab-pane label="报价">
            <el-table
              :data="[]"
              style="width: 100%"
            >
              <el-table-column
                prop=""
                label="序号"
              >
              </el-table-column>
              <el-table-column
                prop=""
                label="报价单号"
              >
              </el-table-column>
              <el-table-column
                prop=""
                label="订单号"
              >
              </el-table-column>
              <el-table-column
                prop=""
                label="客户名称"
              >
              </el-table-column>
              <el-table-column
                prop=""
                label="目的地"
              >
              </el-table-column>
              <el-table-column
                prop=""
                label="销售阶段"
              >
              </el-table-column>
              <el-table-column
                prop=""
                label="预计结束时间"
              >
              </el-table-column>
              <el-table-column
                prop=""
                label="负责人"
              >
              </el-table-column>
            </el-table>
          </el-tab-pane>
          <el-tab-pane label="跟进">
            <customer-follow ref="customerFollow" :id="id" :customer-id="id"></customer-follow>
          </el-tab-pane>
          <el-tab-pane label="客户投诉">
            <customer-complaint ref="customerComplaint" :customer-id="id" hidden-search></customer-complaint>
          </el-tab-pane>
          <el-tab-pane label="账单">

          </el-tab-pane>
          <el-tab-pane label="数据">

          </el-tab-pane>
          <el-tab-pane label="品牌授权">
              <el-table  border style="width:100%" :data="brandAuthorizationList">
                <el-table-column   type="index" prop="序号"></el-table-column>
                <el-table-column  label="中文标题" prop="titleZh" ></el-table-column>
                <el-table-column prop="titleEn" label="英文标题"></el-table-column>
                <el-table-column label="有无备案">
                 <template v-slot="{row}">
                   <dict-tag :type="DICT_TYPE.BRAND_REG_TYPE" :value="row.filing" />
                 </template>
                </el-table-column>
                <el-table-column label="授权开始">
                  <template v-slot="{row}">
                    {{parseTime(row.startTime)}}
                  </template>
                </el-table-column>
                <el-table-column label="授权结束">
                  <template v-slot="{row}">
                    {{parseTime(row.endTime)}}
                  </template>
                </el-table-column>
                <el-table-column label="授权证明">
                  <template v-slot="{row}">
                    <div v-if="!!row.fileUrl && row.fileUrl.length > 0">
                  <span v-for="(item, index) in row.fileUrl.split(',')">
                    <a :href="item" target="_blank">附件{{ index + 1 }}</a>,
                  </span>
                    </div>
                  </template>
                </el-table-column>
                <el-table-column
                  prop="feeScale"
                  :formatter="(row) => getDictDataLabel(DICT_TYPE.BRAND_CUSTOMER_CHARGING_MODEL, row.feeScale)"
                  label="收费标准">
                </el-table-column>
                <el-table-column
                  prop="createUsername"
                  label="添加人">
                </el-table-column>
                <el-table-column label="创建时间">
                  <template v-slot="{row}">
                    {{parseTime(row.createTime)}}
                  </template>
                </el-table-column>
              </el-table>
            <pagination v-show="brandAuthorizationTotal > 0" :total="brandAuthorizationTotal" :page.sync="brandAuthorizationFrom.pageNo" :limit.sync="brandAuthorizationFrom.pageSize"
                        @pagination="getBrankByCustomerList"/>
          </el-tab-pane>
          <el-tab-pane label="信用日志">

          </el-tab-pane>
          <el-tab-pane label="等级日志">

          </el-tab-pane>
        </el-tabs>
      </el-col>
    </el-row>

  </div>
</template>

<script>
import { getCustomer, getCustomerSelect,getBrankByCustomer } from '@/api/ecw/customer'
import { DICT_TYPE, getDictDataLabel } from '@/utils/dict'
import { getProductTypeList } from '@/api/ecw/productType'
import { getNodeList } from '@/api/ecw/node'
import CustomerFollow from "@/components/CustomerFollow"
import { parseTime } from '@/utils/ruoyi'
import CustomerComplaint from '@/views/ecw/customerComplaint'
import { listServiceUser } from '@/api/system/user'
import { getCustomerContactsListByCustomer } from '@/api/ecw/customerContacts'

export default {
  name: 'query',
  props: {
    customerId: String
  },
  components: {
    CustomerFollow,
    CustomerComplaint
  },
  created() {
    getNodeList().then(r => {
      this.nodeList = r.data
    })
    getCustomer(this.id).then(response => {
      this.customer = { ...this.customer, ...response.data }

      getCustomerContactsListByCustomer({customerId: this.id}).then(r => {
        this.customerContacts = r.data
      })
    })
    getProductTypeList().then(r => {
      this.productTypeList = r.data
    })

    getCustomerSelect().then(r => {
      this.customerSelect = r.data
    })
    listServiceUser().then(r => {
      this.serviceUserList = r.data
    })
    this.getBrankByCustomerList()
  },
  data() {
    return {
      DICT_TYPE,
      getDictDataLabel,
      parseTime,
      nodeList: [],
      productTypeList: [],
      customerSelect: [],
      serviceUserList: [],
      customerContacts: [],
      customer: {
        id: undefined,
        number: undefined,
        name: undefined,
        level: undefined,
        country: undefined,
        type: undefined,
        agentId: undefined,
        company: undefined,
        address: undefined,
        productType: undefined,
        productId: undefined,
        pickupPoint: undefined,
        memberId: undefined,
        birthday: undefined,
        balance: undefined,
        source: undefined,
        picture: undefined,
        customerService: undefined,
        customerLines: [],
        promoter: undefined,
        status: undefined,
        founder: undefined,
        department: undefined,
        invoiceTitle: undefined,
        licenseNumber: undefined,
        bank: undefined,
        bankNumber: undefined,
        project: undefined,
        billingAddress: undefined,
        billingTell: undefined,
        taxRate: undefined,
        remarks: undefined,
        arrivalConfirm: undefined,
        weightUnit: undefined,
        createTime: undefined
      },
      brandAuthorizationFrom:{
        pageNo:1,
        pageSize:10,
      },
      brandAuthorizationList:[],
      brandAuthorizationTotal:0,
    }
  },
  computed: {
    productType(){
      const productType = this.productTypeList.find(p => p.id === parseInt(this.customer.productType))
      return productType ? productType.titleZh : ''
    },
    pickupPoint(){
      const pickupPoint = this.nodeList.find(p => p.id === parseInt(this.customer.pickupPoint))
      return pickupPoint ? pickupPoint.titleZh : ''
    },
    promoter() {
      return this.customerSelect.find(e => e.id === this.customer.promoter)?.name || ''
    },
    customerService() {
      return this.serviceUserList.find(e => e.id === this.customer.customerService)?.nickname || ''
    },
    id() {
      return this.customerId ? parseInt(this.customerId) : undefined
    }
  },
  methods:{
    getBrankByCustomerList(){
      getBrankByCustomer({...this.brandAuthorizationFrom,customerId:this.id}).then(r => {this.brandAuthorizationList = r.data.list; this.brandAuthorizationTotal = r.data.total})
    }
  }
}
</script>

<style scoped>

</style>
