diff --git a/app/screens/ProductDetailScreen.tsx b/app/screens/ProductDetailScreen.tsx
index c7350f6..b8053de 100644
--- a/app/screens/ProductDetailScreen.tsx
+++ b/app/screens/ProductDetailScreen.tsx
@@ -609,11 +609,14 @@ export const ProductDetailScreen = () => {
>
{
- setIsHeartRed(!isHeartRed);
+ setProduct({
+ ...product,
+ is_favorited: !product.is_favorited,
+ });
productApi.collectProduct(route.params.offer_id);
}}
>
- {isHeartRed ? (
+ {product.is_favorited ? (
) : (
diff --git a/app/screens/function/Collection.tsx b/app/screens/function/Collection.tsx
index b9ddd01..f8a9f78 100644
--- a/app/screens/function/Collection.tsx
+++ b/app/screens/function/Collection.tsx
@@ -18,47 +18,57 @@ import fontSize from "../../utils/fontsizeUtils";
import BackIcon from "../../components/BackIcon";
import { useNavigation } from "@react-navigation/native";
import { productApi } from "../../services/api/productApi";
+import {getSubjectTransLanguage} from "../../utils/languageUtils";
+
// 收藏商品项组件
const FavoriteItem = ({
favoriteItem,
onDelete,
+ addToCart,
}: {
favoriteItem: any;
- onDelete: (favoriteId: number) => void;
+ onDelete: (offerId: number) => void;
+ addToCart: (product: any) => void;
}) => {
const product = favoriteItem.product;
-
+ const navigation = useNavigation();
return (
-
+ {
+ (navigation as any).navigate("ProductDetail", {
+ offer_id: product.offer_id,
+ });
+ }}>
- {product.subject_trans || product.subject}
+ {getSubjectTransLanguage(product) || product.subject_trans}
- {product.currency}{product.min_price}
+ {product.min_price}{product.currency}
{product.vip_discount > 0 && (
- {product.currency}{product.original_min_price}
+ {product.original_min_price}{product.currency}
)}
-
+ {/* {
+ addToCart(product)
+ }}>
加入购物车
-
+ */}
onDelete(favoriteItem.favorite_id)}
+ onPress={() => onDelete(product.offer_id)}
>
删除
-
+
);
};
@@ -95,7 +105,7 @@ export const Collection = () => {
// 避免重复添加数据
setFavorites(prev => {
const newItems = response.items.filter(
- newItem => !prev.some(existingItem => existingItem.favorite_id === newItem.favorite_id)
+ newItem => !prev.some(existingItem => existingItem.product.offer_id === newItem.product.offer_id)
);
return [...prev, ...newItems];
});
@@ -137,28 +147,15 @@ export const Collection = () => {
}, [hasMore, loadingMore, loading, currentPage, fetchFavorites]);
// 删除收藏
- const handleDelete = useCallback(async (favoriteId: number) => {
- Alert.alert(
- "确认删除",
- "确定要删除这个收藏吗?",
- [
- { text: "取消", style: "cancel" },
- {
- text: "删除",
- style: "destructive",
- onPress: async () => {
- try {
- // 这里需要调用删除收藏的API,如果API没有提供,先在前端删除
- setFavorites(prev => prev.filter(item => item.favorite_id !== favoriteId));
- setTotal(prev => prev - 1);
- } catch (error) {
- console.error("删除收藏失败:", error);
- Alert.alert("错误", "删除失败,请重试");
- }
- }
- }
- ]
- );
+ const handleDelete = useCallback(async (offerId: number) => {
+ setFavorites(prev => prev.filter(item => item.product.offer_id !== offerId));
+ setTotal(prev => prev - 1);
+ productApi.deleteCollectProduct(offerId);
+ }, []);
+
+
+ const addToCart = useCallback((product: any) => {
+ console.log(product);
}, []);
// 滚动事件处理
@@ -247,9 +244,10 @@ export const Collection = () => {
<>
{favorites.map((item) => (
))}
{renderFooter()}
@@ -299,15 +297,12 @@ const styles = StyleSheet.create({
},
container: {
backgroundColor: "#f5f5f5",
- paddingLeft: 20,
- paddingRight: 20,
- paddingBottom: 20,
- marginTop: 20,
+
flex: 1,
},
item: {
flexDirection: "row",
- padding: 12,
+ padding: 19,
backgroundColor: "#fff",
borderBottomWidth: 1,
borderBottomColor: "#eee",
diff --git a/app/services/api/orders.ts b/app/services/api/orders.ts
index 3c28ac8..eacdbd8 100644
--- a/app/services/api/orders.ts
+++ b/app/services/api/orders.ts
@@ -490,4 +490,8 @@ export const ordersApi = {
confirmOrder: (order_id: string) =>
apiService.patch(`/api/orders/${order_id}/shipping/`,{
}),
+
+ // 修改订单状态
+ changeOrderStatus: (order_id: string, status: number) =>
+ apiService.patch(`/api/orders/${order_id}/status/?status=${status}`),
};
diff --git a/app/services/api/productApi.ts b/app/services/api/productApi.ts
index 1931a6a..1c0036d 100644
--- a/app/services/api/productApi.ts
+++ b/app/services/api/productApi.ts
@@ -87,6 +87,7 @@ export type Products = Product[]
export interface ProductDetailParams {
"offer_id": 0,
currency:string
+ is_favorited:boolean
"category_id": 0,
"price": number | string,
"subject": "string",
diff --git a/app/store/orderList.ts b/app/store/orderList.ts
index bd0cbcb..bb79782 100644
--- a/app/store/orderList.ts
+++ b/app/store/orderList.ts
@@ -88,7 +88,7 @@ export const useOrderListStore = create((set, get) => ({
},
// 确定收货
- confirmOrder: async (orderId: string) => {
+ confirmOrder: async (orderId: string,status:number = 3) => {
set((state) => ({
orders: {
...state.orders,
@@ -96,6 +96,6 @@ export const useOrderListStore = create((set, get) => ({
total: state.orders.total - 1,
},
}));
- await ordersApi.confirmOrder(orderId);
+ await ordersApi.changeOrderStatus(orderId,status);
},
}));