import React, { useState, useCallback, useMemo, useEffect } from 'react'; import { Button, Table, Thead, Tbody, Tr, Th, Td, TableContainer, Flex, Box, ModalBody } from '@chakra-ui/react'; import { getBills, checkBalancePayResult } from '@/web/support/wallet/bill/api'; import type { BillSchemaType } from '@fastgpt/global/support/wallet/bill/type.d'; import dayjs from 'dayjs'; import { formatStorePrice2Read } from '@fastgpt/global/support/wallet/usage/tools'; import { useToast } from '@fastgpt/web/hooks/useToast'; import MyIcon from '@fastgpt/web/components/common/Icon'; import { useTranslation } from 'next-i18next'; import { BillTypeEnum, billPayWayMap, billStatusMap, billTypeMap } from '@fastgpt/global/support/wallet/bill/constants'; // import { usePagination } from '@/web/common/hooks/usePagination'; import MyBox from '@fastgpt/web/components/common/MyBox'; import { useRequest } from '@fastgpt/web/hooks/useRequest'; import { standardSubLevelMap, subModeMap } from '@fastgpt/global/support/wallet/sub/constants'; import MySelect from '@fastgpt/web/components/common/MySelect'; import MyModal from '@fastgpt/web/components/common/MyModal'; import { usePagination } from '@fastgpt/web/hooks/usePagination'; import FormLabel from '@fastgpt/web/components/common/MyBox/FormLabel'; const BillTable = () => { const { t } = useTranslation(); const { toast } = useToast(); const [billType, setBillType] = useState(''); const [billDetail, setBillDetail] = useState(); const billTypeList = useMemo( () => [ { label: t('common:common.All'), value: '' }, ...Object.entries(billTypeMap).map(([key, value]) => ({ label: t(value.label), value: key })) ] as { label: string; value: BillTypeEnum | ''; }[], [t] ); const { data: bills, isLoading, Pagination, getData, total } = usePagination({ api: getBills, pageSize: 20, params: { type: billType }, defaultRequest: false }); const { mutate: handleRefreshPayOrder, isLoading: isRefreshing } = useRequest({ mutationFn: async (payId: string) => { try { const data = await checkBalancePayResult(payId); toast({ title: data, status: 'success' }); } catch (error: any) { toast({ title: error?.message, status: 'warning' }); console.log(error); } try { getData(1); } catch (error) {} } }); useEffect(() => { getData(1); }, [billType]); return ( {bills.map((item, i) => ( ))}
# list={billTypeList} value={billType} size={'sm'} onchange={(e) => { setBillType(e); }} w={'130px'} > {t('common:user.Time')} {t('common:support.wallet.Amount')} {t('common:support.wallet.bill.Status')}
{i + 1} {t(billTypeMap[item.type]?.label)} {item.createTime ? dayjs(item.createTime).format('YYYY/MM/DD HH:mm:ss') : '-'} {formatStorePrice2Read(item.price)}元 {t(billStatusMap[item.status]?.label)} {item.status === 'NOTPAY' && ( )}
{total >= 20 && ( )} {!isLoading && bills.length === 0 && ( {t('common:support.wallet.noBill')} )}
{!!billDetail && ( setBillDetail(undefined)} /> )}
); }; export default BillTable; function BillDetailModal({ bill, onClose }: { bill: BillSchemaType; onClose: () => void }) { const { t } = useTranslation(); return ( {t('common:support.wallet.bill.Number')}: {bill.orderId} {t('common:support.wallet.usage.Time')}: {dayjs(bill.createTime).format('YYYY/MM/DD HH:mm:ss')} {t('common:support.wallet.bill.Status')}: {t(billStatusMap[bill.status]?.label)} {!!bill.metadata?.payWay && ( {t('common:support.wallet.bill.payWay.Way')}: {t(billPayWayMap[bill.metadata.payWay]?.label)} )} {t('common:support.wallet.Amount')}: {formatStorePrice2Read(bill.price)}元 {t('common:support.wallet.bill.Type')}: {t(billTypeMap[bill.type]?.label)} {!!bill.metadata?.subMode && ( {t('common:support.wallet.subscription.mode.Period')}: {t(subModeMap[bill.metadata.subMode]?.label)} )} {!!bill.metadata?.standSubLevel && ( {t('common:support.wallet.subscription.Stand plan level')}: {t(standardSubLevelMap[bill.metadata.standSubLevel]?.label)} )} {bill.metadata?.month !== undefined && ( {t('common:support.wallet.subscription.Month amount')}: {bill.metadata?.month} )} {bill.metadata?.datasetSize !== undefined && ( {t('common:support.wallet.subscription.Extra dataset size')}: {bill.metadata?.datasetSize} )} {bill.metadata?.extraPoints !== undefined && ( {t('common:support.wallet.subscription.Extra ai points')}: {bill.metadata.extraPoints} )} ); }