import React, { useEffect, useState } from 'react'; import { View, Text, ScrollView, StyleSheet, TouchableOpacity, } from 'react-native'; import { useNavigation } from '@react-navigation/native'; import { NativeStackNavigationProp } from '@react-navigation/native-stack'; import BackIcon from '../../components/BackIcon'; import fontSize from '../../utils/fontsizeUtils'; import useOrderStore from '../../store/order'; import widthUtils from '../../utils/widthUtils'; import { ordersApi } from '../../services/api/orders'; import { Order } from '../../services/api/orders'; import { t } from '../../i18n'; interface OrderStore { order: any; payment_operator?: string; shipping?: { method: string; estimated_arrival: string; }; } export function ConfirmOrder() { const navigation = useNavigation>(); const orderInfo = useOrderStore() as unknown as OrderStore; const [order, setOrder] = useState(); const getOrder = async () => { const data = orderInfo.order; try { const response = await ordersApi.createOrder(data); console.log(response); setOrder(response); } catch (error) { navigation.goBack(); console.error('创建订单失败:', error); alert('创建订单失败,请重试'); } }; useEffect(() => { getOrder(); }, []); return ( {/* Header */} navigation.goBack()}> {t('confirmOrder.title')} {/* Order Number */} 📋 {t('confirmOrder.orderNumber')} {order?.order_no} {/* Payment Method */} 💳 {t('confirmOrder.paymentMethod')} {order?.payment_method} {orderInfo?.payment_operator} {/* Shipping Info */} 🚢 {t('confirmOrder.shippingInfo')} {t('confirmOrder.shippingMethod')} {orderInfo?.shipping?.method === 'sea' ? t('confirmOrder.seaShipping') : t('confirmOrder.airShipping')} {t('confirmOrder.estimatedArrival')} {orderInfo?.shipping?.estimated_arrival} {/* Recipient Info */} 👤 收件人信息 {order?.receiver_name} {order?.receiver_phone} {order?.receiver_address} {/* Order Items */} 📦 {t('confirmOrder.orderItems')} {order?.items?.map((item) => ( {item.product_name} {item.sku_attributes.map((attr) => ( {attr.attribute_name}: {attr.value} ))} x{item.quantity} ${item.total_price} ))} {/* Price Summary */} {t('confirmOrder.totalPrice')} ${order?.total_amount} {t('confirmOrder.domesticShipping')} ${order?.discount_amount} {t('confirmOrder.internationalShipping')} ${order?.shipping_fee} {t('confirmOrder.actualAmount')} ${order?.actual_amount} {/* Bottom Button */} navigation.navigate('Pay', { order_id: order?.order_id })} > {t('confirmOrder.payNow')} ); } const styles = StyleSheet.create({ mainContainer: { flex: 1, backgroundColor: '#fff', }, container: { flex: 1, backgroundColor: '#fff', }, header: { flexDirection: 'row', alignItems: 'center', padding: 16, backgroundColor: '#fff', elevation: 3, }, title: { fontSize: fontSize(18), fontWeight: '500', flex: 1, textAlign: 'center', }, section: { backgroundColor: '#fff', padding: 16, }, sectionHeader: { flexDirection: 'row', alignItems: 'center', marginBottom: 12, }, sectionIcon: { fontSize: fontSize(18), marginRight: 8, }, sectionTitle: { fontSize: fontSize(16), fontWeight: '500', }, border: { height: widthUtils(6,6).height, backgroundColor: '#f5f5f5', }, orderNumber: { fontSize: fontSize(16), color: '#666', }, paymentInfo: { backgroundColor: '#f8f8f8', padding: 12, borderRadius: 8, }, paymentMethod: { fontSize: fontSize(16), fontWeight: '500', marginBottom: 4, }, paymentOperator: { fontSize: fontSize(14), color: '#666', }, shippingInfo: { backgroundColor: '#f8f8f8', padding: 12, borderRadius: 8, }, shippingRow: { flexDirection: 'row', marginBottom: 8, }, shippingLabel: { fontSize: fontSize(14), color: '#666', width: widthUtils(80,80).width, }, shippingValue: { fontSize: fontSize(14), flex: 1, }, recipientInfo: { backgroundColor: '#f8f8f8', padding: 12, borderRadius: 8, }, recipientName: { fontSize: fontSize(16), fontWeight: '500', marginBottom: 4, }, recipientPhone: { fontSize: fontSize(14), color: '#666', marginBottom: 4, }, recipientAddress: { fontSize: fontSize(14), color: '#666', }, orderItems: { gap: 12, }, orderItem: { flexDirection: 'row', padding: 12, backgroundColor: '#f8f8f8', borderRadius: 8, }, itemDetails: { flex: 1, }, itemName: { fontSize: fontSize(14), marginBottom: 4, }, itemAttribute: { fontSize: fontSize(12), color: '#666', marginBottom: 2, }, itemQuantity: { fontSize: fontSize(12), color: '#999', marginTop: 4, }, itemPrice: { justifyContent: 'center', }, priceText: { fontSize: fontSize(16), fontWeight: '500', color: '#ff6000', }, priceSummary: { backgroundColor: '#f8f8f8', padding: 16, borderRadius: 8, }, priceRow: { flexDirection: 'row', justifyContent: 'space-between', marginBottom: 12, }, priceLabel: { fontSize: fontSize(14), color: '#666', }, priceValue: { fontSize: fontSize(14), color: '#333', }, totalRow: { marginTop: 8, paddingTop: 12, borderTopWidth: 1, borderTopColor: '#eee', }, totalLabel: { fontSize: fontSize(16), fontWeight: '500', }, totalAmount: { fontSize: fontSize(18), fontWeight: '600', color: '#ff6000', }, bottomButton: { width: '100%', padding: 16, backgroundColor: '#fff', }, bottomButtonContent: { backgroundColor: '#ff6000', padding: 16, borderRadius: 25, alignItems: 'center', }, bottomButtonText: { color: '#fff', fontSize: fontSize(16), fontWeight: '500', }, });