import { View, StyleSheet, Text, ScrollView, TouchableOpacity, Image, ActivityIndicator, SafeAreaView, StatusBar, Platform, } from "react-native"; import { useRoute, RouteProp } from "@react-navigation/native"; import { productStatus } from "../../constants/productStatus"; import BackIcon from "../../components/BackIcon"; import MassageIcon from "../../components/MassageIcon"; import { useEffect, useState, useRef } from "react"; import fontSize from "../../utils/fontsizeUtils"; import widthUtils from "../../utils/widthUtils"; import { useTranslation } from "react-i18next"; import { ordersApi, PaginatedOrderResponse, PaginatedOrderRequest, } from "../../services/api/orders"; import { useNavigation } from "@react-navigation/native"; import { NativeStackNavigationProp } from "@react-navigation/native-stack"; import { useOrderListStore } from "../../store/orderList"; // import ImageView from "react-native-image-viewing"; type StatusScreenRouteProp = RouteProp< { Status: { status: number }; }, "Status" >; export function Status() { const navigation = useNavigation>(); const route = useRoute(); const { t } = useTranslation(); const [statusList, setStatusList] = useState(() => { const initialList = [...productStatus]; initialList.unshift({ text: t("order.status.all"), textKey: "order.status.all", status: null, icon: BackIcon, }); return initialList; }); const [status, setStatus] = useState(null); const [page, setPage] = useState(1); const [pageSize, setPageSize] = useState(10); const [loading, setLoading] = useState(true); const [imageViewerVisible, setImageViewerVisible] = useState(false); const [currentImageIndex, setCurrentImageIndex] = useState(0); const [images, setImages] = useState([]); const statusScrollViewRef = useRef(null); const statusItemRef = useRef>(null); const { orders, getAllOrders } = useOrderListStore(); const getAllOrdersList = async () => { setLoading(true); try { const data = { page: page, page_size: pageSize, status: route.params.status, }; await getAllOrders(data, page); } finally { setLoading(false); } }; const scrollToStatus = () => { const itemIndex = statusList.findIndex( (item) => item.status === route.params.status ); console.log(itemIndex); statusItemRef.current?.measure((x, y, width, height, pageX, pageY) => { if (width) { statusScrollViewRef.current?.scrollTo({ x: width * (itemIndex - 1), animated: true, }); } }); }; useEffect(() => { setStatus(route.params.status); scrollToStatus(); setPage(1); getAllOrdersList(); }, []); const getStatus = (status: number) => { switch(status) { case 0: return t("order.status.waiting_payment"); case 1: return t("order.status.waiting_shipment"); case 2: return t("order.status.waiting_receipt"); case 3: return t("order.status.completed"); case 4: return t("order.status.cancelled"); case 5: return t("order.status.refunded"); case 6: return t("order.status.pay_shipping"); case 7: return t("order.status.in_transit"); case 8: return t("order.status.waiting_quote"); default: return t("order.status.unknown"); } }; // const handleImagePress = (imageUrl: string) => { // setImages([imageUrl]); // setCurrentImageIndex(0); // setImageViewerVisible(true); // }; const changeStatus = async (status: number) => { setLoading(true); setPage(1); const data: PaginatedOrderRequest = { page: page, page_size: pageSize, }; if (status) { data.status = status; } if (status === 0) { data.status = 0; } try { await getAllOrders(data, page); // 滚动状态列表到选中项 } finally { setLoading(false); } }; const handleOrderDetailsPress = (orderId: string) => { navigation.navigate("OrderDetails", { orderId, status }); }; return ( navigation.goBack()}> {t("order.status")} {statusList.map((item, index) => ( { setStatus(item.status as number); changeStatus(item.status as number); }} > {t(item.textKey)} ))} {loading && page === 1 ? ( ) : ( { const { contentOffset, contentSize, layoutMeasurement } = event.nativeEvent; console.log('Scroll values:', { contentOffsetY: contentOffset.y, layoutHeight: layoutMeasurement.height, contentHeight: contentSize.height, sum: contentOffset.y + layoutMeasurement.height }); const isAtBottom = contentOffset.y + layoutMeasurement.height >= contentSize.height - 20; if (isAtBottom) { setLoading(true); setPage(page + 1); const data: PaginatedOrderRequest = { page: page, page_size: pageSize, status:status, }; getAllOrders(data,page); } }} > {orders?.items.map((item, index) => ( {item.order_id} {getStatus(item.order_status)} {item.items.map((item, index) => ( {item.product_name} {item.sku_attributes?.map((attr, index) => ( {attr.attribute_name}:{attr.attribute_value} ))} ))} {t("order.total_price")}: {item.actual_amount} {item?.currency} handleOrderDetailsPress(item.order_id)} > {t("order.view_details")} ))} {loading && page > 1 && ( )} )} {/* ({ uri }))} imageIndex={currentImageIndex} visible={imageViewerVisible} onRequestClose={() => setImageViewerVisible(false)} swipeToCloseEnabled={true} doubleTapToZoomEnabled={true} /> */} ); } const styles = StyleSheet.create({ safeArea: { flex: 1, backgroundColor: '#fff', }, safeAreaContent: { flex: 1, paddingTop: 0, }, statusHeader: { width: "100%", backgroundColor: "white", padding: 16, justifyContent: "space-between", flexDirection: "row", alignItems: "center", }, statusTitle: { fontSize: fontSize(16), fontWeight: "600", }, statusList: { width: "100%", borderTopWidth: 1, borderColor: "#f5f5f5", }, statusListScr: { width: "100%", }, statusItem: { padding: 16, paddingHorizontal: 20, backgroundColor: "white", }, statusItemText: { fontSize: fontSize(16), textAlign: "center", }, statusItemTextActive: { color: "#f77f3a", borderBottomWidth: 1, borderColor: "#f77f3a", }, statusItemActive: { borderBottomWidth: 2, borderColor: "#f77f3a", }, statusItemActiveText: { color: "#f77f3a", }, orderContent: { padding: 20, flex: 1, }, orderItem: { width: "100%", backgroundColor: "white", borderRadius: 10, marginBottom: 10, }, orderStatus: { width: "100%", padding: 10, borderBottomWidth: 1, flexDirection: "row", borderColor: "#f5f5f5", justifyContent: "space-between", }, orderStatusOrderText: { fontSize: fontSize(16), fontWeight: "600", width: "70%", }, orderStatusText: { color: "#f77f3a", width: "30%", textAlign: "right", }, orderProductList: { width: "100%", padding: 10, }, orderProductItem: { flexDirection: "row", paddingBottom: 10, paddingTop: 10, borderBottomWidth: 1, borderColor: "#f5f5f5", }, orderProductItemImage: { width: widthUtils(30, 30).width, height: widthUtils(30, 30).height, marginRight: 10, }, orderProductItemInfo: { flex: 1, }, orderProductItemInfoName: { fontSize: fontSize(16), fontWeight: "600", }, orderProductItemInfoPrice: { fontSize: fontSize(14), color: "#666", }, orderProductPrice: { padding: 10, flexDirection: "row", justifyContent: "space-between", }, orderProductView: { width: "50%", borderRadius: 8, alignItems: "flex-end", }, orderProductViewText: { color: "#f77f3a", fontSize: fontSize(14), borderWidth: 1, borderColor: "#f77f3a", width: "50%", borderRadius: 8, padding: 5, textAlign: "center", }, orderProductPriceText: { fontSize: fontSize(16), fontWeight: "600", color: "#f77f3a", textAlign: "right", }, orderProductTotalText: { fontSize: fontSize(16), fontWeight: "600", }, orderProductPriceItem: { flexDirection: "row", width: "50%", }, loadingContainer: { flex: 1, justifyContent: "center", alignItems: "center", }, loadingMoreContainer: { paddingVertical: 10, alignItems: "center", }, });