diff --git a/src/dealer/withdraw/index.tsx b/src/dealer/withdraw/index.tsx index 04a3cef..bd5431e 100644 --- a/src/dealer/withdraw/index.tsx +++ b/src/dealer/withdraw/index.tsx @@ -25,6 +25,12 @@ interface WithdrawRecordWithDetails extends ShopDealerWithdraw { accountDisplay?: string } +// Some backends may return money fields as number; keep internal usage always as string. +const normalizeMoneyString = (money: unknown) => { + if (money === null || money === undefined || money === '') return '0.00' + return typeof money === 'string' ? money : String(money) +} + const DealerWithdraw: React.FC = () => { const [activeTab, setActiveTab] = useState('0') const [selectedAccount, setSelectedAccount] = useState('') @@ -52,7 +58,7 @@ const DealerWithdraw: React.FC = () => { const fetchBalance = useCallback(async () => { console.log(dealerUser, 'dealerUser...') try { - setAvailableAmount(dealerUser?.money || '0.00') + setAvailableAmount(normalizeMoneyString(dealerUser?.money)) } catch (error) { console.error('获取余额失败:', error) } @@ -163,8 +169,8 @@ const DealerWithdraw: React.FC = () => { } // 验证提现金额 - const amount = parseFloat(values.amount) - const available = parseFloat(availableAmount.replace(/,/g, '')) + const amount = parseFloat(String(values.amount)) + const available = parseFloat(normalizeMoneyString(availableAmount).replace(/,/g, '')) if (isNaN(amount) || amount <= 0) { Taro.showToast({ @@ -266,13 +272,13 @@ const DealerWithdraw: React.FC = () => { } const setAllAmount = () => { - formRef.current?.setFieldsValue({amount: availableAmount.replace(/,/g, '')}) + formRef.current?.setFieldsValue({amount: normalizeMoneyString(availableAmount).replace(/,/g, '')}) } // 格式化金额 - const formatMoney = (money?: string) => { - if (!money) return '0.00' - return parseFloat(money).toFixed(2) + const formatMoney = (money?: unknown) => { + const n = parseFloat(normalizeMoneyString(money).replace(/,/g, '')) + return Number.isFinite(n) ? n.toFixed(2) : '0.00' } const renderWithdrawForm = () => ( @@ -320,8 +326,8 @@ const DealerWithdraw: React.FC = () => { type="number" onChange={(value) => { // 实时验证提现金额 - const amount = parseFloat(value) - const available = parseFloat(availableAmount.replace(/,/g, '')) + const amount = parseFloat(String(value)) + const available = parseFloat(normalizeMoneyString(availableAmount).replace(/,/g, '')) if (!isNaN(amount) && amount > available) { // 可以在这里添加实时提示,但不阻止输入 } @@ -354,7 +360,15 @@ const DealerWithdraw: React.FC = () => { - setSelectedAccount}> + { + const next = String(value) + setSelectedAccount(next) + // Ensure Form gets the field value even when Radio.Group is controlled. + formRef.current?.setFieldsValue({accountType: next}) + }} + > 微信钱包