|
|
@ -18,47 +18,57 @@ import fontSize from "../../utils/fontsizeUtils"; |
|
|
|
import BackIcon from "../../components/BackIcon"; |
|
|
|
import BackIcon from "../../components/BackIcon"; |
|
|
|
import { useNavigation } from "@react-navigation/native"; |
|
|
|
import { useNavigation } from "@react-navigation/native"; |
|
|
|
import { productApi } from "../../services/api/productApi"; |
|
|
|
import { productApi } from "../../services/api/productApi"; |
|
|
|
|
|
|
|
import {getSubjectTransLanguage} from "../../utils/languageUtils"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 收藏商品项组件
|
|
|
|
// 收藏商品项组件
|
|
|
|
const FavoriteItem = ({ |
|
|
|
const FavoriteItem = ({ |
|
|
|
favoriteItem, |
|
|
|
favoriteItem, |
|
|
|
onDelete, |
|
|
|
onDelete, |
|
|
|
|
|
|
|
addToCart, |
|
|
|
}: { |
|
|
|
}: { |
|
|
|
favoriteItem: any; |
|
|
|
favoriteItem: any; |
|
|
|
onDelete: (favoriteId: number) => void; |
|
|
|
onDelete: (offerId: number) => void; |
|
|
|
|
|
|
|
addToCart: (product: any) => void; |
|
|
|
}) => { |
|
|
|
}) => { |
|
|
|
const product = favoriteItem.product; |
|
|
|
const product = favoriteItem.product; |
|
|
|
|
|
|
|
const navigation = useNavigation(); |
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<View style={styles.item}> |
|
|
|
<View style={styles.item}> |
|
|
|
<Image
|
|
|
|
<Image
|
|
|
|
source={{ uri: product.product_image_urls[0] || 'https://via.placeholder.com/100' }}
|
|
|
|
source={{ uri: product.product_image_urls[0] || 'https://via.placeholder.com/100' }}
|
|
|
|
style={styles.image}
|
|
|
|
style={styles.image}
|
|
|
|
/> |
|
|
|
/> |
|
|
|
<View style={styles.info}> |
|
|
|
<TouchableOpacity style={styles.info} onPress={() => { |
|
|
|
|
|
|
|
(navigation as any).navigate("ProductDetail", { |
|
|
|
|
|
|
|
offer_id: product.offer_id, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}}> |
|
|
|
<Text style={styles.title} numberOfLines={2}> |
|
|
|
<Text style={styles.title} numberOfLines={2}> |
|
|
|
{product.subject_trans || product.subject} |
|
|
|
{getSubjectTransLanguage(product) || product.subject_trans} |
|
|
|
</Text> |
|
|
|
</Text> |
|
|
|
<Text style={styles.price}> |
|
|
|
<Text style={styles.price}> |
|
|
|
{product.currency}{product.min_price} |
|
|
|
{product.min_price}{product.currency} |
|
|
|
{product.vip_discount > 0 && ( |
|
|
|
{product.vip_discount > 0 && ( |
|
|
|
<Text style={styles.originalPrice}> |
|
|
|
<Text style={styles.originalPrice}> |
|
|
|
{product.currency}{product.original_min_price} |
|
|
|
{product.original_min_price}{product.currency} |
|
|
|
</Text> |
|
|
|
</Text> |
|
|
|
)} |
|
|
|
)} |
|
|
|
</Text> |
|
|
|
</Text> |
|
|
|
<View style={styles.actions}> |
|
|
|
<View style={styles.actions}> |
|
|
|
<TouchableOpacity style={[styles.btn, styles.cart]}> |
|
|
|
{/* <TouchableOpacity style={[styles.btn, styles.cart]} onPress={() => { |
|
|
|
|
|
|
|
addToCart(product) |
|
|
|
|
|
|
|
}}> |
|
|
|
<Text style={styles.cartText}>加入购物车</Text> |
|
|
|
<Text style={styles.cartText}>加入购物车</Text> |
|
|
|
</TouchableOpacity> |
|
|
|
</TouchableOpacity> */} |
|
|
|
<TouchableOpacity
|
|
|
|
<TouchableOpacity
|
|
|
|
style={[styles.btn, styles.delete]} |
|
|
|
style={[styles.btn, styles.delete]} |
|
|
|
onPress={() => onDelete(favoriteItem.favorite_id)} |
|
|
|
onPress={() => onDelete(product.offer_id)} |
|
|
|
> |
|
|
|
> |
|
|
|
<Text style={styles.deleteText}>删除</Text> |
|
|
|
<Text style={styles.deleteText}>删除</Text> |
|
|
|
</TouchableOpacity> |
|
|
|
</TouchableOpacity> |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
</TouchableOpacity> |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
); |
|
|
|
); |
|
|
|
}; |
|
|
|
}; |
|
|
@ -95,7 +105,7 @@ export const Collection = () => { |
|
|
|
// 避免重复添加数据
|
|
|
|
// 避免重复添加数据
|
|
|
|
setFavorites(prev => { |
|
|
|
setFavorites(prev => { |
|
|
|
const newItems = response.items.filter( |
|
|
|
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]; |
|
|
|
return [...prev, ...newItems]; |
|
|
|
}); |
|
|
|
}); |
|
|
@ -137,28 +147,15 @@ export const Collection = () => { |
|
|
|
}, [hasMore, loadingMore, loading, currentPage, fetchFavorites]); |
|
|
|
}, [hasMore, loadingMore, loading, currentPage, fetchFavorites]); |
|
|
|
|
|
|
|
|
|
|
|
// 删除收藏
|
|
|
|
// 删除收藏
|
|
|
|
const handleDelete = useCallback(async (favoriteId: number) => { |
|
|
|
const handleDelete = useCallback(async (offerId: number) => { |
|
|
|
Alert.alert( |
|
|
|
setFavorites(prev => prev.filter(item => item.product.offer_id !== offerId)); |
|
|
|
"确认删除", |
|
|
|
|
|
|
|
"确定要删除这个收藏吗?", |
|
|
|
|
|
|
|
[ |
|
|
|
|
|
|
|
{ text: "取消", style: "cancel" }, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
text: "删除", |
|
|
|
|
|
|
|
style: "destructive", |
|
|
|
|
|
|
|
onPress: async () => { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
// 这里需要调用删除收藏的API,如果API没有提供,先在前端删除
|
|
|
|
|
|
|
|
setFavorites(prev => prev.filter(item => item.favorite_id !== favoriteId)); |
|
|
|
|
|
|
|
setTotal(prev => prev - 1); |
|
|
|
setTotal(prev => prev - 1); |
|
|
|
} catch (error) { |
|
|
|
productApi.deleteCollectProduct(offerId); |
|
|
|
console.error("删除收藏失败:", error); |
|
|
|
}, []); |
|
|
|
Alert.alert("错误", "删除失败,请重试"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
const addToCart = useCallback((product: any) => { |
|
|
|
} |
|
|
|
console.log(product); |
|
|
|
] |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}, []); |
|
|
|
}, []); |
|
|
|
|
|
|
|
|
|
|
|
// 滚动事件处理
|
|
|
|
// 滚动事件处理
|
|
|
@ -247,9 +244,10 @@ export const Collection = () => { |
|
|
|
<> |
|
|
|
<> |
|
|
|
{favorites.map((item) => ( |
|
|
|
{favorites.map((item) => ( |
|
|
|
<FavoriteItem
|
|
|
|
<FavoriteItem
|
|
|
|
key={item.favorite_id}
|
|
|
|
key={item.product.offer_id}
|
|
|
|
favoriteItem={item} |
|
|
|
favoriteItem={item} |
|
|
|
onDelete={handleDelete} |
|
|
|
onDelete={handleDelete} |
|
|
|
|
|
|
|
addToCart={addToCart} |
|
|
|
/> |
|
|
|
/> |
|
|
|
))} |
|
|
|
))} |
|
|
|
{renderFooter()} |
|
|
|
{renderFooter()} |
|
|
@ -299,15 +297,12 @@ const styles = StyleSheet.create({ |
|
|
|
}, |
|
|
|
}, |
|
|
|
container: { |
|
|
|
container: { |
|
|
|
backgroundColor: "#f5f5f5", |
|
|
|
backgroundColor: "#f5f5f5", |
|
|
|
paddingLeft: 20, |
|
|
|
|
|
|
|
paddingRight: 20, |
|
|
|
|
|
|
|
paddingBottom: 20, |
|
|
|
|
|
|
|
marginTop: 20, |
|
|
|
|
|
|
|
flex: 1, |
|
|
|
flex: 1, |
|
|
|
}, |
|
|
|
}, |
|
|
|
item: { |
|
|
|
item: { |
|
|
|
flexDirection: "row", |
|
|
|
flexDirection: "row", |
|
|
|
padding: 12, |
|
|
|
padding: 19, |
|
|
|
backgroundColor: "#fff", |
|
|
|
backgroundColor: "#fff", |
|
|
|
borderBottomWidth: 1, |
|
|
|
borderBottomWidth: 1, |
|
|
|
borderBottomColor: "#eee", |
|
|
|
borderBottomColor: "#eee", |
|
|
|