Browse Source

切换运输方式优化

main
Mac 2 weeks ago
parent
commit
052c70673f
  1. 1
      app.json
  2. 23
      app/screens/previewOrder/ShippingFee.tsx
  3. 12
      app/store/previewShipping.ts

1
app.json

@ -8,6 +8,7 @@
"userInterfaceStyle": "light", "userInterfaceStyle": "light",
"newArchEnabled": true, "newArchEnabled": true,
"scheme": "myapp", "scheme": "myapp",
"owner":"brainnel",
"deepLinking": true, "deepLinking": true,
"splash": { "splash": {
"image": "./assets/splash-icon.png", "image": "./assets/splash-icon.png",

23
app/screens/previewOrder/ShippingFee.tsx

@ -17,13 +17,11 @@ import fontSize from "../../utils/fontsizeUtils";
import LocationPinIcon from "../../components/LocationPinIcon"; import LocationPinIcon from "../../components/LocationPinIcon";
import { import {
AddressDataItem, AddressDataItem,
OrderData,
Address, Address,
CartShippingFeeData, CartShippingFeeData,
DomesticShippingFeeData, DomesticShippingFeeData,
} from "../../services/api/orders"; } from "../../services/api/orders";
import usePreviewShippingStore from "../../store/previewShipping"; import usePreviewShippingStore from "../../store/previewShipping";
import { getSubjectTransLanguage } from "../../utils/languageUtils";
import BackIcon from "../../components/BackIcon"; import BackIcon from "../../components/BackIcon";
import { useNavigation, useRoute, RouteProp } from "@react-navigation/native"; import { useNavigation, useRoute, RouteProp } from "@react-navigation/native";
import useCreateOrderStore from "../../store/createOrder"; import useCreateOrderStore from "../../store/createOrder";
@ -55,6 +53,7 @@ export const ShippingFee = () => {
state, state,
calculateShippingFee, calculateShippingFee,
calculateDomesticShippingFee, calculateDomesticShippingFee,
clearShippingFees,
} = usePreviewShippingStore(); } = usePreviewShippingStore();
const [shippingMethod, setShippingMethod] = useState("sea"); const [shippingMethod, setShippingMethod] = useState("sea");
const [warehouse, setWarehouse] = useState<string>(); const [warehouse, setWarehouse] = useState<string>();
@ -77,7 +76,8 @@ export const ShippingFee = () => {
const userStore = useUserStore(); const userStore = useUserStore();
const { logShippingConfirm } = useBurialPointStore(); const { logShippingConfirm } = useBurialPointStore();
const getFreightForwarderAddress = async () => { const getFreightForwarderAddress = async () => {
await fetchFreightForwarderAddress(0); const transportMode = shippingMethod === "sea" ? 0 : 1;
await fetchFreightForwarderAddress(transportMode);
}; };
useEffect(() => { useEffect(() => {
@ -117,10 +117,10 @@ export const ShippingFee = () => {
// 统一处理loading状态 // 统一处理loading状态
useEffect(() => { useEffect(() => {
if (state.shippingFees && state.domesticShippingFees) { if (state.shippingFees && state.domesticShippingFees && isShippingFeeLoading) {
setIsShippingFeeLoading(false); setIsShippingFeeLoading(false);
} }
}, [state.shippingFees, state.domesticShippingFees]); }, [state.shippingFees, state.domesticShippingFees, isShippingFeeLoading]);
// Call changeCountryHandel when warehouse changes // Call changeCountryHandel when warehouse changes
useEffect(() => { useEffect(() => {
@ -129,6 +129,12 @@ export const ShippingFee = () => {
} }
}, [warehouse, freightForwarderAddress]); }, [warehouse, freightForwarderAddress]);
// 当运输方式改变时重新获取货代中心
useEffect(() => {
const transportMode = shippingMethod === "sea" ? 0 : 1;
fetchFreightForwarderAddress(transportMode);
}, [shippingMethod]);
const changeCountryHandel = async (value: string) => { const changeCountryHandel = async (value: string) => {
if (value && freightForwarderAddress?.other_addresses) { if (value && freightForwarderAddress?.other_addresses) {
const selectedWarehouse = freightForwarderAddress.other_addresses.find( const selectedWarehouse = freightForwarderAddress.other_addresses.find(
@ -148,6 +154,13 @@ export const ShippingFee = () => {
// 设置loading状态为true,开始计算 // 设置loading状态为true,开始计算
setIsShippingFeeLoading(true); setIsShippingFeeLoading(true);
setCount(t("order.shipping.calculating")); setCount(t("order.shipping.calculating"));
// 清空store中的旧数据,确保loading状态正确
clearShippingFees();
// 清空之前的运费数据,确保loading状态正确
setShippingFeeData(undefined);
setDomesticShippingFeeData(undefined);
calculateShippingFee(data); calculateShippingFee(data);
calculateDomesticShippingFee(data); calculateDomesticShippingFee(data);

12
app/store/previewShipping.ts

@ -22,6 +22,8 @@ interface PreviewShippingStore {
calculateDomesticShippingFee: (data: ShippingFeeData) => Promise<void>; calculateDomesticShippingFee: (data: ShippingFeeData) => Promise<void>;
// 重置状态 // 重置状态
resetState: () => void; resetState: () => void;
// 清空运费数据
clearShippingFees: () => void;
} }
const usePreviewShippingStore = create<PreviewShippingStore>((set) => ({ const usePreviewShippingStore = create<PreviewShippingStore>((set) => ({
@ -122,6 +124,16 @@ const usePreviewShippingStore = create<PreviewShippingStore>((set) => ({
error: null, error: null,
} }
}); });
},
clearShippingFees: () => {
set((state) => ({
state: {
...state.state,
shippingFees: null,
domesticShippingFees: null,
}
}));
} }
})); }));

Loading…
Cancel
Save