<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";
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>
