import { Ionicons } from '@expo/vector-icons';
import { useFocusEffect, useRouter } from 'expo-router';
import { useCallback } from 'react';
import { Pressable, ScrollView, StyleSheet, Text, View } from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import { useLegalData, useLegalMembership } from '../../src/hooks';
import { LoadingState, ErrorState, EmptyState } from '../../src/components/StateView';
import { colors , spacing } from '../../src/theme';
import type { LegalPlan } from '../../src/types';
/* ===================== 顶部导航 ===================== */
function Header({ onBack }: { onBack: () => void }) {
return (
开通会员
);
}
/* ===================== 套餐卡片 ===================== */
function PlanCard({ plan, onPress }: { plan: LegalPlan; onPress?: () => void }) {
return (
[
styles.planCard,
plan.recommended && styles.planCardRecommended,
pressed && styles.planPressed,
]}
onPress={onPress}
disabled={!onPress}
>
{plan.recommended && (
推荐
)}
{plan.name}
¥
{plan.price}
{plan.period}
{plan.benefits.map((benefit, idx) => (
{benefit}
))}
立即开通
);
}
/* ===================== 页面 ===================== */
export default function LegalUpgradeScreen() {
const router = useRouter();
const { plans, loading, error, refresh } = useLegalData();
const { membership, refresh: refreshMembership } = useLegalMembership();
useFocusEffect(
useCallback(() => {
refreshMembership();
}, [refreshMembership]),
);
const formatDate = (iso: string) => new Date(iso).toLocaleDateString('zh-CN');
return (
router.back()} />
{loading ? (
) : error ? (
) : plans.length === 0 ? (
) : (
{membership ? (
您已开通{membership.planName},有效期至 {formatDate(membership.expiresAt)}
) : (
开通会员后可享受律师咨询、合同审核等专属法律服务
)}
{plans.map((plan) => (
router.push(`/legal/checkout?planId=${plan.id}`)}
/>
))}
)}
);
}
const styles = StyleSheet.create({
safeArea: {
flex: 1,
backgroundColor: colors.pageBg,
},
header: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
paddingHorizontal: spacing.card,
height: 48,
backgroundColor: colors.white,
borderBottomWidth: 1,
borderBottomColor: colors.borderLight,
},
headerBtn: {
width: 40,
height: 40,
alignItems: 'center',
justifyContent: 'center',
},
headerTitle: {
fontSize: 17,
fontWeight: '700',
color: colors.textPrimary,
},
scroll: {
flex: 1,
},
content: {
padding: spacing.card,
paddingBottom: 24,
},
tip: {
fontSize: 13,
color: colors.textSecondary,
marginBottom: 12,
},
planGrid: {
gap: 8,
},
planCard: {
padding: spacing.card,
borderRadius: spacing.card,
backgroundColor: colors.white,
borderWidth: 1,
borderColor: colors.border,
},
planPressed: {
opacity: 0.85,
},
planCtaRow: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'flex-end',
marginTop: 12,
gap: 2,
},
planCtaText: {
fontSize: 13,
fontWeight: '700',
color: colors.action,
},
memberBanner: {
flexDirection: 'row',
alignItems: 'center',
gap: 6,
paddingHorizontal: spacing.card,
paddingVertical: spacing.card,
borderRadius: spacing.card,
backgroundColor: colors.actionLight,
borderWidth: 1,
borderColor: colors.action,
marginBottom: 8,
},
memberBannerText: {
flex: 1,
fontSize: 13,
fontWeight: '600',
color: colors.actionText,
},
planCardRecommended: {
borderColor: colors.action,
backgroundColor: colors.actionLight,
},
recommendedTag: {
alignSelf: 'flex-start',
paddingHorizontal: 6,
paddingVertical: 2,
borderRadius: 4,
backgroundColor: colors.action,
marginBottom: 8,
},
recommendedText: {
fontSize: 10,
fontWeight: '700',
color: colors.white,
},
planName: {
fontSize: 15,
fontWeight: '700',
color: colors.textPrimary,
},
planPriceRow: {
flexDirection: 'row',
alignItems: 'baseline',
marginTop: 8,
marginBottom: 10,
},
planCurrency: {
fontSize: 14,
fontWeight: '700',
color: colors.actionText,
},
planPrice: {
fontSize: 28,
fontWeight: '700',
color: colors.actionText,
},
planPeriod: {
fontSize: 13,
color: colors.textSecondary,
},
benefits: {
gap: 6,
},
benefitRow: {
flexDirection: 'row',
alignItems: 'center',
gap: 6,
},
benefitText: {
fontSize: 12,
color: colors.textSecondary,
},
});