<template>
  <div class="app-container part-container details-of-party">
    <div style="height: 100%;" v-if="!isCompany">
      <skeleton style="padding-top: 16px"></skeleton>
    </div>
    <Header :company-id="companyId" :companyInfo="companyInfo" :cooDetail="cooDetail" v-if="companyId" @close-detail="closeDetail" />
    <div class="part-main">
      <div class="part-left">
        <side-bar :statisticObj="statisticObj" ref="sidebar" @currentPath="showPartPage" :pathName="currentPath.pathName"
          :partBoxHeight="partBoxHeight" :customerId="customerId" :isCompany="isCompany" :isCustomer="isCustomer" />
      </div>
      <div class="part-right">
        <div id="partBox" v-if="companyId" class="part-common-container-style">
          <template v-if="isCompany">
            <!-- 企业概览 -->
            <Overview v-if="currentPath.pathName=='overview'" :company-id="companyId" :isSkeleton="isSkeleton" :companyInfo="companyInfo" />
            <Qualification v-if="currentPath.pathName=='qualification'" :company-id="companyId" />
            <Businfo v-if="currentPath.pathName=='businfo'" :company-id="companyId" />
            <Holderinfo v-if="currentPath.pathName=='holderinfo'" :company-id="companyId" />
            <Execuinfo v-if="currentPath.pathName=='execuinfo'" :company-id="companyId" />
            <Overseas v-if="currentPath.pathName=='overseas'" :company-id="companyId" />
            <Branch v-if="currentPath.pathName=='branch'" :company-id="companyId" />
            <Financial v-if="currentPath.pathName=='financial'" :company-id="companyId" />
            <!-- 项目商机 -->
            <major-project v-if="currentPath.pathName=='majorProject'" :company-id="companyId"></major-project>
            <Landtransaction v-if="currentPath.pathName=='landtransaction'" :company-id="companyId" />
            <Proposed v-if="currentPath.pathName=='proposed'" :company-id="companyId" />
            <Bond v-if="currentPath.pathName=='bond'" :company-id="companyId" />
            <Biddingplan v-if="currentPath.pathName=='biddingplan'" :company-id="companyId" />
            <Announcement v-if="currentPath.pathName=='announcement'" :company-id="companyId" />
            <Tencent v-if="currentPath.pathName=='tencent'" :company-id="companyId" />
            <Administrative v-if="currentPath.pathName=='administrative'" :company-id="companyId" />
            <!-- 业务往来 -->
            <Custom v-if="currentPath.pathName=='custom'" :company-id="companyId" />
            <Supplier v-if="currentPath.pathName=='supplier'" :company-id="companyId" />
            <Bidagency v-if="currentPath.pathName=='bidagency'" :company-id="companyId" />
            <Hiscontract v-if="currentPath.pathName=='hiscontract'" :company-id="companyId" />
            <Bidrecords v-if="currentPath.pathName=='bidrecords'" :company-id="companyId" />
            <!-- 咨询业务往来 -->
            <!-- 1.常合作业主单位 -->
            <cooperative-owner-units v-if="currentPath.pathName=='cooperativeOwnerUnits'" :company-id="companyId"></cooperative-owner-units>
            <!-- 2、常合作施工单位 -->
            <cooperative-construction-unit v-if="currentPath.pathName=='cooperativeConstructionUnit'"
              :company-id="companyId"></cooperative-construction-unit>
            <!-- 3、常合作集团 -->
            <cooperative-group v-if="currentPath.pathName=='cooperativeGroup'" :company-id="companyId"></cooperative-group>
            <!-- 投诚分析 -->
            <RegionalEconomies v-if="currentPath.pathName=='regionalEconomies'" :company-id="companyId" :companyInfo="companyInfo" />
            <LandAcquisition v-if="currentPath.pathName=='landAcquisition'" :company-id="companyId" />
            <SameRegion v-if="currentPath.pathName=='sameRegion'" :company-id="companyId" :companyInfo="companyInfo" />
            <!-- 风险信息 -->
            <Credit v-if="currentPath.pathName=='credit'" :company-id="companyId" />
            <Punish v-if="currentPath.pathName=='punish'" :company-id="companyId" />
            <BusinessAnomaly v-if="currentPath.pathName=='businessAnomaly'" :company-id="companyId" />
            <IfThePerson v-if="currentPath.pathName=='ifThePerson'" :company-id="companyId" />
            <Dishonesty v-if="currentPath.pathName=='dishonesty'" :company-id="companyId" />
            <!-- 限制高消费 -->
            <limit-high-consumption v-if="currentPath.pathName=='limitHighConsumption'" :company-id="companyId"></limit-high-consumption>
            <!-- 股权冻结 -->
            <equity-freezing v-if="currentPath.pathName=='equityFreezing'" :company-id="companyId"></equity-freezing>
            <!-- <Judgment v-if="currentPath.pathName=='judgment'" :company-id="companyId" />
            <CourtNotice v-if="currentPath.pathName=='courtNotice'" :company-id="companyId" />
            <OpenacourtsessionNotice v-if="currentPath.pathName=='openacourtsessionNotice'" :company-id="companyId" /> -->

            <!-- 内部合作 -->
            <!-- 1、咨询机构合作 -->
            <consulting-agency-cooperation v-if="currentPath.pathName=='consultingAgencyCooperation'"
              :company-id="companyId"></consulting-agency-cooperation>
            <!-- 2、准入情况 -->
            <access-condition v-if="currentPath.pathName=='accessCondition'" :company-id="companyId" :companyInfo="companyInfo"></access-condition>
            <!-- 管理人员信息 -->
            <Managerial v-if="currentPath.pathName=='managerial'" :company-id="companyId" :companyInfo="companyInfo"></Managerial>
            <!-- 设备信息 -->
            <equipment v-if="currentPath.pathName=='equipment'" :company-id="companyId" :companyInfo="companyInfo"></equipment>
            <!-- 工程考察情况记录 -->
            <project-record v-if="currentPath.pathName=='projectRecord'" :company-id="companyId" :companyInfo="companyInfo"></project-record>
            <!-- 3、供应商合作记录 -->
            <cooperation-record v-if="currentPath.pathName=='cooperationRecord'" :company-id="companyId"
              :company-name="companyName" :ctm-id="ctmId"></cooperation-record>
            <!-- 4、施工业绩 -->
            <construction-performance v-if="currentPath.pathName=='constructionPerformance'" :company-id="companyId"></construction-performance>
            <!-- 5、在施工程情况 -->
            <construction-situation v-if="currentPath.pathName=='constructionSituation'" :company-id="companyId"></construction-situation>
            <!-- 生活保障基地 -->
            <living-security v-if="currentPath.pathName=='livingSecurity'" :company-id="companyId"></living-security>
            <!-- 履约评价 -->
            <honour-agreement v-if="currentPath.pathName=='honourAgreement'" :company-id="companyId"></honour-agreement>
            <!-- 信用评价 -->
            <credit-rate v-if="currentPath.pathName=='creditRate'" :company-id="companyId"></credit-rate>
            <!-- 年度考评 -->
            <assessMent class="no-padding" v-if="currentPath.pathName=='assessMent'" :company-id="companyId" :companyInfo="companyInfo"></assessMent>
            <!-- 不良行为列表 -->
            <badlist class="no-padding" v-if="currentPath.pathName=='badlist'" :company-id="companyId" :companyInfo="companyInfo"></badlist>
          </template>
          <template v-if="customerId && isCustomer">
            <!-- 商务信息 -->
            <Business v-if="currentPath.pathName=='business'" :customer-ids="customerId" :companyInfo="companyInfo" :customerInfo="customerInfo" />
            <!-- 招标偏好 -->
            <Preference v-if="currentPath.pathName=='preference'" :customer-ids="customerId" :customerInfo="customerInfo" />
            <!-- 合作情况 -->
            <Cooperate v-if="currentPath.pathName=='cooperate'" :customer-ids="customerId" :companyInfo="companyInfo" :cooDetail="cooDetail"
              :customerInfo="customerInfo" @detail="cooperateDetail" />
            <!-- 决策链条 -->
            <DecisionMaking v-if="currentPath.pathName=='decisionMaking'" :customer-ids="customerId" :companyInfo="companyInfo"
              :customerInfo="customerInfo" />
            <!-- 跟进记录 -->
            <Gjjl v-if="currentPath.pathName=='gjjl'" :isDisabled='false' types="gjdt" :customer-ids="customerId" />
          </template>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { idRemark } from '@/api/common';
import { infoHeader, statistic } from '@/api/detail/party-a/index';
import { customerInfo } from '@/api/detail/party-a/cooperate';
import elementResizeDetectorMaker from "element-resize-detector";
import Header from "./component/Header";
import SideBar from "./component/Sidebar";
import Overview from "./overview/overview";  //企业概览-企业速览
import Qualification from "./qualification/qualification";  //企业概览-资质资格
import Businfo from "./overview/businfo";   //企业概览-工商信息
import Holderinfo from "./overview/holderinfo";   //企业概览-股东信息
import Execuinfo from "./overview/execuinfo";   //企业概览-高管信息
import Overseas from "./overview/overseas";   //企业概览-对外投资
import Branch from "./overview/branch";   //企业概览-分支机构
import Financial from "./financial"; //财务简析
//import Business from "./business" //商务信息
import MajorProject from "./opport/MajorProject.vue"; //项目商机-重点项目
import Landtransaction from "./opport/landtransaction";  //项目商机-土地交易
import Proposed from "./opport/proposed";  //项目商机-拟建项目
import Bond from "./opport/bond";  //项目商机-专项债项目
import Biddingplan from "./opport/biddingplan";  //项目商机-招标计划
import Announcement from "./opport/announcement";  //项目商机-招标公告
import Tencent from "./opport/tencent";  //项目商机-标讯Pro
import Administrative from "./opport/administrative";  //项目商机-行政许可
import Custom from "./dealings/custom";  //业务往来-客户
import Supplier from "./dealings/supplier";  //业务往来-供应商
import Bidagency from "./dealings/bidagency";  //业务往来-招标代理
import Hiscontract from "./dealings/hiscontract";  //业务往来-历史发包
import Bidrecords from "./dealings/bidrecords";  //业务往来-开标记录
import CooperativeOwnerUnits from "@/views/detail/party-a/consultingTransaction/cooperativeOwnerUnits"; //咨询业务往来 常合作业主单位
import CooperativeConstructionUnit from "@/views/detail/party-a/consultingTransaction/cooperativeConstructionUnit"; //咨询业务往来 常合作施工单位
import CooperativeGroup from "@/views/detail/party-a/consultingTransaction/cooperativeGroup"; //咨询业务往来 常合作集团
import LandAcquisition from "./urbanLnvestment/landAcquisition"; //投诚分析-城投拿地
import RegionalEconomies from "./urbanLnvestment/regionalEconomies"; //投诚分析-区域经济
import SameRegion from "./urbanLnvestment/sameRegion"; //投诚分析-同地区城投
import Punish from "./riskInformation/punish"; //风险信息-行政处罚
import Credit from "./credit/credit"; //风险信息-信用中国
import BusinessAnomaly from "./riskInformation/businessAnomaly"; //风险信息-经营异常
import IfThePerson from "./riskInformation/ifThePerson"; //风险信息-被执行人
import Dishonesty from "./riskInformation/dishonesty"; //风险信息-失信被执行
import LimitHighConsumption from "./riskInformation/limitHighConsumption"; //风险信息-限制高消费
import EquityFreezing from "./riskInformation/equityFreezing"; //风险信息-股权冻结
import Judgment from "./riskInformation/judgment"; //风险信息-判决文书
import CourtNotice from "./riskInformation/courtNotice"; //风险信息-法院公告
import OpenacourtsessionNotice from "./riskInformation/openacourtsessionNotice"; //风险信息-开庭公告
import Business from "./business"; //商务信息
import Preference from "./preference"; //招标偏好
import Cooperate from "./cooperate"; //合作情况
import DecisionMaking from "./decisionMaking"; //决策链条
import Gjjl from "../../project/projectList/component/gjjl"; //跟进记录
import ConsultingAgencyCooperation from "@/views/detail/party-a/internalCooperation/consultingAgencyCooperation"; //内部合作 咨询机构合作
import AccessCondition from "@/views/detail/party-a/internalCooperation/accessCondition"; //内部合作 准入情况
import Managerial from "@/views/detail/party-a/internalCooperation/managerial"; //内部合作 管理人员信息
import equipment from "@/views/detail/party-a/internalCooperation/equipment"; //内部合作 设备信息
import projectRecord from "@/views/detail/party-a/internalCooperation/projectRecord"; //内部合作 工程考察情况记录
import badlist from "@/views/detail/party-a/internalCooperation/badlist"; //不良行为列表

import assessMent from "@/views/supplier/supplierlist/assessment"; //年度考评
import CooperationRecord from "@/views/detail/party-a/internalCooperation/cooperationRecord"; //内部合作 供应商合作记录
import ConstructionPerformance from "@/views/detail/party-a/internalCooperation/constructionPerformance"; //内部合作 施工业绩
import ConstructionSituation from "@/views/detail/party-a/internalCooperation/constructionSituation"; //内部合作 在施工程情况
import livingSecurity from "@/views/detail/party-a/internalCooperation/livingSecurity"; //内部合作 生活保障基地

import honourAgreement from "@/views/detail/party-a/ratelist/honourAgreement"; //供应商评价信息 履约评价
import creditRate from "@/views/detail/party-a/ratelist/creditRate"; //供应商评价信息 信用评价

import {
  urbanInvestmentPage,
} from '@/api/detail/party-a/urbanLnvestment';
import skeleton from './component/skeleton';
export default {
  name: 'PartyA',
  components: {
    honourAgreement,
    creditRate,
    livingSecurity,
    equipment,
    projectRecord,
    Header,
    SideBar,
    Overview,
    Qualification,
    Businfo,
    Holderinfo,
    Execuinfo,
    Overseas,
    Branch,
    Financial,
    // Business,
    MajorProject,
    Landtransaction,
    Proposed,
    Bond,
    Biddingplan,
    Announcement,
    Tencent,
    Administrative,
    Custom,
    Supplier,
    Bidagency,
    Hiscontract,
    Bidrecords,
    LandAcquisition,
    RegionalEconomies,
    SameRegion,
    Credit,
    Punish,
    BusinessAnomaly,
    IfThePerson,
    Dishonesty,
    LimitHighConsumption,
    EquityFreezing,
    Judgment,
    CourtNotice,
    OpenacourtsessionNotice,
    Business,
    Preference,
    Cooperate,
    DecisionMaking,
    Gjjl,
    CooperativeOwnerUnits,
    ConsultingAgencyCooperation,
    AccessCondition,
    assessMent,
    badlist,
    CooperationRecord,
    CooperativeConstructionUnit,
    CooperativeGroup,
    ConstructionPerformance,
    ConstructionSituation,
    Managerial,
    skeleton
  },
  data() {
    return {
      isSkeleton: true,
      isSkeleton1: true,
      companyInfo: {},
      customerInfo: {},
      // 企业名称
      companyName: "",
      companyId: '',  //企业Id（测试默认3068）
      // 供应商Id
      ctmId: "",
      customerId: '',  //企业Id（测试默认'a00d582a6041f32c16aac804e4924736'）
      isCompany: false,  //判断是否有建设库数据
      isCustomer: false,  //判断是否展示修改客户信息
      currentPath: {
        pathName: ''  //默认展示页
      },
      statisticObj: {
        basic: {},
        behavior: {},
        business: {},
        combineMember: {},
        credit: {},
        evaluation: {},
        global: {},
        performance: {},
        personnel: {},
        qualification: {}
      },
      partBoxHeight: null,
      cooDetail: false,
    };
  },
  computed: {
    routes() {
      return this.$store.state.permission.routes;
    }
  },
  watch: {
    '$route'(to, from) {
      // 该项目 不要传递 customerId 传递ctmId 该逻辑只是复制央企项目过来 没有实际意义
      if (to.name == 'PartyA' && to.query.customerId) {
        if (to.query.customerId && to.query.path == 'business' || to.query.path == 'gjjl') {
          if (this.companyId == 0) {
            customerInfo(to.query.customerId).then(res => {
              if (res.code == 200) {
                if (res.data.userId == this.$store.state.user.userId) {
                  this.$nextTick(() => {
                    this.customerInfo = res.data;
                    this.customerId = res.data.customerId;
                    this.isCustomer = true;
                    this.isCompany = false;
                    this.currentPath.pathName = this.$route.query.path || 'business';
                    this.companyInfo = {
                      companyName: this.customerInfo.companyName
                    };
                    document.getElementById('tagTitle').innerText = this.customerInfo.companyName;
                    let titlename = document.getElementById('tagTitles');
                    if (titlename) {
                      titlename.innerText = this.customerInfo.companyName;
                    }
                  });
                }
              }
            });
          }
          if (to.query.customerId == this.customerId && to.query.path) {
            this.currentPath.pathName = to.query.path;
          }
        }
      } else {
        if (from.name == 'PartyA' && !from.query.customerId) {
          this.$nextTick(() => {
            this.isCompany = true;
          });
        }
      }
    }
  },
  created() {
    this.init();
  },
  mounted() {
  },
  methods: {
    async init() {
      try {
        if (this.$route.params.id) { // 获取companyId
          const { companyName, ctmId } = this.$route.query;
          let companyId = this.$route.params.id;
          // 有企业名的情况下带上企业名称
          this.companyName = companyName ? companyName : "";
          // 供应商id
          this.ctmId = ctmId ? ctmId : "";
          await this.getCompanyId(companyId);
        }
      } catch (error) {
        console.log(error);
      }
    },
    showPartPage(e) {
      this.currentPath = e;
    },
    // 解密
    async getCompanyId(companyId) {
      let { data } = await idRemark({ mark: companyId });
      if (data) {
        this.companyId = data;
        await this.$nextTick();
        this.listenSider();
        await this.handleQuery();
        await this.getStatistic(this.companyName);
        // await this.association(this.$route.query.customerId);
        await this.association();
        this.$refs.sidebar.getFinancial(data);
      }
    },
    async getStatistic(companyName) {

      let params = {
        companyId: this.companyId
      };
      companyName ? params["companyName"] = companyName : null;
      let res = await statistic(params);
      if (res.code == 200) {
        this.statisticObj = { ...this.statisticObj, ...res.data };
      }
    },
    async handleQuery() {
      this.isSkeleton = true;
      let res = await infoHeader({ companyId: this.companyId });
      if (res.code == 200) {
        this.isSkeleton = false;
        this.companyInfo = res.data || {};
        let data = {
          pageNum: 1,
          pageSize: 5,
          provinceIds: [this.companyInfo.provinceId],
          cityIds: [this.companyInfo.cityId],
        };
        const result = await urbanInvestmentPage(data);
        if (result.code == 200) {
          if (result.data.totalCount < 1) {
            let arr = JSON.parse(JSON.stringify(this.$refs.sidebar.sideRoute));
            arr[0].children[5].children[2].disabled = true;
            this.$refs.sidebar.sideRoute = arr;
          }
        }
        if ((this.companyInfo && this.companyInfo.companyName) || this.companyName) {
          await this.$nextTick();
          const _cname = this.companyInfo.companyName ? this.companyInfo.companyName : this.companyName;
          document.getElementById('tagTitle').innerText = _cname;
          let titlename = document.getElementById('tagTitles');
          if (titlename) {
            titlename.innerText = _cname;
          }
        }
      }
    },
    listenSider() {
      const _this = this, erd = elementResizeDetectorMaker(), partBox = document.getElementById("partBox");
      erd.listenTo(partBox, element => {
        _this.partBoxHeight = partBox.offsetHeight;
      });
    },
    cooperateDetail() {
      this.cooDetail = true;
    },
    closeDetail() {
      this.cooDetail = false;
    },
    // 判断客户是否关联显示修改
    async association(id) {
      if (id) {
        try {
          const res = await customerInfo(id);
          if (res.code == 200) {
            if (res.data.userId == this.$store.state.user.userId) {
              await this.$nextTick();
              this.customerInfo = res.data;
              this.customerId = res.data.customerId;
              if (res.data.companyId == this.companyId) {
                await this.$nextTick();
                this.isCustomer = true;
                this.isCompany = true;
              } else {
                await this.$nextTick();
                this.isCustomer = true;
                this.isCompany = false;
                this.currentPath.pathName = this.$route.query.path || 'business';
                this.companyInfo = {
                  companyName: this.customerInfo.companyName
                };
                document.getElementById('tagTitle').innerText = this.customerInfo.companyName;
                let titlename = document.getElementById('tagTitles');
                if (titlename) {
                  titlename.innerText = this.customerInfo.companyName;
                }
              }
            } else {
              await this.$nextTick();
              this.isCustomer = true;
              this.isCompany = true;
              this.currentPath.pathName = this.$route.query.path ? this.$route.query.path : 'overview';
            }
          }
        } catch (err) {
          await this.$nextTick();
          this.currentPath.pathName = 'overview';
          this.isCompany = true;
        }
      } else {
        await this.$nextTick();
        this.isCompany = true;
        this.currentPath.pathName = this.$route.query.path ? this.$route.query.path : 'overview';
      }
    },

  }
}
</script>

<style lang="scss" scoped>
.part-container {
  padding: 0;
  /*margin: 0 24px;*/
}
.part-main {
  margin-top: 12px;
  width: 100%;
  height: calc(100vh - 155px);
  /* overflow-y: auto; */
  align-items: initial;
}

.part-right {
  /* min-width: 1088px; */
  width: 100%;
  background: #ffffff;
  border-radius: 4px;
  margin-left: 176px;
  ::v-deep .el-table__header-wrapper {
    position: sticky;
    top: 0;
    z-index: 9;
  }
  #groupBox {
    height: 100%;
  }
}
.details-of-party {
  width: 100%;
  height: 100%;
  margin: 0px;
  padding: 16px 24px;
  box-sizing: border-box;
  overflow: hidden;

  ::v-deep .header-container {
    .part-header {
      margin-top: 0px;
    }
  }

  ::v-deep .part-main {
    height: calc(100% - 68px);

    .part-left {
      margin-right: 16px;
      position: fixed;
      background: #ffffff;
      width: 160px;
      height: calc(100% - 156px);

      #detailPart {
        height: 100%;
        min-height: unset;
        padding-bottom: 0px;
      }
    }

    .part-right {
      margin-left: 176px;
      height: 100%;
      width: calc(100% - 176px);
      overflow: hidden;

      .part-common-container-style {
        width: 100%;
        height: 100%;
        overflow: auto;

        .app-container {
          position: relative;
          width: auto;
          height: auto;
          overflow: initial;
          box-sizing: border-box;
          /* min-width: 1200px; */
        }
      }
    }
  }
}


</style>
