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

    <tables
      :indexFixed="true"
      :defaultSort="defaultSort"
      :tableLoading="tableLoading"
      :tableData="tableData"
      :forData="forData"
      :tableDataTotal="tableDataTotal"
      :queryParams="queryParams"
      @handle-current-change="handleCurrentChange"
      @sort-change="sortChange"
    >
      <template slot="projectAllName" slot-scope="scope">
        <router-link to="" tag="a" class="a-link" v-if="scope.row.id&&scope.row.projectAllName " v-html="scope.row.projectAllName"></router-link>
        <div v-else v-html="scope.row.projectAllName  || '--'"></div>
      </template>
      <template slot="companyName" slot-scope="scope">
        <router-link to="" tag="a" class="a-link" v-if="scope.row.companyId&&scope.row.companyName">{{ scope.row.companyName }}</router-link>
        <div v-else>{{ scope.row.companyName || '--' }}</div>
      </template>
    </tables>
  </div>
</template>

<script>
import mixin from '../mixins/mixin'
import {historySendProvince, historySendPage} from '@/api/detail/party-a/dealings'
export default {
  name: 'Hiscontract',
  props: ['companyId'],
  mixins: [mixin],
  components: {

  },
  data() {
    return {
      queryParams: {
        cid: this.companyId,
        sort: 3,
        pageNum: 1,
        pageSize: 20
      },
      defaultSort: {prop: 'winBidTime', order: 'descending'},
      forData: [
        {label: '项目名称', prop: 'projectAllName', minWidth: '560', slot: true},
        {label: '中标时间', prop: 'winBidTime', minWidth: '100', sortable: 'custom', descending: '3', ascending: '4'},
        {label: '中标企业', prop: 'companyName', minWidth: '320', slot: true},
        {label: '中标金额（万元）', prop: 'winBidAmount', minWidth: '140', sortable: 'custom', descending: '1', ascending: '2'},
        {label: '下浮率（%）', prop: 'lowerRate', minWidth: '120', sortable: 'custom', descending: '7', ascending: '8'},
        {label: '项目经理 / 负责人', prop: 'staffName', minWidth: '130'},
        {label: '中标地区', prop: 'region', minWidth: '160'},
        {label: '工期（天）', prop: 'period', minWidth: '110', sortable: 'custom', descending: '9', ascending: '10'},
        {label: '业绩类别', prop: 'boundType', minWidth: '110'}
      ],
      formData: [
        { type: 1, fieldName: 'provinceId', value: '', placeholder: '项目地区', options: [] },
        { type: 5, fieldName: 'time', value: '', placeholder: '中标时间', startTime: 'dateFrom', endTime: 'dateTo' },
        { type: 6, fieldName: 'money', value: '', placeholder: '中标金额', startMoney: 'amountMin', endMoney: 'amountMax' },
        { type: 3, fieldName: 'keys', value: '', placeholder: '输入项目名称查询', options: [] }
      ],
      //列表
      tableLoading:false,
      tableData:[],
      tableDataTotal:0
    }
  },
  computed: {
  },
  created() {
    this.handleOption()
    this.handleQuery()
  },
  methods: {
    async handleOption(){
      let res = await historySendProvince({cid: this.companyId})
      if(res.code==200){
        let region = res.data.map(item => {
          let it = {name:item.province+'('+item.count+')',value:item.provinceId}
          return it
        })
        this.setFormData('provinceId', region)
      }
    },

    async handleQuery(params) {
      this.tableLoading = true
      let param = params?params:this.queryParams
      let res = await historySendPage(param)
      this.tableLoading = false
      if(res.code==200){
        this.tableData = res.rows
      }
      this.tableDataTotal = res.total
    }
  }
}
</script>
<style lang="scss" scoped>
.detail-container{
  background: #ffffff;
  border-radius: 4px;
  padding: 16px;
}
</style>
