import { Images } from '@/constants/images'; import ServiceWallet from '@/services/wallet'; import { Ionicons } from '@expo/vector-icons'; import { Stack, useRouter } from 'expo-router'; import React, { useEffect, useState } from 'react'; import { Dimensions, ImageBackground, ScrollView, StatusBar, StyleSheet, Text, TouchableOpacity, View, } from 'react-native'; import { useSafeAreaInsets } from 'react-native-safe-area-context'; const { width: SCREEN_WIDTH } = Dimensions.get('window'); interface CouponItem { id: string; name: string; amount: number; fullAmount: number; // For "Man X Keyong" status: number; // 1: Valid endTime: string; scene?: string; // LUCK, MALL, TRADE } export default function CouponScreen() { const router = useRouter(); const insets = useSafeAreaInsets(); const [list, setList] = useState([]); const [loading, setLoading] = useState(false); useEffect(() => { loadData(); }, []); const loadData = async () => { try { setLoading(true); const res = await ServiceWallet.coupons(); // Ensure res is array or fetch from res.records if paginated const data = Array.isArray(res) ? res : (res?.records || []); setList(data); } catch (e) { console.error(e); } finally { setLoading(false); } }; const handleUse = (item: CouponItem) => { // Original behavior: goAward() -> /pages/award/index (Box Screen) // We replicate this 1:1, or maintain specific routing if mall requires it. // Given request for 1:1, we prioritize Box screen. if (item.scene === 'MALL') { router.push('/(tabs)/store' as any); } else { router.push('/(tabs)/box' as any); } }; const formatTime = (time: string) => { return time ? time.slice(0, 10) : ''; }; return ( router.back()}> 优惠券 {list.length > 0 ? ( list.map((item, index) => ( handleUse(item)} > ¥ {item.amount} 满{item.fullAmount}可用 {item.name} {formatTime(item.endTime)}过期 立即使用 )) ) : ( 暂无优惠券 )} ); } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#1a1a2e', }, header: { position: 'absolute', top: 0, left: 0, right: 0, zIndex: 100, alignItems: 'center', paddingBottom: 10, }, backBtn: { position: 'absolute', left: 10, bottom: 10, zIndex: 101, }, title: { color: '#fff', fontSize: 16, fontWeight: 'bold', }, background: { flex: 1, width: '100%', height: '100%', }, scrollView: { flex: 1, }, couponItem: { width: '100%', height: 92, // 184rpx / 2 = 92 flexDirection: 'row', alignItems: 'center', marginBottom: 10, paddingHorizontal: 15, // Adjust padding based on image visual }, grayscale: { opacity: 0.6, // React Native doesn't support grayscale prop directly on ImageBackground without filter or tintColor tricks // but opactity is a good enough approximation for invalid state }, left: { width: 80, alignItems: 'center', justifyContent: 'center', }, amountBox: { flexDirection: 'row', alignItems: 'baseline', }, symbol: { fontSize: 12, color: '#404040', }, amount: { fontSize: 30, fontWeight: 'bold', color: '#404040', }, fullAmount: { fontSize: 12, color: '#8F8F8F', marginTop: 2, }, divider: { width: 1, height: 24, backgroundColor: '#C3B3DF', marginHorizontal: 16, // opacity: 0, // Removed to match original design }, right: { flex: 1, flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', paddingLeft: 10, }, info: { justifyContent: 'center', }, name: { fontSize: 15, fontWeight: 'bold', color: '#404040', marginBottom: 5, }, time: { fontSize: 12, color: '#8F8F8F', }, useBtn: { width: 87, // 174rpx / 2 height: 37, // 74rpx / 2 justifyContent: 'center', alignItems: 'center', }, useText: { color: '#fff', fontSize: 12, }, emptyBox: { marginTop: 100, alignItems: 'center', }, emptyText: { color: '#999', fontSize: 14, }, });