<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-else>-</span>
      </template>
      <!-- 项目承接单位 -->
      <template slot="contractOrgName" slot-scope="scope">
        <span v-if="scope.row.contractOrgName" style="color: #0081FF;cursor: pointer;"
          @click="viewEnterprise(scope.row)">{{scope.row.contractOrgName}}</span>
        <span v-else>-</span>
      </template>
      <!-- 咨询机构名称 -->
      <template slot="advisoryBodyName" slot-scope="scope">
        <span v-if="scope.row.advisoryBodyName" style="color: #0081FF;cursor: pointer;"
          @click="viewEnterprise(scope.row)">{{scope.row.advisoryBodyName}}</span>
        <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, exportRecordOfCooperationExcelApi } from "@/api/internalCooperation";
import { getAllAreaApi } from "@/api/common";
import { getTreeSelectAreaList } from "@/utils";
export default {
  name: "consultingAgencyCooperation",
  mixins: [mixin],
  components: {
    skeleton
  },
  props: ['companyId'],
  data() {
    return {
      queryParams: {
        advisoryBodyCid: this.companyId,
        pageNum: 1,
        pageSize: 10,
      },
      forData: [
        { label: '项目列表', prop: 'projectName', width: '222', slot: true, showOverflowTooltip: true },
        { label: '项目编码', prop: 'projectCode', width: '123' },
        { label: '省市', prop: 'provinceName', minWidth: '110', slot: true },
        { label: '项目承接类型', prop: 'isinvestproject', width: '102', showOverflowTooltip: true },
        { label: '工程基础大类', prop: 'projectType1', width: '98', showOverflowTooltip: true },
        { label: '工程类别明细', prop: 'projectType', width: '98', showOverflowTooltip: true },
        { label: '项目负责人姓名', prop: 'projectLeader', width: '110' },
        { label: '项目负责人专业', prop: 'projectLeaderMajor', width: "110" },
        { label: '项目负责人联系电话', prop: 'projectLeaderPhone', width: "135" },
        { label: '合同金额（元）', prop: 'contractOrigValue', width: "110", 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: 'businessTypes', value: '', placeholder: '项目省市', uid: this.getUid(), options: [], props: {
            multiple: true,
            value: "value",
            label: "value",
            // checkStrictly: true
          }
        },
        { type: 4, fieldName: 'causeAction', value: '', placeholder: '项目承接类型', options: [], uid: this.getUid() },
        { type: 4, fieldName: 'causeAction', 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();
      } 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 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 {
        const areaSearchList = this.$refs["searchFormNew"].$refs["cascader"][0].getCheckedNodes();
        if (areaSearchList?.length) {
          const valueList = areaSearchList.map(item => item.value);
          const result = getTreeSelectAreaList(valueList, this.areaList, "value");
          console.log(result);
        }
      } catch (error) {

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

      }
    },
    // 跳转项目详情
    viewProjectDetail(row) {

    },
    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>
