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.
346 lines
9.3 KiB
346 lines
9.3 KiB
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 , spacing } from '../../src/theme';
|
|
|
|
/* ===================== 子组件:顶部导航 ===================== */
|
|
|
|
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>
|
|
);
|
|
}
|
|
|
|
/* ===================== 页面 ===================== */
|
|
|
|
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 (
|
|
<SafeAreaView style={styles.safeArea} edges={['top']}>
|
|
<Header onBack={() => router.back()} />
|
|
<View style={styles.stateBox}>
|
|
<ActivityIndicator size="large" color={colors.primary} />
|
|
</View>
|
|
</SafeAreaView>
|
|
);
|
|
}
|
|
|
|
if (error || !data) {
|
|
return (
|
|
<SafeAreaView style={styles.safeArea} edges={['top']}>
|
|
<Header onBack={() => router.back()} />
|
|
<View style={styles.stateBox}>
|
|
<Ionicons name="alert-circle-outline" size={40} color={colors.danger} />
|
|
<Text style={styles.stateText}>加载失败,请重试</Text>
|
|
<Pressable style={styles.retryBtn} onPress={refresh}>
|
|
<Text style={styles.retryText}>重试</Text>
|
|
</Pressable>
|
|
</View>
|
|
</SafeAreaView>
|
|
);
|
|
}
|
|
|
|
if (done?.success) {
|
|
return (
|
|
<SafeAreaView style={styles.safeArea} edges={['top']}>
|
|
<Header onBack={() => router.back()} />
|
|
<View style={styles.stateBox}>
|
|
<Ionicons name="checkmark-circle" size={48} color={colors.success} />
|
|
<Text style={styles.stateText}>{done.message}</Text>
|
|
<Pressable style={styles.retryBtn} onPress={() => router.back()}>
|
|
<Text style={styles.retryText}>返回</Text>
|
|
</Pressable>
|
|
</View>
|
|
</SafeAreaView>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<SafeAreaView style={styles.safeArea} edges={['top', 'bottom']}>
|
|
<Header onBack={() => router.back()} />
|
|
<ScrollView
|
|
style={styles.scroll}
|
|
contentContainerStyle={styles.content}
|
|
showsVerticalScrollIndicator={false}
|
|
>
|
|
<View style={[styles.warnCard, { backgroundColor: colors.dangerLight }]}>
|
|
<Ionicons name="warning-outline" size={18} color={colors.dangerText} />
|
|
<Text style={[styles.warnText, { color: colors.dangerText }]}>
|
|
提交注销申请后,账号将进入注销审核流程,期间无法登录且不可恢复,审核结束后将永久删除,请谨慎操作
|
|
</Text>
|
|
</View>
|
|
|
|
<View style={styles.section}>
|
|
<Text style={styles.sectionTitle}>注销后将发生</Text>
|
|
<View style={styles.card}>
|
|
{data.consequences.map((item, index) => (
|
|
<View
|
|
key={index}
|
|
style={[styles.bulletRow, index < data.consequences.length - 1 && styles.bulletBorder]}
|
|
>
|
|
<Ionicons name="close-circle-outline" size={18} color={colors.danger} />
|
|
<Text style={styles.bulletText}>{item}</Text>
|
|
</View>
|
|
))}
|
|
</View>
|
|
</View>
|
|
|
|
<View style={styles.section}>
|
|
<Text style={styles.sectionTitle}>注销前待办</Text>
|
|
<View style={styles.card}>
|
|
{data.checklist.map((item, index) => (
|
|
<View
|
|
key={item.id}
|
|
style={[styles.checkRow, index < data.checklist.length - 1 && styles.rowBorder]}
|
|
>
|
|
{/* 原先这里挂着「去提现」入口,但全项目没有钱包/提现页 —— 按「不留假交互」的口径摘掉 */}
|
|
<View style={styles.rowBody}>
|
|
<Text style={styles.rowTitle}>{item.label}</Text>
|
|
</View>
|
|
<Ionicons
|
|
name={item.resolved ? 'checkmark-circle' : 'ellipse-outline'}
|
|
size={20}
|
|
color={item.resolved ? colors.success : colors.textHint}
|
|
/>
|
|
</View>
|
|
))}
|
|
</View>
|
|
</View>
|
|
|
|
<View style={styles.section}>
|
|
<Text style={styles.sectionTitle}>注销原因(选填)</Text>
|
|
<View style={styles.chipWrap}>
|
|
{data.reasons.map((r) => {
|
|
const active = reason === r;
|
|
return (
|
|
<Pressable
|
|
key={r}
|
|
style={[styles.chip, active && styles.chipActive]}
|
|
onPress={() => setReason(active ? '' : r)}
|
|
>
|
|
<Text style={[styles.chipText, active && styles.chipTextActive]}>{r}</Text>
|
|
</Pressable>
|
|
);
|
|
})}
|
|
</View>
|
|
</View>
|
|
|
|
<Pressable
|
|
style={[styles.submitBtn, (!data.canCancel || submitting) && styles.submitDisabled]}
|
|
disabled={!data.canCancel || submitting}
|
|
onPress={handleSubmit}
|
|
>
|
|
<Text style={styles.submitText}>
|
|
{submitting ? '提交中…' : data.canCancel ? '申请注销' : '请先完成注销前待办'}
|
|
</Text>
|
|
</Pressable>
|
|
</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: {
|
|
flex: 1,
|
|
textAlign: 'center',
|
|
fontSize: 17,
|
|
fontWeight: '700',
|
|
color: colors.textPrimary,
|
|
},
|
|
scroll: {
|
|
flex: 1,
|
|
},
|
|
content: {
|
|
padding: spacing.card,
|
|
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: spacing.card,
|
|
borderRadius: 18,
|
|
backgroundColor: colors.primaryBtn,
|
|
},
|
|
retryText: {
|
|
fontSize: 13,
|
|
fontWeight: '600',
|
|
color: colors.white,
|
|
},
|
|
warnCard: {
|
|
flexDirection: 'row',
|
|
alignItems: 'center',
|
|
gap: 8,
|
|
borderRadius: spacing.card,
|
|
padding: spacing.card,
|
|
marginBottom: 8,
|
|
},
|
|
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: spacing.card,
|
|
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,
|
|
},
|
|
});
|
|
|