ac9bbfd472
补齐历史缺译并统一整句插值。九语覆盖 100%,静态检查及 713 项单测通过。
809 lines
28 KiB
React
809 lines
28 KiB
React
/*
|
||
Copyright (C) 2025 QuantumNous
|
||
|
||
This program is free software: you can redistribute it and/or modify
|
||
it under the terms of the GNU Affero General Public License as
|
||
published by the Free Software Foundation, either version 3 of the
|
||
License, or (at your option) any later version.
|
||
|
||
This program is distributed in the hope that it will be useful,
|
||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
GNU Affero General Public License for more details.
|
||
|
||
You should have received a copy of the GNU Affero General Public License
|
||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||
|
||
For commercial licensing, please contact support@quantumnous.com
|
||
*/
|
||
|
||
import { Trans } from 'react-i18next';
|
||
import {
|
||
Check as ActionCheck,
|
||
ArrowUpRight as ActionArrowUpRight,
|
||
} from '@/components/common/icons/ActionIcons';
|
||
import React, { useEffect, useState, useContext } from 'react';
|
||
import { Segmented } from 'antd';
|
||
import {
|
||
Typography,
|
||
Tag,
|
||
Modal,
|
||
Spin,
|
||
Empty,
|
||
Banner,
|
||
Progress,
|
||
} from '@/components/ui';
|
||
import { Crown, Zap, Clock } from 'lucide-react';
|
||
import { useTranslation } from 'react-i18next';
|
||
import { UserContext } from '../../context/User';
|
||
import { API, showError, showSuccess, renderQuota } from '../../helpers';
|
||
import MembershipHistoryModal from '../../components/membership/MembershipHistoryModal';
|
||
|
||
const { Text } = Typography;
|
||
|
||
// 方案时长(原型分段固定展示周卡/月卡/季卡)
|
||
const planTypeConfig = {
|
||
weekly: { label: '周卡' },
|
||
monthly: { label: '月卡' },
|
||
quarterly: { label: '季卡' },
|
||
};
|
||
|
||
const MembershipPanel = () => {
|
||
const { t, i18n } = useTranslation();
|
||
const [, userDispatch] = useContext(UserContext);
|
||
|
||
const [loading, setLoading] = useState(true);
|
||
const [membershipEnabled, setMembershipEnabled] = useState(false);
|
||
const [plans, setPlans] = useState([]);
|
||
const [, setTitle] = useState('会员订阅');
|
||
const [description, setDescription] = useState('');
|
||
|
||
// 当前会员信息
|
||
const [membershipInfo, setMembershipInfo] = useState(null);
|
||
const [infoLoading, setInfoLoading] = useState(true);
|
||
|
||
// 购买相关
|
||
const [selectedPlan, setSelectedPlan] = useState(null);
|
||
const [purchaseModalVisible, setPurchaseModalVisible] = useState(false);
|
||
const [purchasing, setPurchasing] = useState(false);
|
||
|
||
// 升级相关
|
||
const [upgradeModalVisible, setUpgradeModalVisible] = useState(false);
|
||
const [upgradeInfo, setUpgradeInfo] = useState(null);
|
||
const [upgradeLoading, setUpgradeLoading] = useState(false);
|
||
const [upgrading, setUpgrading] = useState(false);
|
||
|
||
// 选中的方案类型 tab
|
||
const [activeType, setActiveType] = useState('monthly');
|
||
|
||
// 会员购买历史弹窗
|
||
const [historyModalVisible, setHistoryModalVisible] = useState(false);
|
||
|
||
// 获取方案列表
|
||
const fetchPlans = async () => {
|
||
setLoading(true);
|
||
try {
|
||
const res = await API.get('/api/user/membership/plans');
|
||
const { success, data } = res.data;
|
||
if (success) {
|
||
setMembershipEnabled(data.membership_enabled);
|
||
setPlans(data.plans || []);
|
||
setTitle(data.title || '会员订阅');
|
||
setDescription(data.description || '');
|
||
}
|
||
} catch (err) {
|
||
console.error('获取会员方案失败:', err);
|
||
} finally {
|
||
setLoading(false);
|
||
}
|
||
};
|
||
|
||
// 获取当前会员信息
|
||
const fetchMembershipInfo = async () => {
|
||
setInfoLoading(true);
|
||
try {
|
||
const res = await API.get('/api/user/membership/info');
|
||
const { success, data } = res.data;
|
||
if (success) {
|
||
setMembershipInfo(data);
|
||
}
|
||
} catch (err) {
|
||
console.error('获取会员信息失败:', err);
|
||
} finally {
|
||
setInfoLoading(false);
|
||
}
|
||
};
|
||
|
||
// 购买会员
|
||
const handlePurchase = async () => {
|
||
if (!selectedPlan) return;
|
||
setPurchasing(true);
|
||
try {
|
||
const res = await API.post('/api/user/membership/purchase', {
|
||
plan_id: selectedPlan.id,
|
||
payment_method: 'balance',
|
||
});
|
||
const { success, message } = res.data;
|
||
if (success) {
|
||
showSuccess(t('购买成功!'));
|
||
setPurchaseModalVisible(false);
|
||
setSelectedPlan(null);
|
||
fetchMembershipInfo();
|
||
// 刷新用户信息
|
||
try {
|
||
const userRes = await API.get('/api/user/self');
|
||
if (userRes.data.success) {
|
||
userDispatch({ type: 'login', payload: userRes.data.data });
|
||
}
|
||
} catch (e) {}
|
||
} else {
|
||
showError(message);
|
||
}
|
||
} catch (err) {
|
||
showError(t('购买失败'));
|
||
} finally {
|
||
setPurchasing(false);
|
||
}
|
||
};
|
||
|
||
// 检查是否为升级场景并获取差价
|
||
const checkUpgrade = async (plan) => {
|
||
if (!membershipInfo?.has_membership) return false;
|
||
if (plan.daily_quota <= membershipInfo.daily_quota) return false;
|
||
if (plan.plan_type !== membershipInfo.plan_type) return false; // 只能同类型内升级
|
||
|
||
setUpgradeLoading(true);
|
||
try {
|
||
const res = await API.get(
|
||
`/api/user/membership/upgrade/cost?plan_id=${plan.id}`,
|
||
);
|
||
const { success, data } = res.data;
|
||
if (success && data.can_upgrade) {
|
||
setUpgradeInfo(data);
|
||
return true;
|
||
}
|
||
} catch (err) {
|
||
console.error('查询升级信息失败:', err);
|
||
} finally {
|
||
setUpgradeLoading(false);
|
||
}
|
||
return false;
|
||
};
|
||
|
||
// 判断是否为当前正在使用的同款方案(匹配 tier + plan_type,可续费但不可升级)
|
||
const isCurrentPlanCheck = (plan) => {
|
||
return (
|
||
membershipInfo?.has_membership &&
|
||
membershipInfo?.daily_quota === plan.daily_quota &&
|
||
membershipInfo?.tier === plan.tier &&
|
||
membershipInfo?.plan_type === plan.plan_type
|
||
);
|
||
};
|
||
|
||
// 判断是否可以升级(同一时长类型内,更高档位)
|
||
const canUpgradeCheck = (plan) => {
|
||
return (
|
||
membershipInfo?.has_membership &&
|
||
plan.daily_quota > (membershipInfo?.daily_quota || 0) &&
|
||
plan.plan_type === membershipInfo?.plan_type
|
||
);
|
||
};
|
||
|
||
// 判断是否为降级(同一时长类型内,更低档位)
|
||
const isDowngradeCheck = (plan) => {
|
||
return (
|
||
membershipInfo?.has_membership &&
|
||
plan.plan_type === membershipInfo?.plan_type &&
|
||
plan.daily_quota < (membershipInfo?.daily_quota || 0)
|
||
);
|
||
};
|
||
|
||
// 判断该方案是否已有未来待生效的续费
|
||
const hasFutureForPlan = (plan) => {
|
||
return (
|
||
membershipInfo?.has_future_membership &&
|
||
membershipInfo?.future_plan_type === plan.plan_type &&
|
||
membershipInfo?.future_tier === plan.tier
|
||
);
|
||
};
|
||
|
||
// 点击方案卡片
|
||
const handlePlanClick = async (plan) => {
|
||
setSelectedPlan(plan);
|
||
// 判断是否为升级场景(同一时长类型内,且每日额度更高)
|
||
if (canUpgradeCheck(plan)) {
|
||
const isUpgrade = await checkUpgrade(plan);
|
||
if (isUpgrade) {
|
||
setUpgradeModalVisible(true);
|
||
return;
|
||
}
|
||
}
|
||
// 普通购买 / 续期(包括同款方案续费)
|
||
setPurchaseModalVisible(true);
|
||
};
|
||
|
||
// 执行升级
|
||
const handleUpgrade = async () => {
|
||
if (!selectedPlan) return;
|
||
setUpgrading(true);
|
||
try {
|
||
const res = await API.post('/api/user/membership/upgrade', {
|
||
plan_id: selectedPlan.id,
|
||
});
|
||
const { success, message } = res.data;
|
||
if (success) {
|
||
showSuccess(message || t('升级成功!'));
|
||
setUpgradeModalVisible(false);
|
||
setSelectedPlan(null);
|
||
setUpgradeInfo(null);
|
||
fetchMembershipInfo();
|
||
// 刷新用户信息
|
||
try {
|
||
const userRes = await API.get('/api/user/self');
|
||
if (userRes.data.success) {
|
||
userDispatch({ type: 'login', payload: userRes.data.data });
|
||
}
|
||
} catch (e) {}
|
||
} else {
|
||
showError(message);
|
||
}
|
||
} catch (err) {
|
||
showError(t('升级失败'));
|
||
} finally {
|
||
setUpgrading(false);
|
||
}
|
||
};
|
||
|
||
useEffect(() => {
|
||
fetchPlans();
|
||
fetchMembershipInfo();
|
||
}, []);
|
||
|
||
if (loading) {
|
||
return (
|
||
<div className='flex items-center justify-center py-20'>
|
||
<Spin size='large' />
|
||
</div>
|
||
);
|
||
}
|
||
|
||
if (!membershipEnabled) {
|
||
return (
|
||
<div className='py-12'>
|
||
<Empty
|
||
title={t('会员功能未开启')}
|
||
description={t('管理员尚未启用会员订阅功能')}
|
||
/>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
// 按类型分组方案
|
||
const plansByType = {};
|
||
plans.forEach((plan) => {
|
||
if (!plansByType[plan.plan_type]) {
|
||
plansByType[plan.plan_type] = [];
|
||
}
|
||
plansByType[plan.plan_type].push(plan);
|
||
});
|
||
|
||
const typeKeys = Object.keys(plansByType);
|
||
|
||
// 格式化日期
|
||
const formatDate = (timestamp) => {
|
||
return new Date(timestamp * 1000).toLocaleDateString(i18n.language);
|
||
};
|
||
|
||
// 原型展示固定的周卡/月卡/季卡三个时长,没有方案的时长显示“待补充”空态
|
||
const periodKeys = [
|
||
...Object.keys(planTypeConfig),
|
||
...typeKeys.filter((type) => !planTypeConfig[type]),
|
||
];
|
||
const currentPeriod = periodKeys.includes(activeType)
|
||
? activeType
|
||
: periodKeys[0];
|
||
const periodPlans = plansByType[currentPeriod] || [];
|
||
|
||
return (
|
||
<div className='rc-membership'>
|
||
{/* 当前会员状态 */}
|
||
{!infoLoading && membershipInfo?.has_membership && (
|
||
<div className='rc-member-status'>
|
||
<div className='rc-member-status-head'>
|
||
<strong>{t('当前会员')}</strong>
|
||
<span>
|
||
<Tag color='blue' size='small'>
|
||
{membershipInfo.plan_name}
|
||
</Tag>{' '}
|
||
<button
|
||
type='button'
|
||
className='rc-section-link'
|
||
onClick={() => setHistoryModalVisible(true)}
|
||
>
|
||
{t('查看记录')}
|
||
</button>
|
||
</span>
|
||
</div>
|
||
<div className='rc-member-status-grid'>
|
||
<div>
|
||
<span className='rc-label'>{t('今日剩余额度')}</span>
|
||
<strong>{renderQuota(membershipInfo.membership_quota)}</strong>
|
||
</div>
|
||
<div>
|
||
<span className='rc-label'>{t('每日额度')}</span>
|
||
<strong>{renderQuota(membershipInfo.daily_quota)}</strong>
|
||
</div>
|
||
</div>
|
||
{membershipInfo.daily_quota > 0 && (
|
||
<Progress
|
||
percent={Math.round(
|
||
(membershipInfo.membership_quota / membershipInfo.daily_quota) *
|
||
100,
|
||
)}
|
||
showInfo
|
||
size='small'
|
||
aria-label={t('今日用量')}
|
||
/>
|
||
)}
|
||
<div className='rc-member-status-meta'>
|
||
<span>
|
||
{t('到期日')}: {formatDate(membershipInfo.end_date)}
|
||
</span>
|
||
<span>
|
||
{t('剩余 {{n}} 天', {
|
||
n: membershipInfo.remaining_days,
|
||
count: membershipInfo.remaining_days,
|
||
})}
|
||
</span>
|
||
</div>
|
||
{/* 已续费提示 */}
|
||
{membershipInfo.has_future_membership && (
|
||
<Banner
|
||
type='success'
|
||
closeIcon={null}
|
||
description={t('已续费:{{plan}},{{start}} ~ {{end}} 生效', {
|
||
plan: membershipInfo.future_plan_name,
|
||
start: formatDate(membershipInfo.future_start_date),
|
||
end: formatDate(membershipInfo.future_end_date),
|
||
})}
|
||
/>
|
||
)}
|
||
</div>
|
||
)}
|
||
|
||
{/* 方案时长切换 */}
|
||
<div className='rc-segmented rc-member-type'>
|
||
<Segmented
|
||
value={currentPeriod}
|
||
onChange={setActiveType}
|
||
options={periodKeys.map((type) => ({
|
||
value: type,
|
||
label: t(planTypeConfig[type]?.label || type),
|
||
}))}
|
||
/>
|
||
</div>
|
||
|
||
<section className='rc-section'>
|
||
<div className='rc-section-head'>
|
||
<div>
|
||
<h3>{t('选择适合你的会员')}</h3>
|
||
<p className='rc-section-desc'>
|
||
{description ||
|
||
t(
|
||
'会员额度每日重置,优先消耗;用完后切换账户余额,不自动续费。',
|
||
)}
|
||
</p>
|
||
</div>
|
||
<button
|
||
type='button'
|
||
className='rc-section-link'
|
||
onClick={() => setHistoryModalVisible(true)}
|
||
>
|
||
{t('购买记录')}
|
||
</button>
|
||
</div>
|
||
|
||
{plans.length === 0 ? (
|
||
<div className='rc-plan-empty'>
|
||
<Empty
|
||
title={t('暂无可用方案')}
|
||
description={t('管理员尚未配置会员方案')}
|
||
/>
|
||
</div>
|
||
) : periodPlans.length === 0 ? (
|
||
<div className='rc-plan-empty'>
|
||
<Clock size={18} />
|
||
<strong>
|
||
<Trans
|
||
t={t}
|
||
i18nKey='{{label}}套餐'
|
||
values={{
|
||
label: t(
|
||
planTypeConfig[currentPeriod]?.label || currentPeriod,
|
||
),
|
||
}}
|
||
/>
|
||
</strong>
|
||
<span>{t('价格与权益待补充')}</span>
|
||
</div>
|
||
) : (
|
||
<div className='rc-plan-grid'>
|
||
{periodPlans.map((plan) => {
|
||
const isSelected = selectedPlan?.id === plan.id;
|
||
const isCurrentPlan = isCurrentPlanCheck(plan);
|
||
const canUpgrade = canUpgradeCheck(plan);
|
||
const isDowngrade = isDowngradeCheck(plan);
|
||
const hasFuture = hasFutureForPlan(plan);
|
||
// 按钮文案沿用原有续费/升级/到期生效判断
|
||
let btnText = t('立即订阅');
|
||
let subText = '';
|
||
if (isCurrentPlan) {
|
||
btnText = hasFuture ? t('再次续费') : t('续费');
|
||
} else if (canUpgrade) {
|
||
btnText = t('立即升级');
|
||
subText = t('立即生效,补差价');
|
||
} else if (isDowngrade) {
|
||
subText = t('到期后生效');
|
||
} else if (membershipInfo?.has_membership) {
|
||
subText = t('到期后生效');
|
||
}
|
||
return (
|
||
<button
|
||
key={plan.id}
|
||
type='button'
|
||
onClick={() => handlePlanClick(plan)}
|
||
aria-pressed={isSelected}
|
||
className={[
|
||
'app-action-button',
|
||
`rc-plan ${isSelected ? 'selected' : ''}`,
|
||
]
|
||
.filter(Boolean)
|
||
.join(' ')}
|
||
>
|
||
{(plan.badge || plan.is_recommend) && (
|
||
<span className='rc-plan-badge'>
|
||
{plan.badge || t('推荐')}
|
||
</span>
|
||
)}
|
||
<span className='rc-plan-name'>{plan.name}</span>
|
||
<span className='rc-plan-price'>
|
||
<small>¥</small>
|
||
<strong>
|
||
{Number(plan.price).toLocaleString('en-US')}
|
||
</strong>
|
||
<span>
|
||
/ {t('{{days}} 天', { days: plan.duration_days })}
|
||
</span>
|
||
</span>
|
||
<span className='rc-plan-quota'>
|
||
<span>{t('每日额度')}</span>
|
||
<strong>{renderQuota(plan.daily_quota)}</strong>
|
||
</span>
|
||
{plan.description && (
|
||
<span className='rc-plan-desc'>{plan.description}</span>
|
||
)}
|
||
<ul className='rc-plan-features'>
|
||
<li>
|
||
<ActionCheck size={12} />
|
||
{t('每日自动重置额度')}
|
||
</li>
|
||
<li>
|
||
<ActionCheck size={12} />
|
||
{t('会员额度优先消耗')}
|
||
</li>
|
||
<li>
|
||
<ActionCheck size={12} />
|
||
{t('额度用完转账户余额')}
|
||
</li>
|
||
</ul>
|
||
<span className='rc-plan-foot'>
|
||
<span>
|
||
{btnText}
|
||
{subText && <small>{subText}</small>}
|
||
</span>
|
||
{isSelected ? (
|
||
<ActionCheck size={14} />
|
||
) : (
|
||
<ActionArrowUpRight size={14} />
|
||
)}
|
||
</span>
|
||
</button>
|
||
);
|
||
})}
|
||
</div>
|
||
)}
|
||
</section>
|
||
|
||
{/* 购买确认弹窗 */}
|
||
<Modal
|
||
title={
|
||
<div className='flex items-center gap-2'>
|
||
<Crown size={20} className='text-amber-500' />
|
||
{selectedPlan && isCurrentPlanCheck(selectedPlan)
|
||
? t('确认续费会员')
|
||
: t('确认购买会员')}
|
||
</div>
|
||
}
|
||
visible={purchaseModalVisible}
|
||
onOk={handlePurchase}
|
||
onCancel={() => {
|
||
setPurchaseModalVisible(false);
|
||
setSelectedPlan(null);
|
||
}}
|
||
confirmLoading={purchasing}
|
||
okText={
|
||
selectedPlan && isCurrentPlanCheck(selectedPlan)
|
||
? t('确认续费')
|
||
: t('确认购买')
|
||
}
|
||
cancelText={t('取消')}
|
||
centered
|
||
maskClosable={false}
|
||
>
|
||
{selectedPlan && (
|
||
<div className='space-y-4 py-2'>
|
||
<div className='p-4 rounded-lg'>
|
||
<div className='flex justify-between items-center mb-2'>
|
||
<Text strong className='text-lg'>
|
||
{selectedPlan.name}
|
||
</Text>
|
||
<Tag color='blue' size='small'>
|
||
{t('{{days}} 天', { days: selectedPlan.duration_days })}
|
||
</Tag>
|
||
</div>
|
||
<div className='flex justify-between items-center mb-2'>
|
||
<Text className='text-gray-500'>{t('每日到账额度')}</Text>
|
||
<Text strong className='text-emerald-600'>
|
||
{renderQuota(selectedPlan.daily_quota)}
|
||
</Text>
|
||
</div>
|
||
<div className='flex justify-between items-center'>
|
||
<Text className='text-gray-500'>{t('总计到账')}</Text>
|
||
<Text strong className='text-blue-600'>
|
||
{renderQuota(
|
||
selectedPlan.daily_quota * selectedPlan.duration_days,
|
||
)}
|
||
</Text>
|
||
</div>
|
||
</div>
|
||
|
||
<div className='flex justify-between items-center pt-2 border-t border-gray-200 dark:border-neutral-700'>
|
||
<Text className='text-gray-500'>{t('支付方式')}</Text>
|
||
<Text strong>{t('账户余额抵扣')}</Text>
|
||
</div>
|
||
|
||
<div className='flex justify-between items-center'>
|
||
<Text className='text-gray-500'>{t('需支付')}</Text>
|
||
<Text strong className='text-2xl text-red-500'>
|
||
¥{selectedPlan.price}
|
||
</Text>
|
||
</div>
|
||
|
||
{/* 场景化提示 */}
|
||
{(() => {
|
||
if (!membershipInfo?.has_membership) {
|
||
// 新用户,无会员
|
||
return (
|
||
<Banner
|
||
type='info'
|
||
description={t(
|
||
'购买后会员立即生效,每日额度将于每天自动重置到账。',
|
||
)}
|
||
closeIcon={null}
|
||
/>
|
||
);
|
||
}
|
||
|
||
const isRenewal = isCurrentPlanCheck(selectedPlan);
|
||
const isDowngrade = isDowngradeCheck(selectedPlan);
|
||
|
||
return (
|
||
<>
|
||
{/* 续费同款方案 */}
|
||
{isRenewal && (
|
||
<Banner
|
||
type='success'
|
||
description={t(
|
||
'续费提示:您将续费当前「{{plan}}」,新的 {{days}} 天会员将在当前会员到期后({{date}})自动生效,届时每日额度保持不变。',
|
||
{
|
||
plan: membershipInfo.plan_name,
|
||
days: selectedPlan.duration_days,
|
||
date: formatDate(membershipInfo.end_date),
|
||
},
|
||
)}
|
||
closeIcon={null}
|
||
/>
|
||
)}
|
||
|
||
{/* 购买不同类型的方案(非升级、非同款) */}
|
||
{!isRenewal && !isDowngrade && (
|
||
<Banner
|
||
type='info'
|
||
description={t(
|
||
'您当前有「{{plan}}」会员(到期日:{{date}})。新购买的「{{newPlan}}」将在当前会员到期后开始生效。',
|
||
{
|
||
plan: membershipInfo.plan_name,
|
||
date: formatDate(membershipInfo.end_date),
|
||
newPlan: selectedPlan.name,
|
||
},
|
||
)}
|
||
closeIcon={null}
|
||
/>
|
||
)}
|
||
|
||
{/* 降级方案提示 */}
|
||
{isDowngrade && (
|
||
<Banner
|
||
type='warning'
|
||
description={t(
|
||
'注意:此方案的每日额度({{newQuota}})低于您当前方案({{currentQuota}})。新会员将在当前会员到期后生效,届时每日额度将降低。如需立即提升额度,建议使用「升级」功能。',
|
||
{
|
||
newQuota: renderQuota(selectedPlan.daily_quota),
|
||
currentQuota: renderQuota(membershipInfo.daily_quota),
|
||
},
|
||
)}
|
||
closeIcon={null}
|
||
/>
|
||
)}
|
||
|
||
{/* 同类型升级提示(用户通过购买而非升级入口来的) */}
|
||
{!isRenewal &&
|
||
!isDowngrade &&
|
||
canUpgradeCheck(selectedPlan) && (
|
||
<Banner
|
||
type='info'
|
||
description={t(
|
||
'提示:此方案额度高于您当前方案,您也可以选择「升级」,升级后立即生效且只需补差价。',
|
||
)}
|
||
closeIcon={null}
|
||
/>
|
||
)}
|
||
|
||
{/* 已有未来待生效的续费 */}
|
||
{membershipInfo.has_future_membership && (
|
||
<Banner
|
||
type='warning'
|
||
description={t(
|
||
'您已有一个待生效的续费会员「{{plan}}」({{date}} 生效)。再次购买将在其到期后生效,请确认是否需要继续。',
|
||
{
|
||
plan: membershipInfo.future_plan_name,
|
||
date: formatDate(membershipInfo.future_start_date),
|
||
},
|
||
)}
|
||
closeIcon={null}
|
||
/>
|
||
)}
|
||
</>
|
||
);
|
||
})()}
|
||
|
||
<Banner
|
||
type='warning'
|
||
description={t(
|
||
'购买后将从您的账户余额中扣除对应额度,会员每日额度不累加,当日未使用次日重置。',
|
||
)}
|
||
closeIcon={null}
|
||
/>
|
||
</div>
|
||
)}
|
||
</Modal>
|
||
|
||
{/* 升级确认弹窗 */}
|
||
<Modal
|
||
title={
|
||
<div className='flex items-center gap-2'>
|
||
<Zap size={20} className='text-orange-500' />
|
||
{t('确认升级会员')}
|
||
</div>
|
||
}
|
||
visible={upgradeModalVisible}
|
||
onOk={handleUpgrade}
|
||
onCancel={() => {
|
||
setUpgradeModalVisible(false);
|
||
setSelectedPlan(null);
|
||
setUpgradeInfo(null);
|
||
}}
|
||
confirmLoading={upgrading}
|
||
okText={t('确认升级')}
|
||
cancelText={t('取消')}
|
||
centered
|
||
maskClosable={false}
|
||
>
|
||
{selectedPlan && upgradeInfo && (
|
||
<div className='space-y-4 py-2'>
|
||
{/* 升级对比 */}
|
||
<div className='p-4 rounded-lg'>
|
||
<div className='flex items-center justify-between mb-3'>
|
||
<div className='text-center flex-1'>
|
||
<Text className='text-xs text-gray-400 block mb-1'>
|
||
{t('当前方案')}
|
||
</Text>
|
||
<Text strong className='text-sm block'>
|
||
{upgradeInfo.current_plan}
|
||
</Text>
|
||
<Text className='text-xs text-gray-500 block mt-1'>
|
||
{t('每日')} {renderQuota(upgradeInfo.current_daily)}
|
||
</Text>
|
||
</div>
|
||
<div className='mx-3 flex flex-col items-center'>
|
||
<Zap size={20} className='text-orange-500' />
|
||
<Text className='text-xs text-orange-500 mt-1'>
|
||
{t('升级')}
|
||
</Text>
|
||
</div>
|
||
<div className='text-center flex-1'>
|
||
<Text className='text-xs text-gray-400 block mb-1'>
|
||
{t('升级方案')}
|
||
</Text>
|
||
<Text strong className='text-sm block text-orange-600'>
|
||
{upgradeInfo.new_plan}
|
||
</Text>
|
||
<Text className='text-xs text-orange-500 block mt-1'>
|
||
{t('每日')} {renderQuota(upgradeInfo.new_daily)}
|
||
</Text>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
{/* 差价明细 */}
|
||
<div className='p-4 rounded-lg'>
|
||
<div className='flex justify-between items-center mb-2'>
|
||
<Text className='text-gray-500'>{t('剩余会员天数')}</Text>
|
||
<Text strong>
|
||
{t('{{days}} 天', { days: upgradeInfo.remaining_days })}
|
||
</Text>
|
||
</div>
|
||
<div className='flex justify-between items-center mb-2'>
|
||
<Text className='text-gray-500'>{t('升级差价')}</Text>
|
||
<Text strong className='text-orange-600'>
|
||
¥{upgradeInfo.upgrade_cost}
|
||
</Text>
|
||
</div>
|
||
<div className='flex justify-between items-center'>
|
||
<Text className='text-gray-500'>{t('需补缴额度')}</Text>
|
||
<Text strong className='text-blue-600'>
|
||
{renderQuota(upgradeInfo.quota_needed)}
|
||
</Text>
|
||
</div>
|
||
</div>
|
||
|
||
<div className='flex justify-between items-center pt-2 border-t border-gray-200 dark:border-neutral-700'>
|
||
<Text className='text-gray-500'>{t('支付方式')}</Text>
|
||
<Text strong>{t('账户余额抵扣')}</Text>
|
||
</div>
|
||
|
||
<div className='flex justify-between items-center'>
|
||
<Text className='text-gray-500'>{t('需支付')}</Text>
|
||
<Text strong className='text-2xl text-red-500'>
|
||
¥{upgradeInfo.upgrade_cost}
|
||
</Text>
|
||
</div>
|
||
|
||
<Banner
|
||
type='info'
|
||
description={t(
|
||
'升级后立即生效,今日额度将重置为新方案额度。到期日期不变。',
|
||
)}
|
||
closeIcon={null}
|
||
/>
|
||
</div>
|
||
)}
|
||
{upgradeLoading && (
|
||
<div className='flex items-center justify-center py-8'>
|
||
<Spin size='large' />
|
||
</div>
|
||
)}
|
||
</Modal>
|
||
|
||
{/* 会员购买历史弹窗 */}
|
||
<MembershipHistoryModal
|
||
visible={historyModalVisible}
|
||
onClose={() => setHistoryModalVisible(false)}
|
||
t={t}
|
||
/>
|
||
</div>
|
||
);
|
||
};
|
||
|
||
export default MembershipPanel;
|