<template>
  <div class="app-container part-container">
    <Header :company-id="companyId" :companyInfo="companyInfo" :cooDetail="cooDetail" v-if="companyId" @close-detail="closeDetail" />
    <div class="flex-box 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">
          <template v-if="isCompany">
            <!-- 企业概览 -->
            <Overview v-if="currentPath.pathName=='overview'" :company-id="companyId" :companyInfo="companyInfo" />
            <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" />
            <!-- 项目商机 -->
            <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" />
            <!-- 投诚分析 -->
            <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" />
            <!-- 风险信息 -->
            <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" />
            <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" />
          </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 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 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 LandAcquisition from "./urbanLnvestment/landAcquisition" //投诚分析-城投拿地
import RegionalEconomies from "./urbanLnvestment/regionalEconomies" //投诚分析-区域经济
import SameRegion from "./urbanLnvestment/sameRegion" //投诚分析-同地区城投
import Punish from "./riskInformation/punish" //风险信息-行政处罚
import BusinessAnomaly from "./riskInformation/businessAnomaly" //风险信息-经营异常
import IfThePerson from "./riskInformation/ifThePerson" //风险信息-被执行人
import Dishonesty from "./riskInformation/dishonesty" //风险信息-失信被执行
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 {
  urbanInvestmentPage,
} from '@/api/detail/party-a/urbanLnvestment'
export default {
  name: 'PartyA',
  components: {
    Header,
    SideBar,
    Overview,
    Businfo,
    Holderinfo,
    Execuinfo,
    Overseas,
    Branch,
    Financial,
    // Business,
    Landtransaction,
    Proposed,
    Bond,
    Biddingplan,
    Announcement,
    Tencent,
    Administrative,
    Custom,
    Supplier,
    Bidagency,
    Hiscontract,
    Bidrecords,
    LandAcquisition,
    RegionalEconomies,
    SameRegion,
    Punish,
    BusinessAnomaly,
    IfThePerson,
    Dishonesty,
    Judgment,
    CourtNotice,
    OpenacourtsessionNotice,
    Business,
    Preference,
    Cooperate,
    DecisionMaking,
    Gjjl
  },
  data() {
    return {
      companyInfo: {},
      customerInfo: {},
      companyId: '',  //企业Id（测试默认3068）
      customerId: '',  //企业Id（测试默认'a00d582a6041f32c16aac804e4924736'）
      isCompany: false,  //判断是否有建设库数据
      isCustomer: false,  //判断是否展示修改客户信息
      currentPath: {
        pathName: 'overview'  //默认展示页
      },
      statisticObj:{},
      partBoxHeight: null,
      cooDetail: false
    }
  },
  computed: {
    routes() {
      return this.$store.state.permission.routes
    }
  },
  watch: {
    '$route'(to, from) {
      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
                  })
                }
              }
            })
          }
          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
          })
        }
      }
    }
  },
  beforeRouteLeave(to, from, next) {
    next(vm => {

    })
  },
  beforeRouteEnter(to, from, next){
    next(vm => {

    })
  },
  created() {
    if (this.$route.params.id) { // 获取companyId
      let companyId = this.$route.params.id
      this.getCompanyId(companyId)
    }
    if (this.$route.query.path) { // 获取跳转对应板块
      this.currentPath.pathName = this.$route.query.path
    }
  },
  mounted(){
  },
  methods: {
    showPartPage(e){
      this.currentPath = e
    },
    // 解密
    async getCompanyId(companyId){
      let { data } = await idRemark({mark:companyId})
      if( data ){
        this.companyId = data
        this.$nextTick(() => {
          this.listenSider()
        })
        this.getStatistic();
        this.handleQuery();
        this.association(this.$route.query.customerId)
      }
    },
    async getStatistic(){
      let res = await statistic({companyId:this.companyId});
      if(res.code==200){
        this.statisticObj = res.data
      }
    },
    async handleQuery() {
      let res = await infoHeader({companyId:this.companyId})
      if(res.code==200){
        this.companyInfo = res.data || {}
        let data = {
          pageNum: 1,
          pageSize: 5,
          provinceIds: [this.companyInfo.provinceId],
          cityIds: [this.companyInfo.cityId],
        }
        urbanInvestmentPage(data).then(res => {
          if(res.data.totalCount<1){
            let arr = JSON.parse(JSON.stringify(this.$refs.sidebar.sideRoute))
            arr[4].children[2].disabled = true;
            this.$refs.sidebar.sideRoute = arr
          }
        })
        if(this.companyInfo && this.companyInfo.companyName){
          this.$nextTick(()=>{
            document.getElementById('tagTitle').innerText = this.companyInfo.companyName
          })
        }
      }
    },
    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
    },
    // 判断客户是否关联显示修改
    association(id){
      if(id) {
        customerInfo(id).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
              })
              if(res.data.companyId == this.companyId){
                this.$nextTick(() => {
                  this.isCustomer = true
                  this.isCompany = true
                })
              }else{
                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
                })
              }
            } else {
              this.$nextTick(() => {
                this.isCustomer = true
                this.isCompany = true
                this.currentPath.pathName = 'overview'
              })
            }
          }
        }).catch(err => {
          this.$nextTick(() => {
            this.currentPath.pathName = 'overview'
            this.isCompany = true
          })
        })
      }else{
        this.$nextTick(() => {
          this.isCompany = true
          this.currentPath.pathName = 'overview'
        })
      }
    },

  }
}
</script>

<style lang="scss" scoped>
  .part-container{
    padding: 0;
  }
  .part-main{
    margin-top: 12px;
    align-items: initial;
  }
  .part-left{
    margin-right: 16px;
  }
  .part-right{
    min-width: 1088px;
    width: 100%;
    background: #FFFFFF;
    border-radius: 4px;
  }
</style>
