import { Image } from 'expo-image'; import { useRouter } from 'expo-router'; import React, { useCallback, useEffect, useState } from 'react'; import { ActivityIndicator, ImageBackground, RefreshControl, ScrollView, StatusBar, StyleSheet, Text, TouchableOpacity, View, } from 'react-native'; import { useSafeAreaInsets } from 'react-native-safe-area-context'; import { Images } from '@/constants/images'; import { getWealRecord } from '@/services/weal'; interface RecordItem { id: string; name: string; type: string; goodsQuantity: number; officialFlag: number; leftTime: number; user: { avatar: string; username: string }; luckRoomGoodsList: { spu: { cover: string } }[]; participatingList: any[]; } export default function WealRecordScreen() { const router = useRouter(); const insets = useSafeAreaInsets(); const [loading, setLoading] = useState(true); const [refreshing, setRefreshing] = useState(false); const [list, setList] = useState([]); const [pageNum, setPageNum] = useState(1); const [hasMore, setHasMore] = useState(true); const loadData = useCallback(async (isRefresh = false) => { if (isRefresh) { setRefreshing(true); setPageNum(1); } else { setLoading(true); } try { const page = isRefresh ? 1 : pageNum; const data = await getWealRecord(page, 10); if (data) { if (page === 1) { setList(data); } else { setList(prev => [...prev, ...data]); } setHasMore(data.length === 10); } } catch (error) { console.error('加载记录失败:', error); } setLoading(false); setRefreshing(false); }, [pageNum]); useEffect(() => { loadData(); }, [loadData]); const handleLoadMore = () => { if (!hasMore || loading || refreshing) return; setPageNum(prev => prev + 1); }; const isItemType = (type: string) => { const map: Record = { COMMON: '福利房', PASSWORD: '口令房', EUROPEAN_GAS: '欧气房', ACHIEVEMENT: '成就房', }; return map[type] || type; }; return ( {/* 导航 */} router.back()} style={styles.backBtn}> 参与记录 loadData(true)} tintColor="#fff" />} onScroll={({ nativeEvent }) => { const { layoutMeasurement, contentOffset, contentSize } = nativeEvent; if (layoutMeasurement.height + contentOffset.y >= contentSize.height - 20) { handleLoadMore(); } }} scrollEventThrottle={400} > {list.length === 0 && !loading ? ( 暂无记录 ) : list.map((item, index) => ( router.push({ pathname: '/weal/detail', params: { id: item.id } } as any)} > {item.officialFlag === 1 && ( )} {item.name} {isItemType(item.type)} {item.user.username} 共{item.goodsQuantity}件赠品 {item.participatingList.length} ))} {loading && } ); } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#1a1a2e' }, background: { flex: 1 }, nav: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', paddingHorizontal: 15, height: 90 }, backBtn: { width: 40 }, backText: { color: '#fff', fontSize: 24 }, navTitle: { color: '#fff', fontSize: 16, fontWeight: 'bold' }, placeholder: { width: 40 }, scrollView: { flex: 1 }, list: { paddingHorizontal: 15 }, itemWrapper: { marginBottom: 6 }, grayscale: { opacity: 0.6 }, // 模拟原项目的置灰效果 item: { width: '100%', height: 84, flexDirection: 'row', alignItems: 'center', paddingHorizontal: 16 }, officialBadge: { position: 'absolute', right: 0, top: 0, width: 48, height: 22 }, officialImg: { width: '100%', height: '100%' }, roomCover: { width: 58, height: 58, justifyContent: 'center', alignItems: 'center', marginRight: 14 }, roomCoverImg: { width: 44, height: 44 }, roomInfo: { flex: 1 }, roomTop: { flexDirection: 'row', alignItems: 'center', marginBottom: 10 }, roomName: { flex: 1, color: '#fff', fontSize: 14, textShadowColor: '#000', textShadowOffset: { width: 1, height: 1 }, textShadowRadius: 1 }, roomTypeLabel: { color: '#2E0000', fontSize: 12 }, roomBottom: { flexDirection: 'row', alignItems: 'center' }, userInfo: { flexDirection: 'row', alignItems: 'center', width: '45%' }, userAvatar: { width: 24, height: 24, borderRadius: 2, backgroundColor: '#FFDD00', borderWidth: 1.5, borderColor: '#000', marginRight: 5 }, userName: { color: '#2E0000', fontSize: 12, fontWeight: 'bold', maxWidth: 60 }, goodsNum: { color: '#2E0000', fontSize: 10, width: '35%' }, participantBox: { flexDirection: 'row', alignItems: 'center', width: '20%' }, participantIcon: { width: 14, height: 14 }, participantNum: { color: '#2E0000', fontSize: 12, marginLeft: 3 }, empty: { alignItems: 'center', marginTop: 100 }, emptyText: { color: '#999', fontSize: 14 }, });