修改易购商品因为没有团购相关信息导致因为start_time报错的问题
This commit is contained in:
parent
1a3fd2c137
commit
3fb80ce105
@ -370,8 +370,8 @@ export default {
|
|||||||
},
|
},
|
||||||
decreaseQuantity(item) {
|
decreaseQuantity(item) {
|
||||||
const currentTime = new Date().getTime();
|
const currentTime = new Date().getTime();
|
||||||
const startTime = new Date(item.commodity_goods_info.group_buy_activity_info.start_time).getTime();
|
const startTime = new Date(item.commodity_goods_info.group_buy_activity_info?.start_time).getTime();
|
||||||
const endTime = new Date(item.commodity_goods_info.group_buy_activity_info.end_time).getTime();
|
const endTime = new Date(item.commodity_goods_info.group_buy_activity_info?.end_time).getTime();
|
||||||
if (item.count > 0) {
|
if (item.count > 0) {
|
||||||
if (currentTime >= startTime && currentTime <= endTime) {
|
if (currentTime >= startTime && currentTime <= endTime) {
|
||||||
if (item.count == item.commodity_goods_info.min_order_quantity) {
|
if (item.count == item.commodity_goods_info.min_order_quantity) {
|
||||||
@ -402,8 +402,8 @@ export default {
|
|||||||
},
|
},
|
||||||
increaseQuantity(item) {
|
increaseQuantity(item) {
|
||||||
const currentTime = new Date().getTime();
|
const currentTime = new Date().getTime();
|
||||||
const startTime = new Date(item.commodity_goods_info.group_buy_activity_info.start_time).getTime();
|
const startTime = new Date(item.commodity_goods_info.group_buy_activity_info?.start_time).getTime();
|
||||||
const endTime = new Date(item.commodity_goods_info.group_buy_activity_info.end_time).getTime();
|
const endTime = new Date(item.commodity_goods_info.group_buy_activity_info?.end_time).getTime();
|
||||||
if (currentTime >= startTime && currentTime <= endTime) {
|
if (currentTime >= startTime && currentTime <= endTime) {
|
||||||
if (item.count == 0) {
|
if (item.count == 0) {
|
||||||
item.count += item.commodity_goods_info.min_order_quantity
|
item.count += item.commodity_goods_info.min_order_quantity
|
||||||
@ -452,8 +452,8 @@ export default {
|
|||||||
let total = 0;
|
let total = 0;
|
||||||
this.orderList1.forEach(goods => {
|
this.orderList1.forEach(goods => {
|
||||||
// 团购活动时间判断
|
// 团购活动时间判断
|
||||||
const startTime = new Date(goods.commodity_goods_info.group_buy_activity_info.start_time).getTime();
|
const startTime = new Date(goods.commodity_goods_info.group_buy_activity_info?.start_time).getTime();
|
||||||
const endTime = new Date(goods.commodity_goods_info.group_buy_activity_info.end_time).getTime();
|
const endTime = new Date(goods.commodity_goods_info.group_buy_activity_info?.end_time).getTime();
|
||||||
if (currentTime >= startTime && currentTime <= endTime) {
|
if (currentTime >= startTime && currentTime <= endTime) {
|
||||||
total += goods.commodity_goods_info.group_buy_price * goods.count + goods.commodity_goods_info.freight;
|
total += goods.commodity_goods_info.group_buy_price * goods.count + goods.commodity_goods_info.freight;
|
||||||
} else {
|
} else {
|
||||||
@ -466,8 +466,8 @@ export default {
|
|||||||
let total = 0;
|
let total = 0;
|
||||||
this.orderList2.forEach(goods => {
|
this.orderList2.forEach(goods => {
|
||||||
// 团购活动时间判断
|
// 团购活动时间判断
|
||||||
const startTime = new Date(goods.commodity_goods_info.group_buy_activity_info.start_time).getTime();
|
const startTime = new Date(goods.commodity_goods_info.group_buy_activity_info?.start_time).getTime();
|
||||||
const endTime = new Date(goods.commodity_goods_info.group_buy_activity_info.end_time).getTime();
|
const endTime = new Date(goods.commodity_goods_info.group_buy_activity_info?.end_time).getTime();
|
||||||
if (currentTime >= startTime && currentTime <= endTime) {
|
if (currentTime >= startTime && currentTime <= endTime) {
|
||||||
total += goods.commodity_goods_info.group_buy_price * goods.count + goods.commodity_goods_info.freight;
|
total += goods.commodity_goods_info.group_buy_price * goods.count + goods.commodity_goods_info.freight;
|
||||||
} else {
|
} else {
|
||||||
@ -671,8 +671,8 @@ export default {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const startTime = new Date(item.commodity_goods_info.group_buy_activity_info.start_time);
|
const startTime = new Date(item.commodity_goods_info.group_buy_activity_info?.start_time);
|
||||||
const endTime = new Date(item.commodity_goods_info.group_buy_activity_info.end_time);
|
const endTime = new Date(item.commodity_goods_info.group_buy_activity_info?.end_time);
|
||||||
return now >= startTime && now <= endTime;
|
return now >= startTime && now <= endTime;
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@ -468,32 +468,72 @@ export default {
|
|||||||
},
|
},
|
||||||
//商品数量变化
|
//商品数量变化
|
||||||
handleQuantityChange(val, item) {
|
handleQuantityChange(val, item) {
|
||||||
|
// 先在前端直接更新数量,确保页面显示及时变化
|
||||||
|
// 注意:这里的val可能是直接的数值,也可能是包含value属性的对象
|
||||||
|
// 我们需要先确定正确的值
|
||||||
|
const quantity = typeof val === 'object' && val !== null && 'value' in val ? val.value : val;
|
||||||
|
|
||||||
|
// 对于有规格的主商品(绑定到items.commodity_goods_info_list[0].quantity)
|
||||||
if (
|
if (
|
||||||
item.commodity_goods_info_list &&
|
item.commodity_goods_info_list &&
|
||||||
item.commodity_goods_info_list.length
|
item.commodity_goods_info_list.length
|
||||||
) {
|
) {
|
||||||
this.goodsId = item.commodity_goods_info_list[0].id;
|
this.goodsId = item.commodity_goods_info_list[0].id;
|
||||||
} else {
|
// 使用$set确保响应式更新
|
||||||
this.goodsId = item.id;
|
this.$set(item.commodity_goods_info_list[0], 'quantity', quantity);
|
||||||
}
|
}
|
||||||
|
// 对于规格列表中的商品(绑定到ite.quantity)
|
||||||
|
else {
|
||||||
|
this.goodsId = item.id;
|
||||||
|
// 使用$set确保响应式更新
|
||||||
|
this.$set(item, 'quantity', quantity);
|
||||||
|
}
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
user_id: uni.getStorageSync("userId"),
|
user_id: uni.getStorageSync("userId"),
|
||||||
goods_id_and_count: [
|
goods_id_and_count: [
|
||||||
{
|
{
|
||||||
goods_id: this.goodsId,
|
goods_id: this.goodsId,
|
||||||
count: val.value,
|
count: quantity,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 发送请求更新后端数据
|
||||||
request(apiArr.updateCar, "POST", params).then((res) => {
|
request(apiArr.updateCar, "POST", params).then((res) => {
|
||||||
console.log(res);
|
console.log(res);
|
||||||
|
// 先更新购物车数据
|
||||||
this.getShopCarList();
|
this.getShopCarList();
|
||||||
|
|
||||||
|
// 延迟一小段时间,确保goodsDetail已经更新
|
||||||
|
setTimeout(() => {
|
||||||
|
// 重新同步商品列表中的数量
|
||||||
|
this.syncGoodsQuantities();
|
||||||
|
}, 100);
|
||||||
|
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: "操作成功!",
|
title: "操作成功!",
|
||||||
success() { },
|
success() { },
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 同步商品列表中的数量
|
||||||
|
syncGoodsQuantities() {
|
||||||
|
// 遍历所有商品,同步数量
|
||||||
|
this.tagList.forEach((tagItem) => {
|
||||||
|
if (tagItem.commodity_info_list) {
|
||||||
|
tagItem.commodity_info_list.forEach((infoItem) => {
|
||||||
|
infoItem.commodity_goods_info_list.forEach((param) => {
|
||||||
|
const goods = this.goodsDetail.find(g => g.goods_id === param.id);
|
||||||
|
if (goods) {
|
||||||
|
this.$set(param, 'quantity', goods.count);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
getPriceRange(goodsList) {
|
getPriceRange(goodsList) {
|
||||||
if (!goodsList || goodsList.length === 0) return '¥0';
|
if (!goodsList || goodsList.length === 0) return '¥0';
|
||||||
const prices = goodsList.map(item => Number(item.sales_price));
|
const prices = goodsList.map(item => Number(item.sales_price));
|
||||||
|
|||||||
@ -466,8 +466,8 @@ export default {
|
|||||||
carItem.commodity_cart_and_goods_model.forEach(goods => {
|
carItem.commodity_cart_and_goods_model.forEach(goods => {
|
||||||
if (goods.checked) {
|
if (goods.checked) {
|
||||||
// 团购活动时间判断
|
// 团购活动时间判断
|
||||||
const startTime = new Date(goods.commodity_goods_info.group_buy_activity_info.start_time).getTime();
|
const startTime = new Date(goods.commodity_goods_info.group_buy_activity_info?.start_time).getTime();
|
||||||
const endTime = new Date(goods.commodity_goods_info.group_buy_activity_info.end_time).getTime();
|
const endTime = new Date(goods.commodity_goods_info.group_buy_activity_info?.end_time).getTime();
|
||||||
if (currentTime >= startTime && currentTime <= endTime) {
|
if (currentTime >= startTime && currentTime <= endTime) {
|
||||||
total += goods.commodity_goods_info.group_buy_price * goods.count;
|
total += goods.commodity_goods_info.group_buy_price * goods.count;
|
||||||
} else {
|
} else {
|
||||||
@ -482,8 +482,8 @@ export default {
|
|||||||
carItem.commodity_cart_and_goods_model.forEach(goods => {
|
carItem.commodity_cart_and_goods_model.forEach(goods => {
|
||||||
if (goods.checked) {
|
if (goods.checked) {
|
||||||
// 团购活动时间判断
|
// 团购活动时间判断
|
||||||
const startTime = new Date(goods.commodity_goods_info.group_buy_activity_info.start_time).getTime();
|
const startTime = new Date(goods.commodity_goods_info.group_buy_activity_info?.start_time).getTime();
|
||||||
const endTime = new Date(goods.commodity_goods_info.group_buy_activity_info.end_time).getTime();
|
const endTime = new Date(goods.commodity_goods_info.group_buy_activity_info?.end_time).getTime();
|
||||||
if (currentTime >= startTime && currentTime <= endTime) {
|
if (currentTime >= startTime && currentTime <= endTime) {
|
||||||
total += goods.commodity_goods_info.group_buy_price * goods.count;
|
total += goods.commodity_goods_info.group_buy_price * goods.count;
|
||||||
} else {
|
} else {
|
||||||
@ -549,8 +549,8 @@ export default {
|
|||||||
|
|
||||||
// 检查商品是否有团购活动且在活动时间内
|
// 检查商品是否有团购活动且在活动时间内
|
||||||
const isGroupBuyActive = carItem.commodity_goods_info.group_buy_activity_info &&
|
const isGroupBuyActive = carItem.commodity_goods_info.group_buy_activity_info &&
|
||||||
currentTime >= new Date(carItem.commodity_goods_info.group_buy_activity_info.start_time).getTime() &&
|
currentTime >= new Date(carItem.commodity_goods_info.group_buy_activity_info?.start_time).getTime() &&
|
||||||
currentTime <= new Date(carItem.commodity_goods_info.group_buy_activity_info.end_time).getTime();
|
currentTime <= new Date(carItem.commodity_goods_info.group_buy_activity_info?.end_time).getTime();
|
||||||
|
|
||||||
if (carItem.count > 0) {
|
if (carItem.count > 0) {
|
||||||
if (isGroupBuyActive && carItem.count === carItem.commodity_goods_info.min_order_quantity) {
|
if (isGroupBuyActive && carItem.count === carItem.commodity_goods_info.min_order_quantity) {
|
||||||
@ -585,8 +585,8 @@ export default {
|
|||||||
const currentTime = new Date().getTime();
|
const currentTime = new Date().getTime();
|
||||||
|
|
||||||
const isGroupBuyActive = carItem.commodity_goods_info.group_buy_activity_info &&
|
const isGroupBuyActive = carItem.commodity_goods_info.group_buy_activity_info &&
|
||||||
currentTime >= new Date(carItem.commodity_goods_info.group_buy_activity_info.start_time).getTime() &&
|
currentTime >= new Date(carItem.commodity_goods_info.group_buy_activity_info?.start_time).getTime() &&
|
||||||
currentTime <= new Date(carItem.commodity_goods_info.group_buy_activity_info.end_time).getTime();
|
currentTime <= new Date(carItem.commodity_goods_info.group_buy_activity_info?.end_time).getTime();
|
||||||
if (isGroupBuyActive) {
|
if (isGroupBuyActive) {
|
||||||
if (carItem.count == 0) {
|
if (carItem.count == 0) {
|
||||||
carItem.count = carItem.commodity_goods_info.min_order_quantity
|
carItem.count = carItem.commodity_goods_info.min_order_quantity
|
||||||
@ -699,8 +699,8 @@ export default {
|
|||||||
//获取价格 - 该显示团购价还是正常价
|
//获取价格 - 该显示团购价还是正常价
|
||||||
getPrice(item) {
|
getPrice(item) {
|
||||||
const currentTime = new Date().getTime();
|
const currentTime = new Date().getTime();
|
||||||
const startTime = new Date(item.commodity_goods_info.group_buy_activity_info.start_time).getTime();
|
const startTime = new Date(item.commodity_goods_info.group_buy_activity_info?.start_time).getTime();
|
||||||
const endTime = new Date(item.commodity_goods_info.group_buy_activity_info.end_time).getTime();
|
const endTime = new Date(item.commodity_goods_info.group_buy_activity_info?.end_time).getTime();
|
||||||
if (currentTime >= startTime && currentTime <= endTime) {
|
if (currentTime >= startTime && currentTime <= endTime) {
|
||||||
return item.commodity_goods_info.group_buy_price;
|
return item.commodity_goods_info.group_buy_price;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user