swipe.tsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. import { Image } from 'expo-image';
  2. import { useLocalSearchParams, useRouter } from 'expo-router';
  3. import React, { useCallback, useEffect, useState } from 'react';
  4. import {
  5. ActivityIndicator,
  6. Dimensions,
  7. ScrollView,
  8. StatusBar,
  9. StyleSheet,
  10. Text,
  11. TouchableOpacity,
  12. View,
  13. } from 'react-native';
  14. import { useSafeAreaInsets } from 'react-native-safe-area-context';
  15. import { getPoolDetail } from '@/services/award';
  16. const { width: SCREEN_WIDTH } = Dimensions.get('window');
  17. interface ProductItem {
  18. id: string;
  19. name: string;
  20. cover: string;
  21. level: string;
  22. probability: number;
  23. quantity?: number;
  24. spu?: {
  25. id: string;
  26. cover: string;
  27. name: string;
  28. marketPrice?: number;
  29. parameter?: string;
  30. brandName?: string;
  31. worksName?: string;
  32. pic?: string;
  33. };
  34. }
  35. interface PoolData {
  36. id: string;
  37. name: string;
  38. price: number;
  39. luckGoodsList: ProductItem[];
  40. recommendedLuckPool?: any[];
  41. }
  42. export default function AwardDetailSwipeScreen() {
  43. const { poolId, index } = useLocalSearchParams<{ poolId: string; index: string }>();
  44. const router = useRouter();
  45. const insets = useSafeAreaInsets();
  46. const [loading, setLoading] = useState(true);
  47. const [data, setData] = useState<PoolData | null>(null);
  48. const [products, setProducts] = useState<ProductItem[]>([]);
  49. const [currentIndex, setCurrentIndex] = useState(parseInt(index || '0', 10));
  50. const loadData = useCallback(async () => {
  51. if (!poolId) return;
  52. setLoading(true);
  53. try {
  54. const detail = await getPoolDetail(poolId);
  55. if (detail) {
  56. setData(detail);
  57. setProducts(detail.luckGoodsList || []);
  58. }
  59. } catch (error) {
  60. console.error('加载数据失败:', error);
  61. }
  62. setLoading(false);
  63. }, [poolId]);
  64. useEffect(() => {
  65. loadData();
  66. }, [poolId]);
  67. const handlePrev = () => {
  68. if (currentIndex > 0) setCurrentIndex(currentIndex - 1);
  69. };
  70. const handleNext = () => {
  71. if (currentIndex < products.length - 1) setCurrentIndex(currentIndex + 1);
  72. };
  73. const parseParameter = (paramStr?: string) => {
  74. if (!paramStr) return [];
  75. try {
  76. return JSON.parse(paramStr);
  77. } catch {
  78. return [];
  79. }
  80. };
  81. if (loading) {
  82. return (
  83. <View style={[styles.loadingContainer, { paddingTop: insets.top }]}>
  84. <ActivityIndicator size="large" color="#ff6600" />
  85. </View>
  86. );
  87. }
  88. if (!data || products.length === 0) {
  89. return (
  90. <View style={[styles.loadingContainer, { paddingTop: insets.top }]}>
  91. <Text style={styles.errorText}>商品不存在</Text>
  92. <TouchableOpacity style={styles.backBtn2} onPress={() => router.back()}>
  93. <Text style={styles.backBtn2Text}>返回</Text>
  94. </TouchableOpacity>
  95. </View>
  96. );
  97. }
  98. const currentProduct = products[currentIndex];
  99. const params = parseParameter(currentProduct?.spu?.parameter);
  100. const detailPics = currentProduct?.spu?.pic ? currentProduct.spu.pic.split(',').filter(Boolean) : [];
  101. const recommendList = data.recommendedLuckPool || [];
  102. return (
  103. <View style={styles.container}>
  104. <StatusBar barStyle="dark-content" />
  105. {/* 顶部导航 */}
  106. <View style={[styles.header, { paddingTop: insets.top }]}>
  107. <TouchableOpacity style={styles.backBtn} onPress={() => router.back()}>
  108. <Text style={styles.backText}>{'<'}</Text>
  109. </TouchableOpacity>
  110. <View style={styles.placeholder} />
  111. </View>
  112. <ScrollView style={styles.scrollView} showsVerticalScrollIndicator={false}>
  113. {/* 商品图片区域 */}
  114. <View style={styles.imageSection}>
  115. <Image
  116. source={{ uri: currentProduct?.spu?.cover || currentProduct?.cover }}
  117. style={styles.productImage}
  118. contentFit="contain"
  119. />
  120. {/* 左右切换按钮 */}
  121. {currentIndex > 0 && (
  122. <TouchableOpacity style={styles.prevBtn} onPress={handlePrev}>
  123. <Text style={styles.arrowText}>{'<'}</Text>
  124. </TouchableOpacity>
  125. )}
  126. {currentIndex < products.length - 1 && (
  127. <TouchableOpacity style={styles.nextBtn} onPress={handleNext}>
  128. <Text style={styles.arrowText}>{'>'}</Text>
  129. </TouchableOpacity>
  130. )}
  131. </View>
  132. {/* 价格和名称区域 */}
  133. <View style={styles.priceSection}>
  134. <View style={styles.priceRow}>
  135. <Text style={styles.priceText}>¥{currentProduct?.spu?.marketPrice || data.price}</Text>
  136. </View>
  137. <Text style={styles.productName}>{currentProduct?.name}</Text>
  138. </View>
  139. {/* 参数区域 */}
  140. <View style={styles.paramSection}>
  141. <View style={styles.paramHeader}>
  142. <Text style={styles.paramTitle}>参数</Text>
  143. </View>
  144. {params.length > 0 && (
  145. <ScrollView horizontal showsHorizontalScrollIndicator={false} style={styles.paramScroll}>
  146. {params.map((param: { label: string; value: string }, idx: number) => (
  147. <View key={idx} style={styles.paramItem}>
  148. <Text style={styles.paramLabel}>{param.label}</Text>
  149. <Text style={styles.paramValue}>{param.value}</Text>
  150. </View>
  151. ))}
  152. </ScrollView>
  153. )}
  154. {currentProduct?.spu?.worksName && (
  155. <View style={styles.paramRow}>
  156. <Text style={styles.paramRowLabel}>IP</Text>
  157. <Text style={styles.paramRowValue}>{currentProduct.spu.worksName}</Text>
  158. </View>
  159. )}
  160. {currentProduct?.spu?.brandName && (
  161. <View style={styles.paramRow}>
  162. <Text style={styles.paramRowLabel}>品牌</Text>
  163. <Text style={styles.paramRowValue}>{currentProduct.spu.brandName}</Text>
  164. </View>
  165. )}
  166. </View>
  167. {/* 放心购 正品保障 */}
  168. <View style={styles.guaranteeSection}>
  169. <Text style={styles.guaranteeTitle}>放心购 正品保障</Text>
  170. <Text style={styles.guaranteeText}>不支持七天无理由退换货 包邮</Text>
  171. </View>
  172. {/* 商品推荐 */}
  173. {recommendList.length > 0 && (
  174. <View style={styles.recommendSection}>
  175. <Text style={styles.recommendTitle}>商品推荐</Text>
  176. <ScrollView horizontal showsHorizontalScrollIndicator={false} contentContainerStyle={styles.recommendScroll}>
  177. {recommendList.map((item: any) => (
  178. <TouchableOpacity
  179. key={item.id}
  180. style={styles.recommendItem}
  181. activeOpacity={0.8}
  182. onPress={() => router.push({ pathname: '/award-detail', params: { poolId: item.id } } as any)}
  183. >
  184. <Image source={{ uri: item.cover }} style={styles.recommendImage} contentFit="contain" />
  185. <Text style={styles.recommendName} numberOfLines={1}>{item.name}</Text>
  186. <Text style={styles.recommendPrice}>¥{item.price}</Text>
  187. </TouchableOpacity>
  188. ))}
  189. </ScrollView>
  190. </View>
  191. )}
  192. {/* 商品详情 */}
  193. <View style={styles.detailSection}>
  194. <Text style={styles.detailTitle}>商品详情</Text>
  195. {detailPics.length > 0 ? (
  196. detailPics.map((pic, idx) => (
  197. <Image key={idx} source={{ uri: pic }} style={styles.detailImage} contentFit="contain" />
  198. ))
  199. ) : (
  200. <View style={styles.detailContent}>
  201. <Text style={styles.detailHeading}>商城购买须知!</Text>
  202. <Text style={styles.detailSubTitle}>商城现货</Text>
  203. <Text style={styles.detailText}>
  204. 商城所售现货商品均为全新正版商品。手办模玩非艺术品,因厂商品控差异导致的微小瑕疵属于正常情况,官图仅供参考,具体以实物为准。
  205. </Text>
  206. <Text style={styles.detailSubTitle}>新品预定</Text>
  207. <Text style={styles.detailText}>
  208. 预定商品的总价=定金+尾款,在预定期限内支付定金后,商品到货并补齐尾款后,超级商城才会发货相应商品预定订单确认成功后,定金不可退。{'\n'}
  209. 商品页面显示的商品制作完成时间及预计补款时间,都是按照官方预估的时间推测,具体到货时间请以实际出货为准。如因厂商、海关等因素造成延期的,不接受以此原因申请定金退款,请耐心等待。
  210. </Text>
  211. <Text style={styles.detailSubTitle}>预售补款</Text>
  212. <Text style={styles.detailText}>
  213. 商品到货后超级商城会通过您在预定时预留的号码进行短信通知请自行留意。为防止错过补款通知,可添加商城客服,并备注所购商品进入对应社群,社群会同步推送新品咨询及补款通知。
  214. </Text>
  215. </View>
  216. )}
  217. </View>
  218. <View style={{ height: 50 }} />
  219. </ScrollView>
  220. </View>
  221. );
  222. }
  223. const styles = StyleSheet.create({
  224. container: { flex: 1, backgroundColor: '#f5f5f5' },
  225. loadingContainer: { flex: 1, backgroundColor: '#f5f5f5', justifyContent: 'center', alignItems: 'center' },
  226. errorText: { color: '#999', fontSize: 16 },
  227. backBtn2: { marginTop: 20, backgroundColor: '#ff6600', paddingHorizontal: 20, paddingVertical: 10, borderRadius: 8 },
  228. backBtn2Text: { color: '#fff', fontSize: 14 },
  229. header: {
  230. flexDirection: 'row',
  231. alignItems: 'center',
  232. justifyContent: 'space-between',
  233. paddingHorizontal: 10,
  234. paddingBottom: 10,
  235. backgroundColor: 'transparent',
  236. position: 'absolute',
  237. top: 0,
  238. left: 0,
  239. right: 0,
  240. zIndex: 10,
  241. },
  242. backBtn: { width: 40, height: 40, justifyContent: 'center', alignItems: 'center' },
  243. backText: { color: '#333', fontSize: 24, fontWeight: 'bold' },
  244. placeholder: { width: 40 },
  245. scrollView: { flex: 1 },
  246. // 图片区域
  247. imageSection: {
  248. paddingTop: 80,
  249. paddingBottom: 20,
  250. alignItems: 'center',
  251. position: 'relative',
  252. },
  253. productImage: {
  254. width: SCREEN_WIDTH * 0.7,
  255. height: 350,
  256. },
  257. prevBtn: {
  258. position: 'absolute',
  259. left: 10,
  260. top: '50%',
  261. width: 36,
  262. height: 36,
  263. backgroundColor: 'rgba(0,0,0,0.3)',
  264. borderRadius: 18,
  265. justifyContent: 'center',
  266. alignItems: 'center',
  267. },
  268. nextBtn: {
  269. position: 'absolute',
  270. right: 10,
  271. top: '50%',
  272. width: 36,
  273. height: 36,
  274. backgroundColor: 'rgba(0,0,0,0.3)',
  275. borderRadius: 18,
  276. justifyContent: 'center',
  277. alignItems: 'center',
  278. },
  279. arrowText: { color: '#fff', fontSize: 18, fontWeight: 'bold' },
  280. // 价格区域
  281. priceSection: {
  282. backgroundColor: '#fff',
  283. paddingHorizontal: 16,
  284. paddingVertical: 12,
  285. },
  286. priceRow: {
  287. flexDirection: 'row',
  288. alignItems: 'baseline',
  289. },
  290. priceText: {
  291. fontSize: 24,
  292. color: '#ff4444',
  293. fontWeight: 'bold',
  294. },
  295. productName: {
  296. fontSize: 16,
  297. color: '#333',
  298. marginTop: 8,
  299. lineHeight: 22,
  300. },
  301. // 参数区域
  302. paramSection: {
  303. backgroundColor: '#fff',
  304. marginTop: 10,
  305. paddingHorizontal: 16,
  306. paddingVertical: 12,
  307. },
  308. paramHeader: {
  309. flexDirection: 'row',
  310. alignItems: 'center',
  311. paddingBottom: 10,
  312. borderBottomWidth: 1,
  313. borderBottomColor: '#eee',
  314. },
  315. paramTitle: {
  316. fontSize: 14,
  317. color: '#666',
  318. },
  319. paramScroll: {
  320. marginTop: 10,
  321. },
  322. paramItem: {
  323. paddingHorizontal: 12,
  324. borderRightWidth: 1,
  325. borderRightColor: '#eee',
  326. },
  327. paramLabel: { fontSize: 14, color: '#666' },
  328. paramValue: { fontSize: 14, color: '#333', marginTop: 4 },
  329. paramRow: {
  330. flexDirection: 'row',
  331. alignItems: 'center',
  332. paddingTop: 12,
  333. },
  334. paramRowLabel: {
  335. fontSize: 14,
  336. color: '#666',
  337. width: 50,
  338. },
  339. paramRowValue: {
  340. fontSize: 14,
  341. color: '#333',
  342. flex: 1,
  343. },
  344. // 放心购区域
  345. guaranteeSection: {
  346. backgroundColor: '#fff',
  347. marginTop: 10,
  348. paddingHorizontal: 16,
  349. paddingVertical: 12,
  350. flexDirection: 'row',
  351. alignItems: 'center',
  352. justifyContent: 'space-between',
  353. },
  354. guaranteeTitle: {
  355. fontSize: 14,
  356. color: '#333',
  357. fontWeight: 'bold',
  358. },
  359. guaranteeText: {
  360. fontSize: 12,
  361. color: '#999',
  362. },
  363. // 商品推荐
  364. recommendSection: {
  365. backgroundColor: '#1a1a1a',
  366. marginTop: 10,
  367. paddingHorizontal: 16,
  368. paddingVertical: 16,
  369. },
  370. recommendTitle: {
  371. fontSize: 16,
  372. fontWeight: 'bold',
  373. color: '#fff',
  374. marginBottom: 12,
  375. },
  376. recommendScroll: {
  377. paddingRight: 10,
  378. },
  379. recommendItem: {
  380. width: 90,
  381. marginRight: 12,
  382. },
  383. recommendImage: {
  384. width: 90,
  385. height: 90,
  386. backgroundColor: '#fff',
  387. borderRadius: 4,
  388. },
  389. recommendName: {
  390. fontSize: 12,
  391. color: '#fff',
  392. marginTop: 6,
  393. },
  394. recommendPrice: {
  395. fontSize: 14,
  396. color: '#ff4444',
  397. fontWeight: 'bold',
  398. marginTop: 4,
  399. },
  400. // 商品详情
  401. detailSection: {
  402. backgroundColor: '#1a1a1a',
  403. marginTop: 10,
  404. paddingHorizontal: 16,
  405. paddingVertical: 16,
  406. },
  407. detailTitle: {
  408. fontSize: 16,
  409. fontWeight: 'bold',
  410. color: '#fff',
  411. marginBottom: 16,
  412. },
  413. detailImage: {
  414. width: SCREEN_WIDTH - 32,
  415. height: 400,
  416. marginBottom: 10,
  417. },
  418. detailContent: {
  419. backgroundColor: '#fff',
  420. borderRadius: 8,
  421. padding: 16,
  422. },
  423. detailHeading: {
  424. fontSize: 18,
  425. fontWeight: 'bold',
  426. color: '#333',
  427. textAlign: 'center',
  428. marginBottom: 20,
  429. },
  430. detailSubTitle: {
  431. fontSize: 16,
  432. fontWeight: 'bold',
  433. color: '#333',
  434. marginTop: 16,
  435. marginBottom: 8,
  436. paddingLeft: 10,
  437. borderLeftWidth: 3,
  438. borderLeftColor: '#333',
  439. },
  440. detailText: {
  441. fontSize: 14,
  442. color: '#666',
  443. lineHeight: 22,
  444. },
  445. });