import React, { useState, useEffect, useCallback } from 'react'; import { paymentAPI } from '@/api'; import { useAuth } from '@/contexts/AuthContext'; import './PricingPage.css'; // ---- SVG Icons ---- const IconCheck = () => ( ); const IconService = () => ( ); const IconTag = () => ( ); const IconCoupon = () => ( OFF ); const IconClock = () => ( ); const IconSparkles = () => ( ); const IconAppCustom = () => ( ); const IconPlatform = () => ( ); const IconDataCustom = () => ( ); const IconPrivateProject = () => ( ); const IconWechat = () => ( ); const IconAlipay = () => ( Alipay ); function formatYuan(n: number): string { return n.toLocaleString('en-US'); } interface ServiceItem { id: string; name: string; description: string; type: string; price: number; features?: string[]; assigned_agent_id?: string; } interface CouponItem { id: string; code: string; type: string; value: number; min_amount: number; expire_at: string; status: string; } const SERVICE_TYPE_CONFIG: Record = { app_custom: { label: '应用定制', icon: , color: '#4F46E5', bg: '#EEF2FF' }, platform_proxy: { label: '平台代理', icon: , color: '#059669', bg: '#ECFDF5' }, data_custom: { label: '数据定制', icon: , color: '#D97706', bg: '#FFFBEB' }, private_project: { label: '私有化项目', icon: , color: '#7C3AED', bg: '#F5F3FF' }, }; const PricingPage: React.FC = () => { const { user } = useAuth(); const [billingCycle, setBillingCycle] = useState<'month' | 'quarter' | 'year'>('month'); const [plans, setPlans] = useState([]); const [services, setServices] = useState([]); const [coupons, setCoupons] = useState([]); const [loading, setLoading] = useState(true); const [subscribeMsg, setSubscribeMsg] = useState(''); // Modal states const [showModal, setShowModal] = useState(null); // service type or null const [appCustomType, setAppCustomType] = useState('skill'); // skill/agent/mcp const [platformForm, setPlatformForm] = useState({ companyName: '', contactName: '', usage: '' }); const [dataRequestForm, setDataRequestForm] = useState({ title: '', description: '', requirements: '' }); const [privateProjectForm, setPrivateProjectForm] = useState({ title: '', description: '', requirements: '' }); const [submitLoading, setSubmitLoading] = useState(false); const currentPlanLevel = user?.membership_level ?? 0; const loadData = useCallback(async () => { try { setLoading(true); const [plansRes, servicesRes, couponsRes] = await Promise.all([ paymentAPI.getPlans(), paymentAPI.getServices(), paymentAPI.getCoupons(), ]); if (plansRes.code === 0) setPlans(plansRes.data); if (servicesRes.code === 0) setServices(servicesRes.data); if (couponsRes.code === 0) setCoupons(couponsRes.data); } catch (e) { console.error('加载付费数据失败', e); } finally { setLoading(false); } }, []); useEffect(() => { loadData(); }, [loadData]); const getPrice = (plan: any, cycle: typeof billingCycle) => { const base = Number(plan.price) || 0; switch (cycle) { case 'quarter': return Math.round(base * 2.7); case 'year': return Math.round(base * 10); default: return base; } }; const getCycleLabel = (cycle: typeof billingCycle) => { switch (cycle) { case 'month': return '/月'; case 'quarter': return '/季'; case 'year': return '/年'; } }; const handleSubscribe = async (plan: any) => { try { setSubscribeMsg(''); const res = await paymentAPI.createOrder({ item_id: plan.id, order_type: 'membership', }); if (res.code === 0) { const payRes = await paymentAPI.payOrder(res.data.id); if (payRes.code === 0) { setSubscribeMsg('成功订阅 ' + plan.name + '!'); await loadData(); } } } catch (e: any) { setSubscribeMsg('订阅失败:' + (e.message || '未知错误')); } }; // 应用定制服务 - 提交 const handleAppCustomSubmit = async (serviceId: string) => { try { setSubmitLoading(true); const res = await paymentAPI.createCustomOrder({ service_id: serviceId, description: '应用定制服务 - ' + (appCustomType === 'skill' ? 'Skills' : appCustomType === 'agent' ? 'Agent' : 'MCP') + ' 类型', budget: 0, contact_info: '', }); if (res.code === 0) { setSubscribeMsg('应用定制服务已提交!即将跳转到定制对话窗口...'); setShowModal(null); // 跳转到聊天页面,带定制服务ID setTimeout(() => { window.location.href = '/chat?service_id=' + res.data.id; }, 1500); } } catch (e: any) { setSubscribeMsg('提交失败:' + (e.message || '未知错误')); } finally { setSubmitLoading(false); } }; // 平台代理申请 - 提交 const handlePlatformProxySubmit = async (serviceId: string) => { if (!platformForm.companyName.trim()) { setSubscribeMsg('请填写公司名称'); return; } try { setSubmitLoading(true); const res = await paymentAPI.createServiceRequest({ service_id: serviceId, title: '平台代理申请 - ' + platformForm.companyName, description: '公司名称: ' + platformForm.companyName + '\n联系人: ' + platformForm.contactName + '\n用途说明: ' + platformForm.usage, requirements: { company_name: platformForm.companyName, contact_name: platformForm.contactName, usage: platformForm.usage, }, }); if (res.code === 0) { setSubscribeMsg('平台代理申请已成功提交!工单号: ' + res.data.id); setShowModal(null); setPlatformForm({ companyName: '', contactName: '', usage: '' }); await loadData(); } } catch (e: any) { setSubscribeMsg('提交失败:' + (e.message || '未知错误')); } finally { setSubmitLoading(false); } }; // 数据定制服务 - 提交 const handleDataCustomSubmit = async (serviceId: string) => { if (!dataRequestForm.title.trim()) { setSubscribeMsg('请填写需求标题'); return; } try { setSubmitLoading(true); const res = await paymentAPI.createServiceRequest({ service_id: serviceId, title: dataRequestForm.title, description: dataRequestForm.description, requirements: { detail: dataRequestForm.requirements }, }); if (res.code === 0) { setSubscribeMsg('数据定制需求已成功提交!工单号: ' + res.data.id); setShowModal(null); setDataRequestForm({ title: '', description: '', requirements: '' }); await loadData(); } } catch (e: any) { setSubscribeMsg('提交失败:' + (e.message || '未知错误')); } finally { setSubmitLoading(false); } }; // 私有化项目服务 - 提交 const handlePrivateProjectSubmit = async (serviceId: string) => { if (!privateProjectForm.title.trim()) { setSubscribeMsg('请填写咨询标题'); return; } try { setSubmitLoading(true); const res = await paymentAPI.createServiceRequest({ service_id: serviceId, title: privateProjectForm.title, description: privateProjectForm.description, requirements: { detail: privateProjectForm.requirements }, }); if (res.code === 0) { setSubscribeMsg('私有化项目咨询已成功提交!工单号: ' + res.data.id); setShowModal(null); setPrivateProjectForm({ title: '', description: '', requirements: '' }); await loadData(); } } catch (e: any) { setSubscribeMsg('提交失败:' + (e.message || '未知错误')); } finally { setSubmitLoading(false); } }; const getServiceAction = (svc: ServiceItem) => { switch (svc.type) { case 'app_custom': return { label: '前往定制', action: () => setShowModal('app_custom_' + svc.id) }; case 'platform_proxy': return { label: '立即申请', action: () => setShowModal('platform_proxy_' + svc.id) }; case 'data_custom': return { label: '提交需求', action: () => setShowModal('data_custom_' + svc.id) }; case 'private_project': return { label: '咨询方案', action: () => setShowModal('private_project_' + svc.id) }; default: return { label: '了解更多', action: () => {} }; } }; if (loading) return

加载中...

; return (

订阅付费中心

选择最适合你的方案,解锁 AI 无限可能

{(['month', 'quarter', 'year'] as const).map((cycle) => ( ))}
{subscribeMsg &&
{subscribeMsg}
}
{plans.map((plan: any, idx: number) => { const isCurrent = currentPlanLevel === plan.level; const price = getPrice(plan, billingCycle); const isPopular = idx === 1; return (
{isPopular && (
最受欢迎
)} {isCurrent &&
当前方案
}
{plan.name}
${price === 0 ? '0' : formatYuan(price)} {getCycleLabel(billingCycle)}

日赠 {formatYuan(plan.daily_free_tokens)} Tokens

{(plan.features || []).map((feat: string, i: number) => (
{feat}
))}
); })}
{/* 增值服务 - 四大类 */}

增值服务

{services.map((svc) => { const config = SERVICE_TYPE_CONFIG[svc.type] || SERVICE_TYPE_CONFIG.app_custom; const actionInfo = getServiceAction(svc); return (
{config.icon}
{config.label}

{svc.name}

{svc.description}

{(svc.features && svc.features.length > 0) && (
{svc.features.map((feat: string, i: number) => ( {feat} ))}
)}
{svc.price > 0 ? ( {formatYuan(svc.price)} 元起 ) : ( 免费咨询 )}
); })} {services.length === 0 &&

暂无增值服务

}
{/* 优惠券 */}

优惠券

{coupons.map((cp) => { const isPercent = cp.type === 'percent'; return (
{isPercent ? `${cp.value}%` : `$${cp.value}`} {isPercent ? '折扣券' : '立减券'}
{cp.code}
满 {formatYuan(cp.min_amount || 0)} 元可用
有效期至 {cp.expire_at || '--'}
{cp.status === 'active' ? '可使用' : cp.status}
); })} {coupons.length === 0 &&

暂无可用优惠券

}
{/* 支付方式 */}

支付方式

微信支付
支付宝
{/* ===== Modal - 应用定制服务 ===== */} {showModal && showModal.startsWith('app_custom_') && (
setShowModal(null)}>
e.stopPropagation()}>

应用定制服务

请选择您需要的定制类型

{[ { type: 'skill', label: 'Skills', desc: '自定义技能开发,扩展AI能力边界' }, { type: 'agent', label: 'Agent', desc: '智能体定制,构建专属AI助手' }, { type: 'mcp', label: 'MCP', desc: 'MCP协议开发,连接外部数据源' }, ].map((item) => (
setAppCustomType(item.type)} >
{item.label}
{item.desc}
))}
)} {/* ===== Modal - 平台代理申请 ===== */} {showModal && showModal.startsWith('platform_proxy_') && (
setShowModal(null)}>
e.stopPropagation()}>

平台代理申请

填写以下信息,提交代理申请

setPlatformForm({ ...platformForm, companyName: e.target.value })} />
setPlatformForm({ ...platformForm, contactName: e.target.value })} />