From 052c70673fddfdde15e4e6c8a533f45deb5a5cbb Mon Sep 17 00:00:00 2001 From: Mac Date: Fri, 23 May 2025 13:31:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=87=E6=8D=A2=E8=BF=90=E8=BE=93=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.json | 1 + app/screens/previewOrder/ShippingFee.tsx | 23 ++++++++++++++++++----- app/store/previewShipping.ts | 12 ++++++++++++ 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/app.json b/app.json index 2634e13..bf3a7eb 100644 --- a/app.json +++ b/app.json @@ -8,6 +8,7 @@ "userInterfaceStyle": "light", "newArchEnabled": true, "scheme": "myapp", + "owner":"brainnel", "deepLinking": true, "splash": { "image": "./assets/splash-icon.png", diff --git a/app/screens/previewOrder/ShippingFee.tsx b/app/screens/previewOrder/ShippingFee.tsx index 232ade9..e8ecf2a 100644 --- a/app/screens/previewOrder/ShippingFee.tsx +++ b/app/screens/previewOrder/ShippingFee.tsx @@ -17,13 +17,11 @@ import fontSize from "../../utils/fontsizeUtils"; import LocationPinIcon from "../../components/LocationPinIcon"; import { AddressDataItem, - OrderData, Address, CartShippingFeeData, DomesticShippingFeeData, } from "../../services/api/orders"; import usePreviewShippingStore from "../../store/previewShipping"; -import { getSubjectTransLanguage } from "../../utils/languageUtils"; import BackIcon from "../../components/BackIcon"; import { useNavigation, useRoute, RouteProp } from "@react-navigation/native"; import useCreateOrderStore from "../../store/createOrder"; @@ -55,6 +53,7 @@ export const ShippingFee = () => { state, calculateShippingFee, calculateDomesticShippingFee, + clearShippingFees, } = usePreviewShippingStore(); const [shippingMethod, setShippingMethod] = useState("sea"); const [warehouse, setWarehouse] = useState(); @@ -77,7 +76,8 @@ export const ShippingFee = () => { const userStore = useUserStore(); const { logShippingConfirm } = useBurialPointStore(); const getFreightForwarderAddress = async () => { - await fetchFreightForwarderAddress(0); + const transportMode = shippingMethod === "sea" ? 0 : 1; + await fetchFreightForwarderAddress(transportMode); }; useEffect(() => { @@ -117,10 +117,10 @@ export const ShippingFee = () => { // 统一处理loading状态 useEffect(() => { - if (state.shippingFees && state.domesticShippingFees) { + if (state.shippingFees && state.domesticShippingFees && isShippingFeeLoading) { setIsShippingFeeLoading(false); } - }, [state.shippingFees, state.domesticShippingFees]); + }, [state.shippingFees, state.domesticShippingFees, isShippingFeeLoading]); // Call changeCountryHandel when warehouse changes useEffect(() => { @@ -129,6 +129,12 @@ export const ShippingFee = () => { } }, [warehouse, freightForwarderAddress]); + // 当运输方式改变时重新获取货代中心 + useEffect(() => { + const transportMode = shippingMethod === "sea" ? 0 : 1; + fetchFreightForwarderAddress(transportMode); + }, [shippingMethod]); + const changeCountryHandel = async (value: string) => { if (value && freightForwarderAddress?.other_addresses) { const selectedWarehouse = freightForwarderAddress.other_addresses.find( @@ -148,6 +154,13 @@ export const ShippingFee = () => { // 设置loading状态为true,开始计算 setIsShippingFeeLoading(true); setCount(t("order.shipping.calculating")); + + // 清空store中的旧数据,确保loading状态正确 + clearShippingFees(); + + // 清空之前的运费数据,确保loading状态正确 + setShippingFeeData(undefined); + setDomesticShippingFeeData(undefined); calculateShippingFee(data); calculateDomesticShippingFee(data); diff --git a/app/store/previewShipping.ts b/app/store/previewShipping.ts index 8998bd6..85bd239 100644 --- a/app/store/previewShipping.ts +++ b/app/store/previewShipping.ts @@ -22,6 +22,8 @@ interface PreviewShippingStore { calculateDomesticShippingFee: (data: ShippingFeeData) => Promise; // 重置状态 resetState: () => void; + // 清空运费数据 + clearShippingFees: () => void; } const usePreviewShippingStore = create((set) => ({ @@ -122,6 +124,16 @@ const usePreviewShippingStore = create((set) => ({ error: null, } }); + }, + + clearShippingFees: () => { + set((state) => ({ + state: { + ...state.state, + shippingFees: null, + domesticShippingFees: null, + } + })); } }));