import { Image } from "expo-image"; import { useLocalSearchParams, useRouter } from "expo-router"; import React, { useCallback, useEffect, useRef, useState } from "react"; import { ActivityIndicator, Alert, ImageBackground, StatusBar, StyleSheet, Text, TouchableOpacity, View, } from "react-native"; import { useSafeAreaInsets } from "react-native-safe-area-context"; import { Images } from "@/constants/images"; import { convertApply, convertPreview, getLuckDetail } from "@/services/award"; const LEVEL_MAP: Record = { A: { title: "超神", color: "#FF3B30" }, B: { title: "欧皇", color: "#FF9500" }, C: { title: "隐藏", color: "#AF52DE" }, D: { title: "普通", color: "#8E8E93" }, }; const FROM_TYPE_MAP: Record = { MALL: "商城", DISTRIBUTION: "分销", LUCK: "奖池", LUCK_PICKUP: "商品提货", LUCK_EXCHANGE: "商品兑换", SUBSTITUTE: "商品置换", TRANSFER: "商品转赠", LUCK_ROOM: "福利房", LUCK_WHEEL: "魔天轮", DOLL_MACHINE: "扭蛋", RECHARGE: "充值", OFFICIAL: "官方", ACTIVITY: "活动", LUCK_ACTIVITY: "奖池活动", REDEEM_CODE_ACTIVITY: "兑换码活动", }; export default function StoreDetailScreen() { const { id } = useLocalSearchParams<{ id: string }>(); const router = useRouter(); const insets = useSafeAreaInsets(); const [loading, setLoading] = useState(true); const [item, setItem] = useState(null); const [converting, setConverting] = useState(false); const loadData = useCallback(async () => { if (!id) return; setLoading(true); try { const data = await getLuckDetail(id); setItem(data); } catch (e) { console.error("加载详情失败:", e); } setLoading(false); }, [id]); useEffect(() => { loadData(); }, [loadData]); const handleConvert = async () => { if (!item || item.magicAmount <= 0) { Alert.alert("提示", "不可兑换"); return; } setConverting(true); try { const preview = await convertPreview([item.id]); if (preview?.data) { Alert.alert( "确认兑换", `将兑换 ${item.spu?.name} 获得 ${preview.data?.totalMagicAmount || item.magicAmount} 果实`, [ { text: "取消", style: "cancel" }, { text: "确定", onPress: async () => { const success = await convertApply([item.id]); if (success) { Alert.alert("提示", "兑换成功", [ { text: "确定", onPress: () => router.back() }, ]); } }, }, ], ); } } catch (e) { Alert.alert("提示", "兑换失败"); } setConverting(false); }; if (loading) { return ( ); } if (!item) { return ( 商品不存在 ); } const levelInfo = LEVEL_MAP[item.level] || { title: "其他", color: "#999" }; return ( {/* 顶部导航 */} router.back()} > 仓库 {/* 商品信息 */} {levelInfo.title} {item.spu?.name} 从{FROM_TYPE_MAP[item.fromRelationType] || "其他"}获得 {/* 兑换按钮 */} {item.magicAmount > 0 && ( 兑换果实 可兑换 {item.magicAmount} 果实 )} ); } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: "#1a1a2e" }, background: { flex: 1 }, loadingBox: { flex: 1, backgroundColor: "#1a1a2e", justifyContent: "center", alignItems: "center", }, header: { flexDirection: "row", alignItems: "center", justifyContent: "space-between", paddingHorizontal: 15, paddingBottom: 10, }, backBtn: { width: 40, height: 40, justifyContent: "center", alignItems: "center", }, backText: { color: "#fff", fontSize: 20 }, title: { color: "#fff", fontSize: 16, fontWeight: "bold" }, placeholder: { width: 40 }, content: { flex: 1, paddingHorizontal: 20, paddingTop: 20 }, detailCard: { backgroundColor: "rgba(255,255,255,0.95)", borderRadius: 16, padding: 24, alignItems: "center", }, coverImage: { width: 180, height: 180, borderRadius: 10, marginBottom: 16, }, levelTag: { fontSize: 16, fontWeight: "bold", marginBottom: 8, textShadowColor: "#000", textShadowOffset: { width: 1, height: 1 }, textShadowRadius: 0, }, goodsName: { fontSize: 16, color: "#333", fontWeight: "bold", textAlign: "center", marginBottom: 12, lineHeight: 22, }, sourceBox: { backgroundColor: "rgba(0,0,0,0.05)", borderRadius: 20, paddingHorizontal: 16, paddingVertical: 6, }, sourceText: { fontSize: 13, color: "#666" }, bottomBar: { paddingHorizontal: 30, paddingTop: 10, alignItems: "center", }, convertBtn: { width: "80%", height: 60, }, convertBtnBg: { width: "100%", height: "100%", justifyContent: "center", alignItems: "center", }, convertBtnText: { color: "#000", fontSize: 16, fontWeight: "bold", }, convertBtnSub: { color: "#735200", fontSize: 11, }, });