create_list.tsx 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. import { Ionicons } from '@expo/vector-icons';
  2. import { useRouter } from 'expo-router';
  3. import React, { useCallback, useEffect, useState } from 'react';
  4. import {
  5. ActivityIndicator,
  6. FlatList,
  7. Image,
  8. ImageBackground,
  9. StyleSheet,
  10. Text,
  11. TouchableOpacity,
  12. View,
  13. } from 'react-native';
  14. import { useSafeAreaInsets } from 'react-native-safe-area-context';
  15. import { Images } from '@/constants/images';
  16. import { getMyCreateList } from '@/services/dimension';
  17. const CreateListScreen = () => {
  18. const router = useRouter();
  19. const insets = useSafeAreaInsets();
  20. const [list, setList] = useState<any[]>([]);
  21. const [loading, setLoading] = useState(false);
  22. const [refreshing, setRefreshing] = useState(false);
  23. const [page, setPage] = useState(1);
  24. const [hasMore, setHasMore] = useState(true);
  25. const loadData = useCallback(async (isRefresh = false) => {
  26. if (loading) return;
  27. const curPage = isRefresh ? 1 : page;
  28. setLoading(true);
  29. try {
  30. const data = await getMyCreateList(curPage, 20);
  31. if (data) {
  32. setList(prev => (isRefresh ? data : [...prev, ...data]));
  33. setHasMore(data.length === 20);
  34. setPage(curPage + 1);
  35. }
  36. } catch (err) {
  37. console.error(err);
  38. } finally {
  39. setLoading(false);
  40. setRefreshing(false);
  41. }
  42. }, [loading, page]);
  43. useEffect(() => {
  44. loadData(true);
  45. }, []);
  46. const onRefresh = () => {
  47. setRefreshing(true);
  48. loadData(true);
  49. };
  50. const onEndReached = () => {
  51. if (hasMore && !loading) {
  52. loadData();
  53. }
  54. };
  55. const getTypeName = (type: string) => {
  56. switch (type) {
  57. case 'COMMON': return '福利房';
  58. case 'PASSWORD': return '口令房';
  59. case 'EUROPEAN_GAS': return '欧气房';
  60. case 'ACHIEVEMENT': return '成就房';
  61. default: return '未知';
  62. }
  63. };
  64. const renderItem = ({ item }: { item: any }) => (
  65. <TouchableOpacity
  66. style={styles.itemContainer}
  67. onPress={() => router.push({ pathname: '/dimension/detail', params: { id: item.id } })}
  68. >
  69. <ImageBackground
  70. source={{ uri: Images.welfare.roomItemBg }}
  71. style={styles.itemBg}
  72. resizeMode="stretch"
  73. >
  74. <View style={styles.itemContent}>
  75. <View style={styles.imgContainer}>
  76. <ImageBackground source={{ uri: Images.welfare.roomItemImgBg }} style={styles.imgBg} resizeMode="contain">
  77. {item.luckRoomGoodsList?.[0]?.spu?.cover && (
  78. <Image
  79. source={{ uri: item.luckRoomGoodsList[0].spu.cover }}
  80. style={styles.goodsImg}
  81. />
  82. )}
  83. </ImageBackground>
  84. </View>
  85. <View style={styles.infoContainer}>
  86. <Text style={styles.roomName} numberOfLines={1}>{item.name}</Text>
  87. <View style={styles.row}>
  88. <Text style={styles.typeName}>{getTypeName(item.type)}</Text>
  89. <Text style={styles.goodsNum}>共{item.goodsQuantity}件赠品</Text>
  90. </View>
  91. </View>
  92. <View style={styles.btnContainer}>
  93. <TouchableOpacity
  94. style={styles.auditBtn}
  95. onPress={() => {
  96. if (item.status === 1 && item.participateMode === 1) {
  97. router.push({ pathname: '/dimension/audit_list', params: { id: item.id } } as any);
  98. } else {
  99. router.push({ pathname: '/dimension/detail', params: { id: item.id } } as any);
  100. }
  101. }}
  102. >
  103. <Text style={styles.auditBtnText}>
  104. {item.status === 1 && item.participateMode === 1 ? '审核列表' : '详情'}
  105. </Text>
  106. </TouchableOpacity>
  107. </View>
  108. </View>
  109. </ImageBackground>
  110. </TouchableOpacity>
  111. );
  112. return (
  113. <View style={styles.container}>
  114. <ImageBackground
  115. source={{ uri: Images.common.commonBg }}
  116. style={styles.background}
  117. resizeMode="cover"
  118. >
  119. <View style={[styles.header, { paddingTop: insets.top }]}>
  120. <TouchableOpacity style={styles.backBtn} onPress={() => router.back()}>
  121. <Ionicons name="chevron-back" size={24} color="#fff" />
  122. </TouchableOpacity>
  123. <Text style={styles.title}>我创建的</Text>
  124. <View style={styles.placeholder} />
  125. </View>
  126. <FlatList
  127. data={list}
  128. renderItem={renderItem}
  129. keyExtractor={(item) => item.id.toString()}
  130. contentContainerStyle={styles.listContent}
  131. onRefresh={onRefresh}
  132. refreshing={refreshing}
  133. onEndReached={onEndReached}
  134. onEndReachedThreshold={0.5}
  135. ListEmptyComponent={() => !loading && (
  136. <View style={styles.emptyContainer as any}>
  137. <Text style={styles.emptyText as any}>暂无创建记录</Text>
  138. </View>
  139. )}
  140. ListFooterComponent={() => loading && (
  141. <ActivityIndicator size="small" color="#fff" style={{ marginVertical: 20 }} />
  142. )}
  143. />
  144. <View style={[styles.footer as any, { paddingBottom: Math.max(insets.bottom, 20) }]}>
  145. <TouchableOpacity
  146. style={styles.createBtn as any}
  147. onPress={() => router.push('/dimension/create')}
  148. >
  149. <ImageBackground
  150. source={{ uri: Images.common.loginBtn }}
  151. style={styles.createBtnBg as any}
  152. resizeMode="stretch"
  153. >
  154. <Text style={styles.createBtnText}>创建房间</Text>
  155. </ImageBackground>
  156. </TouchableOpacity>
  157. </View>
  158. </ImageBackground>
  159. </View>
  160. );
  161. };
  162. const styles = StyleSheet.create({
  163. container: {
  164. flex: 1,
  165. },
  166. background: {
  167. flex: 1,
  168. },
  169. header: {
  170. flexDirection: 'row',
  171. alignItems: 'center',
  172. justifyContent: 'space-between',
  173. paddingHorizontal: 15,
  174. height: 90,
  175. },
  176. backBtn: {
  177. width: 40,
  178. height: 40,
  179. justifyContent: 'center',
  180. },
  181. title: {
  182. fontSize: 18,
  183. fontWeight: 'bold',
  184. color: '#fff',
  185. },
  186. placeholder: {
  187. width: 40,
  188. },
  189. listContent: {
  190. padding: 15,
  191. paddingBottom: 120,
  192. },
  193. itemContainer: {
  194. height: 84,
  195. marginBottom: 6,
  196. },
  197. itemBg: {
  198. flex: 1,
  199. },
  200. itemContent: {
  201. flexDirection: 'row',
  202. alignItems: 'center',
  203. paddingHorizontal: 16,
  204. height: '100%',
  205. },
  206. imgContainer: {
  207. width: 58,
  208. height: 58,
  209. marginRight: 14,
  210. },
  211. imgBg: {
  212. width: '100%',
  213. height: '100%',
  214. justifyContent: 'center',
  215. alignItems: 'center',
  216. padding: 7,
  217. },
  218. goodsImg: {
  219. width: '100%',
  220. height: '100%',
  221. },
  222. infoContainer: {
  223. flex: 1,
  224. },
  225. roomName: {
  226. fontSize: 14,
  227. color: '#fff',
  228. fontWeight: '400',
  229. marginBottom: 10,
  230. textShadowColor: 'rgba(0,0,0,1)',
  231. textShadowOffset: { width: 1, height: 1 },
  232. textShadowRadius: 1,
  233. },
  234. row: {
  235. flexDirection: 'row',
  236. alignItems: 'center',
  237. },
  238. typeName: {
  239. fontSize: 12,
  240. color: '#2E0000',
  241. fontWeight: 'bold',
  242. marginRight: 10,
  243. },
  244. goodsNum: {
  245. fontSize: 10,
  246. color: '#2E0000',
  247. fontWeight: 'normal',
  248. },
  249. btnContainer: {
  250. marginLeft: 10,
  251. },
  252. auditBtn: {
  253. paddingHorizontal: 12,
  254. paddingVertical: 6,
  255. },
  256. auditBtnText: {
  257. fontSize: 12,
  258. color: '#fff',
  259. fontWeight: 'bold',
  260. },
  261. footer: {
  262. position: 'absolute',
  263. bottom: 0,
  264. left: 0,
  265. right: 0,
  266. alignItems: 'center',
  267. paddingTop: 10,
  268. },
  269. createBtn: {
  270. width: 160,
  271. height: 60,
  272. },
  273. createBtnBg: {
  274. width: '100%',
  275. height: '100%',
  276. justifyContent: 'center',
  277. alignItems: 'center',
  278. },
  279. createBtnText: {
  280. fontSize: 15,
  281. fontWeight: '800',
  282. color: '#fff',
  283. textShadowColor: 'rgba(0,0,0,1)',
  284. textShadowOffset: { width: 1, height: 1 },
  285. textShadowRadius: 1,
  286. },
  287. emptyContainer: {
  288. paddingTop: 100,
  289. alignItems: 'center',
  290. },
  291. emptyText: {
  292. color: 'rgba(255,255,255,0.6)',
  293. fontSize: 14,
  294. },
  295. });
  296. export default CreateListScreen;