swipe.tsx 14 KB

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