import React, { useEffect, useState } from "react"; import { View, Text, StyleSheet, TouchableOpacity, ActivityIndicator, ScrollView, Image, Alert, Linking, SafeAreaView, StatusBar, Platform, } from "react-native"; import BackIcon from "../../components/BackIcon"; import MassageIcon from "../../components/MassageIcon"; import fontSize from "../../utils/fontsizeUtils"; import { useNavigation } from "@react-navigation/native"; import { NativeStackNavigationProp } from "@react-navigation/native-stack"; import { useRoute, RouteProp } from "@react-navigation/native"; import { ordersApi, OrderDetailsType } from "../../services/api/orders"; import OrderIcon from "../../components/OrderIcon"; import InfoIcon from "../../components/InfoIcon"; import Progress from "./Progress"; import AddressIcon from "../../components/AddressIcon"; import EditIcon from "../../components/ColorfulEditIcon"; import BrightnessIcon from "../../components/BrightnessIcon"; import PhoneIcon from "../../components/PhoneIcon"; import ShoppingBagIcon from "../../components/ShoppingBagIcon"; import PowerIcon from "../../components/PowerIcon"; import CardIcon from "../../components/ShoppingCartIcon"; import WhatsAppIcon from "../../components/WatchAppIcon"; import { useOrderListStore } from "../../store/orderList"; export const OrderDetails = () => { const navigation = useNavigation>(); const route = useRoute< RouteProp< { OrderDetails: { orderId: string; }; }, "OrderDetails" > >(); const [orderDetails, setOrderDetails] = useState(); const [isLoading, setIsLoading] = useState(true); const { deleteOrder, changeOrder,updateOrderShippingInfo } = useOrderListStore(); const getOrderDetails = async () => { try { setIsLoading(true); const response = await ordersApi.getOrderDetails(route.params.orderId); setOrderDetails(response); } catch (error) { console.error("Error fetching order details:", error); } finally { setIsLoading(false); } }; useEffect(() => { getOrderDetails(); }, []); //拨打电话 const callPhone = async (phoneNumber: string) => { const url = `tel:${phoneNumber}`; try { await Linking.openURL(url); // 直接尝试打开拨号界面 } catch (error) { Alert.alert("错误", "无法打开拨号界面"); console.error("拨号失败:", error); } }; return ( navigation.goBack()}> 订单详情 {isLoading ? ( ) : orderDetails ? ( 订单状态 {/* 订单信息 */} 订单信息 订单id {orderDetails.order_id} 下单时间 {orderDetails.create_time} 运输方式 {orderDetails.shipping_fee} {/* 配送信息 */} 配送信息 仓库 {orderDetails.receiver_address} 付款后联系方式 收货人 {/* 姓名 */} {orderDetails.receiver_name} {/* 电话 */} {orderDetails.receiver_phone} {/* watchApp */} WhatsApp: {orderDetails.receiver_phone} {/* 商品信息 */} 商品信息 ({orderDetails.items.length}) {orderDetails.items.map((item, index) => ( {item.product_name} {item.sku_attributes.map((sku, index) => ( {sku.attribute_name}:{sku.attribute_value} ))} {/* {item.product_name} */} {item.total_price} x{item.quantity} ))} 添加到购物车 {/* 价格信息 */} 价格详情 小计 {orderDetails.total_amount} 平台运费 {orderDetails.shipping_fee} 国际运费 {orderDetails.shipping_fee} 总价 {orderDetails.total_amount} + ${orderDetails.shipping_fee} 预计国际运费 (COD) {/* 代付款 */} {orderDetails.order_status === 0 && ( { deleteOrder(route.params.orderId); }} > 取消订单 { navigation.navigate("Pay", { order_id: route.params.orderId, }); }} > 付款 )} {/* 待发货 */} {orderDetails.order_status === 1 && ( { callPhone("15903995548"); }} > 联系货代中心 { changeOrder(route.params.orderId, 2); navigation.goBack(); }} > 取消订单 )} {/* 代收货 */} {orderDetails.order_status === 2 && ( {}}> 查询物流 { updateOrderShippingInfo(route.params.orderId,{ shipping_status: 0, shipping_info: { shipping_company: "string", shipping_no: "string", shipping_info: {} } }); navigation.goBack(); }} > 确认收货 )} {/* 已完成 */} {orderDetails.order_status === 3 && ( { deleteOrder(route.params.orderId); navigation.goBack(); }} > 取消订单 立即付款 )} {/* 已取消 */} {orderDetails.order_status === 4 && ( {}}> 添加到购物车 重新下单 )} ) : ( 无法加载订单状态 )} ); }; const styles = StyleSheet.create({ safeArea: { flex: 1, backgroundColor: '#fff', }, safeAreaContent: { flex: 1, paddingTop: 0, }, container: { flex: 1, backgroundColor: "#f8f9fa", }, header: { flexDirection: "row", justifyContent: "space-between", alignItems: "center", padding: 16, backgroundColor: "#fff", shadowColor: "#000", shadowOffset: { width: 0, height: 2, }, shadowOpacity: 0.1, shadowRadius: 3, elevation: 3, }, title: { fontSize: fontSize(16), fontWeight: "600", }, orderStatus: { paddingInline: 16, marginTop: 10, }, orderStatusContent: { backgroundColor: "#fff", borderRadius: 16, }, orderStatusTitle: { flexDirection: "row", alignItems: "center", borderBottomWidth: 1, borderColor: "#f5f5f5", padding: 10, }, orderStatusTitleText: { fontSize: fontSize(16), fontWeight: "600", marginLeft: 10, }, orderStatusContentPreview: { padding: 10, justifyContent: "center", }, productItem: { flexDirection: "row", width: "100%", borderBottomWidth: 1, borderColor: "#f5f5f5", padding: 10, }, productItemImage: { width: "15%", height: 50, borderRadius: 10, }, productItemInfo: { width: "75%", justifyContent: "space-between", paddingLeft: 10, }, productItemNum: { width: "10%", alignItems: "center", justifyContent: "flex-end", }, productItemNumText: { fontSize: fontSize(16), color: "#999", }, productItemInfoName: { width: "100%", paddingVertical: 5, }, productItemInfoNameText: { fontSize: fontSize(13), fontWeight: "600", }, productItemInfoSkuText: { fontSize: fontSize(13), color: "#999", }, productItemInfoSku: { width: "100%", paddingVertical: 5, }, productItemInfoPrice: { width: "100%", paddingVertical: 5, }, orderStatusContentPreviewInformation: { flexDirection: "row", justifyContent: "space-between", width: "100%", }, loadingContainer: { flex: 1, justifyContent: "center", alignItems: "center", }, orderId: { flexDirection: "row", justifyContent: "space-between", paddingVertical: 10, width: "100%", }, orderIdText: { color: "#999", width: "50%", fontSize: fontSize(14), }, orderIdText1: { width: "50%", textAlign: "right", fontSize: fontSize(14), }, TotalText: { color: "#f77f3a", fontSize: fontSize(18), fontWeight: "600", width: "50%", }, TotalPrice: { color: "#f77f3a", fontSize: fontSize(18), fontWeight: "600", width: "50%", textAlign: "right", }, warehouse: { width: "50%", }, recipientTitle: { paddingVertical: 5, }, recipientPhoneContainer: { flexDirection: "row", alignItems: "center", }, recipient: { width: "50%", }, orderStatusContentPreviewInformationText: { fontSize: fontSize(16), fontWeight: "600", }, warehousePhone: { padding: 5, backgroundColor: "#f9f9f9", borderRadius: 10, width: "90%", flexDirection: "row", alignItems: "center", }, warehousePhoneText: { fontSize: fontSize(14), fontWeight: "400", color: "#3D3D3D", }, warehousePhoneTextContainer: { paddingRight: 5, }, recipientName: { fontSize: fontSize(16), fontWeight: "600", }, recipientPhone: { fontSize: fontSize(14), fontWeight: "400", color: "#3D3D3D", }, dottedLine: { width: "100%", borderBottomWidth: 2, borderColor: "#f5f5f5", borderStyle: "dashed", }, orderRemakeText: { fontSize: fontSize(14), fontWeight: "400", color: "#999", }, addCard: { width: "100%", justifyContent: "center", alignItems: "center", }, addCardBox: { padding: 10, borderWidth: 1, borderColor: "#0098ef", borderRadius: 10, backgroundColor: "#e2f2fd", opacity: 0.5, flexDirection: "row", alignItems: "center", }, addCardText: { fontSize: fontSize(16), fontWeight: "600", color: "#0098ef", marginLeft: 5, }, bottomButtons: { position: "absolute", bottom: 0, width: "100%", flexDirection: "row", justifyContent: "center", alignItems: "center", padding: 10, backgroundColor: "#fff", shadowColor: "#000", shadowOffset: { width: 0, height: -4, }, shadowOpacity: 0.1, shadowRadius: 3, elevation: 3, }, bottomButton1: { padding: 10, marginHorizontal: 10, alignItems: "center", backgroundColor: "#f0f0f0", borderRadius: 5, flex: 1, }, bottomButton: { padding: 10, marginHorizontal: 10, alignItems: "center", backgroundColor: "#fe7f42", borderRadius: 5, flex: 1, }, bottomButtonText: { fontSize: fontSize(18), fontWeight: "600", color: "#fff", }, bottomButtonText1: { fontSize: fontSize(18), fontWeight: "600", color: "#999", }, });