<template>
  <div class="enterprise-auth">
    <AuthBook ref="authBookRef" :details-info="authBookInfo" />
    <div class="submit-btn">
      <el-button @click="() => { $router.push({ name: 'MyStoreEnterprise', query: { activeName: 'enterprise' } }) }">关闭</el-button>
      <el-button type="primary" @click="submitClick('submit')">保存</el-button>
    </div>
  </div>
</template>

<script>
import { getAuthBooksList, enterpriseAccessStepTwo } from '@/api/myStoreEnterprise';

export default {
  name: 'MyBusinessProjectAuth',
  components: {
    AuthBook: () => import('./components/AuthBook')
  },
  data() {
    return {
      authBookInfo: []
    }
  },
  created() {
    if (this.$route.query.zrId) {
      this.getDetails(this.$route.query.zrId)
    }
  },
  methods: {
    async getDetails(id) {
      const res = await getAuthBooksList(id)

      if (res.success) {
        this.authBookInfo = res.data
      }
    },
    async submitClick(submitType) {
      const params = {
        Loading: true,
        companyZrId: this.$route.query.zrId,
        taskId:  this.$route.query.taskId,
        flag: '通过'
      }

      const authBooksList = await this.$refs.authBookRef.getParams(submitType)

      if (authBooksList.length === this.authBookInfo.length) {
        const res = await enterpriseAccessStepTwo(params)

        if (res.success) {
          this.$message.success('操作成功')

          this.$router.push({
            name: 'MyStoreEnterprise',
            query: { activeName: 'enterprise' }
          })
        }
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.enterprise-supplement {}
</style>
