master #1

Open
gxwebsoft wants to merge 108 commits from developer/template-10584:master into master
Showing only changes of commit 7227ec6d84 - Show all commits

View File

@@ -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<string | number>('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 = () => {
</View>
<Form.Item name="accountType" label="提现方式" required>
<Radio.Group value={selectedAccount} onChange={() => setSelectedAccount}>
<Radio.Group
value={selectedAccount}
onChange={(value) => {
const next = String(value)
setSelectedAccount(next)
// Ensure Form gets the field value even when Radio.Group is controlled.
formRef.current?.setFieldsValue({accountType: next})
}}
>
<Cell.Group>
<Cell>
<Radio value="wechat"></Radio>