import { useEffect, useState } from 'react'; import { WalletCards } from 'lucide-react'; import { MoneyText, Pagination, Tag } from '@/components/ui'; import { clientApi, type RechargeOrder } from '@/api/adminApi'; import { formatCents } from '@/utils/currency'; import { formatDateTime } from '@/utils/dateTime'; export function ClientBillingPage() { const [balanceCents, setBalanceCents] = useState(0); const [creditCents, setCreditCents] = useState(0); const [orders, setOrders] = useState([]); const [page, setPage] = useState(1); const [loading, setLoading] = useState(true); const [error, setError] = useState(''); const [total, setTotal] = useState(0); const pageSize = 10; const totalPages = Math.max(1, Math.ceil(total / pageSize)); const currentPage = Math.min(page, totalPages); const visibleOrders = orders; useEffect(() => { setLoading(true); Promise.all([clientApi.getDashboard(), clientApi.listOrdersPage({ page, pageSize })]) .then(([dashboard, result]) => { setBalanceCents(dashboard.accounts[0]?.balanceCents ?? 0); setCreditCents(dashboard.accounts[0]?.creditCents ?? 0); setOrders(result.items); setTotal(result.total); setError(''); }) .catch((reason: Error) => setError(reason.message || '账户信息加载失败')) .finally(() => setLoading(false)); }, [page]); return (

账户余额

现金余额¥{formatCents(balanceCents)}充值和扣费后的账面余额。
可用发送额度¥{formatCents(balanceCents + creditCents)}大于 0 时可以发送短信。

充值记录

如需充值,请联系平台运营人员。

{total} 条
{loading ?

正在加载账户信息...

: null} {error ?

{error}

: null} {!loading && !error ? (
{visibleOrders.length === 0 ? : visibleOrders.map((order) => ( ))}
订单号充值时间充值金额状态备注
暂无充值记录
{order.orderNo} {formatDateTime(order.paidAt ?? order.createdAt)} ¥{formatCents(order.amountCents)} {order.status === 'paid' ? '已入账' : order.status} {order.remark || '-'}
) : null} = totalPages} onNext={() => setPage((value) => Math.min(totalPages, value + 1))} onPrevious={() => setPage((value) => Math.max(1, value - 1))} page={currentPage} totalPages={totalPages} onPageChange={setPage} previousDisabled={currentPage <= 1} total={total} />
); }