|
|
|
@ -17,6 +17,7 @@ import fontSize from "../utils/fontsizeUtils";
|
|
|
|
|
import CloseIcon from "../components/CloseIcon"; |
|
|
|
|
import XIconBottom from "../components/XIconBottom"; |
|
|
|
|
import XIconTop from "../components/XIconTop"; |
|
|
|
|
import useBurialPointStore from "../store/burialPoint"; |
|
|
|
|
import { |
|
|
|
|
ProductDetailParams, |
|
|
|
|
ProductGroupList, |
|
|
|
@ -29,7 +30,6 @@ import { NativeStackNavigationProp } from "@react-navigation/native-stack";
|
|
|
|
|
import ImageView from "react-native-image-viewing"; |
|
|
|
|
import useProductCartStore from "../store/productCart"; |
|
|
|
|
import useUserStore from "../store/user"; |
|
|
|
|
|
|
|
|
|
interface ProductCardProps { |
|
|
|
|
onClose: () => void; |
|
|
|
|
product: ProductDetailParams; |
|
|
|
@ -51,9 +51,9 @@ const ProductCard: React.FC<ProductCardProps> = ({
|
|
|
|
|
const [currentImageIndex, setCurrentImageIndex] = useState(0); |
|
|
|
|
const [imageViewerVisible, setImageViewerVisible] = useState(false); |
|
|
|
|
const { |
|
|
|
|
user: { user_id, vip_level }, |
|
|
|
|
user: { user_id, vip_level,currency }, |
|
|
|
|
} = useUserStore(); |
|
|
|
|
|
|
|
|
|
const { logAddToCart } = useBurialPointStore(); |
|
|
|
|
const { |
|
|
|
|
product, |
|
|
|
|
groupList, |
|
|
|
@ -105,24 +105,45 @@ const ProductCard: React.FC<ProductCardProps> = ({
|
|
|
|
|
} |
|
|
|
|
if (groupList.length > 1) { |
|
|
|
|
const selectedSku = |
|
|
|
|
hasImg?.attributes.filter((item) => (item.size ?? 0) > 0) || []; |
|
|
|
|
hasImg?.attributes?.filter((item) => (item.size ?? 0) > 0) || []; |
|
|
|
|
const skus: { sku_id: number; quantity: number }[] = []; |
|
|
|
|
selectedSku.forEach((item) => { |
|
|
|
|
item.list.forEach((item) => { |
|
|
|
|
if ((item.size ?? 0) > 0) { |
|
|
|
|
skus.push({ |
|
|
|
|
sku_id: item.sku_id, |
|
|
|
|
quantity: item.size as number, |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
item.list?.forEach((item) => { |
|
|
|
|
if ((item.size ?? 0) > 0) { |
|
|
|
|
skus.push({ |
|
|
|
|
sku_id: item.sku_id, |
|
|
|
|
quantity: item.size as number, |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
const data = { |
|
|
|
|
offer_id: product.offer_id, |
|
|
|
|
skus, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
cartApi(data).then((res) => { |
|
|
|
|
console.log(res); |
|
|
|
|
|
|
|
|
|
const log = selectedSku[0].list?.filter((item) => (item.size ?? 0) > 0) || [] |
|
|
|
|
log.forEach((item) => {
|
|
|
|
|
const logData = { |
|
|
|
|
offer_id: product?.offer_id || 0, |
|
|
|
|
category_id: product?.category_id || 0, |
|
|
|
|
price: item.offer_price || price || 0, |
|
|
|
|
all_price: totalPrice || 0, |
|
|
|
|
currency: currency || '', |
|
|
|
|
sku_id: item?.sku_id || 0, |
|
|
|
|
quantity: (item?.size as number) || 0, |
|
|
|
|
product_name: product?.subject || '', |
|
|
|
|
timestamp: new Date().toISOString(), |
|
|
|
|
sku_img: selectedSku[0].sku_image_url || '', |
|
|
|
|
all_quantity: selectedSize || 0 |
|
|
|
|
} |
|
|
|
|
logAddToCart(logData,navigation.getState().routes[navigation.getState().index - 1]?.name as string)
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
}).catch((err) => { |
|
|
|
|
Alert.alert("添加失败", "请稍后再试"); |
|
|
|
|
}); |
|
|
|
|
} else if (groupList.length === 1) { |
|
|
|
|
const selectedSku = |
|
|
|
@ -138,8 +159,33 @@ const ProductCard: React.FC<ProductCardProps> = ({
|
|
|
|
|
offer_id: product.offer_id, |
|
|
|
|
skus, |
|
|
|
|
}; |
|
|
|
|
cartApi(data).then((res) => { |
|
|
|
|
console.log(res); |
|
|
|
|
cartApi(data).then((res) => {
|
|
|
|
|
console.log(selectedSku); |
|
|
|
|
|
|
|
|
|
selectedSku.forEach((item) => {
|
|
|
|
|
console.log(item); |
|
|
|
|
|
|
|
|
|
const logData = { |
|
|
|
|
offer_id: product?.offer_id || 0, |
|
|
|
|
category_id: product?.category_id || 0, |
|
|
|
|
price: item.offer_price || price || 0, |
|
|
|
|
all_price: totalPrice || 0, |
|
|
|
|
currency: currency || '', |
|
|
|
|
sku_id: item?.sku_id || 0, |
|
|
|
|
quantity: (item?.size as number) || 0, |
|
|
|
|
product_name: product?.subject || '', |
|
|
|
|
timestamp: new Date().toISOString(), |
|
|
|
|
sku_img: selectedSku[0].sku_image_url || '', |
|
|
|
|
all_quantity: selectedSize || 0 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
console.log(logData); |
|
|
|
|
|
|
|
|
|
// logAddToCart(logData,navigation.getState().routes[navigation.getState().index - 1]?.name as string)
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
}).catch((err) => { |
|
|
|
|
Alert.alert("添加失败", "请稍后再试"); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
setDeleteModalVisible(true); |
|
|
|
@ -272,22 +318,22 @@ const ProductCard: React.FC<ProductCardProps> = ({
|
|
|
|
|
<TouchableOpacity |
|
|
|
|
style={[ |
|
|
|
|
styles.productBoxImgListBox, |
|
|
|
|
item.has_color && styles.productBoxImgListBoxActive, |
|
|
|
|
item?.has_color && styles.productBoxImgListBoxActive, |
|
|
|
|
]} |
|
|
|
|
key={index} |
|
|
|
|
onPress={() => |
|
|
|
|
handleColorSelect( |
|
|
|
|
item.value, |
|
|
|
|
item?.value || '', |
|
|
|
|
index, |
|
|
|
|
item.sku_image_url |
|
|
|
|
item?.sku_image_url || '' |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
> |
|
|
|
|
<Image |
|
|
|
|
source={{ uri: item.sku_image_url }} |
|
|
|
|
source={{ uri: item?.sku_image_url || '' }} |
|
|
|
|
style={styles.productBoxImgListBoxImg} |
|
|
|
|
/> |
|
|
|
|
{item.size && ( |
|
|
|
|
{(item?.size ?? 0) > 0 && ( |
|
|
|
|
<View style={styles.fixedCornerView}> |
|
|
|
|
<Text style={styles.fixedCornerViewText}> |
|
|
|
|
x{item.size} |
|
|
|
@ -312,7 +358,7 @@ const ProductCard: React.FC<ProductCardProps> = ({
|
|
|
|
|
<View style={styles.sizePriceBox}> |
|
|
|
|
{hasImg && |
|
|
|
|
hasImg.attributes |
|
|
|
|
?.find((item) => item.has_color) |
|
|
|
|
?.find((item) => item?.has_color) |
|
|
|
|
?.list.map((list, index1) => ( |
|
|
|
|
<View style={styles.sizePriceBoxItems} key={index1}> |
|
|
|
|
<View style={styles.sizePriceBoxItem}> |
|
|
|
@ -323,18 +369,18 @@ const ProductCard: React.FC<ProductCardProps> = ({
|
|
|
|
|
</Text> |
|
|
|
|
)} |
|
|
|
|
<Text style={styles.priceText}> |
|
|
|
|
{list.offer_price || price} |
|
|
|
|
{list?.offer_price || price || 0} |
|
|
|
|
</Text> |
|
|
|
|
<Text |
|
|
|
|
style={styles.sizePriceBoxItemText} |
|
|
|
|
numberOfLines={1} |
|
|
|
|
ellipsizeMode="tail" |
|
|
|
|
> |
|
|
|
|
{list.attributes[0].value} |
|
|
|
|
{list.attributes?.[0]?.value} |
|
|
|
|
</Text> |
|
|
|
|
</View> |
|
|
|
|
<Text style={styles.amountText}> |
|
|
|
|
库存 {list?.amount_on_sale} |
|
|
|
|
库存 {list?.amount_on_sale ?? 0} |
|
|
|
|
</Text> |
|
|
|
|
</View> |
|
|
|
|
<View style={styles.sizePriceBoxStepForward}> |
|
|
|
@ -342,10 +388,10 @@ const ProductCard: React.FC<ProductCardProps> = ({
|
|
|
|
|
style={styles.sizePriceBoxStepForwardButton} |
|
|
|
|
onPress={() => |
|
|
|
|
handleSizeSelect( |
|
|
|
|
list?.attributes[0]?.value, |
|
|
|
|
list?.attributes?.[0]?.value, |
|
|
|
|
"-", |
|
|
|
|
index1, |
|
|
|
|
list.amount_on_sale |
|
|
|
|
list?.amount_on_sale ?? 0 |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
> |
|
|
|
@ -353,14 +399,14 @@ const ProductCard: React.FC<ProductCardProps> = ({
|
|
|
|
|
</TouchableOpacity> |
|
|
|
|
<TextInput |
|
|
|
|
style={styles.sizePriceBoxStepForwardInput} |
|
|
|
|
value={list.size?.toString() ?? "0"} |
|
|
|
|
value={list?.size?.toString() ?? "0"} |
|
|
|
|
keyboardType="numeric" |
|
|
|
|
onChangeText={(text) => |
|
|
|
|
handleSizeSelect( |
|
|
|
|
list?.attributes[0]?.value, |
|
|
|
|
list?.attributes?.[0]?.value, |
|
|
|
|
text, |
|
|
|
|
index1, |
|
|
|
|
list.amount_on_sale |
|
|
|
|
list?.amount_on_sale ?? 0 |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
/> |
|
|
|
@ -368,10 +414,10 @@ const ProductCard: React.FC<ProductCardProps> = ({
|
|
|
|
|
style={styles.sizePriceBoxStepForwardButton} |
|
|
|
|
onPress={() => |
|
|
|
|
handleSizeSelect( |
|
|
|
|
list?.attributes[0]?.value, |
|
|
|
|
list?.attributes?.[0]?.value, |
|
|
|
|
"+", |
|
|
|
|
index1, |
|
|
|
|
list.amount_on_sale |
|
|
|
|
list?.amount_on_sale ?? 0 |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
> |
|
|
|
@ -389,25 +435,25 @@ const ProductCard: React.FC<ProductCardProps> = ({
|
|
|
|
|
{hasImg && groupList.length > 1 && !hasImg.has_image && ( |
|
|
|
|
<View style={styles.productBox}> |
|
|
|
|
<View style={styles.productTit}> |
|
|
|
|
<Text style={styles.productTitText}>{hasImg.attribute_name}</Text> |
|
|
|
|
<Text style={styles.productTitText}>{hasImg?.attribute_name || ''}</Text> |
|
|
|
|
</View> |
|
|
|
|
|
|
|
|
|
{hasImg.attributes?.map((item, index) => { |
|
|
|
|
return ( |
|
|
|
|
<TouchableOpacity |
|
|
|
|
style={[ |
|
|
|
|
style={[ |
|
|
|
|
styles.noImgBoxs, |
|
|
|
|
item.has_color && styles.productBoxImgListBoxActive, |
|
|
|
|
item?.has_color && styles.productBoxImgListBoxActive, |
|
|
|
|
]} |
|
|
|
|
key={index} |
|
|
|
|
onPress={() => { |
|
|
|
|
handleColorSelect(item.value, index, item.sku_image_url); |
|
|
|
|
handleColorSelect(item?.value || '', index, item?.sku_image_url || ''); |
|
|
|
|
}} |
|
|
|
|
> |
|
|
|
|
{(item?.size ?? 0) > 0 && ( |
|
|
|
|
<Text style={styles.selectedNumText}>x{item?.size}</Text> |
|
|
|
|
)} |
|
|
|
|
<Text style={styles.noImgBoxsText}>{item.value}</Text> |
|
|
|
|
<Text style={styles.noImgBoxsText}>{item?.value || ''}</Text> |
|
|
|
|
</TouchableOpacity> |
|
|
|
|
); |
|
|
|
|
})} |
|
|
|
@ -424,7 +470,7 @@ const ProductCard: React.FC<ProductCardProps> = ({
|
|
|
|
|
<View style={styles.sizePriceBox}> |
|
|
|
|
{hasImg && |
|
|
|
|
hasImg.attributes |
|
|
|
|
?.find((item) => item.has_color) |
|
|
|
|
?.find((item) => item?.has_color) |
|
|
|
|
?.list.map((list, index1) => ( |
|
|
|
|
<View style={styles.sizePriceBoxItems} key={index1}> |
|
|
|
|
<View style={styles.sizePriceBoxItem}> |
|
|
|
@ -435,18 +481,18 @@ const ProductCard: React.FC<ProductCardProps> = ({
|
|
|
|
|
</Text> |
|
|
|
|
)} |
|
|
|
|
<Text style={styles.priceText}> |
|
|
|
|
{list.offer_price || price} |
|
|
|
|
{list?.offer_price || price || 0} |
|
|
|
|
</Text> |
|
|
|
|
<Text |
|
|
|
|
style={styles.sizePriceBoxItemText} |
|
|
|
|
numberOfLines={1} |
|
|
|
|
ellipsizeMode="tail" |
|
|
|
|
> |
|
|
|
|
{list.attributes[0].value} |
|
|
|
|
{list.attributes?.[0]?.value} |
|
|
|
|
</Text> |
|
|
|
|
</View> |
|
|
|
|
<Text style={styles.amountText}> |
|
|
|
|
库存 {list?.amount_on_sale} |
|
|
|
|
库存 {list?.amount_on_sale ?? 0} |
|
|
|
|
</Text> |
|
|
|
|
</View> |
|
|
|
|
<View style={styles.sizePriceBoxStepForward}> |
|
|
|
@ -454,10 +500,10 @@ const ProductCard: React.FC<ProductCardProps> = ({
|
|
|
|
|
style={styles.sizePriceBoxStepForwardButton} |
|
|
|
|
onPress={() => |
|
|
|
|
handleSizeSelect( |
|
|
|
|
list?.attributes[0]?.value, |
|
|
|
|
list?.attributes?.[0]?.value, |
|
|
|
|
"-", |
|
|
|
|
index1, |
|
|
|
|
list.amount_on_sale |
|
|
|
|
list?.amount_on_sale ?? 0 |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
> |
|
|
|
@ -465,14 +511,14 @@ const ProductCard: React.FC<ProductCardProps> = ({
|
|
|
|
|
</TouchableOpacity> |
|
|
|
|
<TextInput |
|
|
|
|
style={styles.sizePriceBoxStepForwardInput} |
|
|
|
|
value={list.size?.toString() ?? "0"} |
|
|
|
|
value={list?.size?.toString() ?? "0"} |
|
|
|
|
keyboardType="numeric" |
|
|
|
|
onChangeText={(text) => |
|
|
|
|
handleSizeSelect( |
|
|
|
|
list?.attributes[0]?.value, |
|
|
|
|
list?.attributes?.[0]?.value, |
|
|
|
|
text, |
|
|
|
|
index1, |
|
|
|
|
list.amount_on_sale |
|
|
|
|
list?.amount_on_sale ?? 0 |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
/> |
|
|
|
@ -480,10 +526,10 @@ const ProductCard: React.FC<ProductCardProps> = ({
|
|
|
|
|
style={styles.sizePriceBoxStepForwardButton} |
|
|
|
|
onPress={() => |
|
|
|
|
handleSizeSelect( |
|
|
|
|
list?.attributes[0]?.value, |
|
|
|
|
list?.attributes?.[0]?.value, |
|
|
|
|
"+", |
|
|
|
|
index1, |
|
|
|
|
list.amount_on_sale |
|
|
|
|
list?.amount_on_sale ?? 0 |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
> |
|
|
|
@ -519,18 +565,18 @@ const ProductCard: React.FC<ProductCardProps> = ({
|
|
|
|
|
</Text> |
|
|
|
|
)} |
|
|
|
|
<Text style={styles.priceText}> |
|
|
|
|
{list.offer_price || price} |
|
|
|
|
{list?.offer_price || price || 0} |
|
|
|
|
</Text> |
|
|
|
|
<Text |
|
|
|
|
style={styles.sizePriceBoxItemText} |
|
|
|
|
numberOfLines={1} |
|
|
|
|
ellipsizeMode="tail" |
|
|
|
|
> |
|
|
|
|
{list.attributes[0].value} |
|
|
|
|
{list.attributes?.[0]?.value} |
|
|
|
|
</Text> |
|
|
|
|
</View> |
|
|
|
|
<Text style={styles.amountText}> |
|
|
|
|
库存 {list?.amount_on_sale} |
|
|
|
|
库存 {list?.amount_on_sale ?? 0} |
|
|
|
|
</Text> |
|
|
|
|
</View> |
|
|
|
|
<View style={styles.sizePriceBoxStepForward}> |
|
|
|
@ -538,10 +584,10 @@ const ProductCard: React.FC<ProductCardProps> = ({
|
|
|
|
|
style={styles.sizePriceBoxStepForwardButton} |
|
|
|
|
onPress={() => |
|
|
|
|
handleNoImgSizeSelect( |
|
|
|
|
list?.attributes[0]?.value, |
|
|
|
|
list?.attributes?.[0]?.value, |
|
|
|
|
"-", |
|
|
|
|
index1, |
|
|
|
|
list.amount_on_sale |
|
|
|
|
list?.amount_on_sale ?? 0 |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
> |
|
|
|
@ -549,14 +595,14 @@ const ProductCard: React.FC<ProductCardProps> = ({
|
|
|
|
|
</TouchableOpacity> |
|
|
|
|
<TextInput |
|
|
|
|
style={styles.sizePriceBoxStepForwardInput} |
|
|
|
|
value={list.size?.toString() ?? "0"} |
|
|
|
|
value={list?.size?.toString() ?? "0"} |
|
|
|
|
keyboardType="numeric" |
|
|
|
|
onChangeText={(text) => |
|
|
|
|
handleNoImgSizeSelect( |
|
|
|
|
list?.attributes[0]?.value, |
|
|
|
|
list?.attributes?.[0]?.value, |
|
|
|
|
text, |
|
|
|
|
index1, |
|
|
|
|
list.amount_on_sale |
|
|
|
|
list?.amount_on_sale ?? 0 |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
/> |
|
|
|
@ -564,10 +610,10 @@ const ProductCard: React.FC<ProductCardProps> = ({
|
|
|
|
|
style={styles.sizePriceBoxStepForwardButton} |
|
|
|
|
onPress={() => |
|
|
|
|
handleNoImgSizeSelect( |
|
|
|
|
list?.attributes[0]?.value, |
|
|
|
|
list?.attributes?.[0]?.value, |
|
|
|
|
"+", |
|
|
|
|
index1, |
|
|
|
|
list.amount_on_sale |
|
|
|
|
list?.amount_on_sale ?? 0 |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
> |
|
|
|
@ -597,7 +643,7 @@ const ProductCard: React.FC<ProductCardProps> = ({
|
|
|
|
|
<View style={styles.allImageBox} key={index1}> |
|
|
|
|
<View style={styles.allImageBoxImg}> |
|
|
|
|
<Image |
|
|
|
|
source={{ uri: list.attributes[0].sku_image_url }} |
|
|
|
|
source={{ uri: list.attributes?.[0]?.sku_image_url }} |
|
|
|
|
style={styles.allImageBoxImgImg} |
|
|
|
|
/> |
|
|
|
|
</View> |
|
|
|
@ -616,19 +662,19 @@ const ProductCard: React.FC<ProductCardProps> = ({
|
|
|
|
|
marginRight: 5, |
|
|
|
|
}} |
|
|
|
|
> |
|
|
|
|
{list.offer_price || price} |
|
|
|
|
{list?.offer_price || price || 0} |
|
|
|
|
</Text> |
|
|
|
|
<Text |
|
|
|
|
style={styles.allImageBoxListBoxText} |
|
|
|
|
numberOfLines={1} |
|
|
|
|
ellipsizeMode="tail" |
|
|
|
|
> |
|
|
|
|
{list.attributes[0].value} |
|
|
|
|
{list.attributes?.[0]?.value} |
|
|
|
|
</Text> |
|
|
|
|
</View> |
|
|
|
|
|
|
|
|
|
<Text style={styles.amountText}> |
|
|
|
|
库存 {list?.amount_on_sale} |
|
|
|
|
库存 {list?.amount_on_sale ?? 0} |
|
|
|
|
</Text> |
|
|
|
|
</View> |
|
|
|
|
<View style={styles.allImageBoxListStop}> |
|
|
|
@ -636,10 +682,10 @@ const ProductCard: React.FC<ProductCardProps> = ({
|
|
|
|
|
style={styles.sizePriceBoxStepForwardButton} |
|
|
|
|
onPress={() => |
|
|
|
|
handleNoImgSizeSelect( |
|
|
|
|
list.attributes[0]?.value, |
|
|
|
|
list.attributes?.[0]?.value, |
|
|
|
|
"-", |
|
|
|
|
index1, |
|
|
|
|
list.amount_on_sale |
|
|
|
|
list?.amount_on_sale ?? 0 |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
> |
|
|
|
@ -648,13 +694,13 @@ const ProductCard: React.FC<ProductCardProps> = ({
|
|
|
|
|
<TextInput |
|
|
|
|
style={styles.sizePriceBoxStepForwardInput} |
|
|
|
|
keyboardType="numeric" |
|
|
|
|
value={list.size?.toString() ?? "0"} |
|
|
|
|
value={list?.size?.toString() ?? "0"} |
|
|
|
|
onChangeText={(text) => |
|
|
|
|
handleNoImgSizeSelect( |
|
|
|
|
list.attributes[0]?.value, |
|
|
|
|
list.attributes?.[0]?.value, |
|
|
|
|
text, |
|
|
|
|
index1, |
|
|
|
|
list.amount_on_sale |
|
|
|
|
list?.amount_on_sale ?? 0 |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
/> |
|
|
|
@ -662,10 +708,10 @@ const ProductCard: React.FC<ProductCardProps> = ({
|
|
|
|
|
style={styles.sizePriceBoxStepForwardButton} |
|
|
|
|
onPress={() => |
|
|
|
|
handleNoImgSizeSelect( |
|
|
|
|
list.attributes[0]?.value, |
|
|
|
|
list.attributes?.[0]?.value, |
|
|
|
|
"+", |
|
|
|
|
index1, |
|
|
|
|
list.amount_on_sale |
|
|
|
|
list?.amount_on_sale ?? 0 |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
> |
|
|
|
|