You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
255 lines
6.7 KiB
255 lines
6.7 KiB
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 (
|
|
<View style={styles.header}>
|
|
<Pressable style={styles.headerBtn} onPress={onBack} hitSlop={8}>
|
|
<Ionicons name="chevron-back" size={24} color={colors.textPrimary} />
|
|
</Pressable>
|
|
<Text style={styles.headerTitle}>开通会员</Text>
|
|
<View style={styles.headerBtn} />
|
|
</View>
|
|
);
|
|
}
|
|
|
|
/* ===================== 套餐卡片 ===================== */
|
|
|
|
function PlanCard({ plan, onPress }: { plan: LegalPlan; onPress?: () => void }) {
|
|
return (
|
|
<Pressable
|
|
style={({ pressed }) => [
|
|
styles.planCard,
|
|
plan.recommended && styles.planCardRecommended,
|
|
pressed && styles.planPressed,
|
|
]}
|
|
onPress={onPress}
|
|
disabled={!onPress}
|
|
>
|
|
{plan.recommended && (
|
|
<View style={styles.recommendedTag}>
|
|
<Text style={styles.recommendedText}>推荐</Text>
|
|
</View>
|
|
)}
|
|
<Text style={styles.planName}>{plan.name}</Text>
|
|
<View style={styles.planPriceRow}>
|
|
<Text style={styles.planCurrency}>¥</Text>
|
|
<Text style={styles.planPrice}>{plan.price}</Text>
|
|
<Text style={styles.planPeriod}>{plan.period}</Text>
|
|
</View>
|
|
<View style={styles.benefits}>
|
|
{plan.benefits.map((benefit, idx) => (
|
|
<View key={idx} style={styles.benefitRow}>
|
|
<Ionicons name="checkmark-circle" size={14} color={colors.success} />
|
|
<Text style={styles.benefitText}>{benefit}</Text>
|
|
</View>
|
|
))}
|
|
</View>
|
|
<View style={styles.planCtaRow}>
|
|
<Text style={styles.planCtaText}>立即开通</Text>
|
|
<Ionicons name="chevron-forward" size={16} color={colors.action} />
|
|
</View>
|
|
</Pressable>
|
|
);
|
|
}
|
|
|
|
/* ===================== 页面 ===================== */
|
|
|
|
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 (
|
|
<SafeAreaView style={styles.safeArea} edges={['top']}>
|
|
<Header onBack={() => router.back()} />
|
|
{loading ? (
|
|
<LoadingState text="加载套餐中…" />
|
|
) : error ? (
|
|
<ErrorState message="加载失败,请重试" onRetry={refresh} />
|
|
) : plans.length === 0 ? (
|
|
<EmptyState icon="card-outline" title="暂无会员套餐" subtitle="如有疑问,可前往法律咨询" />
|
|
) : (
|
|
<ScrollView
|
|
style={styles.scroll}
|
|
contentContainerStyle={styles.content}
|
|
showsVerticalScrollIndicator={false}
|
|
>
|
|
{membership ? (
|
|
<View style={styles.memberBanner}>
|
|
<Ionicons name="shield-checkmark" size={16} color={colors.action} />
|
|
<Text style={styles.memberBannerText}>
|
|
您已开通{membership.planName},有效期至 {formatDate(membership.expiresAt)}
|
|
</Text>
|
|
</View>
|
|
) : (
|
|
<Text style={styles.tip}>开通会员后可享受律师咨询、合同审核等专属法律服务</Text>
|
|
)}
|
|
<View style={styles.planGrid}>
|
|
{plans.map((plan) => (
|
|
<PlanCard
|
|
key={plan.id}
|
|
plan={plan}
|
|
onPress={() => router.push(`/legal/checkout?planId=${plan.id}`)}
|
|
/>
|
|
))}
|
|
</View>
|
|
</ScrollView>
|
|
)}
|
|
</SafeAreaView>
|
|
);
|
|
}
|
|
|
|
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: 8,
|
|
paddingBottom: 24,
|
|
},
|
|
tip: {
|
|
fontSize: 13,
|
|
color: colors.textSecondary,
|
|
marginBottom: 12,
|
|
},
|
|
planGrid: {
|
|
gap: 8,
|
|
},
|
|
planCard: {
|
|
padding: 8,
|
|
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: 8,
|
|
paddingVertical: 8,
|
|
borderRadius: 8,
|
|
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,
|
|
},
|
|
});
|
|
|