<template>
  <div class="account-details">
    <!-- 基础信息 -->
    <base-info ref="baseInfoRef" client-type="C" :page-type="$route.query.type" />
    <!-- 付款方账户信息 | 静默户账户信息 -->
    <payment-account ref="paymentRef" client-type="C" />

    <div class="submit-btn">
      <el-button
        @click="
          () => {
            $router.go(-1)
          }
        "
      >取消</el-button>
      <el-button type="primary" @click="submitClick('submit')">保存</el-button>
    </div>
    <authorization ref="authorizationRef" :active-info="authActiveInfo" :go-list="true" />
  </div>
</template>

<script>
import { addMemberRegister } from '@/api/accountCenter/cyAccountManage'

export default {
  name: 'CyAccountaccountAdd',
  components: {
    BaseInfo: () => import('./components/BaseInfo.vue'),
    Authorization: () => import('./components/Authorization.vue'),
    PaymentAccount: () => import('./components/PaymentAccount.vue')
  },

  data() {
    return {
      authActiveInfo: []
    }
  },
  methods: {
    async submitClick() {
      const params = {
        ...this.$refs.baseInfoRef.ruleForm,
        silentAccountInfoList: this.$refs.paymentRef.tableData,
        bocomBasicInfoId: this.$route.query.addId,
        Loading: true
      }

      if (!this.$refs.baseInfoRef.ruleForm.customerNumber) {
        this.$message.warning('请输入客户号')
        return
      }
      if (!this.$refs.baseInfoRef.ruleForm.customerName) {
        this.$message.warning('请输入客户名称')
        return
      }
      if (!this.$refs.baseInfoRef.ruleForm.accountName) {
        this.$message.warning('请输入账号名称')
        return
      }
      const res = await addMemberRegister(params)

      console.log('addMemberRegister----', res)

      if (res.success && res.data && res.data.authorizationStatus !== 4) {
        this.authActiveInfo = res.data.noticeInfoList
        // 回调触发微信授权
        this.$refs.authorizationRef.openDialog(true)
      }
    }
  }
}
</script>

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