import { Box, Flex, Grid, Button, VStack } from '@chakra-ui/react'; import { useTranslation } from 'next-i18next'; import React, { useCallback, useState } from 'react'; import { useSystemStore } from '@/web/common/system/useSystemStore'; import MyIcon from '@fastgpt/web/components/common/Icon'; import { useForm } from 'react-hook-form'; import { useToast } from '@fastgpt/web/hooks/useToast'; import { getErrText } from '@fastgpt/global/common/error/utils'; import { getWxPayQRCode } from '@/web/support/wallet/bill/api'; import { BillTypeEnum } from '@fastgpt/global/support/wallet/bill/constants'; import QRCodePayModal, { type QRPayProps } from '@/components/support/wallet/QRCodePayModal'; import MyNumberInput from '@fastgpt/web/components/common/Input/NumberInput'; const ExtraPlan = ({ onPaySuccess }: { onPaySuccess?: () => void }) => { const { t } = useTranslation(); const { toast } = useToast(); const { subPlans } = useSystemStore(); const [loading, setLoading] = useState(false); const [qrPayData, setQRPayData] = useState(); // extra dataset const extraDatasetPrice = subPlans?.extraDatasetSize?.price || 0; const { register: registerDatasetSize, handleSubmit: handleSubmitDatasetSize } = useForm({ defaultValues: { datasetSize: 0, month: 1 } }); const onclickBuyDatasetSize = useCallback( async ({ datasetSize, month }: { datasetSize: number; month: number }) => { try { datasetSize = Math.ceil(datasetSize); month = Math.ceil(month); const datasetSizePayAmount = datasetSize * month * extraDatasetPrice; if (datasetSizePayAmount === 0) { return toast({ status: 'warning', title: t('common:support.wallet.amount_0') }); } setLoading(true); const res = await getWxPayQRCode({ type: BillTypeEnum.extraDatasetSub, month, extraDatasetSize: datasetSize }); setQRPayData({ readPrice: res.readPrice, codeUrl: res.codeUrl, billId: res.billId }); } catch (err) { toast({ title: getErrText(err), status: 'error' }); } setLoading(false); }, [extraDatasetPrice, toast] ); // extra ai points const extraPointsPrice = subPlans?.extraPoints?.price || 0; const { register: registerExtraPoints, handleSubmit: handleSubmitExtraPoints } = useForm({ defaultValues: { points: 0, month: 1 } }); const onclickBuyExtraPoints = useCallback( async ({ points }: { points: number }) => { try { points = Math.ceil(points); const month = 1; const payAmount = points * month * extraPointsPrice; if (payAmount === 0) { return toast({ status: 'warning', title: t('common:support.wallet.amount_0') }); } setLoading(true); const res = await getWxPayQRCode({ type: BillTypeEnum.extraPoints, extraPoints: points }); setQRPayData({ readPrice: res.readPrice, codeUrl: res.codeUrl, billId: res.billId }); } catch (err) { toast({ title: getErrText(err), status: 'error' }); } setLoading(false); }, [extraPointsPrice, toast] ); return ( {t('common:support.wallet.subscription.Extra dataset size')} {`¥${extraDatasetPrice}/1000` + t('common:core.dataset.data.group')} /{t('common:common.month')} {t('common:support.wallet.buy_resource')} {t('common:support.wallet.subscription.Month amount')} {t('common:common.month')} {t('common:support.wallet.subscription.Update extra dataset size')} 000{t('common:core.dataset.data.unit')} {/* points */} {t('common:support.wallet.subscription.Extra ai points')} {`¥${extraPointsPrice}/1000` + t('common:support.wallet.subscription.point')} /{t('common:common.month')} {t('common:support.wallet.buy_resource')} {t('common:support.wallet.subscription.Month amount')} 1 {t('common:common.month')} {t('common:support.wallet.subscription.Update extra ai points')} {'000' + t('common:support.wallet.subscription.point')} {!!qrPayData && } ); }; export default React.memo(ExtraPlan);