From 9e4ef7d5a8b76107a66099f1fa120208d6754151 Mon Sep 17 00:00:00 2001 From: Mac Date: Sun, 25 May 2025 19:52:40 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E5=88=86=E7=B1=BB=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/constants/productStatus.ts | 8 +- app/screens/productStatus/OrderDatails.tsx | 66 +++++----- app/services/api/orders.ts | 9 ++ app/store/orderList.ts | 146 +++++++++++++-------- 4 files changed, 137 insertions(+), 92 deletions(-) diff --git a/app/constants/productStatus.ts b/app/constants/productStatus.ts index b2f0419..888827e 100644 --- a/app/constants/productStatus.ts +++ b/app/constants/productStatus.ts @@ -13,8 +13,8 @@ export const productStatus: ProductStatus[] = [ // { icon: DocumentClockIcon, text: '付运费', textKey: 'order.status.pay_shipping', status: 6 }, { icon: DocumentClockIcon, text: '待发货', textKey: 'order.status.waiting_shipment', status: 1 }, { icon: DocumentApprovedIcon, text: '运输中', textKey: 'order.status.in_transit', status: 2 }, - { icon: DocumentApprovedIcon, text: '代收货', textKey: 'order.status.waiting_receipt', status: 3 }, - { icon: PdfDocumentIcon, text: '已完成', textKey: 'order.status.completed', status: 4 }, - { icon: DocumentClockIcon, text: '已取消', textKey: 'order.status.cancelled', status: 5 }, - { icon: DocumentClockIcon, text: '已退款', textKey: 'order.status.refunded', status: 6 } + // { icon: DocumentApprovedIcon, text: '代收货', textKey: 'order.status.waiting_receipt', status: 3 }, + { icon: PdfDocumentIcon, text: '已完成', textKey: 'order.status.completed', status: 3 }, + { icon: DocumentClockIcon, text: '已过期', textKey: 'order.status.cancelled', status: 4 }, + // { icon: DocumentClockIcon, text: '已退款', textKey: 'order.status.refunded', status: 6 } ] \ No newline at end of file diff --git a/app/screens/productStatus/OrderDatails.tsx b/app/screens/productStatus/OrderDatails.tsx index 2617b30..967fa5e 100644 --- a/app/screens/productStatus/OrderDatails.tsx +++ b/app/screens/productStatus/OrderDatails.tsx @@ -75,7 +75,7 @@ export const OrderDetails = () => { >(); const [orderDetails, setOrderDetails] = useState(); const [isLoading, setIsLoading] = useState(true); - const { deleteOrder, changeOrder, updateOrderShippingInfo } = + const { deleteOrder, changeOrder, updateOrderShippingInfo,cancelOrder,confirmOrder } = useOrderListStore(); const [showPaymentModal, setShowPaymentModal] = useState(false); @@ -717,6 +717,7 @@ export const OrderDetails = () => { + {/* {route.params.status} */} {/* 价格信息 */} @@ -767,12 +768,13 @@ export const OrderDetails = () => { {/* 代付款 */} - {orderDetails.order_status === 0 && ( + {route.params.status === 0 && ( { - deleteOrder(route.params.orderId); + cancelOrder(route.params.orderId); + navigation.goBack(); }} > @@ -790,7 +792,7 @@ export const OrderDetails = () => { )} {/* 待发货 */} - {orderDetails.order_status === 1 && ( + {route.params.status === 1 && ( { )} {/* 代收货 */} - {orderDetails.order_status === 2 && ( + {route.params.status === 2 && ( { { - updateOrderShippingInfo(route.params.orderId, { - shipping_status: 0, - shipping_info: { - shipping_company: "string", - shipping_no: "string", - shipping_info: {}, - }, - }); + confirmOrder(route.params.orderId); + navigation.goBack(); }} > @@ -847,32 +843,36 @@ export const OrderDetails = () => { )} {/* 已完成 */} - {orderDetails.order_status === 3 && ( - - { - deleteOrder(route.params.orderId); - navigation.goBack(); - }} - > - - {t("order.cancel")} - - - - - {t("order.pay_now")} - - + {route.params.status === 3 && ( + + // + // { + // addToCart(orderDetails.items); + // // navigation.goBack(); + // }} + // > + // + // {t("order.add_to_cart")} + // + // + // + // + // {t("order.reorder")} + // + // + // )} {/* 已取消 */} - {orderDetails.order_status === 4 && ( + {route.params.status === 4 && ( {}} + onPress={() => { + addToCart(orderDetails.items); + }} > {t("order.add_to_cart")} diff --git a/app/services/api/orders.ts b/app/services/api/orders.ts index 80ca361..5ad96b6 100644 --- a/app/services/api/orders.ts +++ b/app/services/api/orders.ts @@ -402,4 +402,13 @@ export const ordersApi = { // 修改支付方式 updateOrderPaymentMethod: (data: UpdateOrderPaymentMethod) => apiService.put(`/api/orders/edit/`, data), + + // 取消订单 + cancelOrder: (order_id: string) => + apiService.post(`/api/orders/${order_id}/cancel/`), + + // 确定收货 + confirmOrder: (order_id: string) => + apiService.patch(`/api/orders/${order_id}/shipping/`,{ + }), }; diff --git a/app/store/orderList.ts b/app/store/orderList.ts index 0c90da9..bd0cbcb 100644 --- a/app/store/orderList.ts +++ b/app/store/orderList.ts @@ -1,65 +1,101 @@ -import { create } from 'zustand'; -import { ordersApi, PaginatedOrderResponse, PaginatedOrderRequest,UpdateOrderShippingInfo} from '../services/api/orders'; +import { create } from "zustand"; +import { + ordersApi, + PaginatedOrderResponse, + PaginatedOrderRequest, + UpdateOrderShippingInfo, +} from "../services/api/orders"; interface OrderListState { - orders: PaginatedOrderResponse, - getAllOrders: (data: PaginatedOrderRequest,page:number) => Promise, - deleteOrder: (orderId: string) => Promise, - changeOrder: (orderId: string,status:number) => Promise, - updateOrderShippingInfo: (orderId: string,data:UpdateOrderShippingInfo) => Promise, + orders: PaginatedOrderResponse; + getAllOrders: (data: PaginatedOrderRequest, page: number) => Promise; + deleteOrder: (orderId: string) => Promise; + changeOrder: (orderId: string, status: number) => Promise; + updateOrderShippingInfo: ( + orderId: string, + data: UpdateOrderShippingInfo + ) => Promise; + cancelOrder: (orderId: string) => Promise; + confirmOrder: (orderId: string) => Promise; } export const useOrderListStore = create((set, get) => ({ - orders: { - items: [], - total: 0, - page: 1, - page_size: 10, - }, + orders: { + items: [], + total: 0, + page: 1, + page_size: 10, + }, - getAllOrders: async (data: PaginatedOrderRequest,page:number) => { - const response = await ordersApi.getAllOrders(data); - set((state) => ({ - orders: { - ...response, - items: page === 1 - ? response.items - : [...state.orders.items, ...response.items], - } - })); - }, + getAllOrders: async (data: PaginatedOrderRequest, page: number) => { + const response = await ordersApi.getAllOrders(data); + set((state) => ({ + orders: { + ...response, + items: + page === 1 + ? response.items + : [...state.orders.items, ...response.items], + }, + })); + }, - deleteOrder: async (orderId: string) => { - await ordersApi.deleteOrder(orderId); - set((state) => ({ - orders: { - ...state.orders, - items: state.orders.items.filter(item => item.order_id !== orderId), - total: state.orders.total - 1 - } - })); - }, + deleteOrder: async (orderId: string) => { + await ordersApi.deleteOrder(orderId); + set((state) => ({ + orders: { + ...state.orders, + items: state.orders.items.filter((item) => item.order_id !== orderId), + total: state.orders.total - 1, + }, + })); + }, - changeOrder: async (orderId: string,status:number) => { - await ordersApi.changeOrder(orderId,status); - set((state) => ({ - orders: { - ...state.orders, - items: state.orders.items.filter(item => item.order_id !== orderId), - total: state.orders.total - 1 - } - })); - }, + changeOrder: async (orderId: string, status: number) => { + await ordersApi.changeOrder(orderId, status); + set((state) => ({ + orders: { + ...state.orders, + items: state.orders.items.filter((item) => item.order_id !== orderId), + total: state.orders.total - 1, + }, + })); + }, - updateOrderShippingInfo: async (orderId: string,data:UpdateOrderShippingInfo) => { - await ordersApi.updateOrderShippingInfo(orderId,data); - set((state) => ({ - orders: { - ...state.orders, - items: state.orders.items.filter(item => item.order_id !== orderId), - total: state.orders.total - 1 - } - })); - }, -})); + updateOrderShippingInfo: async ( + orderId: string, + data: UpdateOrderShippingInfo + ) => { + await ordersApi.updateOrderShippingInfo(orderId, data); + set((state) => ({ + orders: { + ...state.orders, + items: state.orders.items.filter((item) => item.order_id !== orderId), + total: state.orders.total - 1, + }, + })); + }, + // 取消订单 + cancelOrder: async (orderId: string) => { + set((state) => ({ + orders: { + ...state.orders, + items: state.orders.items.filter((item) => item.order_id !== orderId), + total: state.orders.total - 1, + }, + })); + await ordersApi.cancelOrder(orderId); + }, + // 确定收货 + confirmOrder: async (orderId: string) => { + set((state) => ({ + orders: { + ...state.orders, + items: state.orders.items.filter((item) => item.order_id !== orderId), + total: state.orders.total - 1, + }, + })); + await ordersApi.confirmOrder(orderId); + }, +}));