li.shaoyi 3 سال پیش
والد
کامیت
630a12609f
3فایلهای تغییر یافته به همراه93 افزوده شده و 19 حذف شده
  1. 33 1
      src/constants/account.ts
  2. 40 14
      src/packages/mobile/views/home/components/mine/index.vue
  3. 20 4
      src/stores/modules/account.ts

+ 33 - 1
src/constants/account.ts

@@ -3,6 +3,38 @@ import { useEnumStore } from '@/stores'
 const { getEnumTypeList, getEnumTypeName, getEnumTypeValue } = useEnumStore()
 
 /**
+ * 实名认证状态
+ */
+export enum AuthStatus {
+    Uncertified = 0, // 未认证
+    Certified = 1, // 已认证
+    Submitted = 2, // 已提交
+    Rejected = 3, // 已拒绝
+}
+
+/**
+ * 实名认证状态列表
+ * @returns 
+ */
+export function getAuthStatusList() {
+    return [
+        { label: '未实名', value: AuthStatus.Uncertified },
+        { label: '已实名', value: AuthStatus.Certified },
+        { label: '实名审核中', value: AuthStatus.Submitted },
+        { label: '实名未通过', value: AuthStatus.Rejected },
+    ]
+}
+
+/**
+ * 获取实名认证状态名称
+ * @returns 
+ */
+export function getAuthStatusName(value: number) {
+    const enums = getAuthStatusList()
+    return getEnumTypeName(enums, value)
+}
+
+/**
  * 获取对应的证件类型列表
  * @returns 
  */
@@ -23,7 +55,7 @@ export function getCertificateTypeCodeName(value: number) {
  * 获取对应的证件类型名称的值
  * @returns 
  */
- export function getCertificateTypeCodeValue(label: string) {
+export function getCertificateTypeCodeValue(label: string) {
     const enums = getCertificateTypeList()
     return getEnumTypeValue(enums, label)
 }

+ 40 - 14
src/packages/mobile/views/home/components/mine/index.vue

@@ -12,8 +12,7 @@
             </div>
             <div class="profile-user__info">
               <div>
-                <Tag type="success" v-if="hasAuth">已实名</Tag>
-                <Tag type="primary" v-else>未实名</Tag>
+                <Tag :type="authStatus ? 'success' : 'primary'">{{ getAuthStatusName(authStatus) }}</Tag>
               </div>
               <span>{{ getLoginId() }}</span>
             </div>
@@ -30,11 +29,11 @@
           </div>
           <div class="bank-item">
             <span>冻结</span>
-            <span>{{ accountInfo.freezemargin }}</span>
+            <span>{{ freezeMargin }}</span>
           </div>
           <div class="bank-item">
             <span>可用</span>
-            <span>{{ accountInfo.usedmargin }}</span>
+            <span>{{ avaiableMoney }}</span>
           </div>
           <div class="bank-item">
             <span>
@@ -70,12 +69,13 @@
     </div>
     <div class="g-navmenu">
       <CellGroup>
-        <Cell is-link :to="{ name: 'account-certification' }" v-if="!hasAuth">
+        <Cell is-link :to="{ name: 'account-certification' }"
+          v-if="[AuthStatus.Uncertified, AuthStatus.Rejected].includes(authStatus)">
           <template #title>
             <app-iconfont icon="icon-shimingrenzheng">实名认证</app-iconfont>
           </template>
         </Cell>
-        <Cell is-link :to="{ name: 'bank-sign' }">
+        <Cell is-link :to="{ name: 'bank-sign' }" v-if="authStatus === AuthStatus.Certified">
           <template #title>
             <app-iconfont icon="icon-qianyuezhanghu">签约账户</app-iconfont>
           </template>
@@ -119,21 +119,23 @@
 </template>
 
 <script lang="ts" setup>
-import { shallowRef } from 'vue'
+import { shallowRef, onActivated } from 'vue'
 import { Cell, CellGroup, Button, Tag, Toast } from 'vant'
 import { fullloading, dialog } from '@/utils/vant'
 import { useNavigation } from '@/hooks/navigation'
-import { useLoginStore, useUserStore, useAccountStore, } from '@/stores'
+import { useLoginStore, useAccountStore, } from '@/stores'
 import { useAuth } from '@/business/auth'
 import AppIconfont from '@mobile/components/base/iconfont/index.vue'
 import { useBankAccountSign } from '@/business/bank'
+import { queryUserAccount } from '@/services/api/account'
+import { AuthStatus, getAuthStatusName } from '@/constants/account';
 
 const { router, routerTo } = useNavigation()
-const { getLoginId, getFirstAccountId } = useLoginStore()
-const { hasAuth } = useUserStore()
+const { getUserId, getLoginId, getFirstAccountId } = useLoginStore()
 const { getBankAccountList, bankInfo } = useBankAccountSign()
 const { logout } = useAuth()
-const { accountInfo } = useAccountStore()
+const { accountInfo, freezeMargin, avaiableMoney } = useAccountStore()
+const authStatus = shallowRef(AuthStatus.Uncertified) // 实名认证状态
 const headerRef = shallowRef<HTMLDivElement>()
 
 const onReady = (el: HTMLDivElement) => {
@@ -143,7 +145,7 @@ const onReady = (el: HTMLDivElement) => {
 
 /// 进行出入金操作判断
 const doInOutMoney = (tab: string) => {
-  if (hasAuth) {
+  if (authStatus.value === AuthStatus.Certified) {
     fullloading((hideLoading) => {
       getBankAccountList().then(() => {
         hideLoading()
@@ -151,14 +153,24 @@ const doInOutMoney = (tab: string) => {
         if (signstatus && signstatus !== 1) {
           router.push({ name: 'bank-wallet', query: { tab } })
         } else {
-          dialog('当前未签约,请先进行账户签约才进行出入金操作')
+          dialog('请先添加签约账户信息。', {
+            showCancelButton: true,
+            confirmButtonText: '去签约'
+          }).then(() => {
+            router.push({ name: 'bank-sign' })
+          })
         }
       }).catch(() => {
         Toast.fail('加载失败')
       })
     }, '正在加载...')
   } else {
-    dialog('请先实名认证,再进行出入金操作业务!')
+    dialog('请先实名认证,再进行出入金操作业务。', {
+      showCancelButton: true,
+      confirmButtonText: '去实名'
+    }).then(() => {
+      router.push({ name: 'account-certification' })
+    })
   }
 }
 
@@ -169,6 +181,20 @@ const userLogout = () => {
     logout()
   })
 }
+
+onActivated(() => {
+  if (authStatus.value !== AuthStatus.Certified) {
+    // 获取用户账号信息
+    queryUserAccount({
+      data: {
+        userID: getUserId()
+      },
+      success: (res) => {
+        authStatus.value = res.data.hasauth
+      }
+    })
+  }
+})
 </script>
 
 <style lang="less">

+ 20 - 4
src/stores/modules/account.ts

@@ -28,11 +28,27 @@ const store = new (class extends VueStore<StoreState> {
         })
     }
 
+    /** 当前资金账户信息 */
+    private accountInfo = computed(() => {
+        return this.state.accountList.find((e) => e.accountid === this.state.accountId)
+    })
+
+    /** 冻结资金 */
+    private freezeMargin = computed(() => {
+        const { freezecharge = 0, freezemargin = 0, otherfreezemargin = 0, outamountfreeze = 0 } = this.accountInfo.value ?? {}
+        return freezecharge + freezemargin + otherfreezemargin + outamountfreeze
+    })
+
+    /** 可用资金 */
+    private avaiableMoney = computed(() => {
+        const { currentbalance = 0 } = this.accountInfo.value ?? {}
+        return currentbalance - this.freezeMargin.value
+    })
+
     getters = {
-        /** 当前资金账户信息 */
-        accountInfo: computed(() => {
-            return this.state.accountList.find((e) => e.accountid === this.state.accountId)
-        })
+        accountInfo: this.accountInfo,
+        freezeMargin: this.freezeMargin,
+        avaiableMoney: this.avaiableMoney
     }
 
     actions = {