轻松聘
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.
 
 
 

137 lines
3.7 KiB

import { Ionicons } from '@expo/vector-icons';
import { useRouter } from 'expo-router';
import { Pressable, ScrollView, StyleSheet, Text, View } from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import { useState } from 'react';
import { useLegalData } from '../../src/hooks';
import { LoadingState, ErrorState, EmptyState } from '../../src/components/StateView';
import { colors , spacing } from '../../src/theme';
import type { LegalFAQ } 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>
);
}
/* ===================== FAQ 项 ===================== */
function FAQItem({ faq }: { faq: LegalFAQ }) {
const [expanded, setExpanded] = useState(false);
return (
<Pressable style={styles.faqItem} onPress={() => setExpanded((v) => !v)}>
<View style={styles.faqRow}>
<Text style={styles.faqQ}>{faq.question}</Text>
<Ionicons
name={expanded ? 'chevron-up' : 'chevron-down'}
size={18}
color={colors.textHint}
/>
</View>
{expanded && <Text style={styles.faqA}>{faq.answer}</Text>}
</Pressable>
);
}
/* ===================== 页面 ===================== */
export default function LegalFaqScreen() {
const router = useRouter();
const { faqs, loading, error, refresh } = useLegalData();
return (
<SafeAreaView style={styles.safeArea} edges={['top']}>
<Header onBack={() => router.back()} />
{loading ? (
<LoadingState text="加载问题中…" />
) : error ? (
<ErrorState message="加载失败,请重试" onRetry={refresh} />
) : faqs.length === 0 ? (
<EmptyState icon="help-circle-outline" title="暂无常见问题" subtitle="如有疑问,可前往法律咨询" />
) : (
<ScrollView
style={styles.scroll}
contentContainerStyle={styles.content}
showsVerticalScrollIndicator={false}
>
<View style={styles.faqCard}>
{faqs.map((faq) => (
<FAQItem key={faq.id} faq={faq} />
))}
</View>
</ScrollView>
)}
</SafeAreaView>
);
}
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,
},
faqCard: {
backgroundColor: colors.white,
borderRadius: spacing.card,
paddingHorizontal: spacing.card,
},
faqItem: {
paddingVertical: 12,
borderBottomWidth: 1,
borderBottomColor: colors.borderLight,
},
faqRow: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
},
faqQ: {
flex: 1,
fontSize: 14,
fontWeight: '600',
color: colors.textPrimary,
marginRight: 8,
},
faqA: {
marginTop: 8,
fontSize: 13,
lineHeight: 19,
color: colors.textSecondary,
},
});