<template>
  <div class="client-details">
    <el-dialog
      :visible.sync="drawer"
      size="80%"
      :title="title"
      custom-class="client-dialog"
      :with-header="false"
      @closed="cancel">
      <head-detail-form
        :form-data="formData"
        :query-params="queryParams"
        :total="tableDataTotal"
        :amountTotal="amountTotal"
        @handle-search="handleSearch"
      />
      <tables
        :indexFixed="true"
        :tableLoading="tableLoading"
        :tableData="tableData"
        :forData="forData"
        :tableDataTotal="tableDataTotal"
        :queryParams="queryParams"
        @handle-current-change="handleCurrentChange"
      >
        <template slot="sourceType" slot-scope="scope">
          <div class="flex-box">
            <div class="a-link" @click="linkTo(scope)" v-if="scope.row.sourceId&&scope.row.sourceType=='中标业绩'" v-html="scope.row.sourceType" style="cursor: pointer"></div>
            <span v-else v-html="scope.row.sourceType || '--'"></span>
          </div>
        </template>
      </tables>
    </el-dialog>
  </div>
</template>

<script>
import mixin from '../../mixins/mixin'
import {clientProjectPage} from '@/api/detail/party-a/dealings'
import HeadDetailForm from "../../component/HeadDetailForm"

export default {
  props: [
    'data',
    'company-id',
    'title'
  ],
  components: {
    HeadDetailForm
  },
  mixins: [mixin],
  data() {
    return {
      drawer: false,
      queryParams: {
        cid: this.companyId,
        companyId: this.data.companyId,
        pageNum: 1,
        pageSize: 20
      },
      formData: [
        { type: 6, fieldName: 'money', value: '', placeholder: '合同金额', startMoney: 'amountMin', endMoney: 'amountMax' },
        { type: 3, fieldName: 'keys', value: '', placeholder: '输入项目/工程名称查询', options: []},
      ],
      forData: [
        {label: '项目名称', prop: 'projectName', fixed: true},
        {label: '公布时间', prop: 'time', width: '100'},
        {label: '本次合同金额（万元）', prop: 'amount', width: '160'},
        {label: '项目类型', prop: 'projectTtype', width: '130'},
        {label: '数据来源', prop: 'sourceType', width: '90', slot: true}
      ],
      //列表
      tableLoading:false,
      tableData:[],
      tableDataTotal:0,
      amountTotal: 0
    }
  },
  created() {
    this.drawer = true
    this.handleQuery()
  },
  methods: {
    async handleQuery(params) {
      this.tableLoading = true
      let param = params?params:this.queryParams
      let res = await clientProjectPage(param)
      this.tableLoading = false
      if(res.code==200){
        this.tableData = res.rows
      }
      this.tableDataTotal = res.total
      this.amountTotal = res.totalAmount
    },
    handlePic(url, isPic){
      isPic ? url = 'https://imgs.jiansheku.com/'+url : ''
      if(url){
        window.open(url, "_blank")
      }
    },
    linkTo(scope){
      this.drawer = false
      this.$router.push(`/biddetail/${scope.row.sourceId}`)
    },
    cancel() {
      this.$emit('cancel')
    }
  }
}
</script>

<style lang="scss" scoped>
  .client-details {
    ::v-deep .client-dialog{
      width: 80%;
      min-width: 900px;
      background: #FFFFFF;
      .el-dialog__body{
        padding-top: 0;
      }
      .fixed-table{
        .el-table__header-wrapper,.el-table__fixed-header-wrapper{
          top: 0;
        }
      } 
      .el-dialog__header{
        border-bottom: 1px solid #E1E1E1;
      }
      .el-dialog__title{
        font-size: 16px;
        color: #232323;
        font-weight: bold;
        margin-right: 4px;
      }
    }
    .tip-img{
      width: 14px;
      height: 14px;
      margin-right: 4px;
      cursor: pointer;
    }
  }
</style>
