1
This commit is contained in:
@ -13,7 +13,7 @@
|
|||||||
<view class="flex-row-start">
|
<view class="flex-row-start">
|
||||||
<text class="fs-28 price-text">
|
<text class="fs-28 price-text">
|
||||||
¥
|
¥
|
||||||
<text class="fs-28">{{data.prices[0].original_price || 0 }}</text>
|
<text class="fs-28">{{data.prices[0].original_price / 100 || 0 }}</text>
|
||||||
</text>
|
</text>
|
||||||
<!-- <text class="fs-20 price-label">到手价</text> -->
|
<!-- <text class="fs-20 price-label">到手价</text> -->
|
||||||
</view>
|
</view>
|
||||||
|
|||||||
@ -321,24 +321,39 @@ export default {
|
|||||||
// 立即购买
|
// 立即购买
|
||||||
addToCar(goodsData) {
|
addToCar(goodsData) {
|
||||||
console.log(goodsData,'--=')
|
console.log(goodsData,'--=')
|
||||||
uni.navigateTo({
|
// Parse image_list and get the first image URL
|
||||||
url: `/pages/client/order/create`,
|
let firstImageUrl = '';
|
||||||
success: (res) => {
|
const imageList = goodsData.product.attr_key_value_map.image_list;
|
||||||
// 通过eventChannel向被打开页面传送数据
|
if (imageList) {
|
||||||
res.eventChannel.emit("createOrder", {
|
try {
|
||||||
goodList: [{
|
// Try to parse as JSON if it's a string
|
||||||
...this.goodsData,
|
const parsedList = typeof imageList === 'string' ? JSON.parse(imageList) : imageList;
|
||||||
goods_id:goodsData.product.out_id,
|
if (Array.isArray(parsedList) && parsedList.length > 0) {
|
||||||
// price_id:goodsData.prices[0].price_id,
|
firstImageUrl = parsedList[0].url || parsedList[0] || '';
|
||||||
number:1,
|
}
|
||||||
goods_name: goodsData.product.product_name,
|
} catch (e) {
|
||||||
price_name: goodsData?.product.product_name,
|
console.error('Error parsing image_list:', e);
|
||||||
goods_price: goodsData.product.product_type,
|
}
|
||||||
product_pic:goodsData.product.product_type
|
}
|
||||||
}, ],
|
|
||||||
});
|
uni.navigateTo({
|
||||||
},
|
url: `/pages/client/order/create`,
|
||||||
});
|
success: (res) => {
|
||||||
|
// 通过eventChannel向被打开页面传送数据
|
||||||
|
res.eventChannel.emit("createOrder", {
|
||||||
|
goodList: [{
|
||||||
|
...this.goodsData,
|
||||||
|
goods_id:goodsData.product.out_id,
|
||||||
|
// price_id:goodsData.prices[0].price_id,
|
||||||
|
product_pic: firstImageUrl,
|
||||||
|
number:1,
|
||||||
|
goods_name: goodsData.product.product_name,
|
||||||
|
price_name: goodsData?.product.product_name,
|
||||||
|
goods_price: goodsData.sku.actual_amount / 100
|
||||||
|
}, ],
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@ -195,8 +195,41 @@ export default {
|
|||||||
|
|
||||||
const eventChannel = this.getOpenerEventChannel();
|
const eventChannel = this.getOpenerEventChannel();
|
||||||
eventChannel.on("createOrder", (data) => {
|
eventChannel.on("createOrder", (data) => {
|
||||||
this.orderData = data?.goodList || [];
|
// Helper function to extract first image from image_list
|
||||||
this.payPrice = (data?.goodList || []).reduce(
|
const extractFirstImage = (imageList) => {
|
||||||
|
if (!imageList) return '';
|
||||||
|
try {
|
||||||
|
const parsedList = typeof imageList === 'string' ? JSON.parse(imageList) : imageList;
|
||||||
|
if (Array.isArray(parsedList) && parsedList.length > 0) {
|
||||||
|
return parsedList[0].url || parsedList[0] || '';
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error parsing image_list:', e);
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
};
|
||||||
|
|
||||||
|
this.orderData = (data?.goodList || []).map(item => {
|
||||||
|
// Check if product_pic is actually an image_list that needs parsing
|
||||||
|
let processedItem = { ...item };
|
||||||
|
if (processedItem.product_pic) {
|
||||||
|
// If product_pic looks like an array or JSON string, try to parse it
|
||||||
|
if (typeof processedItem.product_pic === 'string' && (processedItem.product_pic.startsWith('[') || processedItem.product_pic.startsWith('{'))) {
|
||||||
|
const extractedUrl = extractFirstImage(processedItem.product_pic);
|
||||||
|
if (extractedUrl) {
|
||||||
|
processedItem.product_pic = extractedUrl;
|
||||||
|
}
|
||||||
|
} else if (Array.isArray(processedItem.product_pic)) {
|
||||||
|
const extractedUrl = extractFirstImage(processedItem.product_pic);
|
||||||
|
if (extractedUrl) {
|
||||||
|
processedItem.product_pic = extractedUrl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return processedItem;
|
||||||
|
});
|
||||||
|
|
||||||
|
this.payPrice = this.orderData.reduce(
|
||||||
(sum, item) =>
|
(sum, item) =>
|
||||||
sum +
|
sum +
|
||||||
Number((item.product_price || item.goods_price) * item.number || 0),
|
Number((item.product_price || item.goods_price) * item.number || 0),
|
||||||
@ -236,6 +269,7 @@ export default {
|
|||||||
plugin.createOrder({
|
plugin.createOrder({
|
||||||
skuList: res.data.skuList,
|
skuList: res.data.skuList,
|
||||||
payment: res.data.payment,
|
payment: res.data.payment,
|
||||||
|
bookInfo:res.data.bookInfo,
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
const { orderId, outOrderNo } = res;
|
const { orderId, outOrderNo } = res;
|
||||||
console.log("success res", res);
|
console.log("success res", res);
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<view class="goods-item" >
|
<view class="goods-item" >
|
||||||
<image class="goods-img" :src="data.product_pic" mode="aspectFill" />
|
<image class="goods-img" :src="getProductImage(data)" mode="aspectFill" />
|
||||||
<view class=" fs-24 app-fc-main goods-name">
|
<view class=" fs-24 app-fc-main goods-name">
|
||||||
{{ data.product.product_name || "" }}
|
{{ data.product.product_name || "" }}
|
||||||
</view>
|
</view>
|
||||||
@ -13,7 +13,7 @@
|
|||||||
<text class="fs-28" style="color: #3D3D3D;">
|
<text class="fs-28" style="color: #3D3D3D;">
|
||||||
¥
|
¥
|
||||||
<text class="fs-28">{{
|
<text class="fs-28">{{
|
||||||
data.product.product_type || 0
|
data.sku.actual_amount / 100 || 0
|
||||||
}}</text>
|
}}</text>
|
||||||
</text>
|
</text>
|
||||||
<!-- <text class="fs-24 origin-price">
|
<!-- <text class="fs-24 origin-price">
|
||||||
@ -65,6 +65,27 @@
|
|||||||
// 触发购买事件,通知父组件
|
// 触发购买事件,通知父组件
|
||||||
this.$emit('addToCar', this.data);
|
this.$emit('addToCar', this.data);
|
||||||
},
|
},
|
||||||
|
getProductImage(data) {
|
||||||
|
// Try to get product_pic first
|
||||||
|
if (data.product_pic) {
|
||||||
|
return data.product_pic;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to parse image_list from attr_key_value_map
|
||||||
|
if (data.product?.attr_key_value_map?.image_list) {
|
||||||
|
try {
|
||||||
|
const imageList = data.product.attr_key_value_map.image_list;
|
||||||
|
const parsedList = typeof imageList === 'string' ? JSON.parse(imageList) : imageList;
|
||||||
|
if (Array.isArray(parsedList) && parsedList.length > 0) {
|
||||||
|
return parsedList[0].url || parsedList[0] || '';
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error parsing image_list:', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -21,7 +21,7 @@
|
|||||||
<view class="flex-row-between" style="margin-top: 20rpx">
|
<view class="flex-row-between" style="margin-top: 20rpx">
|
||||||
<view class="">
|
<view class="">
|
||||||
<text class="app-fc-mark fs-28">¥</text>
|
<text class="app-fc-mark fs-28">¥</text>
|
||||||
<text class="app-fc-mark fs-28">{{picList[0].actual_price || 0 }}</text>
|
<text class="app-fc-mark fs-28">{{picList[0].actual_price / 100 || 0 }}</text>
|
||||||
<!-- <text class="fs-24 origin-price">
|
<!-- <text class="fs-24 origin-price">
|
||||||
¥{{ minPrice.price_shichang || 0 }}
|
¥{{ minPrice.price_shichang || 0 }}
|
||||||
</text> -->
|
</text> -->
|
||||||
@ -410,7 +410,7 @@
|
|||||||
number,
|
number,
|
||||||
goods_name: this.details.goods_name,
|
goods_name: this.details.goods_name,
|
||||||
price_name: priceInfo?.price_name,
|
price_name: priceInfo?.price_name,
|
||||||
goods_price: +(+priceInfo?.actual_price * number).toFixed(2),
|
goods_price: +((priceInfo?.actual_price / 100) * number).toFixed(2),
|
||||||
}, ],
|
}, ],
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
@ -274,8 +274,7 @@ export default {
|
|||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
const list = res?.data || [];
|
const list = res?.data || [];
|
||||||
this.goodsList =
|
this.goodsList = list;
|
||||||
this.page === 1 ? list : [...this.goodsList, ...list];
|
|
||||||
this.total = res?.count || 0;
|
this.total = res?.count || 0;
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
@ -397,8 +396,8 @@ export default {
|
|||||||
product_id: good.product_id,
|
product_id: good.product_id,
|
||||||
product_name: good.product_name,
|
product_name: good.product_name,
|
||||||
product_pic: good.product_pic,
|
product_pic: good.product_pic,
|
||||||
goods_price: good.prices?.[0]?.actual_price,
|
goods_price: good.prices?.[0]?.actual_price / 100,
|
||||||
product_price: good.prices?.[0]?.actual_price,
|
product_price: good.prices?.[0]?.actual_price / 100,
|
||||||
original_price: good.prices?.[0]?.original_price,
|
original_price: good.prices?.[0]?.original_price,
|
||||||
yunfei: good.yunfei || 0,
|
yunfei: good.yunfei || 0,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user