<template>
  <div class="detail-container">
    <head-form
      title="客户"
      :form-data="formData"
      :query-params="queryParams"
      :total="tableDataTotal"
      :isExcel="true"
      @handle-search="handleSearch"
    />

    <tables
      :indexFixed="true"
      :tableLoading="tableLoading"
      :tableData="tableData"
      :forData="forData"
      :tableDataTotal="tableDataTotal"
      :queryParams="queryParams"
      @handle-current-change="handleCurrentChange"
      @sort-change="sortChange"
    >
      <template slot="companyName" slot-scope="scope">
        <router-link to="" tag="a" class="a-link" v-if="scope.row.companyId&&scope.row.companyName" v-html="scope.row.companyName"></router-link>
        <div v-else v-html="scope.row.companyName || '--'"></div>
      </template>
      <template slot="projectAllName" slot-scope="scope">
        <router-link to="" tag="a" class="a-link" v-if="scope.row.projectId&&scope.row.projectAllName" v-html="scope.row.projectAllName"></router-link>
        <div v-else v-html="scope.row.projectAllName || '--'"></div>
        <div v-if="scope.row.count>1" @click="handleClick($event, scope.row)" style="color: #FF7E38;cursor: pointer;">有{{scope.row.count}}个合作项目/工程 ></div>
      </template>
    </tables>
    <client-detail
      v-if="isDetails"
      :data="rowData"
      :title="'合作项目/工程明细'"
      :company-id="companyId"
      @cancel="isDetails=false" />
  </div>
</template>

<script>
import mixin from '../mixins/mixin'
import { clientPage } from '@/api/detail/party-a/dealings'
import ClientDetail from './component/customDetail'
export default {
  name: 'Custom',
  props: ['companyId'],
  mixins: [mixin],
  components: {
    ClientDetail
  },
  data() {
    return {
      queryParams: {
        cid: this.companyId,
        sort: 3,
        pageNum: 1,
        pageSize: 10
      },
      forData: [
        {label: '客户名称', prop: 'companyName', minWidth: '350', slot: true},
        {label: '合作项目/工程名称', prop: 'projectAllName', minWidth: '400', sortable: true, slot: true},
        {label: '合作总金额（万元）', prop: 'amount', minWidth: '150', sortable: true},
        {label: '最近一次合作时间', prop: 'time', minWidth: '140', sortable: true}
      ],
      formData: [
        { type: 3, fieldName: 'keys', value: '', placeholder: '输入企业名称查询', options: []},
      ],
      //列表
      tableLoading:false,
      tableData:[],
      tableDataTotal:0,
      isDetails: false,
      rowData: {}
    }
  },
  computed: {
  },
  created() {
    this.handleQuery()
  },
  methods: {
    async handleQuery(params) {
      this.tableLoading = true
      let param = params?params:this.queryParams
      let res = await clientPage(param)
      this.tableLoading = false
      if(res.code==200){
        this.tableData = res.rows
      }
      this.tableDataTotal = res.total
    },
    //排序-测试
    sortChange(e){
      this.tableData = []
      let sortRule = e.prop+','+e.order
      switch (sortRule){
        case 'amount,descending':
          this.queryParams.sort = 1
          break
        case 'amount,ascending':
          this.queryParams.sort = 2
          break
        case 'time,descending':
          this.queryParams.sort = 3
          break
        case 'time,ascending':
          this.queryParams.sort = 4
          break
        case 'projectAllName,descending':
          this.queryParams.sort = 5
          break
        case 'projectAllName,ascending':
          this.queryParams.sort = 6
          break
      }
      this.handleSearch()
    },
    handleClick(e, data) {
      this.rowData = data
      this.isDetails = true
    }
  }
}
</script>
<style lang="scss" scoped>
.detail-container{
  background: #ffffff;
  border-radius: 4px;
  padding: 16px;
}
</style>
