import { useState } from 'react'; import { Ionicons } from '@expo/vector-icons'; import { useRouter } from 'expo-router'; import { ActivityIndicator, Pressable, ScrollView, StyleSheet, Text, View, } from 'react-native'; import { SafeAreaView } from 'react-native-safe-area-context'; import { useAccountCancel } from '../../src/hooks'; import { colors } from '../../src/theme'; /* ===================== 子组件:顶部导航 ===================== */ function Header({ onBack }: { onBack: () => void }) { return ( 账号注销 ); } /* ===================== 页面 ===================== */ export default function AccountCancelScreen() { const router = useRouter(); const { data, loading, error, refresh, submit } = useAccountCancel(); const [reason, setReason] = useState(''); const [submitting, setSubmitting] = useState(false); const [done, setDone] = useState<{ success: boolean; message: string } | null>(null); const handleSubmit = async () => { setSubmitting(true); try { const res = await submit(reason); setDone(res); } finally { setSubmitting(false); } }; if (loading) { return (
router.back()} /> ); } if (error || !data) { return (
router.back()} /> 加载失败,请重试 重试 ); } if (done?.success) { return (
router.back()} /> {done.message} router.back()}> 返回 ); } return (
router.back()} /> 注销后账号将无法恢复,请谨慎操作 注销后将发生 {data.consequences.map((item, index) => ( {item} ))} 注销前待办 {data.checklist.map((item, index) => ( {item.label} {item.actionText ? ( console.log('[account-cancel] 去处理', item.id)}> {item.actionText} ) : null} ))} 注销原因(选填) {data.reasons.map((r) => { const active = reason === r; return ( setReason(active ? '' : r)} > {r} ); })} {submitting ? '提交中…' : data.canCancel ? '申请注销' : '请先完成注销前待办'} ); } 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: { flex: 1, textAlign: 'center', fontSize: 17, fontWeight: '700', color: colors.textPrimary, }, scroll: { flex: 1, }, content: { padding: 12, paddingBottom: 24, }, stateBox: { flex: 1, alignItems: 'center', justifyContent: 'center', gap: 12, }, stateText: { marginTop: 12, fontSize: 14, color: colors.textSecondary, paddingHorizontal: 32, textAlign: 'center', }, retryBtn: { marginTop: 16, paddingHorizontal: 24, paddingVertical: 8, borderRadius: 18, backgroundColor: colors.primaryBtn, }, retryText: { fontSize: 13, fontWeight: '600', color: colors.white, }, warnCard: { flexDirection: 'row', alignItems: 'center', gap: 8, borderRadius: 12, padding: 14, marginBottom: 16, }, warnText: { flex: 1, fontSize: 13, fontWeight: '600', lineHeight: 18, }, section: { marginBottom: 16, }, sectionTitle: { fontSize: 14, fontWeight: '700', color: colors.textPrimary, marginBottom: 10, }, card: { backgroundColor: colors.white, borderRadius: 12, overflow: 'hidden', }, bulletRow: { flexDirection: 'row', alignItems: 'flex-start', paddingHorizontal: 14, paddingVertical: 12, gap: 8, }, bulletBorder: { borderBottomWidth: 1, borderBottomColor: colors.borderLight, }, bulletText: { flex: 1, fontSize: 13, lineHeight: 19, color: colors.textSecondary, }, checkRow: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', paddingHorizontal: 14, paddingVertical: 14, }, rowBorder: { borderBottomWidth: 1, borderBottomColor: colors.borderLight, }, rowBody: { flex: 1, marginRight: 12, }, rowTitle: { fontSize: 15, fontWeight: '600', color: colors.textPrimary, }, actionText: { marginTop: 3, fontSize: 12, fontWeight: '600', color: colors.primary, }, chipWrap: { flexDirection: 'row', flexWrap: 'wrap', gap: 8, }, chip: { paddingVertical: 7, paddingHorizontal: 14, borderRadius: 16, backgroundColor: colors.white, borderWidth: 1, borderColor: colors.border, }, chipActive: { backgroundColor: colors.primaryLight, borderColor: colors.primary, }, chipText: { fontSize: 13, fontWeight: '600', color: colors.textSecondary, }, chipTextActive: { color: colors.primary, }, submitBtn: { marginTop: 8, height: 48, borderRadius: 24, backgroundColor: colors.danger, alignItems: 'center', justifyContent: 'center', }, submitDisabled: { backgroundColor: colors.border, }, submitText: { fontSize: 15, fontWeight: '700', color: colors.white, }, });