<template>
  <div class="cooperation-record">
    <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>
    </tables>

    <el-dialog :title="dialogTitle" :visible.sync="cooperationRecordDialog" width="1100px" @close="dialogClose"
      class="cooperation-record-dialog-container" custom-class="cooperation-record-dialog" :destroy-on-close="true">
      <div class="cooperation-record-dialog-innner">
        <dialog-head-form-new title="" :form-data="dialogFormData" :query-params="dialogQueryParams" :total="dialogtableDataTotal" :isExcel="false"
          @handle-search="dialogHandleSearch" ref="dialogSearchFormNew" />

        <skeleton v-if="dialogIsSkeleton" style="padding: 16px"></skeleton>

        <!-- 列表 -->
        <dialog-tables v-if="!dialogIsSkeleton" :indexFixed="true" :tableData="dialogTableData" :forData="forData"
          :tableDataTotal="dialogtableDataTotal" :queryParams="dialogQueryParams" @handle-current-change="dialogCurrentChange">

        </dialog-tables>

      </div>
    </el-dialog>
  </div>
</template>
<script>
import skeleton from '../component/skeleton';
import mixin from '@/views/detail/party-a/mixins/mixin';
import { getSupplierCooperationRecordListApi } from "@/api/internalCooperation";
import { getAllAreaApi } from "@/api/common";
import { getTreeSelectAreaList } from "@/utils";
import DialogHeadFormNew from "../component/HeadFormNew";
import DialogTables from "../component/Tables";
export default {
  name: "cooperationRecord",
  mixins: [mixin],
  components: {
    skeleton,
    DialogHeadFormNew,
    DialogTables
  },
  props: ['companyId'],
  data() {
    return {
      queryParams: {
        customerId: this.companyId,
        pageNum: 1,
        pageSize: 10,
      },
      forData: [
        { label: '工程名称', prop: 'projectName', width: '244', slot: true, showOverflowTooltip: true },
        { label: '合作区域', prop: 'areaName', width: '102' },
        { label: '省份', prop: 'provinceName', width: '102' },
        { label: '城市', prop: 'cityName', width: '102' },
        { label: '项目联系人', prop: 'projectManagerName', width: '86' },
        { label: '联系电话', prop: 'projectManagerPhone', width: '102' },
        { label: '资源平台类型', prop: 'projectType2', width: '98' },
        { label: '合同签订日期', prop: 'signDate', width: '149' },
        { label: '合同总价', prop: 'subcontractValue', width: '79' },
        { label: '结算总价', prop: 'settleValue', width: '79' },
        { label: '分包内容', prop: 'jobScope', width: '126' },
        { label: '工程类型', prop: 'projectType2', width: '78' },
        { label: '队伍完工评价', prop: '', minWidth: '98' },
        { label: '合同完工评价', prop: '', minWidth: '98' },
        { label: '评价有效性', prop: '', minWidth: '86' },
        { label: '无效原因', prop: '', minWidth: '74' },
      ],
      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: [],
      // 合作记录弹窗
      cooperationRecordDialog: false,
      dialogTitle: "",
      dialogQueryParams: {

      },
      dialogFormData: [
        { type: 4, fieldName: 'causeAction', value: '', placeholder: '合作项目类型', options: [], uid: this.getUid() },
        { type: 6, 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() },
      ],
      dialogIsSkeleton: true,
      dialogtableDataTotal: 0,
      dialogTableData: [],
    };
  },
  //可访问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 getSupplierCooperationRecordListApi(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) {

      }
    },
    handleExcel() {

    },
    dialogClose() {

    },
    dialogHandleSearch() {

    },
    dialogCurrentChange() {
      
    }
  },
}
</script>
<style lang="scss" scoped>
.cooperation-record {
  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";

  ::v-deep .cooperation-record-dialog-container {
    .cooperation-record-dialog {
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
      border-radius: 4px;
      margin: 0px !important;

      .el-dialog__header {
        padding: 20px;
        height: 56px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        box-sizing: border-box;
        border-bottom: 1px solid #eeeeee;

        .el-dialog__title {
          color: #232323;
          font-weight: bold;
          line-height: 16px;
        }

        .el-dialog__headerbtn {
          position: static;
          width: 16px;
          height: 16px;
        }
      }

      .el-dialog__body {
        padding: 24px 20px;
        box-sizing: border-box;

        .cooperation-record-dialog-innner {
          width: 100%;
          height: 100%;
        }
      }
    }
  }
}
</style>
