<!-- 会员中心-会员信息 -->
<template>
    <app-view>
        <el-descriptions title="会员信息" :column="2" style="padding:20px">
            <el-descriptions-item label="登录代码">{{ handleNoneValue(loginInfo.logincode) }}</el-descriptions-item>
            <el-descriptions-item label="企业名称">{{ handleNoneValue(userInfo.customername) }}</el-descriptions-item>
            <el-descriptions-item label="登录账号">{{ loginInfo.loginid }}</el-descriptions-item>
            <el-descriptions-item label="手机号">{{ handleNoneValue(userInfo.mobile2) }}</el-descriptions-item>
            <el-descriptions-item label="机构代码">{{ userInfo.userid }}</el-descriptions-item>
            <el-descriptions-item label="法人姓名">{{ handleNoneValue(userInfo.legalpersonname) }}</el-descriptions-item>
            <el-descriptions-item label="证件类型">{{ getCertificateTypeName(userInfo.cardtypeid) }}</el-descriptions-item>
            <el-descriptions-item label="企业地址">{{ handleNoneValue(userInfo.address) }}</el-descriptions-item>
            <el-descriptions-item label="证件号码">{{ handleNoneValue(decryptAES(userInfo.cardnum)) }}
            </el-descriptions-item>
            <el-descriptions-item label="联系人">{{ handleNoneValue(userInfo.contactname) }}</el-descriptions-item>
            <el-descriptions-item label="联系电话">{{ handleNoneValue(decryptAES(userInfo.telphone))
            }}</el-descriptions-item>
        </el-descriptions>
        <el-divider />
        <el-descriptions title="签约信息" :column="2" style="padding:20px" v-if="accountInfo">
            <el-descriptions-item label="资金账号">{{ accountInfo.accountid }}</el-descriptions-item>
            <el-descriptions-item label="余额">{{ accountInfo.currentbalance.toFixed(2) }}</el-descriptions-item>
            <el-descriptions-item label="冻结资金">{{ freezeMargin.toFixed(2) }}</el-descriptions-item>
            <el-descriptions-item label="可用资金">{{ avaiableMoney.toFixed(2) }}</el-descriptions-item>
            <template v-if="bankInfo">
                <el-descriptions-item label="托管银行">{{ bankInfo.cusbankname }}</el-descriptions-item>
                <el-descriptions-item label="开户银行">{{ bankInfo.bankname }}</el-descriptions-item>
                <el-descriptions-item label="证件类型">{{
                    bankInfo.cardtype ?
                        getCertificateTypeName(Number(bankInfo.cardtype)) : handleNoneValue('')
                }}
                </el-descriptions-item>
                <el-descriptions-item label="银行卡户名">{{ bankInfo.bankaccountname }}</el-descriptions-item>
                <el-descriptions-item label="证件号码">{{ handleNoneValue(bankInfo.cardno) }}</el-descriptions-item>
                <el-descriptions-item label="银行子账号">{{ handleNoneValue(bankInfo.bankchildaccount) }}
                </el-descriptions-item>
                <el-descriptions-item label="手机号">{{ handleNoneValue(bankInfo.mobilephone) }}</el-descriptions-item>
                <el-descriptions-item label="签约状态">{{ getSignStatusName(bankInfo.signstatus) }}</el-descriptions-item>
            </template>
        </el-descriptions>
        <app-auth-operation :menus="handleTableButtons" :options="{ bankInfo }" @closed="getBankAccountSign" />
    </app-view>
</template>

<script lang="ts" setup>
import { computed } from 'vue'
import { useAccount } from '@/business/account'
import { decryptAES } from '@/utils/websocket/crypto'
import { handleNoneValue } from '@/filters'
import { getCertificateTypeName } from '@/constants/certificate'
import { SignStatus, getSignStatusName } from '@/constants/bank'
import { useAccountStore } from '@/stores'
import AppAuthOperation from '@pc/components/modules/auth-operation/index.vue'

const { accountInfo, avaiableMoney, freezeMargin } = useAccountStore()
const { loading, loginInfo, userInfo, bankInfo, getBankAccountSign } = useAccount()

const handleTableButtons = computed(() => {
    const buttons = ['mine_profile_loginpassword', 'mine_profile_accountpassword']
    if (!loading.value) {
        if (bankInfo.value) {
            switch (bankInfo.value.signstatus) {
                case SignStatus.Signed: {
                    buttons.push('mine_profile_rescind')
                    break
                }
                case SignStatus.Unsigned:
                case SignStatus.Rescinded:
                case SignStatus.Refuse: {
                    buttons.push('mine_profile_sign')
                    break
                }
            }
        } else {
            buttons.push('mine_profile_sign')
        }
    }
    return buttons
})

getBankAccountSign()
</script>