import React, { useState, useEffect, useMemo } from 'react'; import { useSearchParams, useNavigate } from 'react-router-dom'; import { Button, Input, App, Form, DatePicker } from 'antd'; import { useTranslation } from 'react-i18next'; import copy from 'copy-to-clipboard' import dayjs from 'dayjs'; import { submitPaymentVoucherAPI } from '@/api/order'; import corporateImg from '@/assets/images/order/corporate.svg' import checkImg from '@/assets/images/order/check.svg' import type { PriceItem, VoucherForm } from './types' const { TextArea } = Input; const paymentInfo = { payee: '上海算模算样科技有限公司', bankName: '交通银行上海同济支行', bankAccount: '3100 6634 4013 0082 44111' }; const OrderPayment: React.FC = () => { const [searchParams] = useSearchParams(); const { message, modal } = App.useApp() const navigate = useNavigate(); const { t } = useTranslation(); const [form] = Form.useForm() const [isSubmitting, setIsSubmitting] = useState(false); const [selectedType, setSelectedType] = useState('biz'); const PRICE_LIST: PriceItem[] = [ { type: 'personal', label: 'pricing.personal.label', typeDesc: 'pricing.personal.typeDesc', priceDescObj: { solution: 'pricing.personal.solution', targetAudience: 'pricing.personal.targetAudience', }, priceObj: { type: 'default', price: 0, time: 'pricing.personal.priceDesc', }, btnType: 'started', memoryCapacity: '2000', intelligentSearchFrequency: '100', }, { type: 'team', label: 'pricing.team.label', typeDesc: 'pricing.team.typeDesc', priceDescObj: { solution: 'pricing.team.solution', targetAudience: 'pricing.team.targetAudience', }, priceObj: { type: 'default', price: 19, time: 'pricing.team.priceDesc' }, btnType: 'choosePlan', memoryCapacity: '20,000', intelligentSearchFrequency: '10,000', }, { type: 'biz', label: 'pricing.biz.label', typeDesc: 'pricing.biz.typeDesc', priceDescObj: { solution: 'pricing.biz.solution', targetAudience: 'pricing.biz.targetAudience', }, mostPopular: true, priceObj: { type: 'default', price: 299, time: 'pricing.biz.priceDesc' }, btnType: 'choosePlan', memoryCapacity: '100,000', intelligentSearchFrequency: '50,000', }, { type: 'commerce', label: 'pricing.commerce.label', typeDesc: 'pricing.commerce.typeDesc', priceDescObj: { solution: 'pricing.commerce.solution', targetAudience: 'pricing.commerce.targetAudience', }, priceObj: { type: 'commerce', time: 'pricing.commerce.priceDesc' }, btnType: 'contact', memoryCapacity: '20,000', intelligentSearchFrequency: '10,000', flexibleDeployment: true, reliableGuarantee: true }, ]; const selectedPlan = useMemo(() => { return PRICE_LIST.find(item => item.type === selectedType) || PRICE_LIST[2]; }, [selectedType]); const translations = useMemo(() => ({ title: t('pricing.title'), desc: t('pricing.desc'), mostPopular: t('pricing.mostPopular'), startedBtn: t('pricing.startedBtn'), choosePlanBtn: t('pricing.choosePlanBtn'), contactBtn: t('pricing.contactBtn'), memoryCapacity: t('pricing.memoryCapacity'), entries: t('pricing.entries'), intelligentSearchFrequency: t('pricing.intelligentSearchFrequency'), timesMonth: t('pricing.timesMonth'), supportServices: t('pricing.supportServices'), flexibleDeployment: t('pricing.flexibleDeployment'), reliableGuarantee: t('pricing.reliableGuarantee'), getItemType: (type: string) => t(`pricing.${type}.type`), getItemLabel: (labelKey: string) => t(labelKey), getItemDesc: (descKey: string) => t(descKey), getPriceKey: (key: string) => t(`pricing.${key}`), getItemPriceDesc: (descKey: string) => t(descKey), getPriceTime: (timeKey: string) => t(timeKey), getTypeSupportService: (type: string, key: string) => t(`pricing.${type}.${key}`), }), [t]); const getProductType = (type: string) => { const typeMap: Record = { 'personal': 'FREE', 'team': 'TEAM', 'biz': 'ENTERPRISE', 'commerce': 'OEM' }; return typeMap[type] || 'ENTERPRISE'; }; const generateOrderNumber = () => { const date = new Date(); const dateStr = date.getFullYear().toString() + (date.getMonth() + 1).toString().padStart(2, '0') + date.getDate().toString().padStart(2, '0'); const random = Math.floor(Math.random() * 1000000).toString().padStart(6, '0'); return `ORD-${dateStr}${random}`; }; const orderInfo = useMemo(() => { const plan = selectedPlan; return { orderNumber: generateOrderNumber(), creationTime: dayjs().format('YYYY-MM-DD HH:mm:ss'), comboName: t(`pricing.${plan.type}.type`), comboEdition: t(plan.typeDesc), solutionPositioning: t(plan.priceDescObj.solution), targetAudience: t(plan.priceDescObj.targetAudience), memoryCapacity: `${plan.memoryCapacity} ${t('pricing.entries')}`, searchFrequency: `${plan.intelligentSearchFrequency} ${t('pricing.timesMonth')}`, supportServices: t(`pricing.${plan.type}.supportServices`), flexibleDeployment: t(`pricing.${plan.type}.flexibleDeployment`), reliableGuarantee: t(`pricing.${plan.type}.reliableGuarantee`), orderingCycle: '1 month', orderAmount: plan.priceObj.price || 'Contact Us' }; }, [selectedPlan, t]); const copyText = (text: string) => { copy(text) message.success(t('common.copySuccess')) }; const submitPayment = (values: VoucherForm) => { if (isSubmitting) return; setIsSubmitting(true); const submitData = { product_type: getProductType(selectedType), ...values, payable_amount: orderInfo.orderAmount, pay_time: values.transferDate.valueOf(), }; submitPaymentVoucherAPI(submitData) .then(res => { form.resetFields() modal.confirm({ title: t('pricing.confirmRedirect'), content: t('pricing.confirmRedirectContent'), okText: t('pricing.goBack'), cancelText: t('pricing.stayCurrentPage'), onOk() { navigate('/pricing') }, }); }) .finally(() => { setIsSubmitting(false); }) }; useEffect(() => { const type = searchParams.get('type'); if (type && PRICE_LIST.find(item => item.type === type)) { setSelectedType(type); } }, [searchParams]); return (
{/* 订单信息 */}

{t('pricing.orderInformation')}

{t('pricing.creationTime')}: {orderInfo.creationTime}
{/* 订单详情表格 */}
{/* 桌面端表头 */}
{t('pricing.comboName')}
{t('pricing.spAndTa')}
{t('pricing.versionInformation')}
{t('pricing.orderCycle')}
{t('pricing.orderAmount')}
{/* 表格内容 */}
{/* 套餐名称 */}
{t('pricing.comboName')}
{orderInfo.comboName}
{orderInfo.comboEdition}
{/* 解决方案和目标受众 */}
{t('pricing.spAndTa')}
{translations.getPriceKey('solution')}
{orderInfo.solutionPositioning}
{translations.getPriceKey('targetAudience')}
{orderInfo.targetAudience}
{/* 版本信息 */}
{t('pricing.versionInformation')}
{translations.memoryCapacity} {orderInfo.memoryCapacity}
{translations.intelligentSearchFrequency} {orderInfo.searchFrequency}
{translations.supportServices} {orderInfo.supportServices}
{selectedType === 'commerce' && ( <>
{translations.flexibleDeployment} {translations.getTypeSupportService('commerce', 'flexibleDeployment')}
{translations.reliableGuarantee} {translations.getTypeSupportService('commerce', 'reliableGuarantee')}
)}
{/* 订购周期和金额 */}
{orderInfo.orderingCycle}
{t('pricing.orderAmount')}: {selectedType === 'commerce' ? '' : '$'}{orderInfo.orderAmount}
{/* 支付方式和支付凭证 */}
{/* 支付方式 */}

{t('pricing.paymentMethod')}

{t('pricing.corporateTransfer')}
{t('pricing.corporateTransferDesc')}

{t('pricing.payeeInformation')}

{t('pricing.receivingEntity')}:
{paymentInfo.payee}
{t('pricing.bankName')}:
{paymentInfo.bankName}
{t('pricing.bankAccountNumber')}:
{paymentInfo.bankAccount}
copyText(paymentInfo.bankAccount)} >
{/* 支付凭证 */}

{t('pricing.paymentVoucher')}