<template>
  <div class="account-details">
    <!-- 基础信息 -->
    <base-info
      ref="baseInfoRef"
      :details-info="baseInfo"
      client-type="B"
      :page-type="$route.query.type"
    />

    <!-- 资金信息 -->
    <fund-info ref="fundInfoRef" :details-info="fundInfo" :disabled="true" />

    <div class="submit-btn">
      <el-button
        @click="
          () => {
            $router.go(-1)
          }
        "
      >取消</el-button>
      <el-button type="primary" @click="submitClick('submit')">保存</el-button>
    </div>
  </div>
</template>

<script>
import {
  updateMemberRegister,
  getMemberRegister
} from '@/api/cyAccountManage/memberAccountManage/index'

export default {
  name: 'CyAccountaccountDetails',
  components: {
    BaseInfo: () => import('./components/BaseInfo.vue'),
    FundInfo: () => import('./components/FundInfo.vue')
  },

  data() {
    return {
      baseInfo: {
        customerNumber: '',
        customerName: '',
        customerType: '',
        accountName: '',
        accountAlias: '',
        socialCreditCode: '',
        accountStatus: '',
        authorizationStatus: '',
        channel: '',
        customerSource: ''
      },
      fundInfo: {
        accountBalance: '',
        availableBalance: '',
        freezeAmount: '',
        currency: ''
      },
      operateId: ''
    }
  },
  watch: {
    $route: {
      handler(val) {
        if (val.query.id) {
          getMemberRegister({ id: val.query.id }).then(({ data }) => {
            if (data) {
              Object.keys(this.baseInfo).forEach(key => {
                this.$set(this.baseInfo, key, data[key])
              })
              Object.keys(this.fundInfo).forEach(key => {
                this.$set(this.fundInfo, key, data[key])
              })
              this.operateId = data.id
            }
          })
        }
      },
      immediate: true
    }
  },
  methods: {
    async submitClick() {
      const res = await updateMemberRegister({
        ...this.$refs.baseInfoRef.ruleForm,
        ...this.$refs.fundInfoRef.ruleForm,
        id: this.operateId
      })

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

      if (res.success) {
        this.$message.success('账户信息修改成功')
        this.$router.go(-1)
      }
    }
  }
}
</script>

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