<template>
  <div class="enterprise-edit">
    <basic-info ref="baseInfo" :base-info="baseInfo" :disabled="true" />
    <PersonInfo ref="legalPersonInfoRef" :person-type="'legal'" :details-info="legalPersonInfo" :disabled="true" />
    <PersonInfo ref="controlPersonInfoRef" :person-type="'control'" :details-info="controlPersonInfo" :disabled="true" />
    <ContactInfo ref="contactInfoRef" :details-info="contactInfo" :disabled="true" />
    <AuthBook v-if="authBookInfo.length > 0" ref="authBookRef" :details-info="authBookInfo" :disabled="true" />
    <div class="submit-btn">
      <el-button @click="() => { $router.push({ name: 'MyStoreEnterprise', query: { activeName: 'enterprise' } }) }">关闭</el-button>
    </div>
  </div>
</template>

<script>
import { getRegion } from '@/api/dictionary'
import { treeChildrenEmpty } from '@/utils'
import { getEnterpriseDetail } from '@/api/myStoreEnterprise';

export default {
  name: 'MyBusinessProjectEdit',
  components: {
    BasicInfo: () => import('./components/BasicInfo'),
    PersonInfo: () => import('./components/PersonInfo.vue'),
    ContactInfo: () => import('./components/ContactInfo.vue'),
    AuthBook: () => import('./components/AuthBook')
  },
  data() {
    return {
      baseInfo: {},
      legalPersonInfo: {},
      controlPersonInfo: {},
      contactInfo: {},
      authBookInfo: [
        {
          contractType: 0,
          contractName: '测试合同名称',
          shortAuthUrl: 'http://www.baidu.com'
        },
        {
          contractType: 1,
          contractName: '测试合同名称1',
          shortAuthUrl: 'http://www.baidu.com'
        },
        {
          contractType: 2,
          contractName: '测试合同名称2',
          shortAuthUrl: 'http://www.baidu.com'
        }
      ]
    }
  },
  created() {
    this.queryReginList()

    if (this.$route.query.id && this.$route.query.companyZrId) {
      this.getDetails(this.$route.query.id)
    }
  },
  methods: {
    async queryReginList() {
      getRegion({ flag: false }).then(({ data }) => {
        this.regionList = treeChildrenEmpty(data)
      })
    },
    async getDetails(queryId) {
      const res = await getEnterpriseDetail(queryId)
      const { code, name  } = this.$route.query

      if (res.success) {
        this.baseInfo = {
          companyType: res.data.companyZrVo.companyType || '',
          socialCreditCode: code || '',
          enterpriseName: name || ''
        }

        this.legalPersonInfo = res.data.companyZrVo
        this.controlPersonInfo =  res.data.companyZrVo
        this.contactInfo = res.data.companyZrVo
        this.authBookInfo = res.data.companyZrCreditVOList || []
      }
    },
    async submitClick(type) {
    }
  }
}
</script>

<style lang="scss" scoped></style>
