import { Image } from 'expo-image'; import { useRouter } from 'expo-router'; import React, { useCallback, useEffect, useRef, useState } from 'react'; import { ActivityIndicator, Dimensions, ImageBackground, RefreshControl, ScrollView, StatusBar, StyleSheet, Text, TextInput, TouchableOpacity, View, Platform, } from 'react-native'; import { useSafeAreaInsets } from 'react-native-safe-area-context'; import { Images } from '@/constants/images'; import { getRoomTypePermission, getWealList } from '@/services/dimension'; import { RuleModal, RuleModalRef } from './components/RuleModal'; interface RoomItem { id: string; name: string; type: string; goodsQuantity: number; officialFlag: number; user: { avatar: string; username: string }; luckRoomGoodsList: { spu: { cover: string } }[]; participatingList: any[]; mode?: string; } export default function RoomScreen() { const router = useRouter(); const insets = useSafeAreaInsets(); const [loading, setLoading] = useState(true); const [refreshing, setRefreshing] = useState(false); const [list, setList] = useState([]); const [searchVal, setSearchVal] = useState(''); const [type, setType] = useState(''); const [typeIndex, setTypeIndex] = useState(0); const [scrollTop, setScrollTop] = useState(0); const [roomTab, setRoomTab] = useState([ { name: '全部', value: '' } ]); const ruleRef = useRef(null); const loadPermission = async () => { try { const permission = await getRoomTypePermission(); let tabs = [{ name: '全部', value: '' }]; if (permission && permission.roomConfig !== 0) { tabs.push({ name: '福利房', value: 'COMMON' }); tabs.push({ name: '口令房', value: 'PASSWORD' }); } if (permission && permission.roomGAS !== 0) { tabs.push({ name: '欧气房', value: 'EUROPEAN_GAS' }); } if (permission && permission.roomCjf !== 0) { tabs.push({ name: '成就房', value: 'ACHIEVEMENT' }); } setRoomTab(tabs); } catch (error) { console.error('获取房间类型权限失败:', error); } }; const loadData = useCallback(async (isRefresh = false) => { if (isRefresh) setRefreshing(true); else setLoading(true); try { const data = await getWealList(1, 20, searchVal, type); setList(data || []); } catch (error) { console.error('加载房间列表失败:', error); } setLoading(false); setRefreshing(false); }, [type, searchVal]); useEffect(() => { loadPermission(); }, []); useEffect(() => { loadData(); }, [type]); const handleSearch = () => { loadData(); }; const handleTypeChange = (item: any, index: number) => { setTypeIndex(index); setType(item.value); }; const handleRoomPress = (item: RoomItem) => { if (item.mode === 'YFS_PRO') { router.push({ pathname: '/award-detail-yfs', params: { id: item.id } } as any); } else { router.push({ pathname: '/dimension/detail', params: { id: item.id } } as any); } }; const isItemType = (type: string) => { const map: Record = { COMMON: '福利房', PASSWORD: '口令房', EUROPEAN_GAS: '欧气房', ACHIEVEMENT: '成就房', }; return map[type] || type; }; const headerBg = scrollTop > 0 ? '#333' : 'transparent'; return ( {/* 顶部导航 */} router.back()}> 房间 {/* 头部背景 */} setScrollTop(e.nativeEvent.contentOffset.y)} scrollEventThrottle={16} refreshControl={ loadData(true)} tintColor="#fff" />} > {/* iOS 特有免责声明 (应 Apple 审核要求显眼展示) */} {Platform.OS === 'ios' && ( 特别声明:本平台所有活动与苹果公司(Apple Inc.)无关 )} {/* 搜索栏和功能按钮 */} router.push('/dimension/create' as any)}> 创建 router.push('/dimension/record' as any)}> 我的 ruleRef.current?.show()}> 玩法 {/* 类型切换 */} {roomTab.map((item, index) => ( handleTypeChange(item, index)} > {item.name} {typeIndex === index && ( <> )} ))} {/* 房间列表 */} {loading ? ( ) : list.length === 0 ? ( 暂无房间 ) : ( {list.map((item) => ( handleRoomPress(item)} activeOpacity={0.8}> {/* 官方标签 */} {item.officialFlag === 1 && ( )} {/* 成就房标签 */} {item.type === 'ACHIEVEMENT' && ( )} {/* 商品图片 */} {item.luckRoomGoodsList?.[0]?.spu?.cover && ( )} {/* 房间信息 */} {item.name} {isItemType(item.type)} {item.user?.avatar && ( )} {item.user?.username || '匿名'} 共{item.goodsQuantity}件赠品 {item.participatingList?.length || 0} ))} )} ); } const { width: SCREEN_WIDTH } = Dimensions.get('window'); const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#1a1a2e' }, background: { flex: 1 }, header: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', paddingHorizontal: 15, paddingBottom: 10, position: 'absolute', top: 0, left: 0, right: 0, zIndex: 100, height: 90, }, backBtn: { width: 40, height: 40, justifyContent: 'center', alignItems: 'center' }, backText: { color: '#fff', fontSize: 20 }, title: { color: '#fff', fontSize: 16, fontWeight: 'bold' }, placeholder: { width: 40 }, headBg: { position: 'absolute', top: 0, left: 0, right: 0, height: 215 }, scrollView: { flex: 1 }, // 顶部搜索和功能区 topSection: { flexDirection: 'row', alignItems: 'center', paddingHorizontal: 15, marginTop: 10, marginBottom: 15 }, searchBox: { flex: 1, height: 37, flexDirection: 'row', alignItems: 'center', paddingHorizontal: 15 }, searchIcon: { width: 19, height: 19, marginRight: 8 }, searchInput: { flex: 1, fontSize: 12, color: '#000', padding: 0 }, funcBtns: { flexDirection: 'row', marginLeft: 10 }, funcItem: { alignItems: 'center', marginLeft: 12 }, funcIcon: { width: 16, height: 16 }, funcText: { fontSize: 10, color: '#DFDFDF', marginTop: 2 }, // 类型切换 typeContainer: { paddingHorizontal: 15, marginBottom: 40 }, typeSection: {}, typeItem: { marginRight: 15, width: 55, height: 38, justifyContent: 'center', alignItems: 'center', position: 'relative' }, typeText: { fontSize: 12, color: '#DFDFDF' }, typeTextActive: { color: '#e79018', fontWeight: 'bold', fontSize: 15, textShadowColor: '#000', textShadowOffset: { width: 1, height: 1 }, textShadowRadius: 1 }, typeSelectIconT: { position: 'absolute', right: -5, top: 5, zIndex: 2, width: 28, height: 10, }, typeSelectIconB: { position: 'absolute', left: 0, bottom: 0, zIndex: 2, width: 24, height: 14, }, // 房间列表 roomList: { paddingHorizontal: 0, alignItems: 'center' }, roomItem: { width: SCREEN_WIDTH - 12, height: 84, flexDirection: 'row', alignItems: 'center', paddingHorizontal: 16, marginBottom: 6, position: 'relative' }, officialBadge: { position: 'absolute', right: 0, top: 0, width: 48, height: 22 }, officialImg: { width: '100%', height: '100%' }, mustBeBadge: { position: 'absolute', left: 0, top: 0, width: 51, height: 51 }, mustBeImg: { 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, fontWeight: '400', marginRight: 10, 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 }, emptyBox: { alignItems: 'center', paddingTop: 50 }, emptyText: { color: '#999', fontSize: 14 }, });