|
|
@ -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); |
|
|
|