<template>
  <div class="supplementary-info">
    <cy-info-title>基础信息</cy-info-title>
    <basic-info :basic-info="basicInfo" />
    <cy-info-title type="collapse" name="补充信息">
      <add-info ref="addInfo" :add-info="addInfo" :has-guarantee-enterprise="hasGuaranteeEnterprise" />
      <financial-situation v-if="!hasGuaranteeEnterprise" ref="financial" :financial-info="financialInfo" :has-guarantee-enterprise="hasGuaranteeEnterprise" />
      <business-situation v-if="!hasGuaranteeEnterprise" ref="business" :business-info="businessInfo" />
      <related-enterprises v-if="!hasGuaranteeEnterprise" ref="related" :related-info="relatedInfo" />
    </cy-info-title>
    <template v-if="hasGuaranteeEnterprise">
      <cy-info-title type="collapse" name="担保企业基础信息">
        <basic-info :basic-info="guaranteeBasicInfo" />
      </cy-info-title>
      <cy-info-title type="collapse" name="担保企业补充信息">
        <guarantee-add-info ref="guaranteeAddInfo" :add-info="guaranteeAddInfo" />
        <financial-situation ref="guaranteeFinancial" :has-guarantee-enterprise="hasGuaranteeEnterprise" :financial-info="guaranteeAddInfo" />
        <business-situation ref="guaranteeBusiness" :business-info="guaranteeAddInfo" />
        <related-enterprises ref="guaranteeRelated" :related-info="guaranteeAddInfo" />
      </cy-info-title>
    </template>
  </div>
</template>

<script>
// import { getSupplementaryInfo, submitSupplementaryAddInfo } from '@/api/myBusiness/supplementaryInfo'
export default {
  components: {
    BasicInfo: () => import('./components/BasicInfo'),
    AddInfo: () => import('./components/AddInfo'),
    GuaranteeAddInfo: () => import('./components/GuaranteeAddInfo'),
    FinancialSituation: () => import('./components/FinancialSituation'),
    BusinessSituation: () => import('./components/BusinessSituation'),
    RelatedEnterprises: () => import('./components/RelatedEnterprises')
  },
  props: {
    disabled: {
      type: Boolean,
      default: false
    },
    deatailsInfo: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      hasGuaranteeEnterprise: null,
      basicInfo: {},
      addInfo: {},
      guaranteeBasicInfo: {},
      guaranteeAddInfo: {},
      financialInfo: {},
      businessInfo: {},
      relatedInfo: {}
    }
  },
  watch: {
    deatailsInfo: {
      handler(newV) {
        if (newV && Object.keys(newV).length) {
          const { enterprise, hasGuaranteeEnterprise, guaranteeEnterprise } = JSON.parse(JSON.stringify(newV))
          this.hasGuaranteeEnterprise = hasGuaranteeEnterprise
          if (!hasGuaranteeEnterprise) {
            this.financialInfo = enterprise
            this.businessInfo = enterprise
            this.relatedInfo = enterprise
          }
          // 基础信息
          this.basicInfo = {
            corporateName: enterprise?.corporateName,
            socialCreditCode: enterprise?.socialCreditCode
          }
          // 补充信息
          this.addInfo = enterprise

          // 担保企业基础信息
          this.guaranteeBasicInfo = {
            corporateName: guaranteeEnterprise?.corporateName,
            socialCreditCode: guaranteeEnterprise?.socialCreditCode
          }
          // 担保企业补充信息
          this.guaranteeAddInfo = guaranteeEnterprise
        }
      },
      immediate: true,
      deep: true
    }
  },
  created() {
    // this.getDetails()
  },
  methods: {

  }
}
</script>

<style lang="scss" scoped>
.supplementary-info {
}
</style>
<style lang="scss">
.supplementary-info {
  .iconfont {
    font-size: 26px;
  }
}
</style>
