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 } 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: 8, 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: 12, paddingBottom: 24, }, tip: { fontSize: 13, color: colors.textSecondary, marginBottom: 12, }, planGrid: { gap: 12, }, planCard: { padding: 14, borderRadius: 8, 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: 12, paddingVertical: 10, borderRadius: 8, backgroundColor: colors.actionLight, borderWidth: 1, borderColor: colors.action, marginBottom: 12, }, 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, }, });