Files
monkey-ai-web/src/pages/Organization/OrgRecharge.jsx
T
qiubaishen 870b51d054 feat: 同步权限管理、企业成员排行与消费计费明细
- 接入平台与企业角色权限,按权限展示菜单、页面及操作。
- 企业成员排行按需加载,翻页沿用同一榜单快照,保留连续名次与前三名样式。
- 更新消费日志的费用明细、超管指标和官方价格汇率设置,补齐翻译与回归测试。
2026-11-25 21:08:24 +08:00

901 lines
32 KiB
React
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { I18N_TECHNICAL_TEXT } from '../../i18n/technicalText.js';
import { formatNumber } from '../../helpers/safeDisplay';
import { Check as ActionCheck } from '@/components/common/icons/ActionIcons';
import React, { useEffect, useState, useCallback, useMemo } from 'react';
import { timestamp2string } from '../../helpers/utils';
import { useTranslation } from 'react-i18next';
import { useThrottledCallback } from 'use-debounce';
import { Typography, Button, Spin, Table, Tag, Select } from '@/components/ui';
import { CheckCircle, Clock, XCircle } from 'lucide-react';
import { Button as AntButton, Input as AntInput } from 'antd';
import {
MAX_CUSTOM_AMOUNT,
normalizeCustomAmount,
} from './customRechargeAmount';
import {
API,
showError,
showInfo,
showSuccess,
renderQuota,
getQuotaPerUnit,
} from '../../helpers';
import AmountCard from '../Recharge/AmountCard';
import usePayPalQuote from '../../hooks/common/usePayPalQuote';
import WechatQRModal from '../../components/topup/modals/WechatQRModal';
import PaymentConfirmModal from '../../components/topup/modals/PaymentConfirmModal';
import OrgPageHeader from './components/OrgPageHeader';
import '../../styles/org-center.css';
import { orgStatusColor } from './components/orgStatus';
import { usePerm } from '../../authz';
import {
formatPayPalUSD,
getPayPalReturnState,
parsePayPalQuote,
requestPayPalOrder,
removePayPalReturnState,
} from '../../helpers/paypalPayment';
const { Text } = Typography;
const OrgRecharge = ({ orgId }) => {
const { t } = useTranslation();
// 发起充值:本页仅管理员可进(路由守卫),旧判断恒为可操作;已切新体系按 org.recharge.pay 判断
const canPay = usePerm('org.recharge.pay', true);
// 企业信息
const [orgQuota, setOrgQuota] = useState(0);
const [orgGiftQuota, setOrgGiftQuota] = useState(0);
const [orgUsedQuota, setOrgUsedQuota] = useState(0);
// 充值配置
const [presetAmounts, setPresetAmounts] = useState([]);
const [payMethods, setPayMethods] = useState([]);
const [enableWechatTopUp, setEnableWechatTopUp] = useState(false);
const [enableAlipayTopUp, setEnableAlipayTopUp] = useState(false);
const [enablePayPalTopUp, setEnablePayPalTopUp] = useState(false);
const [infoLoading, setInfoLoading] = useState(true);
// 充值交互状态
const [selectedPreset, setSelectedPreset] = useState(null);
const [selectedPresetObj, setSelectedPresetObj] = useState(null);
const [payWay, setPayWay] = useState('');
const [confirmOpen, setConfirmOpen] = useState(false);
const [confirmLoading, setConfirmLoading] = useState(false);
const [amountLoading, setAmountLoading] = useState(false);
// 自定义充值(与预设档位互斥;自定义金额无折扣,原价到账)
const [isCustomMode, setIsCustomMode] = useState(false);
const [customAmount, setCustomAmount] = useState(null);
const [customAmountExceeded, setCustomAmountExceeded] = useState(false);
// Clamp the amount immediately; throttle feedback so payment state never lags.
const reportCustomAmountExceeded = useThrottledCallback(
() => setCustomAmountExceeded(true),
200,
{ leading: false, trailing: true },
);
const clearCustomAmountError = () => {
reportCustomAmountExceeded.cancel();
setCustomAmountExceeded(false);
};
const [customUnit, setCustomUnit] = useState(1000); // 1000=千 / 10000=万
const customEffectiveAmount = useMemo(() => {
if (!customAmount || customAmount < 1) return 0;
return Math.floor(Number(customAmount)) * customUnit;
}, [customAmount, customUnit]);
const customValid =
Number.isInteger(customAmount) &&
customAmount >= 1 &&
customAmount <= MAX_CUSTOM_AMOUNT &&
customEffectiveAmount >= 1000;
// 当前生效的金额/折扣/赠送(自定义优先)
const effectiveAmountYuan = isCustomMode
? customEffectiveAmount
: selectedPresetObj?.value || 0;
const effectiveDiscount = isCustomMode
? 1.0
: selectedPresetObj?.discount || 1.0;
const effectiveBonus = isCustomMode ? 0 : selectedPresetObj?.bonus || 0;
const {
quote: payPalQuote,
setQuote: setPayPalQuote,
loading: quoteLoading,
refresh: refreshPayPalQuote,
} = usePayPalQuote(
'/api/org/topup/paypal/amount',
isCustomMode
? { custom_amount: customEffectiveAmount }
: { amount_option_id: selectedPresetObj?.id },
payWay === 'paypal' &&
effectiveAmountYuan > 0 &&
(!isCustomMode || customValid),
orgId,
);
// 微信二维码
const [wechatQRVisible, setWechatQRVisible] = useState(false);
const [wechatOrderData, setWechatOrderData] = useState(null);
// 充值记录
const [history, setHistory] = useState([]);
const [historyTotal, setHistoryTotal] = useState(0);
const [historyPage, setHistoryPage] = useState(1);
const [historyPageSize, setHistoryPageSize] = useState(10);
const [historyLoading, setHistoryLoading] = useState(false);
const [refreshHistory, setRefreshHistory] = useState(0);
const orgHeaders = useMemo(() => ({ 'X-Org-Id': String(orgId) }), [orgId]);
// 获取企业配额
const fetchOrgQuota = useCallback(async () => {
try {
const res = await API.get('/api/org/quota', { headers: orgHeaders });
if (res.data.success) {
const { quota, gift_quota, used_quota } = res.data.data;
setOrgQuota(quota || 0);
setOrgGiftQuota(gift_quota || 0);
setOrgUsedQuota(used_quota || 0);
}
} catch (e) {
// ignore
}
}, [orgHeaders]);
// 获取充值配置
const fetchTopUpInfo = useCallback(async () => {
setInfoLoading(true);
try {
const res = await API.get('/api/org/topup/info', { headers: orgHeaders });
if (res.data.success) {
const data = res.data.data;
setEnableWechatTopUp(data.enable_wechat_topup || false);
setEnableAlipayTopUp(data.enable_alipay_topup || false);
setEnablePayPalTopUp(data.enable_paypal_topup || false);
setPayMethods(data.pay_methods || []);
if (data.amount_options_v2 && data.amount_options_v2.length > 0) {
const sorted = [...data.amount_options_v2].sort(
(a, b) => (a.sort || 0) - (b.sort || 0),
);
setPresetAmounts(
sorted.map((opt) => ({
id: opt.id,
value: opt.amount,
discount: opt.discount || 1.0,
label: opt.label,
badge: opt.badge,
badgeColor: opt.badge_color,
isRecommend: opt.is_recommend,
isHot: opt.is_hot,
bonus: opt.bonus,
minVipLevel: opt.min_vip_level,
})),
);
}
}
} catch (e) {
showError(t('获取充值配置失败'));
} finally {
setInfoLoading(false);
}
}, [orgHeaders, t]);
// 获取充值记录
const fetchHistory = useCallback(
async (page = 1) => {
setHistoryLoading(true);
try {
const res = await API.get(
`/api/org/topup?p=${page}&page_size=${historyPageSize}`,
{
headers: orgHeaders,
},
);
if (res.data.success) {
const data = res.data.data;
setHistory(data.items || []);
setHistoryTotal(data.total || 0);
} else {
showError(res.data.message);
}
} catch (e) {
showError(e.message);
} finally {
setHistoryLoading(false);
}
},
[historyPageSize, orgHeaders],
);
useEffect(() => {
fetchOrgQuota();
fetchTopUpInfo();
}, [fetchOrgQuota, fetchTopUpInfo]);
useEffect(() => {
fetchHistory(historyPage);
}, [fetchHistory, historyPage, refreshHistory]);
useEffect(() => {
const result = getPayPalReturnState(window.location.search);
if (!result) return;
if (result.status === 'success') showSuccess(t('PayPal 充值成功'));
else if (result.status === 'pending')
showInfo(t('PayPal 支付处理中,请稍后查看充值记录'));
else if (result.status === 'cancelled') showInfo(t('已取消 PayPal 支付'));
else showError(t('PayPal 支付确认失败,请稍后重试'));
fetchOrgQuota();
setRefreshHistory((previous) => previous + 1);
window.history.replaceState(
{},
'',
removePayPalReturnState(window.location.href),
);
// The callback query must be consumed exactly once on page entry.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
const selectPreset = (preset) => {
clearCustomAmountError();
setSelectedPreset(preset.id);
setSelectedPresetObj(preset);
setIsCustomMode(false);
setCustomAmount(null);
};
const handleCustomAmountChange = (v) => {
const result = normalizeCustomAmount(v);
if (!result) return;
if (result.exceeded) {
reportCustomAmountExceeded();
} else {
clearCustomAmountError();
}
setCustomAmount(result.value);
if (result.value) {
setIsCustomMode(true);
setSelectedPreset(null);
setSelectedPresetObj(null);
} else {
setIsCustomMode(false);
}
};
const handleCustomUnitChange = (v) => {
setCustomUnit(v);
if (customAmount && Number(customAmount) > 0) {
setIsCustomMode(true);
setSelectedPreset(null);
setSelectedPresetObj(null);
}
};
// 自定义充值快速选择档位
const customQuickPicks = [
{ amount: 1, unit: 1000 },
{ amount: 5, unit: 1000 },
{ amount: 1, unit: 10000 },
{ amount: 5, unit: 10000 },
{ amount: 10, unit: 10000 },
];
const applyCustomQuickPick = (amount, unit) => {
clearCustomAmountError();
setCustomAmount(amount);
setCustomUnit(unit);
setIsCustomMode(true);
setSelectedPreset(null);
setSelectedPresetObj(null);
};
// 自定义充值预览额度(与后端 service.CalculateQuota 一致:originalMoney * QuotaPerUnit + bonus,自定义 bonus=0)
const customPreviewQuota =
customEffectiveAmount > 0
? customEffectiveAmount * (getQuotaPerUnit() || 500000)
: 0;
const handlePreTopUp = async (paymentType) => {
if (isCustomMode) {
if (!customValid) {
showError(t('自定义充值金额最少为 1000 元'));
return;
}
} else if (!selectedPresetObj) {
showError(t('请先选择充值金额'));
return;
}
setPayWay(paymentType);
if (paymentType === 'paypal') {
if (!enablePayPalTopUp) {
showError(t('管理员未开启 PayPal 充值!'));
return;
}
setAmountLoading(true);
try {
if (!(await refreshPayPalQuote())) return;
} catch (error) {
showError(error?.message || t('获取金额失败'));
return;
} finally {
setAmountLoading(false);
}
}
setConfirmOpen(true);
};
const buildPayBody = () =>
isCustomMode
? { custom_amount: customEffectiveAmount }
: { amount_option_id: selectedPresetObj.id };
const isMobile = /iPhone|Android|iPad|Mobile/i.test(navigator.userAgent);
const handleConfirmPay = async () => {
if (!isCustomMode && !selectedPresetObj) return;
if (isCustomMode && !customValid) return;
setConfirmLoading(true);
try {
let res;
const payBody = buildPayBody();
if (payWay === 'wxpay' && enableWechatTopUp) {
const wechatEndpoint = isMobile
? '/api/org/topup/wechat/h5'
: '/api/org/topup/wechat/native';
res = await API.post(wechatEndpoint, payBody, { headers: orgHeaders });
if (res.data.success) {
if (isMobile) {
// H5:直接跳转微信支付页
window.location.href = res.data.data.h5_url;
setConfirmOpen(false);
const onFocus = () => {
fetchOrgQuota();
setRefreshHistory((p) => p + 1);
window.removeEventListener('focus', onFocus);
};
window.addEventListener('focus', onFocus);
} else {
// Native:弹出二维码
setWechatOrderData(res.data.data);
setConfirmOpen(false);
setWechatQRVisible(true);
}
return;
}
} else if (payWay === 'paypal' && enablePayPalTopUp) {
res = await requestPayPalOrder(
API,
'/api/org/topup/paypal',
{ ...payBody, quote_token: payPalQuote?.quoteToken },
{ headers: orgHeaders, skipErrorHandler: true },
);
if (res.data.success && res.data.data?.approval_url) {
setPayPalQuote(parsePayPalQuote(res));
window.location.href = res.data.data.approval_url;
return;
}
if (
res.status === 202 &&
res.data?.message === 'PAYPAL_ORDER_CREATING'
) {
showInfo(t('PayPal 订单创建中,请稍后重试'));
return;
}
} else if (payWay === 'alipay' && enableAlipayTopUp) {
const alipayEndpoint = isMobile
? '/api/org/topup/alipay/wap'
: '/api/org/topup/alipay/pc';
res = await API.post(alipayEndpoint, payBody, { headers: orgHeaders });
if (res.data.success) {
// Safari 会拦截 await 之后的 window.open(用户手势已过期),改为同标签跳转
const isSafari =
navigator.userAgent.indexOf('Safari') > -1 &&
navigator.userAgent.indexOf('Chrome') < 1;
if (isSafari) {
window.location.href = res.data.data.pay_url;
return;
}
window.open(res.data.data.pay_url, '_blank');
setConfirmOpen(false);
// 用户从支付宝标签页切回时自动刷新余额和记录
const onFocus = () => {
fetchOrgQuota();
setRefreshHistory((p) => p + 1);
window.removeEventListener('focus', onFocus);
};
window.addEventListener('focus', onFocus);
return;
}
}
// 失败处理
const msg = res?.data?.message || t('支付请求失败');
showError(msg);
} catch (e) {
const code = e?.response?.data?.message;
if (payWay === 'paypal' && code?.startsWith('PAYPAL_QUOTE_')) {
try {
const response = await API.post(
'/api/org/topup/paypal/amount',
buildPayBody(),
{ headers: orgHeaders },
);
if (!response.data.success) throw new Error(response.data.message);
setPayPalQuote(parsePayPalQuote(response));
showInfo(t('PayPal 报价已更新,请重新确认'));
} catch {
showError(t('获取金额失败'));
}
} else {
showError(e?.response?.data?.message || t('支付请求失败'));
}
} finally {
setConfirmLoading(false);
}
};
const handleWechatComplete = (success) => {
setWechatQRVisible(false);
setWechatOrderData(null);
if (success) {
showSuccess(t('充值成功!'));
fetchOrgQuota();
setRefreshHistory((p) => p + 1);
}
};
const renderAmount = () => {
if (payWay === 'paypal') {
return formatPayPalUSD(payPalQuote?.payAmount);
}
if (effectiveAmountYuan <= 0) return '';
const pay = effectiveAmountYuan * effectiveDiscount;
return `${formatNumber(pay, 2, '0.00')} ${t('元')}`;
};
// 充值记录状态渲染
const renderStatus = (status) => {
const map = {
success: {
icon: <CheckCircle size={12} />,
text: t('成功'),
},
pending: {
icon: <Clock size={12} />,
text: t('待支付'),
},
expired: { icon: <XCircle size={12} />, text: t('已过期') },
};
const s = map[status] || { icon: null, text: status };
return (
<Tag
color={orgStatusColor(status)}
bordered={false}
className='oc-recharge-status'
>
{s.icon}
{s.text}
</Tag>
);
};
const historyColumns = [
{
title: t('订单号'),
dataIndex: 'trade_no',
width: 320,
ellipsis: true,
render: (v) => <span className='oc-rc-order-id'>{v}</span>,
},
{
title: t('金额'),
dataIndex: 'money',
width: 140,
render: (v) => `¥${formatNumber(v, 2, '0.00')}`,
},
{
title: t('获得额度'),
dataIndex: 'amount',
width: 140,
render: (v) => renderQuota(v),
},
{
title: t('支付方式'),
dataIndex: 'payment_channel',
width: 120,
render: (v) => (v === 'paypal_checkout' ? 'PayPal' : v || '-'),
},
{
title: t('状态'),
dataIndex: 'status',
width: 110,
render: (v) => renderStatus(v),
},
{
title: t('时间'),
dataIndex: 'create_time',
width: 190,
render: (v) => timestamp2string(v),
},
];
const hasAnyPayment =
enableWechatTopUp || enableAlipayTopUp || enablePayPalTopUp;
// 充值订单卡(原型 .rp-checkout):展示当前选择的到账额度 / 支付方式 / 应付金额;
// “立即充值”与点击支付方式相同,进入原有 handlePreTopUp 预充值校验与确认弹窗
const selectedMethod = payMethods.find((m) => m.type === payWay);
const quotaPerUnit = getQuotaPerUnit() || 500000;
// 到账额度:自定义沿用原实时预览 customPreviewQuota;档位与确认弹窗 renderQuotaWithAmount 同口径
const arrivalQuota =
effectiveAmountYuan <= 0
? '-'
: isCustomMode
? renderQuota(customPreviewQuota)
: renderQuota(effectiveAmountYuan * quotaPerUnit + effectiveBonus);
const payableYuan = effectiveAmountYuan * effectiveDiscount;
const payableValue =
payWay === 'paypal' ? payPalQuote?.payAmount : payableYuan;
const canCheckout =
effectiveAmountYuan > 0 &&
(!isCustomMode || customValid) &&
Boolean(selectedMethod) &&
!amountLoading &&
!quoteLoading &&
(payWay !== 'paypal' || Boolean(payPalQuote));
const customInvalid = customEffectiveAmount > 0 && !customValid;
const renderPayIcon = (type) =>
type === 'wxpay' ? (
<i className='oc-pay-dot' aria-hidden='true' />
) : type === 'paypal' ? (
<strong className='oc-pay-pal' aria-hidden='true'>
P
</strong>
) : null;
return (
<div className='uc-page oc-page oc-recharge'>
<OrgPageHeader title={t('企业充值')} subtitle={t('为企业账户充值额度')} />
<div className='oc-rc-layout'>
{/* 企业钱包(原型 .rlc-account-rail) */}
<aside className='oc-rc-rail'>
<h2>{t('企业钱包')}</h2>
<div className='oc-rc-rule' />
<div className='oc-rc-account'>
<div>
<span>{t('企业可用余额')}</span>
{/* 企业总剩余含赠送钱包,与预算中心「部门资金」口径一致 */}
<strong className='oc-rc-balance'>
{renderQuota(orgQuota + orgGiftQuota)}
</strong>
{orgGiftQuota > 0 && (
<span>
{t('主池 {{main}} · 赠送 {{gift}}', {
main: renderQuota(orgQuota),
gift: renderQuota(orgGiftQuota),
})}
</span>
)}
</div>
<div>
<span>{t('累计消耗')}</span>
<strong>{renderQuota(orgUsedQuota)}</strong>
</div>
</div>
<div className='oc-rc-rail-foot'>
<i aria-hidden='true' />
<span>{t('余额用于模型调用')}</span>
</div>
</aside>
{/* 充值工作区(原型 .rlc-workspace);无发起充值权限时只看余额与记录 */}
{canPay && (
<section className='oc-rc-workspace'>
<header className='oc-rc-workspace-head'>
<h2>{t('为下一次调用补充能量')}</h2>
<p>{t('为企业账户补充额度,支持团队持续调用模型。')}</p>
</header>
{infoLoading ? (
<div className='oc-rc-loading'>
<Spin />
</div>
) : presetAmounts.length > 0 ? (
<div className='oc-rc-purchase'>
<div className='oc-rc-content'>
<div className='oc-rc-section-heading'>
<h3>{t('选择充值额度')}</h3>
<p>{t('为企业账户充值,额度用于团队模型调用。')}</p>
</div>
<div className='oc-rc-amount-grid'>
{presetAmounts.map((preset, idx) => (
<AmountCard
key={idx}
preset={preset}
selected={selectedPreset === preset.id}
onClick={() => selectPreset(preset)}
topupInfo={{ amount_options: [], discount: {} }}
priceRatio={1}
t={t}
/>
))}
</div>
{/* 自定义充值(与档位互斥;自定义金额无折扣,原价到账) */}
<div
className={`oc-rc-custom${isCustomMode ? ' selected' : ''}`}
>
<h3>
{t('自定义充值')}
{isCustomMode && (
<Tag color='green' bordered={false}>
{t('已选')}
</Tag>
)}
</h3>
<div className='oc-rc-custom-input'>
<div className='oc-rc-custom-field'>
<AntInput
value={customAmount ?? ''}
onChange={(event) =>
handleCustomAmountChange(event.target.value)
}
inputMode='numeric'
pattern='[0-9]*'
placeholder={t('请输入整数,如 1、5、10')}
status={
customAmountExceeded || customInvalid
? 'error'
: undefined
}
aria-invalid={customAmountExceeded || customInvalid}
aria-describedby='org-recharge-custom-amount-error'
style={{ width: '100%' }}
/>
<div
className='oc-rc-custom-feedback'
aria-live='polite'
>
<span
id='org-recharge-custom-amount-error'
className={
customAmountExceeded ? undefined : 'is-hidden'
}
aria-hidden={!customAmountExceeded}
>
<Text type='danger'>
{t('输入数量不能超过 10000,已自动调整为 10000')}
</Text>
</span>
</div>
</div>
<Select
value={customUnit}
onChange={handleCustomUnitChange}
optionList={[
{ label: t('千'), value: 1000 },
{ label: t('万'), value: 10000 },
]}
/>
</div>
<div className='oc-rc-quick'>
<span>{t('快速选择:')}</span>
{customQuickPicks.map((pick) => {
const active =
isCustomMode &&
Number(customAmount) === pick.amount &&
customUnit === pick.unit;
return (
<AntButton
key={`${pick.amount}-${pick.unit}`}
size='small'
aria-pressed={active}
className={active ? 'is-active' : ''}
onClick={() =>
applyCustomQuickPick(pick.amount, pick.unit)
}
>
{`${pick.amount}${pick.unit === 1000 ? t('千') : t('万')}`}
</AntButton>
);
})}
</div>
{/* 底部说明(金额不达标时变为错误提示) */}
<p
className={customInvalid ? 'oc-rc-error' : ''}
role={customInvalid ? 'alert' : undefined}
>
{customInvalid
? t('当前 ¥{{amount}},未达到最低 ¥1,000', {
amount: customEffectiveAmount.toLocaleString(),
})
: `${t('最少 1000 元,必须为 1000 元的整倍数')};${t('原价到账,不参与折扣')}`}
</p>
</div>
{/* 支付方式(点击沿用 handlePreTopUp:校验后进入确认弹窗) */}
<div className='oc-rc-pay'>
<h3>{t('支付方式')}</h3>
{hasAnyPayment ? (
<div className='oc-rc-pay-methods'>
{payMethods.map((method) => {
const isWechat = method.type === 'wxpay';
const isAlipay = method.type === 'alipay';
const isPayPal = method.type === 'paypal';
const disabled =
(isWechat && !enableWechatTopUp) ||
(isAlipay && !enableAlipayTopUp) ||
(isPayPal && !enablePayPalTopUp);
const selected = payWay === method.type;
return (
<AntButton
key={method.type}
disabled={disabled}
loading={amountLoading && selected}
aria-pressed={selected}
icon={renderPayIcon(method.type)}
className={`oc-rc-pay-method${selected ? ' is-selected' : ''}`}
onClick={() => handlePreTopUp(method.type)}
>
{method.name}
{selected && <ActionCheck size={14} />}
</AntButton>
);
})}
</div>
) : (
<p className='oc-rc-pay-empty'>
{t('暂无可用的支付方式,请联系管理员配置')}
</p>
)}
</div>
</div>
{/* 企业充值订单(原型 .rlc-checkout-card) */}
<aside className='oc-rc-checkout'>
<h3>{t('企业充值订单')}</h3>
<dl>
<div>
<dt>{t('到账额度')}</dt>
<dd>{arrivalQuota}</dd>
</div>
<div>
<dt>{t('优惠金额')}</dt>
<dd>
¥
{formatNumber(
effectiveAmountYuan - payableYuan,
2,
'0.00',
)}
</dd>
</div>
<div>
<dt>{t('支付方式')}</dt>
<dd>{selectedMethod?.name || '-'}</dd>
</div>
{payWay === 'paypal' && payPalQuote && (
<div>
<dt>{t('支付服务费')}</dt>
<dd>{formatPayPalUSD(payPalQuote.serviceFee)}</dd>
</div>
)}
</dl>
<div className='oc-rc-payable'>
<span>{t('应付金额')}</span>
<strong>
{payableValue > 0 ? (
<>
<span>{payWay === 'paypal' ? '$' : '¥'}</span>
<b>
{payableValue.toLocaleString('en-US', {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
})}
</b>
{payWay === 'paypal' && (
<span> {I18N_TECHNICAL_TEXT.USD}</span>
)}
</>
) : (
'-'
)}
</strong>
</div>
<Button
type='primary'
size='large'
block
disabled={!canCheckout}
loading={amountLoading || quoteLoading}
onClick={() => handlePreTopUp(payWay)}
>
{t('立即充值')}
</Button>
</aside>
</div>
) : (
<p className='oc-rc-pay-empty'>
{t('暂无充值档位,请联系管理员配置')}
</p>
)}
</section>
)}
</div>
{/* 充值记录(原型 .rlc-history) */}
<section className='oc-rc-history' aria-label={t('充值记录')}>
<Table
rowKey={(record) => record.id ?? record.trade_no}
columns={historyColumns}
dataSource={history}
loading={historyLoading}
scroll={{ x: 900 }}
pagination={{
currentPage: historyPage,
total: historyTotal,
pageSize: historyPageSize,
onPageChange: setHistoryPage,
onPageSizeChange: (size) => {
setHistoryPage(1);
setHistoryPageSize(size);
},
showTotal: (n) => t('共 {{total}} 条', { total: n }),
}}
empty={<Text type='tertiary'>{t('暂无充值记录')}</Text>}
/>
</section>
{/* 支付确认弹窗 */}
<PaymentConfirmModal
t={t}
open={confirmOpen}
onlineTopUp={handleConfirmPay}
handleCancel={() => setConfirmOpen(false)}
confirmLoading={confirmLoading}
topUpCount={effectiveAmountYuan}
renderQuotaWithAmount={() => {
if (payWay === 'paypal' && payPalQuote?.quota) {
return renderQuota(payPalQuote.quota);
}
if (effectiveAmountYuan <= 0) return renderQuota(0);
// 额度 = 原始金额 × QuotaPerUnit + 赠送额度(与后端 CalculateQuota 逻辑一致,折扣只影响实付金额,不影响获得的额度)
const quotaPerUnit = getQuotaPerUnit() || 500000;
const baseQuota = effectiveAmountYuan * quotaPerUnit;
return renderQuota(baseQuota + effectiveBonus);
}}
amountLoading={amountLoading || quoteLoading}
renderAmount={renderAmount}
payWay={payWay}
payMethods={payMethods}
amountNumber={
payWay === 'paypal' ? 0 : effectiveAmountYuan * effectiveDiscount
}
discountRate={payWay === 'paypal' ? 1 : effectiveDiscount}
payPalQuote={payPalQuote}
/>
{/* 微信二维码弹窗 */}
<WechatQRModal
visible={wechatQRVisible}
onClose={handleWechatComplete}
orderData={wechatOrderData}
pollFn={async (tradeNo) => {
const res = await API.get(
`/api/org/topup?p=1&page_size=1&keyword=${tradeNo}`,
{ headers: orgHeaders },
);
const items = res.data.data?.items || [];
return items.length > 0 ? items[0] : null;
}}
/>
</div>
);
};
export default OrgRecharge;