create_list.tsx 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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/weal';
  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: '/weal/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. // router.push({ pathname: '/weal/audit_list', params: { id: item.id } })
  97. }}
  98. >
  99. <Text style={styles.auditBtnText}>
  100. {item.status === 1 && item.participateMode === 1 ? '审核列表' : '详情'}
  101. </Text>
  102. </TouchableOpacity>
  103. </View>
  104. </View>
  105. </ImageBackground>
  106. </TouchableOpacity>
  107. );
  108. return (
  109. <View style={styles.container}>
  110. <ImageBackground
  111. source={{ uri: Images.common.commonBg }}
  112. style={styles.background}
  113. resizeMode="cover"
  114. >
  115. <View style={[styles.header, { paddingTop: insets.top }]}>
  116. <TouchableOpacity style={styles.backBtn} onPress={() => router.back()}>
  117. <Ionicons name="chevron-back" size={24} color="#fff" />
  118. </TouchableOpacity>
  119. <Text style={styles.title}>我创建的</Text>
  120. <View style={styles.placeholder} />
  121. </View>
  122. <FlatList
  123. data={list}
  124. renderItem={renderItem}
  125. keyExtractor={(item) => item.id.toString()}
  126. contentContainerStyle={styles.listContent}
  127. onRefresh={onRefresh}
  128. refreshing={refreshing}
  129. onEndReached={onEndReached}
  130. onEndReachedThreshold={0.5}
  131. ListEmptyComponent={() => !loading && (
  132. <View style={styles.emptyContainer as any}>
  133. <Text style={styles.emptyText as any}>暂无创建记录</Text>
  134. </View>
  135. )}
  136. ListFooterComponent={() => loading && (
  137. <ActivityIndicator size="small" color="#fff" style={{ marginVertical: 20 }} />
  138. )}
  139. />
  140. <View style={[styles.footer as any, { paddingBottom: Math.max(insets.bottom, 20) }]}>
  141. <TouchableOpacity
  142. style={styles.createBtn as any}
  143. onPress={() => router.push('/weal/create')}
  144. >
  145. <ImageBackground
  146. source={{ uri: Images.common.loginBtn }}
  147. style={styles.createBtnBg as any}
  148. resizeMode="stretch"
  149. >
  150. <Text style={styles.createBtnText}>创建房间</Text>
  151. </ImageBackground>
  152. </TouchableOpacity>
  153. </View>
  154. </ImageBackground>
  155. </View>
  156. );
  157. };
  158. const styles = StyleSheet.create({
  159. container: {
  160. flex: 1,
  161. },
  162. background: {
  163. flex: 1,
  164. },
  165. header: {
  166. flexDirection: 'row',
  167. alignItems: 'center',
  168. justifyContent: 'space-between',
  169. paddingHorizontal: 15,
  170. height: 90,
  171. },
  172. backBtn: {
  173. width: 40,
  174. height: 40,
  175. justifyContent: 'center',
  176. },
  177. title: {
  178. fontSize: 18,
  179. fontWeight: 'bold',
  180. color: '#fff',
  181. },
  182. placeholder: {
  183. width: 40,
  184. },
  185. listContent: {
  186. padding: 15,
  187. paddingBottom: 120,
  188. },
  189. itemContainer: {
  190. height: 84,
  191. marginBottom: 6,
  192. },
  193. itemBg: {
  194. flex: 1,
  195. },
  196. itemContent: {
  197. flexDirection: 'row',
  198. alignItems: 'center',
  199. paddingHorizontal: 16,
  200. height: '100%',
  201. },
  202. imgContainer: {
  203. width: 58,
  204. height: 58,
  205. marginRight: 14,
  206. },
  207. imgBg: {
  208. width: '100%',
  209. height: '100%',
  210. justifyContent: 'center',
  211. alignItems: 'center',
  212. padding: 7,
  213. },
  214. goodsImg: {
  215. width: '100%',
  216. height: '100%',
  217. },
  218. infoContainer: {
  219. flex: 1,
  220. },
  221. roomName: {
  222. fontSize: 14,
  223. color: '#fff',
  224. fontWeight: '400',
  225. marginBottom: 10,
  226. textShadowColor: 'rgba(0,0,0,1)',
  227. textShadowOffset: { width: 1, height: 1 },
  228. textShadowRadius: 1,
  229. },
  230. row: {
  231. flexDirection: 'row',
  232. alignItems: 'center',
  233. },
  234. typeName: {
  235. fontSize: 12,
  236. color: '#2E0000',
  237. fontWeight: 'bold',
  238. marginRight: 10,
  239. },
  240. goodsNum: {
  241. fontSize: 10,
  242. color: '#2E0000',
  243. fontWeight: 'normal',
  244. },
  245. btnContainer: {
  246. marginLeft: 10,
  247. },
  248. auditBtn: {
  249. paddingHorizontal: 12,
  250. paddingVertical: 6,
  251. },
  252. auditBtnText: {
  253. fontSize: 12,
  254. color: '#fff',
  255. fontWeight: 'bold',
  256. },
  257. footer: {
  258. position: 'absolute',
  259. bottom: 0,
  260. left: 0,
  261. right: 0,
  262. alignItems: 'center',
  263. paddingTop: 10,
  264. },
  265. createBtn: {
  266. width: 160,
  267. height: 60,
  268. },
  269. createBtnBg: {
  270. width: '100%',
  271. height: '100%',
  272. justifyContent: 'center',
  273. alignItems: 'center',
  274. },
  275. createBtnText: {
  276. fontSize: 15,
  277. fontWeight: '800',
  278. color: '#fff',
  279. textShadowColor: 'rgba(0,0,0,1)',
  280. textShadowOffset: { width: 1, height: 1 },
  281. textShadowRadius: 1,
  282. },
  283. emptyContainer: {
  284. paddingTop: 100,
  285. alignItems: 'center',
  286. },
  287. emptyText: {
  288. color: 'rgba(255,255,255,0.6)',
  289. fontSize: 14,
  290. },
  291. });
  292. export default CreateListScreen;