<template>
  <div class="detail-container">
    <head-form
      title="常合作招标代理单位"
      :form-data="formData"
      :query-params="queryParams"
      :total="tableDataTotal"
      :isExcel="true"
      @handle-search="handleSearch"
    />
    <skeleton style="margin-left:16px;" v-if="isSkeleton"></skeleton>
    <tables
      v-else
      :indexFixed="true"
      :defaultSort="defaultSort"
      :tableLoading="tableLoading"
      :tableData="tableData"
      :forData="forData"
      :tableDataTotal="tableDataTotal"
      :queryParams="queryParams"
      @handle-current-change="handleCurrentChange"
      @sort-change="sortChange"
    >
      <template slot="agency" slot-scope="scope">
        <router-link :to="scope.row.uipId?`/enterprise/${encodeStr(scope.row.agencyId)}`:`/company/${encodeStr(scope.row.agencyId)}`" tag="a" class="a-link" v-if="scope.row.agencyId&&scope.row.agency" v-html="scope.row.agency"></router-link>
        <div v-else v-html="scope.row.agency || '--'"></div>
      </template>
      <template slot="projectInfo" slot-scope="scope">
        <router-link :to="`/radar/Notice/details/${scope.row.projectInfo.bid}`" tag="a" class="a-link" v-if="scope.row.projectInfo.bid&&scope.row.projectInfo.dealTitle" v-html="scope.row.projectInfo.dealTitle"></router-link>
        <div v-else v-html="scope.row.projectInfo.dealTitle || '--'"></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="'合作项目/工程明细'"
      @cancel="isDetails=false" />
  </div>
</template>

<script>
import mixin from '../mixins/mixin'
import {oftenAgencyPage} from '@/api/detail/party-a/dealings'
import ClientDetail from './component/bidagencyDetail'
export default {
  name: 'Bidagency',
  props: ['companyId'],
  mixins: [mixin],
  components: {
    ClientDetail
  },
  data() {
    return {
      queryParams: {
        cid: this.companyId,
        sort: 3,
        pageNum: 1,
        pageSize: 20
      },
      defaultSort: {prop: 'issueTime', order: 'descending'},
      forData: [
        {label: '招标代理单位名称', prop: 'agency', minWidth: '350', slot: true},
        {label: '合作项目/工程名称', prop: 'projectInfo', minWidth: '400', slot: true, sortable: 'custom', descending: '5', ascending: '6'},
        {label: '最近一次合作时间', prop: 'issueTime', minWidth: '140', sortable: 'custom', descending: '3', ascending: '4'}
      ],
      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 oftenAgencyPage(param)
      this.tableLoading = false
      if(res.code==200){
        this.isSkeleton = false;
        this.tableData = res.rows.map((item)=>{
          item.projectInfo = typeof item.projectInfo == 'string' ? JSON.parse(item.projectInfo) : item.projectInfo
          return item
        })
      }
      this.tableDataTotal = res.total
    },
    handleClick(e, data) {
      this.rowData = data
      this.isDetails = true
    }
  }
}
</script>
<style lang="scss" scoped>
.detail-container{
  background: #ffffff;
  border-radius: 4px;
  padding: 16px;
}
</style>
