Browse Source

运费规则

main
Mac 2 weeks ago
parent
commit
7493657e81
  1. 4
      app/locales/en/translation.json
  2. 4
      app/locales/fr/translation.json
  3. 355
      app/screens/CartScreen.tsx
  4. 189
      app/screens/previewOrder/PaymentMethod.tsx
  5. 8
      app/screens/previewOrder/PreviewAddress.tsx
  6. 134
      app/screens/previewOrder/ShippingFee.tsx

4
app/locales/en/translation.json

@ -252,7 +252,7 @@
"order.shipping.estimated_time": "Estimated arrival time", "order.shipping.estimated_time": "Estimated arrival time",
"order.shipping.sea_time": "45 days", "order.shipping.sea_time": "45 days",
"order.shipping.air_time": "20 days", "order.shipping.air_time": "20 days",
"order.shipping.domestic_fee": "Domestic shipping fee", "order.shipping.domestic_fee": "Freight charges in China",
"order.shipping.international_fee": "International shipping fee", "order.shipping.international_fee": "International shipping fee",
"order.shipping.submit": "Submit", "order.shipping.submit": "Submit",
"order.shipping.calculating": "Calculating shipping fee...", "order.shipping.calculating": "Calculating shipping fee...",
@ -452,6 +452,7 @@
}, },
"cart": { "cart": {
"cart":"Cart", "cart":"Cart",
"minimum":"The minimum purchase quantity is",
"add_failed": "Add Failed", "add_failed": "Add Failed",
"login_required": "Please login first", "login_required": "Please login first",
"select_products": "Please select products", "select_products": "Please select products",
@ -543,6 +544,7 @@
"yes": "Yes", "yes": "Yes",
"no": "No", "no": "No",
"preview": { "preview": {
"Cash_on_delivery":"International cash on delivery",
"login_required": "Please login first", "login_required": "Please login first",
"payment_failed": "Payment failed, please try again", "payment_failed": "Payment failed, please try again",
"Insufficient_balance": "Insufficient balance", "Insufficient_balance": "Insufficient balance",

4
app/locales/fr/translation.json

@ -180,7 +180,7 @@
"order.shipping.estimated_time": "Temps d'arrivée estimé", "order.shipping.estimated_time": "Temps d'arrivée estimé",
"order.shipping.sea_time": "45 jours", "order.shipping.sea_time": "45 jours",
"order.shipping.air_time": "20 jours", "order.shipping.air_time": "20 jours",
"order.shipping.domestic_fee": "Frais de livraison nationale", "order.shipping.domestic_fee": "Fret en Chine",
"order.shipping.international_fee": "Frais de livraison internationale", "order.shipping.international_fee": "Frais de livraison internationale",
"order.shipping.submit": "Soumettre", "order.shipping.submit": "Soumettre",
"order.shipping.calculating": "Calcul des frais de livraison...", "order.shipping.calculating": "Calcul des frais de livraison...",
@ -463,6 +463,7 @@
}, },
"cart": { "cart": {
"cart":"Panier", "cart":"Panier",
"minimum":"La quantité minimum de commande est",
"add_failed": "Ajout échoué", "add_failed": "Ajout échoué",
"login_required": "Veuillez vous connecter d'abord", "login_required": "Veuillez vous connecter d'abord",
"select_products": "Veuillez sélectionner des produits", "select_products": "Veuillez sélectionner des produits",
@ -622,6 +623,7 @@
"yes": "Oui", "yes": "Oui",
"no": "Non", "no": "Non",
"preview": { "preview": {
"Cash_on_delivery":"Paiement international à l’arrivée",
"login_required": "Veuillez vous connecter d'abord", "login_required": "Veuillez vous connecter d'abord",
"payment_failed": "Le paiement a échoué", "payment_failed": "Le paiement a échoué",
"Insufficient_balance": "Solde insuffisant", "Insufficient_balance": "Solde insuffisant",

355
app/screens/CartScreen.tsx

@ -12,6 +12,7 @@ import {
Platform, Platform,
StatusBar, StatusBar,
SafeAreaView, SafeAreaView,
ActivityIndicator,
} from "react-native"; } from "react-native";
import fontSize from "../utils/fontsizeUtils"; import fontSize from "../utils/fontsizeUtils";
import CircleOutlineIcon from "../components/CircleOutlineIcon"; import CircleOutlineIcon from "../components/CircleOutlineIcon";
@ -33,7 +34,11 @@ import useUserStore from "../store/user";
import { t } from "../i18n"; import { t } from "../i18n";
import { payApi } from "../services/api/payApi"; import { payApi } from "../services/api/payApi";
import IconComponent from "../components/IconComponent"; import IconComponent from "../components/IconComponent";
import {getSubjectTransLanguage,getAttributeTransLanguage} from "../utils/languageUtils"; import {
getSubjectTransLanguage,
getAttributeTransLanguage,
} from "../utils/languageUtils";
import Toast from "react-native-toast-message";
export const CartScreen = () => { export const CartScreen = () => {
const [cartList, setCartList] = useState<GetCartList[]>([]); const [cartList, setCartList] = useState<GetCartList[]>([]);
@ -45,7 +50,9 @@ export const CartScreen = () => {
}>({}); }>({});
const [allSelected, setAllSelected] = useState(false); const [allSelected, setAllSelected] = useState(false);
const [totalAmount, setTotalAmount] = useState(0); const [totalAmount, setTotalAmount] = useState(0);
const [convertedMinAmount, setConvertedMinAmount] = useState<number | null>(null); const [convertedMinAmount, setConvertedMinAmount] = useState<number | null>(
null
);
const [deleteModalVisible, setDeleteModalVisible] = useState(false); const [deleteModalVisible, setDeleteModalVisible] = useState(false);
const [itemToDelete, setItemToDelete] = useState<{ const [itemToDelete, setItemToDelete] = useState<{
cartId: number; cartId: number;
@ -63,6 +70,7 @@ export const CartScreen = () => {
const { setItems } = useCreateOrderStore(); const { setItems } = useCreateOrderStore();
const [minQuantityModalVisible, setMinQuantityModalVisible] = useState(false); const [minQuantityModalVisible, setMinQuantityModalVisible] = useState(false);
const [minQuantityMessage, setMinQuantityMessage] = useState(""); const [minQuantityMessage, setMinQuantityMessage] = useState("");
const [loading, setLoading] = useState(false);
// 货币转换函数 // 货币转换函数
const convertCurrency = async () => { const convertCurrency = async () => {
@ -72,16 +80,7 @@ export const CartScreen = () => {
} }
console.log(country_code); console.log(country_code);
// 如果 country_code 是 255,不需要转换
if (country_code === 225) {
setConvertedMinAmount(null);
return;
}
try { try {
console.log(`Converting currency for country_code: ${country_code}, from FCFA to ${currency}`);
const data = { const data = {
from_currency: "FCFA", // 固定使用 FCFA from_currency: "FCFA", // 固定使用 FCFA
to_currency: currency, // 使用用户的货币 to_currency: currency, // 使用用户的货币
@ -93,22 +92,28 @@ export const CartScreen = () => {
const response = await payApi.convertCurrency(data); const response = await payApi.convertCurrency(data);
console.log("Currency conversion response:", response); console.log("Currency conversion response:", response);
if (response && response.converted_amounts_list && response.converted_amounts_list.length > 0) { if (
response &&
response.converted_amounts_list &&
response.converted_amounts_list.length > 0
) {
const convertedTotal = response.converted_amounts_list.find( const convertedTotal = response.converted_amounts_list.find(
(item: any) => item.item_key === "total_amount" (item: any) => item.item_key === "total_amount"
); );
if (convertedTotal) { if (convertedTotal) {
console.log(`Converted minimum amount: ${convertedTotal.converted_amount} ${currency}`); console.log(
setConvertedMinAmount(convertedTotal.converted_amount); `Converted minimum amount: ${convertedTotal.converted_amount} ${currency}`
);
return convertedTotal.converted_amount;
} }
} else { } else {
console.warn("No converted amounts found in response"); console.warn("No converted amounts found in response");
setConvertedMinAmount(null); return null;
} }
} catch (error) { } catch (error) {
console.error("货币转换失败:", error); console.error("货币转换失败:", error);
// 转换失败时不设置转换金额,使用原始逻辑 // 转换失败时不设置转换金额,使用原始逻辑
setConvertedMinAmount(null); return null;
} }
}; };
@ -461,17 +466,20 @@ export const CartScreen = () => {
// 只有在用户已登录时才执行API调用 // 只有在用户已登录时才执行API调用
if (user_id) { if (user_id) {
getCart(); getCart();
convertCurrency(); // 添加货币转换调用
} }
}, [user_id]) }, [user_id])
); );
const gotoOrder = () => { const gotoOrder = async () => {
if (!user_id) { if (!user_id) {
Alert.alert(t("cart.add_failed"), t("cart.login_required")); Alert.alert(t("cart.add_failed"), t("cart.login_required"));
return; return;
} }
// 立即设置loading状态
setLoading(true);
try {
// 检查是否有选中的商品 // 检查是否有选中的商品
const items: { cart_item_id: number }[] = []; const items: { cart_item_id: number }[] = [];
cartList.forEach((item) => { cartList.forEach((item) => {
@ -493,54 +501,92 @@ export const CartScreen = () => {
// 检查每个商品组的最小起订量 // 检查每个商品组的最小起订量
for (const item of cartList) { for (const item of cartList) {
// 检查该商品组是否有选中的SKU // 检查该商品组是否有选中的SKU
const hasSelectedSku = item.skus.some(sku => sku.selected === 1); const hasSelectedSku = item.skus.some((sku) => sku.selected === 1);
if (hasSelectedSku) { if (hasSelectedSku) {
const currentGroupTotal = calculateProductGroupTotalQuantity(item.cart_id); const currentGroupTotal = calculateProductGroupTotalQuantity(
if (currentGroupTotal < item.min_order_quantity) { item.cart_id
Alert.alert(
t("cart.notice"),
`${getSubjectTransLanguage(item)} ${t("cart.min_order")}${item.min_order_quantity}${t("cart.pieces")}${t("cart.current_quantity", "当前数量")}${currentGroupTotal}${t("cart.pieces")}`
); );
if (currentGroupTotal < item.min_order_quantity) {
Toast.show({
text1: `${getSubjectTransLanguage(item)} ${t("cart.min_order")}${
item.min_order_quantity
}${t("cart.pieces")}${t(
"cart.current_quantity",
"当前数量"
)}${currentGroupTotal}${t("cart.pieces")}`,
});
return; return;
} }
} }
} }
console.log(totalAmount);
// 检查最低订单金额 console.log(country_code);
const conver = await convertCurrency();
console.log(conver);
let isFei = true
if (country_code !== 225) { if (country_code !== 225) {
// 只有当 country_code 不是 255 时才进行最低订单金额检查 if (totalAmount < conver) {
if (convertedMinAmount !== null) { Toast.show({
// 如果有转换后的最低金额,检查当前总价是否满足要求 text1: `${t('cart.minimum')}${conver}${currency}`,
console.log(`Checking converted minimum amount: ${convertedMinAmount} ${currency} vs current total: ${totalAmount}`); });
if (totalAmount < convertedMinAmount) {
Alert.alert(
t("cart.notice"),
t("cart.minimum_order_required", {
amount: convertedMinAmount.toFixed(2),
currency: currency
})
);
return; return;
} }
}else{ }else{
// 如果转换失败,使用原始的 50,000 FCFA 检查 if (totalAmount < conver) {
console.log(`Checking original minimum amount: 50000 FCFA vs current total: ${totalAmount}`); isFei = false
if (totalAmount < 50000) { }else{
Alert.alert( isFei = true
t("cart.notice"),
t("cart.minimum_order_required", {
amount: "50,000",
currency: "FCFA"
})
);
return;
}
} }
} }
// 检查最低订单金额
// if (country_code !== 225) {
// // 只有当 country_code 不是 255 时才进行最低订单金额检查
// if (convertedMinAmount !== null) {
// // 如果有转换后的最低金额,检查当前总价是否满足要求
// console.log(`Checking converted minimum amount: ${convertedMinAmount} ${currency} vs current total: ${totalAmount}`);
// if (totalAmount < convertedMinAmount) {
// Alert.alert(
// t("cart.notice"),
// t("cart.minimum_order_required", {
// amount: convertedMinAmount.toFixed(2),
// currency: currency
// })
// );
// return;
// }
// } else {
// // 如果转换失败,使用原始的 50,000 FCFA 检查
// console.log(`Checking original minimum amount: 50000 FCFA vs current total: ${totalAmount}`);
// if (totalAmount < 50000) {
// Alert.alert(
// t("cart.notice"),
// t("cart.minimum_order_required", {
// amount: "50,000",
// currency: "FCFA"
// })
// );
// return;
// }
// }
// }
// 如果 country_code === 255,则不进行任何最低订单金额检查 // 如果 country_code === 255,则不进行任何最低订单金额检查
setItems(items); setItems(items);
navigation.navigate("PreviewAddress"); navigation.navigate("PreviewAddress",{isFei:isFei});
} catch (error) {
console.error("提交订单失败:", error);
Toast.show({
text1: t("cart.submit_failed", "提交失败,请重试"),
});
} finally {
// 确保在所有情况下都重置loading状态
setLoading(false);
}
}; };
// 添加更新商品数量的方法 // 添加更新商品数量的方法
@ -596,7 +642,7 @@ export const CartScreen = () => {
// 计算同一商品组的总数量 // 计算同一商品组的总数量
const calculateProductGroupTotalQuantity = (cartId: number) => { const calculateProductGroupTotalQuantity = (cartId: number) => {
const product = cartList.find(item => item.cart_id === cartId); const product = cartList.find((item) => item.cart_id === cartId);
if (!product) return 0; if (!product) return 0;
return product.skus.reduce((total, sku) => total + sku.quantity, 0); return product.skus.reduce((total, sku) => total + sku.quantity, 0);
@ -621,7 +667,11 @@ export const CartScreen = () => {
if (newGroupTotal >= minOrderQuantity) { if (newGroupTotal >= minOrderQuantity) {
updateQuantity(cartId, cartItemId, currentQuantity - 1); updateQuantity(cartId, cartItemId, currentQuantity - 1);
} else { } else {
showMinQuantityModal(`${t("cart.notice")}${t("cart.min_order")}${minOrderQuantity}${t("cart.pieces")}`); showMinQuantityModal(
`${t("cart.notice")}${t("cart.min_order")}${minOrderQuantity}${t(
"cart.pieces"
)}`
);
} }
}; };
@ -653,17 +703,23 @@ export const CartScreen = () => {
} }
const { cartId, cartItemId } = editingItem; const { cartId, cartItemId } = editingItem;
const product = cartList.find(item => item.cart_id === cartId); const product = cartList.find((item) => item.cart_id === cartId);
const minOrderQuantity = product?.min_order_quantity || 1; const minOrderQuantity = product?.min_order_quantity || 1;
// 计算修改数量后,该商品组的总数量 // 计算修改数量后,该商品组的总数量
const currentGroupTotal = calculateProductGroupTotalQuantity(cartId); const currentGroupTotal = calculateProductGroupTotalQuantity(cartId);
const currentSkuQuantity = product?.skus.find(sku => sku.cart_item_id === cartItemId)?.quantity || 0; const currentSkuQuantity =
product?.skus.find((sku) => sku.cart_item_id === cartItemId)?.quantity ||
0;
const quantityDifference = newQuantity - currentSkuQuantity; const quantityDifference = newQuantity - currentSkuQuantity;
const newGroupTotal = currentGroupTotal + quantityDifference; const newGroupTotal = currentGroupTotal + quantityDifference;
if (newGroupTotal < minOrderQuantity) { if (newGroupTotal < minOrderQuantity) {
showMinQuantityModal(`${t("cart.notice")}${t("cart.min_order")}${minOrderQuantity}${t("cart.pieces")}`); showMinQuantityModal(
`${t("cart.notice")}${t("cart.min_order")}${minOrderQuantity}${t(
"cart.pieces"
)}`
);
} else { } else {
updateQuantity(cartId, cartItemId, newQuantity); updateQuantity(cartId, cartItemId, newQuantity);
setQuantityInputVisible(false); setQuantityInputVisible(false);
@ -750,7 +806,9 @@ export const CartScreen = () => {
{getSubjectTransLanguage(item) || item.subject} {getSubjectTransLanguage(item) || item.subject}
</Text> </Text>
<Text style={styles.productDetailsTextStyle1}> <Text style={styles.productDetailsTextStyle1}>
{t("cart.min_order")}: {calculateProductGroupTotalQuantity(item.cart_id)}/{item.min_order_quantity} {t("cart.min_order")}:{" "}
{calculateProductGroupTotalQuantity(item.cart_id)}/
{item.min_order_quantity}
{t("cart.pieces")} {t("cart.pieces")}
</Text> </Text>
</View> </View>
@ -768,11 +826,13 @@ export const CartScreen = () => {
alignItems: "center", alignItems: "center",
width: 80, width: 80,
}} }}
onPress={() => handleDeleteSku( onPress={() =>
handleDeleteSku(
item.cart_id, item.cart_id,
sku.cart_item_id, sku.cart_item_id,
item.cart_id item.cart_id
)} )
}
disabled={!user_id} disabled={!user_id}
> >
<Text <Text
@ -800,11 +860,14 @@ export const CartScreen = () => {
> >
<View style={styles.svgContainer1}> <View style={styles.svgContainer1}>
<TouchableOpacity <TouchableOpacity
onPress={() => user_id && toggleSelection( onPress={() =>
user_id &&
toggleSelection(
String(sku.cart_item_id), String(sku.cart_item_id),
index1, index1,
index index
)} )
}
disabled={!user_id} disabled={!user_id}
> >
<View style={[styles.iconContainer]}> <View style={[styles.iconContainer]}>
@ -823,7 +886,8 @@ export const CartScreen = () => {
? sku.attributes[0]?.sku_image_url ? sku.attributes[0]?.sku_image_url
: item.product_image, : item.product_image,
}} }}
style={styles.productImageDisplayStyle} /> style={styles.productImageDisplayStyle}
/>
<View style={styles.productCardWidget1}> <View style={styles.productCardWidget1}>
{/* 1. SKU attributes at the top */} {/* 1. SKU attributes at the top */}
{sku.attributes[0]?.value && ( {sku.attributes[0]?.value && (
@ -833,9 +897,17 @@ export const CartScreen = () => {
numberOfLines={2} numberOfLines={2}
ellipsizeMode="tail" ellipsizeMode="tail"
> >
{getAttributeTransLanguage(sku.attributes[0]) || sku.attributes[0].attribute_name_trans}{" "} {getAttributeTransLanguage(
sku.attributes[0]
) ||
sku.attributes[0].attribute_name_trans}{" "}
{sku.attributes[1] ? "/" : ""}{" "} {sku.attributes[1] ? "/" : ""}{" "}
{sku.attributes[1] ? getAttributeTransLanguage(sku.attributes[1]) || sku.attributes[1].attribute_name_trans : ""} {sku.attributes[1]
? getAttributeTransLanguage(
sku.attributes[1]
) ||
sku.attributes[1].attribute_name_trans
: ""}
</Text> </Text>
</View> </View>
)} )}
@ -853,8 +925,11 @@ export const CartScreen = () => {
<View style={styles.vipContainer}> <View style={styles.vipContainer}>
<Image <Image
source={require("../../assets/img/zkVIP1.png")} source={require("../../assets/img/zkVIP1.png")}
style={styles.VipImg} /> style={styles.VipImg}
<Text style={styles.discountPercentageTextStyle}> />
<Text
style={styles.discountPercentageTextStyle}
>
-{((1 - vip_discount) * 100).toFixed(0)}% -{((1 - vip_discount) * 100).toFixed(0)}%
</Text> </Text>
</View> </View>
@ -878,12 +953,15 @@ export const CartScreen = () => {
styles.svgContainer4, styles.svgContainer4,
{ borderRightWidth: 0 }, { borderRightWidth: 0 },
]} ]}
onPress={() => user_id && handleDecreaseQuantity( onPress={() =>
user_id &&
handleDecreaseQuantity(
item.cart_id, item.cart_id,
sku.cart_item_id, sku.cart_item_id,
sku.quantity, sku.quantity,
item.min_order_quantity item.min_order_quantity
)} )
}
disabled={!user_id} disabled={!user_id}
> >
<Text <Text
@ -898,11 +976,14 @@ export const CartScreen = () => {
</TouchableOpacity> </TouchableOpacity>
<TouchableOpacity <TouchableOpacity
style={styles.quantityLabelContainer} style={styles.quantityLabelContainer}
onPress={() => user_id && handleQuantityPress( onPress={() =>
user_id &&
handleQuantityPress(
item.cart_id, item.cart_id,
sku.cart_item_id, sku.cart_item_id,
sku.quantity sku.quantity
)} )
}
disabled={!user_id} disabled={!user_id}
> >
<Text style={styles.quantityText}> <Text style={styles.quantityText}>
@ -914,11 +995,14 @@ export const CartScreen = () => {
styles.svgContainer4, styles.svgContainer4,
{ borderLeftWidth: 0, marginLeft: 0 }, { borderLeftWidth: 0, marginLeft: 0 },
]} ]}
onPress={() => user_id && handleIncreaseQuantity( onPress={() =>
user_id &&
handleIncreaseQuantity(
item.cart_id, item.cart_id,
sku.cart_item_id, sku.cart_item_id,
sku.quantity sku.quantity
)} )
}
disabled={!user_id} disabled={!user_id}
> >
<Text <Text
@ -952,7 +1036,7 @@ export const CartScreen = () => {
{/* Fixed Bottom Section */} {/* Fixed Bottom Section */}
<View style={styles.fixedBottomContainer}> <View style={styles.fixedBottomContainer}>
{/* Order Summary */} {/* Order Summary */}
{country_code !== 225 && ( {/* {country_code !== 225 && (
<View style={styles.orderSummaryHeader}> <View style={styles.orderSummaryHeader}>
<View style={styles.svgContainer6}> <View style={styles.svgContainer6}>
<Image <Image
@ -971,11 +1055,14 @@ export const CartScreen = () => {
</Text> </Text>
</Text> </Text>
</View> </View>
)} )} */}
<View style={styles.flexboxContainerWithButton}> <View style={styles.flexboxContainerWithButton}>
<View style={styles.productInfoContainer}> <View style={styles.productInfoContainer}>
<TouchableOpacity onPress={user_id ? selectAllHandel : undefined} disabled={!user_id}> <TouchableOpacity
onPress={user_id ? selectAllHandel : undefined}
disabled={!user_id}
>
<View style={styles.svgContainer1}> <View style={styles.svgContainer1}>
{allSelected ? ( {allSelected ? (
<OrangeCircleIcon size={fontSize(24)} /> <OrangeCircleIcon size={fontSize(24)} />
@ -994,10 +1081,17 @@ export const CartScreen = () => {
<Text style={styles.priceLabel}>{currency}</Text> <Text style={styles.priceLabel}>{currency}</Text>
</View> </View>
<TouchableOpacity <TouchableOpacity
style={[styles.submitButtonStyle, !user_id && styles.disabledButton]} style={[
onPress={user_id ? gotoOrder : undefined} styles.submitButtonStyle,
disabled={!user_id} !user_id && styles.disabledButton,
loading && styles.disabledButton,
]}
onPress={user_id && !loading ? gotoOrder : undefined}
disabled={!user_id || loading}
> >
{loading ? (
<ActivityIndicator size="small" color="white" />
) : (
<Text <Text
style={{ style={{
color: "white", color: "white",
@ -1007,6 +1101,7 @@ export const CartScreen = () => {
> >
{t("cart.submit")} {t("cart.submit")}
</Text> </Text>
)}
</TouchableOpacity> </TouchableOpacity>
</View> </View>
</View> </View>
@ -1024,7 +1119,10 @@ export const CartScreen = () => {
{t("cart.login_required_title", "请先登录")} {t("cart.login_required_title", "请先登录")}
</Text> </Text>
<Text style={styles.loginPromptSubtitle}> <Text style={styles.loginPromptSubtitle}>
{t("cart.login_required_subtitle", "登录后即可使用购物车功能")} {t(
"cart.login_required_subtitle",
"登录后即可使用购物车功能"
)}
</Text> </Text>
<TouchableOpacity <TouchableOpacity
style={styles.loginButton} style={styles.loginButton}
@ -1127,12 +1225,16 @@ export const CartScreen = () => {
<View style={styles.warningIconContainer}> <View style={styles.warningIconContainer}>
<IconComponent name="exclamation" size={28} color="#FF5100" /> <IconComponent name="exclamation" size={28} color="#FF5100" />
</View> </View>
<Text style={[styles.promptText, styles.minQuantityText]}>{minQuantityMessage}</Text> <Text style={[styles.promptText, styles.minQuantityText]}>
{minQuantityMessage}
</Text>
<TouchableOpacity <TouchableOpacity
style={[styles.confirmButton, styles.minQuantityButton]} style={[styles.confirmButton, styles.minQuantityButton]}
onPress={() => setMinQuantityModalVisible(false)} onPress={() => setMinQuantityModalVisible(false)}
> >
<Text style={[styles.confirmText, styles.minQuantityButtonText]}>{t("cart.confirm")}</Text> <Text style={[styles.confirmText, styles.minQuantityButtonText]}>
{t("cart.confirm")}
</Text>
</TouchableOpacity> </TouchableOpacity>
</View> </View>
</View> </View>
@ -1317,12 +1419,12 @@ const styles = StyleSheet.create({
fontFamily: "PingFang SC", fontFamily: "PingFang SC",
fontWeight: "600", fontWeight: "600",
color: "#9a9a9a", color: "#9a9a9a",
textDecorationLine: 'line-through', textDecorationLine: "line-through",
}, },
vipContainer: { vipContainer: {
position: 'relative', position: "relative",
justifyContent: 'center', justifyContent: "center",
alignItems: 'center', alignItems: "center",
marginLeft: 10, marginLeft: 10,
}, },
VipImg: { VipImg: {
@ -1330,13 +1432,13 @@ const styles = StyleSheet.create({
height: widthUtils(28, 28).height, height: widthUtils(28, 28).height,
}, },
discountPercentageTextStyle: { discountPercentageTextStyle: {
position: 'absolute', position: "absolute",
fontSize: fontSize(12), fontSize: fontSize(12),
fontFamily: "Segoe UI", fontFamily: "Segoe UI",
fontWeight: "900", fontWeight: "900",
fontStyle: "italic", fontStyle: "italic",
color: "#4e2000", color: "#4e2000",
textAlign: 'center', textAlign: "center",
}, },
borderBoxDivider: { borderBoxDivider: {
width: "100%", width: "100%",
@ -1819,30 +1921,31 @@ const styles = StyleSheet.create({
opacity: 0.6, opacity: 0.6,
}, },
loginOverlay: { loginOverlay: {
position: 'absolute', position: "absolute",
top: 0, top: 0,
left: 0, left: 0,
right: 0, right: 0,
bottom: 0, bottom: 0,
backgroundColor: 'rgba(255, 255, 255, 0.9)', backgroundColor: "rgba(255, 255, 255, 0.9)",
backdropFilter: 'blur(10px)', // iOS 毛玻璃效果 backdropFilter: "blur(10px)", // iOS 毛玻璃效果
justifyContent: 'center', justifyContent: "center",
alignItems: 'center', alignItems: "center",
zIndex: 1000, zIndex: 1000,
}, },
blurContainer: { blurContainer: {
width: '100%', width: "100%",
height: '100%', height: "100%",
justifyContent: 'center', justifyContent: "center",
alignItems: 'center', alignItems: "center",
backgroundColor: Platform.OS === 'android' ? 'rgba(255, 255, 255, 0.95)' : 'transparent', backgroundColor:
Platform.OS === "android" ? "rgba(255, 255, 255, 0.95)" : "transparent",
}, },
loginPromptContainer: { loginPromptContainer: {
backgroundColor: 'white', backgroundColor: "white",
borderRadius: 20, borderRadius: 20,
padding: 40, padding: 40,
alignItems: 'center', alignItems: "center",
shadowColor: '#000', shadowColor: "#000",
shadowOffset: { shadowOffset: {
width: 0, width: 0,
height: 2, height: 2,
@ -1850,90 +1953,90 @@ const styles = StyleSheet.create({
shadowOpacity: 0.25, shadowOpacity: 0.25,
shadowRadius: 3.84, shadowRadius: 3.84,
elevation: 5, elevation: 5,
maxWidth: '80%', maxWidth: "80%",
}, },
loginIcon: { loginIcon: {
width: 80, width: 80,
height: 80, height: 80,
marginBottom: 20, marginBottom: 20,
justifyContent: 'center', justifyContent: "center",
alignItems: 'center', alignItems: "center",
backgroundColor: 'rgba(255, 81, 0, 0.1)', backgroundColor: "rgba(255, 81, 0, 0.1)",
borderRadius: 40, borderRadius: 40,
}, },
loginIconText: { loginIconText: {
fontSize: 40, fontSize: 40,
fontWeight: 'bold', fontWeight: "bold",
color: '#FF5100', color: "#FF5100",
}, },
loginPromptTitle: { loginPromptTitle: {
fontSize: fontSize(24), fontSize: fontSize(24),
fontWeight: '700', fontWeight: "700",
color: '#333', color: "#333",
marginBottom: 10, marginBottom: 10,
textAlign: 'center', textAlign: "center",
}, },
loginPromptSubtitle: { loginPromptSubtitle: {
fontSize: fontSize(16), fontSize: fontSize(16),
color: '#666', color: "#666",
marginBottom: 30, marginBottom: 30,
textAlign: 'center', textAlign: "center",
lineHeight: fontSize(22), lineHeight: fontSize(22),
}, },
loginButton: { loginButton: {
backgroundColor: '#FF5100', backgroundColor: "#FF5100",
paddingHorizontal: 40, paddingHorizontal: 40,
paddingVertical: 15, paddingVertical: 15,
borderRadius: 25, borderRadius: 25,
minWidth: 160, minWidth: 160,
}, },
loginButtonText: { loginButtonText: {
color: 'white', color: "white",
fontSize: fontSize(18), fontSize: fontSize(18),
fontWeight: '700', fontWeight: "700",
textAlign: 'center', textAlign: "center",
}, },
warningIconContainer: { warningIconContainer: {
backgroundColor: "#FFF2E9", backgroundColor: "#FFF2E9",
borderRadius: 20, borderRadius: 20,
padding: 12, padding: 12,
marginBottom: 16, marginBottom: 16,
alignSelf: 'center', alignSelf: "center",
width: 52, width: 52,
height: 52, height: 52,
justifyContent: 'center', justifyContent: "center",
alignItems: 'center', alignItems: "center",
}, },
warningIcon: { warningIcon: {
width: 32, width: 32,
height: 32, height: 32,
}, },
minQuantityPopup: { minQuantityPopup: {
width: '80%', width: "80%",
padding: 24, padding: 24,
}, },
minQuantityText: { minQuantityText: {
fontSize: fontSize(16), fontSize: fontSize(16),
color: '#333', color: "#333",
marginVertical: 16, marginVertical: 16,
textAlign: 'center', textAlign: "center",
lineHeight: fontSize(22), lineHeight: fontSize(22),
fontWeight: '500', fontWeight: "500",
}, },
minQuantityButton: { minQuantityButton: {
width: '100%', width: "100%",
height: 44, height: 44,
borderRadius: 22, borderRadius: 22,
backgroundColor: '#FF5100', backgroundColor: "#FF5100",
marginTop: 16, marginTop: 16,
}, },
minQuantityButtonText: { minQuantityButtonText: {
fontSize: fontSize(16), fontSize: fontSize(16),
fontWeight: '600', fontWeight: "600",
}, },
productGroupDivider: { productGroupDivider: {
height: 5, height: 5,
backgroundColor: '#f0f0f0', backgroundColor: "#f0f0f0",
width: '100%', width: "100%",
}, },
}); });

189
app/screens/previewOrder/PaymentMethod.tsx

@ -37,6 +37,7 @@ import payMap from "../../utils/payMap";
// Define route params type // Define route params type
type PaymentMethodRouteParams = { type PaymentMethodRouteParams = {
freight_forwarder_address_id?: number; freight_forwarder_address_id?: number;
isFei?: boolean;
}; };
// Define the root navigation params // Define the root navigation params
type RootStackParamList = { type RootStackParamList = {
@ -47,8 +48,8 @@ type RootStackParamList = {
amount: number; amount: number;
}; };
Pay: { order_id: string }; Pay: { order_id: string };
ShippingFee: { freight_forwarder_address_id?: number }; ShippingFee: { freight_forwarder_address_id?: number; isFei?: boolean };
PaymentMethod: { freight_forwarder_address_id?: number }; PaymentMethod: { freight_forwarder_address_id?: number; isFei?: boolean };
PreviewAddress: undefined; PreviewAddress: undefined;
AddressList: undefined; AddressList: undefined;
// Add other routes as needed // Add other routes as needed
@ -333,6 +334,44 @@ export const PaymentMethod = () => {
const { logPaymentConfirm } = useBurialPointStore(); const { logPaymentConfirm } = useBurialPointStore();
const [isWaveExpanded, setIsWaveExpanded] = useState(false); const [isWaveExpanded, setIsWaveExpanded] = useState(false);
// Get isFei parameter from route
const isFei = route.params?.isFei || false;
// State to store the original total price (fixed, won't change)
const [originalTotalPrice, setOriginalTotalPrice] = useState(0);
// Helper function to get shipping fee - always return actual fee for display
const getShippingFee = () => {
return orderData?.shipping_fee || 0;
};
// Helper function to get converted shipping fee - always return actual converted fee for display
const getConvertedShippingFee = () => {
return convertedAmount.find((item) => item.item_key === "shipping_fee")?.converted_amount || 0;
};
// Helper function to get shipping fee for calculation (0 if isFei is true)
const getShippingFeeForCalculation = () => {
return isFei ? 0 : (orderData?.shipping_fee || 0);
};
// Helper function to get converted shipping fee for calculation (0 if isFei is true)
const getConvertedShippingFeeForCalculation = () => {
if (isFei) return 0;
return convertedAmount.find((item) => item.item_key === "shipping_fee")?.converted_amount || 0;
};
// Helper function to get converted total amount for calculation (excluding shipping fee if isFei is true)
const getConvertedTotalForCalculation = () => {
if (isFei) {
// If isFei is true, subtract the shipping fee from the total converted amount
const totalConverted = convertedAmount.reduce((acc, item) => acc + item.converted_amount, 0);
const shippingFeeConverted = convertedAmount.find((item) => item.item_key === "shipping_fee")?.converted_amount || 0;
return totalConverted - shippingFeeConverted;
}
return convertedAmount.reduce((acc, item) => acc + item.converted_amount, 0);
};
const toggleExpanded = () => { const toggleExpanded = () => {
setIsPaypalExpanded(!isPaypalExpanded); setIsPaypalExpanded(!isPaypalExpanded);
}; };
@ -536,6 +575,17 @@ export const PaymentMethod = () => {
console.log("orderData", orderData); console.log("orderData", orderData);
}, [orderData]); }, [orderData]);
// Set original total price when both previewOrder and orderData are available
useEffect(() => {
if (previewOrder && orderData && originalTotalPrice === 0) {
const originalTotal =
(previewOrder.total_amount || 0) +
(orderData.domestic_shipping_fee || 0) +
(isFei ? 0 : (orderData.shipping_fee || 0));
setOriginalTotalPrice(originalTotal);
}
}, [previewOrder, orderData, originalTotalPrice, isFei]);
const handleSubmit = async () => { const handleSubmit = async () => {
if (!selectedPayment) { if (!selectedPayment) {
Alert.alert(t("payment.select_payment")); Alert.alert(t("payment.select_payment"));
@ -564,38 +614,26 @@ export const PaymentMethod = () => {
createOrderData.payment_method = selectedPayment; createOrderData.payment_method = selectedPayment;
createOrderData.total_amount = createOrderData.total_amount =
selectedPayment === "paypal" selectedPayment === "paypal"
? convertedAmount.reduce( ? getConvertedTotalForCalculation()
(acc, item) => acc + item.converted_amount,
0
)
: selectedPayment === "wave" : selectedPayment === "wave"
? convertedAmount.reduce( ? getConvertedTotalForCalculation()
(acc, item) => acc + item.converted_amount,
0
)
: Number( : Number(
( (
(previewOrder?.total_amount || 0) + (previewOrder?.total_amount || 0) +
(orderData?.domestic_shipping_fee || 0) + (orderData?.domestic_shipping_fee || 0) +
(orderData?.shipping_fee || 0) getShippingFeeForCalculation()
).toFixed(2) ).toFixed(2)
); );
createOrderData.actual_amount = createOrderData.actual_amount =
selectedPayment === "paypal" selectedPayment === "paypal"
? convertedAmount.reduce( ? getConvertedTotalForCalculation()
(acc, item) => acc + item.converted_amount,
0
)
: selectedPayment === "wave" : selectedPayment === "wave"
? convertedAmount.reduce( ? getConvertedTotalForCalculation()
(acc, item) => acc + item.converted_amount,
0
)
: Number( : Number(
( (
(previewOrder?.total_amount || 0) + (previewOrder?.total_amount || 0) +
(orderData?.domestic_shipping_fee || 0) + (orderData?.domestic_shipping_fee || 0) +
(orderData?.shipping_fee || 0) getShippingFeeForCalculation()
).toFixed(2) ).toFixed(2)
); );
createOrderData.currency = createOrderData.currency =
@ -612,12 +650,10 @@ export const PaymentMethod = () => {
: orderData?.domestic_shipping_fee; : orderData?.domestic_shipping_fee;
createOrderData.shipping_fee = createOrderData.shipping_fee =
selectedPayment === "paypal" selectedPayment === "paypal"
? convertedAmount.find((item) => item.item_key === "shipping_fee") ? getConvertedShippingFeeForCalculation()
?.converted_amount || 0
: selectedPayment === "wave" : selectedPayment === "wave"
? convertedAmount.find((item) => item.item_key === "shipping_fee") ? getConvertedShippingFeeForCalculation()
?.converted_amount || 0 : getShippingFeeForCalculation();
: orderData?.shipping_fee;
} }
setOrderData(createOrderData || {}); setOrderData(createOrderData || {});
const data = { const data = {
@ -625,20 +661,14 @@ export const PaymentMethod = () => {
offline_payment: currentTab === "offline" ? 0 : 1, offline_payment: currentTab === "offline" ? 0 : 1,
all_price: all_price:
selectedPayment === "paypal" selectedPayment === "paypal"
? convertedAmount.reduce( ? getConvertedTotalForCalculation()
(acc, item) => acc + item.converted_amount,
0
)
: selectedPayment === "wave" : selectedPayment === "wave"
? convertedAmount.reduce( ? getConvertedTotalForCalculation()
(acc, item) => acc + item.converted_amount,
0
)
: Number( : Number(
( (
(previewOrder?.total_amount || 0) + (previewOrder?.total_amount || 0) +
(orderData?.domestic_shipping_fee || 0) + (orderData?.domestic_shipping_fee || 0) +
(orderData?.shipping_fee || 0) getShippingFeeForCalculation()
).toFixed(2) ).toFixed(2)
), ),
all_quantity: previewOrder?.items?.reduce( all_quantity: previewOrder?.items?.reduce(
@ -647,7 +677,7 @@ export const PaymentMethod = () => {
), ),
currency: selectedPayment === "paypal" ? selectedCurrency : selectedPayment === "wave" ? "FCFA" : user.currency, currency: selectedPayment === "paypal" ? selectedCurrency : selectedPayment === "wave" ? "FCFA" : user.currency,
shipping_method: orderData?.transport_type || 0, shipping_method: orderData?.transport_type || 0,
shipping_price_outside: orderData?.shipping_fee || 0, shipping_price_outside: getShippingFeeForCalculation(),
shipping_price_within: orderData?.domestic_shipping_fee || 0, shipping_price_within: orderData?.domestic_shipping_fee || 0,
timestamp: new Date().toISOString(), timestamp: new Date().toISOString(),
pay_product: JSON.stringify( pay_product: JSON.stringify(
@ -694,20 +724,14 @@ export const PaymentMethod = () => {
selectedPayment === "paypal" ? selectedCurrency : selectedPayment === "wave" ? "FCFA" : user.currency, selectedPayment === "paypal" ? selectedCurrency : selectedPayment === "wave" ? "FCFA" : user.currency,
amount: amount:
selectedPayment === "paypal" selectedPayment === "paypal"
? convertedAmount.reduce( ? getConvertedTotalForCalculation()
(acc, item) => acc + item.converted_amount,
0
)
: selectedPayment === "wave" : selectedPayment === "wave"
? convertedAmount.reduce( ? getConvertedTotalForCalculation()
(acc, item) => acc + item.converted_amount,
0
)
: Number( : Number(
( (
(previewOrder?.total_amount || 0) + (previewOrder?.total_amount || 0) +
(createOrderData?.domestic_shipping_fee || 0) + (orderData?.domestic_shipping_fee || 0) +
(createOrderData?.shipping_fee || 0) getShippingFeeForCalculation()
).toFixed(2) ).toFixed(2)
), ),
}); });
@ -884,7 +908,7 @@ export const PaymentMethod = () => {
</View> </View>
</View> </View>
<View style={styles.priceBox1}> <View style={styles.priceBox1}>
<Text>{t("payment.domestic_shipping")}</Text> <Text>{t("order.shipping.domestic_fee")}</Text>
<View> <View>
<Text> <Text>
{selectedPayment === "paypal" {selectedPayment === "paypal"
@ -908,17 +932,13 @@ export const PaymentMethod = () => {
</View> </View>
<View style={styles.priceBox1}> <View style={styles.priceBox1}>
<Text>{t("payment.international_shipping")}</Text> <Text>{t("payment.international_shipping")}</Text>
<View> <View style={styles.shippingFeeAmountRow}>
<Text> <Text>
{selectedPayment === "paypal" {selectedPayment === "paypal"
? convertedAmount.find( ? getConvertedShippingFee()
(item) => item.item_key === "shipping_fee"
)?.converted_amount || 0
: selectedPayment === "wave" : selectedPayment === "wave"
? convertedAmount.find( ? getConvertedShippingFee()
(item) => item.item_key === "shipping_fee" : getShippingFee()}{" "}
)?.converted_amount || 0
: orderData?.shipping_fee || 0}{" "}
{selectedPayment === "paypal" {selectedPayment === "paypal"
? selectedCurrency === "USD" ? selectedCurrency === "USD"
? "USD" ? "USD"
@ -927,6 +947,17 @@ export const PaymentMethod = () => {
? "FCFA" ? "FCFA"
: previewOrder?.currency} : previewOrder?.currency}
</Text> </Text>
{isFei && (
<TouchableOpacity
style={styles.warningIconContainer}
onPress={() => Alert.alert(
t("payment.notice") || "Notice",
t("payment.cash_on_delivery") || "Cash on Delivery"
)}
>
<Text style={styles.warningIcon}></Text>
</TouchableOpacity>
)}
</View> </View>
</View> </View>
</View> </View>
@ -953,11 +984,7 @@ export const PaymentMethod = () => {
textDecorationLine: "line-through", textDecorationLine: "line-through",
}} }}
> >
{( {originalTotalPrice.toFixed(2)}{" "}
(previewOrder?.total_amount || 0) +
(createOrderData?.domestic_shipping_fee || 0) +
(createOrderData?.shipping_fee || 0)
).toFixed(2)}{" "}
{previewOrder?.currency} {previewOrder?.currency}
</Text> </Text>
<Text <Text
@ -968,12 +995,7 @@ export const PaymentMethod = () => {
marginLeft: 10, marginLeft: 10,
}} }}
> >
{convertedAmount {getConvertedTotalForCalculation().toFixed(2)}
.reduce(
(acc, item) => acc + item.converted_amount,
0
)
.toFixed(2)}
{selectedCurrency === "USD" ? "USD" : "EUR"} {selectedCurrency === "USD" ? "USD" : "EUR"}
</Text> </Text>
</View> </View>
@ -988,12 +1010,7 @@ export const PaymentMethod = () => {
color: "#ff6000", color: "#ff6000",
}} }}
> >
{convertedAmount {getConvertedTotalForCalculation().toFixed(2)}
.reduce(
(acc, item) => acc + item.converted_amount,
0
)
.toFixed(2)}
{selectedCurrency === "USD" ? "USD" : "EUR"} {selectedCurrency === "USD" ? "USD" : "EUR"}
</Text> </Text>
</View> </View>
@ -1008,11 +1025,7 @@ export const PaymentMethod = () => {
textDecorationLine: "line-through", textDecorationLine: "line-through",
}} }}
> >
{( {originalTotalPrice.toFixed(2)}{" "}
(previewOrder?.total_amount || 0) +
(createOrderData?.domestic_shipping_fee || 0) +
(createOrderData?.shipping_fee || 0)
).toFixed(2)}{" "}
{previewOrder?.currency} {previewOrder?.currency}
</Text> </Text>
<Text <Text
@ -1023,12 +1036,7 @@ export const PaymentMethod = () => {
marginLeft: 10, marginLeft: 10,
}} }}
> >
{convertedAmount {getConvertedTotalForCalculation().toFixed(2)}{" "}
.reduce(
(acc, item) => acc + item.converted_amount,
0
)
.toFixed(2)}{" "}
FCFA FCFA
</Text> </Text>
</View> </View>
@ -1041,11 +1049,7 @@ export const PaymentMethod = () => {
color: "#ff6000", color: "#ff6000",
}} }}
> >
{( {originalTotalPrice.toFixed(2)}{" "}
(previewOrder?.total_amount || 0) +
(createOrderData?.domestic_shipping_fee || 0) +
(createOrderData?.shipping_fee || 0)
).toFixed(2)}{" "}
{previewOrder?.currency} {previewOrder?.currency}
</Text> </Text>
)} )}
@ -1715,4 +1719,15 @@ const styles = StyleSheet.create({
fontWeight: "600", fontWeight: "600",
color: "#FF5100", color: "#FF5100",
}, },
shippingFeeAmountRow: {
flexDirection: "row",
alignItems: "center",
},
warningIconContainer: {
padding: 5,
},
warningIcon: {
fontSize: fontSize(16),
color: "#ff6000",
},
}); });

8
app/screens/previewOrder/PreviewAddress.tsx

@ -33,14 +33,12 @@ import { useTranslation } from "react-i18next";
import fontSize from "../../utils/fontsizeUtils"; import fontSize from "../../utils/fontsizeUtils";
type RootStackParamList = { type RootStackParamList = {
AddRess: { address?: AddressItem; cart_item_id?: number | string }; AddRess: { address?: AddressItem; cart_item_id?: number | string; totalAmount?: number; isFei?: boolean };
AddressList: undefined; AddressList: undefined;
ShippingFee: { cart_item_id : {}}; ShippingFee: { cart_item_id: any; totalAmount?: number; isFei?: boolean };
}; };
type AddRessRouteProp = RouteProp<RootStackParamList, "AddRess">; type AddRessRouteProp = RouteProp<RootStackParamList, "AddRess">;
export const PreviewAddress = () => { export const PreviewAddress = () => {
const { t } = useTranslation(); const { t } = useTranslation();
const { const {
@ -68,7 +66,6 @@ export const PreviewAddress = () => {
is_default: false, is_default: false,
}); });
const [selectedCountry, setSelectedCountry] = useState<any>(null); const [selectedCountry, setSelectedCountry] = useState<any>(null);
const [isDefault, setIsDefault] = useState(false);
const [copyPhoneToWhatsApp, setCopyPhoneToWhatsApp] = useState(false); const [copyPhoneToWhatsApp, setCopyPhoneToWhatsApp] = useState(false);
const [phoneNumbersMatch, setPhoneNumbersMatch] = useState(true); const [phoneNumbersMatch, setPhoneNumbersMatch] = useState(true);
const [errors, setErrors] = useState<Record<string, string>>({}); const [errors, setErrors] = useState<Record<string, string>>({});
@ -230,6 +227,7 @@ export const PreviewAddress = () => {
navigation.navigate("ShippingFee",{ navigation.navigate("ShippingFee",{
cart_item_id: route.params, cart_item_id: route.params,
isFei: route.params.isFei || false
}); });
} }
}; };

134
app/screens/previewOrder/ShippingFee.tsx

@ -30,26 +30,22 @@ import useUserStore from "../../store/user";
import useBurialPointStore from "../../store/burialPoint"; import useBurialPointStore from "../../store/burialPoint";
import { getBurialPointData } from "../../store/burialPoint"; import { getBurialPointData } from "../../store/burialPoint";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { getCurrentLanguage } from '../../i18n'; import { getCurrentLanguage } from "../../i18n";
type RootStackParamList = { type RootStackParamList = {
ShippingFee: undefined; ShippingFee: { cart_item_id: any; totalAmount?: number; isFei?: boolean };
PaymentMethod: { freight_forwarder_address_id: number }; PaymentMethod: { freight_forwarder_address_id: number; isFei?: boolean };
}; };
type ShippingFeeParams = { type ShippingFeeParams = {
cart_item_id: { cart_item_id: any;
items: any[]; totalAmount: number;
cart_item_id: number;
};
}; };
export const ShippingFee = () => { export const ShippingFee = () => {
const { t } = useTranslation(); const { t } = useTranslation();
const navigation = const navigation =
useNavigation<NativeStackNavigationProp<RootStackParamList>>(); useNavigation<NativeStackNavigationProp<RootStackParamList>>();
const route = const route = useRoute<RouteProp<RootStackParamList, "ShippingFee">>();
useRoute<RouteProp<Record<string, ShippingFeeParams>, string>>();
const { const {
fetchFreightForwarderAddress, fetchFreightForwarderAddress,
state, state,
@ -69,8 +65,7 @@ export const ShippingFee = () => {
const [selectedWarehouse, setSelectedWarehouse] = useState<Address>(); const [selectedWarehouse, setSelectedWarehouse] = useState<Address>();
const [domesticShippingFeeData, setDomesticShippingFeeData] = const [domesticShippingFeeData, setDomesticShippingFeeData] =
useState<DomesticShippingFeeData>(); useState<DomesticShippingFeeData>();
const [isShippingFeeLoading, setIsShippingFeeLoading] = const [isShippingFeeLoading, setIsShippingFeeLoading] = useState(false);
useState(false);
const [count, setCount] = useState<string>(); const [count, setCount] = useState<string>();
const { setOrderData, orderData, items } = useCreateOrderStore(); const { setOrderData, orderData, items } = useCreateOrderStore();
@ -97,7 +92,12 @@ export const ShippingFee = () => {
state.freightForwarderAddress.other_addresses.length > 0 state.freightForwarderAddress.other_addresses.length > 0
) { ) {
const firstItem = state.freightForwarderAddress.other_addresses[0]; const firstItem = state.freightForwarderAddress.other_addresses[0];
const label = (getCurrentLanguage() === 'fr' ? firstItem.country_name : firstItem.country_name_en) + " | " + firstItem.city; const label =
(getCurrentLanguage() === "fr"
? firstItem.country_name
: firstItem.country_name_en) +
" | " +
firstItem.city;
setWarehouse(label); setWarehouse(label);
setSelectedWarehouseLabel(label); setSelectedWarehouseLabel(label);
setCountryCode(firstItem.country_code); setCountryCode(firstItem.country_code);
@ -119,7 +119,11 @@ export const ShippingFee = () => {
// 统一处理loading状态 // 统一处理loading状态
useEffect(() => { useEffect(() => {
if (state.shippingFees && state.domesticShippingFees && isShippingFeeLoading) { if (
state.shippingFees &&
state.domesticShippingFees &&
isShippingFeeLoading
) {
setIsShippingFeeLoading(false); setIsShippingFeeLoading(false);
} }
}, [state.shippingFees, state.domesticShippingFees, isShippingFeeLoading]); }, [state.shippingFees, state.domesticShippingFees, isShippingFeeLoading]);
@ -140,7 +144,10 @@ export const ShippingFee = () => {
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(
(item) => getCurrentLanguage() === 'fr' ? item.country_name : item.country_name_en+ " | " + item.city === value (item) =>
getCurrentLanguage() === "fr"
? item.country_name
: item.country_name_en + " | " + item.city === value
); );
setSelectedWarehouse(selectedWarehouse); setSelectedWarehouse(selectedWarehouse);
@ -205,10 +212,15 @@ export const ShippingFee = () => {
country_city: selectedWarehouseLabel, country_city: selectedWarehouseLabel,
timestamp: new Date().toISOString(), timestamp: new Date().toISOString(),
}; };
logShippingConfirm(data,navigation.getState().routes[navigation.getState().index - 1]?.name as string); logShippingConfirm(
data,
navigation.getState().routes[navigation.getState().index - 1]
?.name as string
);
console.log(getBurialPointData()); console.log(getBurialPointData());
navigation.navigate("PaymentMethod", { navigation.navigate("PaymentMethod", {
freight_forwarder_address_id: selectedWarehouse?.address_id || 0, freight_forwarder_address_id: selectedWarehouse?.address_id || 0,
isFei:route.params.isFei
}); });
} else { } else {
Alert.alert(t("order.shipping.select_method")); Alert.alert(t("order.shipping.select_method"));
@ -228,7 +240,9 @@ export const ShippingFee = () => {
</TouchableOpacity> </TouchableOpacity>
</View> </View>
<Text style={styles.titleHeading}>{t("order.shipping.method")}</Text> <Text style={styles.titleHeading}>
{t("order.shipping.method")}
</Text>
</View> </View>
{state.isLoading ? ( {state.isLoading ? (
<View style={styles.loadingContainer}> <View style={styles.loadingContainer}>
@ -239,7 +253,9 @@ export const ShippingFee = () => {
<View style={styles.section}> <View style={styles.section}>
<View style={styles.sectionHeader}> <View style={styles.sectionHeader}>
<Text style={styles.sectionIcon}>🚢</Text> <Text style={styles.sectionIcon}>🚢</Text>
<Text style={styles.sectionTitle}>{t("order.shipping.method")}</Text> <Text style={styles.sectionTitle}>
{t("order.shipping.method")}
</Text>
</View> </View>
<View style={styles.shippingOptions}> <View style={styles.shippingOptions}>
{[ {[
@ -286,7 +302,9 @@ export const ShippingFee = () => {
<View style={styles.section}> <View style={styles.section}>
<View style={styles.sectionHeader}> <View style={styles.sectionHeader}>
<Text style={styles.sectionIcon}>🏭</Text> <Text style={styles.sectionIcon}>🏭</Text>
<Text style={styles.sectionTitle}>{t("order.shipping.warehouse")}</Text> <Text style={styles.sectionTitle}>
{t("order.shipping.warehouse")}
</Text>
</View> </View>
<View style={{ marginTop: 12 }}> <View style={{ marginTop: 12 }}>
<View style={styles.selectBox}> <View style={styles.selectBox}>
@ -298,7 +316,8 @@ export const ShippingFee = () => {
onPress={() => setModalVisible(true)} onPress={() => setModalVisible(true)}
> >
<Text style={styles.selectedText}> <Text style={styles.selectedText}>
{selectedWarehouseLabel || t("order.shipping.select_warehouse")} {selectedWarehouseLabel ||
t("order.shipping.select_warehouse")}
</Text> </Text>
<Text style={styles.dropdownIcon}></Text> <Text style={styles.dropdownIcon}></Text>
</TouchableOpacity> </TouchableOpacity>
@ -337,21 +356,36 @@ export const ShippingFee = () => {
style={[ style={[
styles.optionItem, styles.optionItem,
warehouse === warehouse ===
(getCurrentLanguage() === 'fr' ? item.country_name : item.country_name_en+ " | " + item.city) && (getCurrentLanguage() === "fr"
styles.selectedOption, ? item.country_name
: item.country_name_en +
" | " +
item.city) && styles.selectedOption,
]} ]}
onPress={() => onPress={() =>
handleSelectWarehouse( handleSelectWarehouse(
item.country_code, item.country_code,
(getCurrentLanguage() === 'fr' ? item.country_name : item.country_name_en) + " | " + item.city (getCurrentLanguage() === "fr"
? item.country_name
: item.country_name_en) +
" | " +
item.city
) )
} }
> >
<Text style={styles.optionText}> <Text style={styles.optionText}>
{(getCurrentLanguage() === 'fr' ? item.country_name : item.country_name_en) + " | " + item.city} {(getCurrentLanguage() === "fr"
? item.country_name
: item.country_name_en) +
" | " +
item.city}
</Text> </Text>
{warehouse === {warehouse ===
(getCurrentLanguage() === 'fr' ? item.country_name : item.country_name_en) + " | " + item.city && ( (getCurrentLanguage() === "fr"
? item.country_name
: item.country_name_en) +
" | " +
item.city && (
<Text style={styles.checkmark}></Text> <Text style={styles.checkmark}></Text>
)} )}
</TouchableOpacity> </TouchableOpacity>
@ -376,18 +410,16 @@ export const ShippingFee = () => {
marginLeft: 10, marginLeft: 10,
}} }}
> >
{shippingMethod === "sea" ? {shippingMethod === "sea"
t("order.shipping.sea_time") : ? t("order.shipping.sea_time")
t("order.shipping.air_time")} : t("order.shipping.air_time")}
</Text> </Text>
</Text> </Text>
{isShippingFeeLoading ? ( {isShippingFeeLoading ? (
// 统一显示一个加载状态 // 统一显示一个加载状态
<View style={styles.loadingFeesContainer}> <View style={styles.loadingFeesContainer}>
<Text style={styles.calculatingText}> <Text style={styles.calculatingText}>{count}</Text>
{count}
</Text>
<ActivityIndicator <ActivityIndicator
size="small" size="small"
color="#ff6000" color="#ff6000"
@ -436,6 +468,23 @@ export const ShippingFee = () => {
{userStore.user?.currency} {userStore.user?.currency}
</Text> </Text>
</View> </View>
{userStore.user.country_code !== 225 ? (
<View style={styles.delivery}>
<Text style={styles.deliveryText}>
{t("order.preview.Cash_on_delivery")}
</Text>
</View>
) : (
route.params.isFei ? (
<View style={styles.delivery}>
<Text style={styles.deliveryText}>
{t("order.preview.Cash_on_delivery")}
</Text>
</View>
) : (
<View></View>
)
)}
</> </>
)} )}
</View> </View>
@ -458,7 +507,9 @@ export const ShippingFee = () => {
domesticShippingFeeData?.total_shipping_fee == null domesticShippingFeeData?.total_shipping_fee == null
} }
> >
<Text style={styles.buttonText}>{t("order.shipping.submit")}</Text> <Text style={styles.buttonText}>
{t("order.shipping.submit")}
</Text>
</TouchableOpacity> </TouchableOpacity>
</View> </View>
</View> </View>
@ -736,14 +787,25 @@ const styles = StyleSheet.create({
backgroundColor: "#ccc", backgroundColor: "#ccc",
}, },
loadingFeesContainer: { loadingFeesContainer: {
flexDirection: 'row', flexDirection: "row",
alignItems: 'center', alignItems: "center",
justifyContent: 'center', justifyContent: "center",
marginVertical: 15, marginVertical: 15,
}, },
calculatingText: { calculatingText: {
color: "#ff6000", color: "#ff6000",
fontSize: fontSize(14), fontSize: fontSize(14),
fontWeight: "500" fontWeight: "500",
},
delivery: {
alignItems: "center",
justifyContent: "center",
marginTop: 8,
},
deliveryText: {
color: "#ff6000",
fontSize: fontSize(20),
fontWeight: "900",
textAlign: "center",
}, },
}); });

Loading…
Cancel
Save