import { View, Text, Pressable, Image, ScrollView, Alert, ImageBackground, ActivityIndicator } from 'react-native'; import { SafeAreaView } from 'react-native-safe-area-context'; import { router, useLocalSearchParams } from 'expo-router'; import { PreviousPageBlackSvg } from '../global/SVG'; import { useEffect, useState } from 'react'; import { authenticationService } from '../../service/authService'; import { FlashList } from '@shopify/flash-list'; import { walletService } from '../../service/walletService'; import { convertToHKTime } from '../../util/lib'; import { useTranslation } from '../../util/hooks/useTranslation'; interface TransactionRecordItem { date: string; description: string; amount: number; actual_total_power: string | number; current_price?: number; } const TransactionRow: React.FC = ({ date, description, amount, actual_total_power, current_price }) => { const { t } = useTranslation(); // 使用翻译钩子 return ( {date} {t(`payment_record.descriptions.${description}`) || description} {actual_total_power !== '-' ? Number(actual_total_power).toFixed(1) : actual_total_power} {current_price ? `${current_price}` : '-'} ${amount} ); }; const PaymentRecordPageComponent = () => { const { t } = useTranslation(); // 使用翻译钩子 const params = useLocalSearchParams(); const walletBalance = params.walletBalance; const [transactionRecord, setTransactionRecord] = useState([]); const [loading, setLoading] = useState(false); useEffect(() => { const fetchTransactionRecord = async () => { try { const response = await walletService.getTransactionRecord(); const formattedData: TransactionRecordItem[] = response .sort((a: any, b: any) => new Date(b.createdAt) - new Date(a.createdAt)) .filter( (item: any) => item.type !== 'wallet' || item.goods_name === 'Penalty' || item.goods_name === 'manual_refund' || item.goods_name === 'manual_deduction' || (item.goods_name === 'Walk In' && Number(item.actual_total_power) >= 1) ) .map((item: any) => { let description; if (item.type === 'wallet') { switch (item.goods_name) { case 'withdrawl': description = 'withdraw_balance'; break; case 'Penalty': description = 'pay_penalty'; break; case 'Book a connector': description = 'booking_summary'; break; case 'Walk In': description = 'charging_summary'; break; case 'manual_refund': description = 'system_refund'; break; case 'manual_deduction': description = 'system_deduction'; break; default: description = 'charging'; } } else if (item.type === 'qfpay') { description = 'wallet_top_up'; } return { date: convertToHKTime(item.createdAt).hkDate, description: description, amount: (() => { if (item.goods_name === 'Walk In') { return item.amountNew ? (item.amountNew).toFixed(1) : '0'; } else { if (item.type === 'qfpay' || item.goods_name === 'Penalty' || item.goods_name === 'manual_refund' || item.goods_name === 'manual_deduction') { return item.amount; } else { return item.current_price && item.actual_total_power ? (item.current_price * item.actual_total_power).toFixed(1) : '-'; } } })(), actual_total_power: item.goods_name === 'manual_refund' || item.goods_name === 'manual_deduction' ? '-' : item.actual_total_power !== undefined && item.actual_total_power !== null && item.actual_total_power !== '' && !isNaN(Number(item.actual_total_power)) ? item.actual_total_power : '-', current_price: item.type === 'qfpay' || item.goods_name === 'Penalty' || item.goods_name === 'manual_refund' || item.goods_name === 'manual_deduction' ? '-' : item.current_price }; }); setTransactionRecord(formattedData.slice(0, 10)); console.log('ddd', formattedData); } catch (error) { console.error(t('payment_record.error_fetching_records'), error); } }; fetchTransactionRecord(); }, []); return ( { if (router.canGoBack()) { router.back(); } else { router.replace('/accountMainPage'); } }} > {t('payment_record.title')} {t('payment_record.balance_label')} {loading ? ( ) : ( <> $ {walletBalance} )} {t('payment_record.headers.date')} {t('payment_record.headers.content')} {t('payment_record.headers.actual_power')} {t('payment_record.headers.electricity_price')} {t('payment_record.headers.amount')} ( )} /> ); }; export default PaymentRecordPageComponent;