<template>
  <div class="detail-container beacon-pro">
    <head-form-new title="标讯Pro" :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" :tableLoading="tableLoading" :tableData="tableData" :forData="forData" :tableDataTotal="tableDataTotal"
      :queryParams="queryParams" @handle-current-change="handleCurrentChange">
      <template slot="projectName" slot-scope="scope">
        <router-link :to="`/radar/bxprozbgg/details/${scope.row.id}`" tag="a" class="a-link" v-if="scope.row.id&&scope.row.projectName "
          v-html="scope.row.projectName"></router-link>
        <div v-else v-html="scope.row.projectName  || '--'"></div>
      </template>
      <template slot="tenderee" slot-scope="scope">
        <router-link :to="scope.row.uipId?`/enterprise/${encodeStr(scope.row.tendereeId)}`:`/company/${encodeStr(scope.row.tendereeId)}`" tag="a"
          class="a-link" v-if="scope.row.tendereeId&&scope.row.tenderee " v-html="scope.row.tenderee"></router-link>
        <div v-else v-html="scope.row.tenderee  || '--'"></div>
      </template>
      <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="province" slot-scope="scope">
        {{scope.row.province}}{{`${scope.row.city?'-'+scope.row.city:''}`}}{{`${scope.row.area?'-'+scope.row.area:''}`}}
      </template>
    </tables>

  </div>
</template>

<script>
import mixin from '../mixins/mixin';
import skeleton from '@/views/project/projectList/component/skeleton';
import { bidNoticeProProjectType, bidNoticeProProjectPurposes, bidNoticeProAssessmentWay, bidNoticeProPage } from '@/api/detail/party-a/opport';
export default {
  name: 'Tencent',
  props: ['companyId'],
  mixins: [mixin],
  components: {
    skeleton
  },
  data() {
    return {
      queryParams: {
        cid: this.companyId,
        pageNum: 1,
        pageSize: 20
      },
      forData: [
        { label: '项目名称', prop: 'projectName', minWidth: '320', slot: true },
        { label: '发布日期', prop: 'pubdate', width: '110' },
        {
          label: '金额（万元）', prop: '', children: [
            { label: '建安费暂估', prop: 'projectSafeAmount', width: '98px' },
            { label: '勘察费暂估', prop: 'projectSurveyAmount', width: '98px' },
            { label: '保证金', prop: 'projectEnsureAmount', width: '98px' }
          ]
        },
        {
          label: '招标人及联系方式', prop: '', children: [
            { label: '招标人', prop: 'tenderee', width: '98px', slot: true },
            { label: '联系人', prop: 'tendereeTel', width: '98px' }
          ]
        },
        {
          label: '代理机构及联系方式', prop: '', children: [
            { label: '代理机构', prop: 'agency', width: '88px', slot: true },
            { label: '联系人', prop: 'agencyTel', width: '88px' }
          ]
        },
        { label: '项目分类', prop: 'projectType', width: '130' },
        { label: '工程类别', prop: 'projectPurposes', width: '130' },
        { label: '分部分项', prop: 'projectSub', width: '130' },
        { label: '项目级别', prop: 'projectLevel', width: '130' },
        { label: '评标办法', prop: 'bidAssessmentWay', width: '130' },
        { label: '项目属地', prop: 'province', width: '130', slot: true }
      ],
      formData: [
        { type: 1, fieldName: 'projectType', value: '', placeholder: '项目类别', options: [], uid: this.getUid() },
        { type: 1, fieldName: 'projectPurposes', value: '', placeholder: '工程类别', options: [], uid: this.getUid() },
        { type: 1, fieldName: 'bidAssessmentWay', value: '', placeholder: '评标办法', options: [], uid: this.getUid() },
        { type: 3, fieldName: 'keys', value: '', placeholder: '输入关键词查询', options: [], uid: this.getUid() }
      ],
      //列表
      tableLoading: false,
      tableData: [],
      tableDataTotal: 0,
      isSkeleton: true,
    };
  },
  computed: {
  },
  created() {
    this.handleOption();
    this.handleQuery();
  },
  methods: {
    async handleOption() {
      let [projectType, projectPurposes, proAssessmentWay] = await Promise.all([
        bidNoticeProProjectType({ cid: this.companyId }),
        bidNoticeProProjectPurposes({ cid: this.companyId }),
        bidNoticeProAssessmentWay({ cid: this.companyId })
      ]);
      if (projectType.code == 200) {
        let type = projectType.data.map(item => {
          let it = { name: item.projectType + '(' + item.count + ')', value: item.projectType };
          return it;
        });
        this.setFormData('projectType', type);
      }
      if (projectPurposes.code == 200) {
        let purposes = projectPurposes.data.map(item => {
          let it = { name: item.projectPurposes + '(' + item.count + ')', value: item.projectPurposes };
          return it;
        });
        this.setFormData('projectPurposes', purposes);
      }
      if (proAssessmentWay.code == 200) {
        let way = proAssessmentWay.data.map(item => {
          let it = { name: item.bidAssessmentWay + '(' + item.count + ')', value: item.bidAssessmentWay };
          return it;
        });
        this.setFormData('bidAssessmentWay', way);
      }
    },
    async handleQuery(params) {
      this.tableLoading = true;
      let param = params ? params : this.queryParams;
      let res = await bidNoticeProPage(param);
      this.tableLoading = false;
      if (res.code == 200) {
        this.isSkeleton = false;
        this.tableData = res.rows;
        if (this.tableData && this.tableData.length > 0) {
          this.tableData.forEach(item => {
            item.projectSafeAmount ? item.projectSafeAmount = parseFloat(parseFloat(item.projectSafeAmount).toFixed(4)) : '';
            item.projectSurveyAmount ? item.projectSurveyAmount = parseFloat(parseFloat(item.projectSurveyAmount).toFixed(4)) : '';
            item.projectEnsureAmount ? item.projectEnsureAmount = parseFloat(parseFloat(item.projectEnsureAmount).toFixed(4)) : '';
          });
        }
      }
      this.tableDataTotal = res.total;
    }
  }
}
</script>
<style lang="scss" scoped>
.detail-container {
  background: #ffffff;
  border-radius: 4px;
  padding: 16px;
}

.beacon-pro {
  @import "@/assets/styles/search-common.scss";
}
</style>
