修复转账提示bug,并在切换按钮时清空输入框

This commit is contained in:
mazh 2026-04-25 21:08:07 +08:00
parent a6301e13d8
commit f5b3faa318
1 changed files with 53 additions and 32 deletions

View File

@ -45,8 +45,8 @@
</div> </div>
</el-card> </el-card>
</div> </div>
<TransferForm :form-data="transferForm" :form-rules="transferFormRules" <TransferForm :key="transferType" class="transfer-main-form" :form-data="transferForm" :form-rules="transferFormRules"
:form-items="transferFormItemOptions" :options-map="transferFormOptionsMap" ref="transferFormRef"> :form-items="transferFormItemOptions" :options-map="transferFormOptionsMap" ref="mainTransferFormRef">
</TransferForm> </TransferForm>
<div class="transfer-type verify" v-if="transferType === 'external'"> <div class="transfer-type verify" v-if="transferType === 'external'">
<div class="type-title">验证方式</div> <div class="type-title">验证方式</div>
@ -57,7 +57,7 @@
@click="handleVerifyTabClick('phone')">手机号验证</el-button> @click="handleVerifyTabClick('phone')">手机号验证</el-button>
</div> </div>
<div class="username">{{ verifyType === "email" ? userInfo.email : userInfo.phone }}</div> <div class="username">{{ verifyType === "email" ? userInfo.email : userInfo.phone }}</div>
<el-form class="verify-form" :model="transferForm" :rules="transferFormRules" ref="transferFormRef"> <el-form class="verify-form" :model="transferForm" :rules="transferFormRules" ref="verifyFormRef">
<el-form-item prop="code"> <el-form-item prop="code">
<el-input v-model="transferForm.code" style="max-width: 300px" placeholder="请输入验证码"> <el-input v-model="transferForm.code" style="max-width: 300px" placeholder="请输入验证码">
@ -98,9 +98,9 @@ import { sendCaptcha, initCaptchaState, clearCaptchaTimer } from '@/utils/sendCa
const transferType = ref('internal') const transferType = ref('internal')
/** /**
* @description 转账表单数据 * @description 创建默认转账表单数据
*/ */
const transferForm = ref({ const createDefaultTransferForm = () => ({
transferOutAccount: -1, transferOutAccount: -1,
transferInAccount: '', transferInAccount: '',
transferAmount: '', transferAmount: '',
@ -110,10 +110,16 @@ const transferForm = ref({
type: '', type: '',
code: '' code: ''
}) })
/** /**
* @description 转账表单引用 * @description 转账表单数据
*/ */
const transferFormRef = ref() const transferForm = ref(createDefaultTransferForm())
/**
* @description 主转账表单和验证码表单引用
*/
const mainTransferFormRef = ref()
const verifyFormRef = ref()
const transferFormItemOptions = computed(() => transferType.value === 'internal' ? internalFormItem : externalFormItem) const transferFormItemOptions = computed(() => transferType.value === 'internal' ? internalFormItem : externalFormItem)
const transferFormRules = ref(rules(transferForm.value)) const transferFormRules = ref(rules(transferForm.value))
const transferFormOptionsMap = ref({ const transferFormOptionsMap = ref({
@ -279,13 +285,31 @@ onMounted(() => {
getTransferWalletOptions() getTransferWalletOptions()
}) })
//
const getDefaultMaxOutAmount = () => {
return transferFormOptionsMap.value.transferOutAccount.find((item: any) => item.value === -1)?.amount || ''
}
// /
const resetTransferForm = async () => {
Object.assign(transferForm.value, createDefaultTransferForm(), {
MaxOutAmount: getDefaultMaxOutAmount(),
})
await nextTick()
verifyFormRef.value?.clearValidate?.()
}
/** /**
* @description 切换转账类型 * @description 切换转账类型
* @param type 转账类型 * @param type 转账类型
*/ */
const handleTransferTabClick = (type: string) => { const handleTransferTabClick = async (type: string) => {
// /
if (transferType.value === type) return
transferType.value = type transferType.value = type
transferForm.value.MaxOutAmount = transferFormOptionsMap.value.transferOutAccount.find((item: any) => item.value === -1)?.amount await resetTransferForm()
} }
/** /**
* @description 切换验证方式 * @description 切换验证方式
@ -311,7 +335,12 @@ const handleVerifyParams = (type: string) => {
* @description 提交转账表单 * @description 提交转账表单
*/ */
const handleSubmit = async () => { const handleSubmit = async () => {
await transferFormRef.value.validate() await mainTransferFormRef.value?.validate?.()
if (transferType.value === 'external') {
await verifyFormRef.value?.validate?.()
}
const params = { const params = {
type: transferType.value === 'internal' ? '1' : '2', type: transferType.value === 'internal' ? '1' : '2',
from: String(transferForm.value.transferOutAccount), from: String(transferForm.value.transferOutAccount),
@ -322,33 +351,14 @@ const handleSubmit = async () => {
description: transferForm.value.remark, description: transferForm.value.remark,
} }
console.log(params) console.log(params)
if (transferType.value === 'internal') { if (transferType.value === 'internal') {
await transferApi(params) await transferApi(params)
transferForm.value = {
transferOutAccount: -1,
transferInAccount: '',
transferAmount: '',
remark: '',
//
MaxOutAmount: '',
type: '',
code: ''
}
} else { } else {
await transferApi({ ...params, verify_type: verifyType.value === 'email' ? '1' : '2', verify_code: transferForm.value.code }) await transferApi({ ...params, verify_type: verifyType.value === 'email' ? '1' : '2', verify_code: transferForm.value.code })
transferForm.value = {
transferOutAccount: -1,
transferInAccount: '',
transferAmount: '',
remark: '',
//
MaxOutAmount: '',
type: '',
code: ''
}
} }
await resetTransferForm()
} }
</script> </script>
@ -386,6 +396,17 @@ const handleSubmit = async () => {
} }
.transfer-form { .transfer-form {
//
:deep(.transfer-main-form .el-form-item) {
margin-bottom: 24px;
}
:deep(.transfer-main-form .el-form-item__error) {
position: static;
padding-top: 4px;
line-height: 18px;
}
.external-item { .external-item {
margin-bottom: 10px; margin-bottom: 10px;