<template>
  <div class="project-view">
    <basic-info ref="baseInfo" :base-info="baseInfo" />
    <cy-info-title type="collapse" name="项目信息">
      <project-info ref="projectInfo" :project-info="projectInfo" :details="details" />
    </cy-info-title>
    <cy-info-title type="collapse" name="本次合作相关">
      <cooperation ref="cooperation" :details="details" />
    </cy-info-title>
    <cy-info-title type="collapse" name="核心企业">
      <core-enterprise ref="coreEnterprise" :details="coreEnterprise" @isHistoricalCooperation="isHistoricalCooperation" />
    </cy-info-title>
    <cy-info-title v-if="hasHistory" type="collapse" name="历史合作情况">
      <history-cooperation ref="historyCooperation" :details="historyInfo" />
    </cy-info-title>
    <div class="submit-btn">
      <el-button @click="closePage">关闭</el-button>
    </div>
  </div>
</template>

<script>
import { getProjectSupplementInfo } from '@/api/myBusiness/projectInfo'
export default {
  name: 'MyBusinessProjectView',
  components: {
    BasicInfo: () => import('./components/BasicInfo'),
    ProjectInfo: () => import('./components/ProjectInfo'),
    Cooperation: () => import('./components/Cooperation'),
    CoreEnterprise: () => import('./components/CoreEnterprise'),
    HistoryCooperation: () => import('./components/HistoryCooperation')
  },
  data() {
    return {
      hasHistory: 0,
      coreEnterpriseStatus: '',
      details: {},
      baseInfo: {},
      projectInfo: {},
      cooperation: {},
      coreEnterprise: {},
      historyInfo: {}
    }
  },
  created() {
    this.getDetails()
  },
  methods: {
    getDetails() {
      const { id } = this.$route.query
      getProjectSupplementInfo({ id }).then(({ data }) => {
        this.details = data
        const { supplierName, projectName, projectType, projectCoreEnterprise } = data

        this.baseInfo = { corporateName: supplierName }
        this.projectInfo = {
          projectName,
          projectType
        }

        // 核心企业
        const { enterprise: { corporateName }, historicalCooperation, status } = projectCoreEnterprise
        this.coreEnterprise = { ...projectCoreEnterprise, corporateName }
        this.hasHistory = historicalCooperation
        this.coreEnterpriseStatus = status

        // 历史
        this.historyInfo = projectCoreEnterprise
      })
    },
    isHistoricalCooperation(v) {
      this.hasHistory = v
    },
    closePage() {
      const { id } = this.$route.query
      this.$router.push({
        path: '/myBusiness/admittanceDetail/child',
        query: {
          id: id
        }
      })
    }

  }
}
</script>

  <style lang="scss" scoped>
  .project-view {

  }
  </style>
