update money currency

This commit is contained in:
LittleBoy 2024-06-23 12:38:45 +08:00
parent e3c9e81fa8
commit 77f5b76762
3 changed files with 41 additions and 7 deletions

View File

@ -113,7 +113,7 @@ export const BillList: React.FC<BillListProps> = (props) => {
title: t('bill.title_actual_payment_amount'),
dataIndex: 'actual_payment_amount',
width: 150,
render: (_) => (<MoneyFormat money={_}/>),
render: (_,record) => (<MoneyFormat money={_} currency={record.currency}/>),
},
{
title: t('bill.title_pay_method'),

View File

@ -2,11 +2,37 @@ import React from "react";
type MoneyFormatProps = {
money?: number | string | null;
currency?: 'US$' | 'HK$' | 'RMB';
currency?: string;
}
const AsiaPayCurrencyConfig: {
[key: string]: string
} = {
'344': 'HKD',
'840': 'USD',
"702": 'SGD',
"156": 'CNY(RMB)',
"392": 'JPY',
"901": 'TWD',
"036": 'AUD',
"978": 'EUR',
"826": 'GBP',
"124": 'CAD',
"446": 'MOP',
"608": 'PHP',
"764": 'THB',
"458": 'MYR',
"360": 'IDR',
"410": 'KRW',
"682": 'SAR',
"554": 'NZD',
"784": 'AED',
"096": 'BND',
"704": 'VND',
"356": 'INR',
}
function formatCurrency(amount: string | number) {
if(amount === '0' || amount === '0.00') {
function formatMoneyNumber(amount: string | number) {
if (amount === '0' || amount === '0.00') {
return '0.00';
}
// 将金额转换为字符串,并限制小数点后两位
@ -25,8 +51,16 @@ function formatCurrency(amount: string | number) {
return (isNegative ? '-' : '') + formattedIntPart + '.' + decimalPart;
}
const MoneyFormat: React.FC<MoneyFormatProps> = ({money, currency = 'HK$'}) => {
const formatCurrency = (currency = 'HKD') => {
if (currency && /^\d{3}$/.test(currency)) {
return AsiaPayCurrencyConfig[currency] || currency || 'HKD';
}
return currency || 'HKD';
}
const MoneyFormat: React.FC<MoneyFormatProps> = ({money, currency = 'HKD'}) => {
// 将货币数字转换为千分位格式且带2位小数
return (money||money==0||money=='0') ?<span className={'money-format'}>{currency} {formatCurrency(money)}</span>:null;
return (money || money == 0 || money == '0') ?
<span className={'money-format'}>{formatCurrency(currency)} {formatMoneyNumber(money)}</span> : null;
}
export default MoneyFormat;

2
src/types/bill.d.ts vendored
View File

@ -52,7 +52,7 @@ declare type BillModel = {
payment_amount?: number;
actual_payment_amount?: null | number;
payment_method?: null | string | number;
currency?: null | string | number;
currency?: string;
payment_channel?: null | string | number;
expiration_time?: BaseDate;
status: string;