<template>
  <div class="consulting-agency-cooperation">
    <head-form-new title="咨询机构合作" :form-data="formData" :query-params="queryParams" :total="tableDataTotal" :isExcel="true"
      @handle-search="handleSearch" ref="searchFormNew" @handle-excel="handleExcel" />
    <skeleton v-if="isSkeleton" style="padding: 16px"></skeleton>
    <!-- table 列表 -->
    <div class="table-item" v-if="!isSkeleton">
      <el-table
        ref="tableRef"
        :data="tableData"
        highlight-current-row
        style="margin-top: 16px;"
      >
        <el-table-column label="序号" width="60" align="left">
          <template slot-scope="scope">{{ queryParams.pageNum * queryParams.pageSize - queryParams.pageSize + scope.$index + 1 }}</template>
        </el-table-column>
        <el-table-column label="工程名称" min-width="200" prop="projectName">
          <template slot-scope="scope">
            <div v-if="scope.row.projectName" class="no-line-feed" v-html="scope.row.projectName" @click="viewProjectDetail(scope.row)">{{scope.row.projectName}}</div>
            <span v-else>-</span>
          </template>
        </el-table-column>
        <el-table-column label="发包人名称" min-width="170" prop="ownerName">
          <template slot-scope="scope">
            <!--<span v-if="scope.row.ownerUnitCid" class="no-line-feed" @click="viewOwnerUnit(scope.row)">{{scope.row.ownerName}}</span>-->
            <span v-if="scope.row.ownerName" class="no-line-feed" @click="viewOwnerUnit(scope.row)">{{scope.row.ownerName}}</span>
            <span v-else>-</span>
          </template>
        </el-table-column>
        <el-table-column label="对接人员">
          <el-table-column label="项目经理及联系方式" min-width="150" prop="projectManagerAndPhone">
            <template slot-scope="scope">
              <span v-if="scope.row.projectManagerAndPhone">{{scope.row.projectManagerAndPhone}}</span>
              <span v-else>-</span>
            </template>
          </el-table-column>
          <el-table-column label="商务经理联及系方式" min-width="150" prop="businessManagerAndPhone">
            <template slot-scope="scope">
              <span v-if="scope.row.businessManagerAndPhone">{{scope.row.businessManagerAndPhone}}</span>
              <span v-else>-</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="咨询机构信息">
          <el-table-column label="招标代理机构名称" min-width="150" prop="bidAgencyUnit">
            <template slot-scope="scope">
              <span v-if="scope.row.bidAgencyUnit">{{scope.row.bidAgencyUnit}}</span>
              <span v-else>-</span>
            </template>
          </el-table-column>
          <el-table-column label="造价咨询单位（项目状态目前无法明确的，可不填写）" min-width="150">
            <el-table-column label="一审单位" min-width="100" prop="firstAuditUnit">
              <template slot-scope="scope">
                <span v-if="scope.row.firstAuditUnit">{{scope.row.firstAuditUnit}}</span>
                <span v-else>-</span>
              </template>
            </el-table-column>
            <el-table-column label="二审单位" min-width="100" prop="secondAuditUnit">
              <template slot-scope="scope">
                <span v-if="scope.row.secondAuditUnit">{{scope.row.secondAuditUnit}}</span>
                <span v-else>-</span>
              </template>
            </el-table-column>
            <el-table-column label="三审单位" min-width="100" prop="thirdAuditUnit">
              <template slot-scope="scope">
                <span v-if="scope.row.thirdAuditUnit">{{scope.row.thirdAuditUnit}}</span>
                <span v-else>-</span>
              </template>
            </el-table-column>
          </el-table-column>
        </el-table-column>
      </el-table>
      <div class="pagination-box" v-if="tableDataTotal>queryParams.pageSize">
        <el-pagination background :current-page="queryParams.pageNum" :page-size="queryParams.pageSize" :total="tableDataTotal" layout="prev, pager, next, jumper" @current-change="handleCurrentChange"/>
      </div>
    </div>
    <!--<tables v-if="!isSkeleton" :indexFixed="true" :tableData="tableData" :forData="forData" :tableDataTotal="tableDataTotal"-->
      <!--:queryParams="queryParams" @handle-current-change="handleCurrentChange">-->
      <!--&lt;!&ndash; 项目列表 &ndash;&gt;-->
      <!--<template slot="projectName" slot-scope="scope">-->
        <!--<span v-if="scope.row.projectName" style="color: #0081FF;cursor: pointer;"-->
          <!--@click="viewProjectDetail(scope.row)">{{scope.row.projectName}}</span>-->
        <!--<span v-else>-</span>-->
      <!--</template>-->
      <!--&lt;!&ndash; 省市区 &ndash;&gt;-->
      <!--<template slot="provinceName" slot-scope="scope">-->
        <!--<span>{{`${scope.row.provinceName}${scope.row.provinceName || scope.row.cityName ? " - " : ""}${scope.row.cityName}`}}</span>-->
      <!--</template>-->
      <!--&lt;!&ndash; 业主单位 &ndash;&gt;-->
      <!--<template slot="ownerName" slot-scope="scope">-->
        <!--&lt;!&ndash;<span v-if="scope.row.ownerName" style="color: #0081FF;cursor: pointer;" @click="viewEnterprise(scope.row)">{{scope.row.ownerName}}</span>&ndash;&gt;-->
        <!--&lt;!&ndash;<span v-if="scope.row.ownerName" @click="viewEnterprise(scope.row)">{{scope.row.ownerName}}</span>&ndash;&gt;-->
        <!--<router-link :to="`/enterprise/${encodeStr(scope.row.ownerCid)}}`" tag="a" class="a-link" v-if="scope.row.ownerCid" v-html="scope.row.ownerName"></router-link>-->
        <!--<span v-else>-</span>-->
      <!--</template>-->
      <!--&lt;!&ndash; 项目承接单位 &ndash;&gt;-->
      <!--<template slot="contractOrgName" slot-scope="scope">-->
        <!--&lt;!&ndash;<span v-if="scope.row.contractOrgName" @click="viewEnterprise(scope.row)">{{scope.row.contractOrgName}}</span>&ndash;&gt;-->
        <!--<router-link :to="`/enterprise/${encodeStr(scope.row.contractOrgCid)}}`" tag="a" class="a-link" v-if="scope.row.contractOrgCid" v-html="scope.row.contractOrgName"></router-link>-->
        <!--<span v-else>-</span>-->
      <!--</template>-->
      <!--&lt;!&ndash; 咨询机构名称 &ndash;&gt;-->
      <!--<template slot="advisoryBodyName" slot-scope="scope">-->
        <!--<router-link :to="`/enterprise/${encodeStr(scope.row.advisoryBodyCid)}}`" tag="a" class="a-link" v-if="scope.row.advisoryBodyCid" v-html="scope.row.advisoryBodyName"></router-link>-->
        <!--<span v-else>-</span>-->
      <!--</template>-->
    <!--</tables>-->
  </div>
</template>
<script>
import skeleton from '../component/skeleton';
import mixin from '@/views/detail/party-a/mixins/mixin';
import { getConsultingAgencyCooperationListApi, getConsultingAgencyCooperationTypesApi, exportRecordOfCooperationExcelApi } from "@/api/internalCooperation";
import { getAllAreaApi } from "@/api/common";
import { getTreeSelectAreaList } from "@/utils";
import { encodeStr } from "@/assets/js/common";
import { getProjectUndertakingTypesApi } from "@/api/consultingOrgManagement";
export default {
  name: "consultingAgencyCooperation",
  mixins: [mixin],
  components: {
    skeleton
  },
  props: ['companyId'],
  data() {
    return {
      encodeStr,
      queryParams: {
        advisoryBodyCid: this.companyId,
        pageNum: 1,
        pageSize: 10,
      },
      forData: [
        { label: '项目列表', prop: 'projectName', width: '222', slot: true, showOverflowTooltip: true },
        { label: '项目编码', prop: 'projectCode', width: '140' },
        { label: '省市', prop: 'provinceName', minWidth: '140', slot: true },
        { label: '项目承接类型', prop: 'isinvestproject', width: '120', showOverflowTooltip: true },
        { label: '工程基础大类', prop: 'projectType1', width: '120', showOverflowTooltip: true },
        { label: '工程类别明细', prop: 'projectType2', width: '120', showOverflowTooltip: true },
        { label: '项目负责人姓名', prop: 'projectLeader', width: '120' },
        { label: '项目负责人专业', prop: 'projectLeaderMajor', width: "120" },
        { label: '项目负责人联系电话', prop: 'projectLeaderPhone', width: "160" },
        { label: '合同金额（元）', prop: 'contractOrigValue', width: "160", align: "right" },
        { label: '业主单位', prop: 'ownerName', slot: true, width: "185", showOverflowTooltip: true },
        { label: '项目承接单位', prop: 'contractOrgName', width: "196", slot: true },
        { label: '咨询机构名称', prop: 'advisoryBodyName', width: "172", slot: true },
        { label: '创建时间', prop: 'loadTime', width: "172" },
      ],
      formData: [
        // {
        //   type: 7, fieldName: 'projectProvince', value: '', placeholder: '项目省市', uid: this.getUid(), options: [], props: {
        //     multiple: true,
        //     value: "value",
        //     label: "value",
        //     // checkStrictly: true
        //   }
        // },
        // { type: 1, fieldName: 'isinvestproject', value: '', placeholder: '项目承接类型', options: [], uid: this.getUid() },
        // { type: 1, fieldName: 'projectType2', value: '', placeholder: '工程类别明细', options: [], uid: this.getUid() },
        { type: 3, fieldName: 'projectName', value: '', placeholder: '请输入', uid: this.getUid() },
      ],
      //列表
      tableLoading: false,
      tableData: [],
      tableDataTotal: 0,
      isSkeleton: true,
      areaList: [],
      engineeringCategoryDetailOptions: [
        {
          value: "住宅",
          label: "住宅"
        },
        {
          value: "房建其他",
          label: "房建其他"
        },
        {
          value: "装饰",
          label: "装饰"
        },
        {
          value: "专业其他",
          label: "专业其他"
        },
        {
          value: "市政工程",
          label: "市政工程"
        },
        {
          value: "教育",
          label: "教育"
        },
        {
          value: "安装",
          label: "安装"
        },
        {
          value: "工业厂房",
          label: "工业厂房"
        },
        {
          value: "商业综合",
          label: "商业综合"
        }
      ]
    };
  },
  //可访问data属性
  created() {
    this.initDetail();
    // this.formData[2].options=this.engineeringCategoryDetailOptions
  },
  //计算集
  computed: {

  },
  //方法集
  methods: {
    async initDetail() {
      try {
        this.getProjectUndertakingTypes()
        await this.handleQuery();
        await this.getAllArea();
        await this.getConsultingAgencyCooperationTypes();
      } catch (error) {

      }
    },
    async getProjectUndertakingTypes() {
      try {
        const result = await getProjectUndertakingTypesApi();
        if (result.code == 200 && result?.data?.length) {
          // this.formData[1].options = result.data.map(item => ({ value: item, label: item }));
        }
      } catch (error) {

      }
    },
    async getAllArea() {
      try {
        const area = await getAllAreaApi();
        if (area.code == 200) {
          this.areaList = area.data;
          // this.$set(this.formData[0], "options", this.areaList);
          console.log();
        }
      } catch (error) {

      }
    },
    async getConsultingAgencyCooperationTypes(projectTypeId) {
      try {
        const params = {};
        if (projectTypeId) params["projectTypeId"] = projectTypeId;
        const types = await getConsultingAgencyCooperationTypesApi(params);
        // if (types.code == 200 && types.data instanceof Array) {
        //   const _temp = types.data.map(item => {
        //     item.name = item.projectTypeName;
        //     item.value = item.projectTypeId;
        //     return item;
        //   });
        //   this.$set(this.formData[1], "options", _temp);
        // }
      } catch (error) {

      }
    },
    async handleQuery(params) {
      try {
        let data = params ? params : this.queryParams;
        this.isSkeleton = true;
        const res = await getConsultingAgencyCooperationListApi(data);
        this.tableData = res.rows ? res.rows : [];
        this.tableDataTotal = res.total ? res.total : 0;
      } catch (error) {
        console.log(error);
      } finally {
        this.isSkeleton = false;
      }
    },
    async handleSearch() {
      try {
        let params = this.formParams();
        const areaSearchList = this.$refs["searchFormNew"].$refs["cascader"][0].getCheckedNodes();
        let province=[]
        let city=[]
        // if(params.projectProvince){
        //   for (let i=0; i<params.projectProvince.length; i++){
        //     province.push(params.projectProvince[i][1])
        //     city.push(params.projectProvince[i][2])
        //   }
        // }
        // province=province.filter((item, index, self) => self.indexOf(item) === index);
        // if(province){
        //   params.province=province
        // }
        // if(city){
        //   params.city=city
        // }
        // delete params.projectProvince
        this.handleQuery(params)

      } catch (error) {

      }
    },
    // 导出excel
    async handleExcel() {
      try {
        const result = await exportRecordOfCooperationExcelApi(this.queryParams);
        this.$download.saveAs(result);
      } catch (error) {

      }
    },
    // 跳转项目详情
    viewProjectDetail(row) {
      this.$tab.openPage(row.projectName, `/consultingOrgManagement/projectDetail?advisoryBodyCid=${row.advisoryBody?.advisoryBodyCid ? row.advisoryBody?.advisoryBodyCid : ""}&projectKey=${row.projectKey}`);
    },
    viewEnterprise(row) {

    }
  }
}
</script>
<style lang="scss" scoped>
.consulting-agency-cooperation {
  background: #ffffff;
  border-radius: 4px;
  padding: 16px;
  input {
    border: 1px solid #efefef;
  }
  ::v-deep .el-form-item {
    margin-right: 8px !important;
  }

  .query-box {
    margin: 10px 0 20px;
  }
  .cell-span {
    display: inline-block;
    position: relative;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 4;
    cursor: pointer;

    > span {
      display: inline-block;
      width: 37px;
      position: absolute;
      right: 0;
      bottom: 0;
      background-color: #fff;
      z-index: 1;
    }
  }
  @import "@/assets/styles/search-common.scss";
}
</style>
