<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>
    <tables v-if="!isSkeleton" :indexFixed="true" :tableData="tableData" :forData="forData" :tableDataTotal="tableDataTotal"
      :queryParams="queryParams" @handle-current-change="handleCurrentChange">
      <!-- 项目列表 -->
      <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>
      <!-- 省市区 -->
      <template slot="provinceName" slot-scope="scope">
        <span>{{`${scope.row.provinceName}${scope.row.provinceName || scope.row.cityName ? " - " : ""}${scope.row.cityName}`}}</span>
      </template>
      <!-- 业主单位 -->
      <template slot="ownerName" slot-scope="scope">
        <!--<span v-if="scope.row.ownerName" style="color: #0081FF;cursor: pointer;" @click="viewEnterprise(scope.row)">{{scope.row.ownerName}}</span>-->
        <!--<span v-if="scope.row.ownerName" @click="viewEnterprise(scope.row)">{{scope.row.ownerName}}</span>-->
        <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>
      <!-- 项目承接单位 -->
      <template slot="contractOrgName" slot-scope="scope">
        <!--<span v-if="scope.row.contractOrgName" @click="viewEnterprise(scope.row)">{{scope.row.contractOrgName}}</span>-->
        <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>
      <!-- 咨询机构名称 -->
      <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";
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: 'projectType', 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: 4, fieldName: 'projectUndertakingType', value: '', placeholder: '项目承接类型', options: [], uid: this.getUid() },
        { type: 4, fieldName: 'detailOfWorksCategory', value: '', placeholder: '工程类别明细', options: [], uid: this.getUid() },
        { type: 3, fieldName: 'advisoryBodyName', value: '', placeholder: '请输入', uid: this.getUid() },
      ],
      //列表
      tableLoading: false,
      tableData: [],
      tableDataTotal: 0,
      isSkeleton: true,
      areaList: []
    };
  },
  //可访问data属性
  created() {
    this.initDetail();
  },
  //计算集
  computed: {

  },
  //方法集
  methods: {
    async initDetail() {
      try {
        await this.handleQuery();
        await this.getAllArea();
        await this.getConsultingAgencyCooperationTypes();
      } 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(params) {
      try {
        console.log(params);
        const areaSearchList = this.$refs["searchFormNew"].$refs["cascader"][0].getCheckedNodes();
        console.log(areaSearchList);
      } 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>
