修改易购模块部分bug

This commit is contained in:
赵毅 2025-09-02 08:56:48 +08:00
parent 567af67ef1
commit 6d0a011836
5 changed files with 306 additions and 130 deletions

View File

@ -108,6 +108,7 @@ image {
color: #C7C7C7; color: #C7C7C7;
margin-left: 30rpx; margin-left: 30rpx;
padding-bottom: 4rpx; padding-bottom: 4rpx;
text-decoration: line-through;
} }
.GGBox { .GGBox {

View File

@ -301,7 +301,7 @@ export default {
activeTab: 'pickup', // activeTab: 'pickup', //
quantity: 1, // quantity: 1, //
selectedPayment: 'wechat', selectedPayment: 'wechat',
boxshadow1: true, boxshadow1: false,
boxshadow2: false, boxshadow2: false,
defAddress: {}, defAddress: {},
defZTAddress: [], defZTAddress: [],
@ -345,7 +345,8 @@ export default {
item.commodity_goods_info.commodity_pic = picUrl + item.commodity_goods_info.commodity_pic item.commodity_goods_info.commodity_pic = picUrl + item.commodity_goods_info.commodity_pic
} }
const list = item.commodity_goods_info.group_buy_activity_info // const list = item.commodity_goods_info.group_buy_activity_info
const list = true
if (list) { if (list) {
this.orderList2.push(item) this.orderList2.push(item)
} else { } else {
@ -368,7 +369,11 @@ export default {
NavgateTo('../ztLocation/index?item=' + JSON.stringify(item)); NavgateTo('../ztLocation/index?item=' + JSON.stringify(item));
}, },
decreaseQuantity(item) { decreaseQuantity(item) {
const currentTime = new Date().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();
if (item.count > 0) { if (item.count > 0) {
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) {
uni.showToast({ uni.showToast({
title: '最少购买' + item.commodity_goods_info.min_order_quantity + '件', title: '最少购买' + item.commodity_goods_info.min_order_quantity + '件',
@ -378,10 +383,28 @@ export default {
} else { } else {
item.count-- item.count--
} }
} else {
item.count--
}
// 0carList
if (item.count === 0) {
const index = this.carList.findIndex(carItem => carItem.goods_id === item.goods_id);
if (index > -1) {
this.carList.splice(index, 1);
//
this.getGoodsList();
}
}
this.changeCart(item) this.changeCart(item)
} }
}, },
increaseQuantity(item) { increaseQuantity(item) {
const currentTime = new Date().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();
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
} else { } else {
@ -400,6 +423,7 @@ export default {
return return
} }
} }
}
item.count++; item.count++;
this.changeCart(item); this.changeCart(item);
}, },
@ -423,17 +447,32 @@ export default {
// //
calculateTotal(order) { calculateTotal(order) {
const currentTime = new Date().getTime();
if (order === 'order1') { if (order === 'order1') {
let total = 0; let total = 0;
this.orderList1.forEach(item => { this.orderList1.forEach(goods => {
total += item.commodity_goods_info.sales_price * item.count + item.commodity_goods_info.freight; //
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();
if (currentTime >= startTime && currentTime <= endTime) {
total += goods.commodity_goods_info.group_buy_price * goods.count + goods.commodity_goods_info.freight;
} else {
total += goods.commodity_goods_info.sales_price * goods.count + goods.commodity_goods_info.freight;
}
}); });
// //
return total; return total;
} else { } else {
let total = 0; let total = 0;
this.orderList2.forEach(item => { this.orderList2.forEach(goods => {
total += item.commodity_goods_info.group_buy_price * item.count + item.commodity_goods_info.freight; //
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();
if (currentTime >= startTime && currentTime <= endTime) {
total += goods.commodity_goods_info.group_buy_price * goods.count + goods.commodity_goods_info.freight;
} else {
total += goods.commodity_goods_info.sales_price * goods.count + goods.commodity_goods_info.freight;
}
}); });
// //
return total; return total;

View File

@ -106,6 +106,10 @@ page {
white-space: nowrap; white-space: nowrap;
} }
.slide_item_active{
color: #ff5f3c;
}
.Con { .Con {
flex: 1; flex: 1;
display: flex; display: flex;
@ -567,9 +571,16 @@ page {
width: 140rpx; width: 140rpx;
height: 140rpx; height: 140rpx;
position: fixed; position: fixed;
right: 33rpx; right: -95rpx;
bottom: 180rpx; bottom: 180rpx;
z-index: 10; z-index: 10;
transition: right 0.3s ease;
}
.shop_car:hover,
.shop_car.show {
right: 33rpx;
/* 鼠标悬停或滚动时完全显示 */
} }
.shop_car image { .shop_car image {
@ -579,6 +590,8 @@ page {
.u-badge { .u-badge {
position: absolute; position: absolute;
right: 0; right: 70rpx;
/* 调整角标位置,使其在隐藏状态下也能看到 */
top: -10rpx; top: -10rpx;
z-index: 11;
} }

View File

@ -46,7 +46,7 @@
<view class="slide"> <view class="slide">
<view class="slide_con"> <view class="slide_con">
<view v-for="(item, index) in CateList" :key="index" class="slide_conBox"> <view v-for="(item, index) in CateList" :key="index" class="slide_conBox" @click="changeCate(item.id)">
<view class="slide_item"> <view class="slide_item">
<image :src="picUrl + item.category_pic" mode="aspectFill"></image> <image :src="picUrl + item.category_pic" mode="aspectFill"></image>
<text>{{ item.category_name }}</text> <text>{{ item.category_name }}</text>
@ -227,6 +227,7 @@ export default {
search: "", search: "",
value: "1", value: "1",
cateListShow: false, cateListShow: false,
conRightElement: null,
iconList: [ iconList: [
{ {
icon: "https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_icon1.png", icon: "https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_icon1.png",
@ -296,15 +297,45 @@ export default {
NavgateTo('1') NavgateTo('1')
}, },
//
showShopCar() {
this.$nextTick(() => {
try {
const shopCar = document.querySelector('.shop_car');
if (shopCar) {
shopCar.classList.add('show');
// 2
clearTimeout(this.hideShopCarTimer);
this.hideShopCarTimer = setTimeout(() => {
const carElement = document.querySelector('.shop_car');
if (carElement) {
carElement.classList.remove('show');
}
}, 2000);
}
} catch (error) {
console.log(error);
}
});
},
changeCate(id) { changeCate(id) {
// id // id
const category = this.CateList.find((item) => item.id === id); const category = this.CateList.find((item) => item.id === id);
if (category) { if (category) {
// leftCateListnull // leftCateListnull
this.leftCateList = category.level_two_category || []; this.leftCateList = category.level_two_category || [];
this.secondId = this.leftCateList[0]?.id; if (this.leftCateList.length > 0) {
this.currentLeftCateId = this.leftCateList[0].id;
this.secondId = this.leftCateList[0].id;
} else {
this.currentLeftCateId = null;
this.secondId = null;
}
this.getGoodsList(); this.getGoodsList();
} }
this.topShow = false;
}, },
// //
changeCateListShow() { changeCateListShow() {
@ -440,10 +471,39 @@ export default {
this.localHeight = meun.height; this.localHeight = meun.height;
this.getCateList(); this.getCateList();
// this.getShopCarList(); // this.getShopCarList();
//
this.hideShopCarTimer = null;
}, },
onShow() { onShow() {
this.getShopCarList(); this.getShopCarList();
this.getGoodsList(); this.getGoodsList();
// - 使nextTickDOM
this.$nextTick(() => {
try {
const conRight = document.querySelector('.Con_right');
if (conRight) {
this.conRightElement = conRight;
conRight.addEventListener('scroll', this.showShopCar);
}
} catch (error) {
console.log(error);
}
});
},
onHide() {
//
if (this.conRightElement) {
this.conRightElement.removeEventListener('scroll', this.showShopCar);
this.conRightElement = null;
}
//
if (this.hideShopCarTimer) {
clearTimeout(this.hideShopCarTimer);
}
}, },
onReachBottom() { onReachBottom() {
if (this.flag) { if (this.flag) {

View File

@ -70,9 +70,10 @@
</view> </view>
<view class="goodsItem_msg_right_msg"> <view class="goodsItem_msg_right_msg">
<view class="goodsItem_msg_right_msg_left"> <view class="goodsItem_msg_right_msg_left">
<span></span>{{ item.commodity_goods_info.group_buy_price ? <span></span>{{ getPrice(item) }}
<!-- {{ item.commodity_goods_info.group_buy_price ?
item.commodity_goods_info.group_buy_price : item.commodity_goods_info.group_buy_price :
item.commodity_goods_info.sales_price }} item.commodity_goods_info.sales_price }} -->
<span>/{{ item.commodity_goods_info.goods_unit }}</span> <span>/{{ item.commodity_goods_info.goods_unit }}</span>
</view> </view>
<view class="goodsItem_msg_right_msg_right"> <view class="goodsItem_msg_right_msg_right">
@ -148,9 +149,10 @@
</view> </view>
<view class="goodsItem_msg_right_msg"> <view class="goodsItem_msg_right_msg">
<view class="goodsItem_msg_right_msg_left"> <view class="goodsItem_msg_right_msg_left">
<span></span>{{ item.commodity_goods_info.group_buy_price ? <span></span>{{ getPrice(item) }}
<!-- {{ item.commodity_goods_info.group_buy_price ?
item.commodity_goods_info.group_buy_price : item.commodity_goods_info.group_buy_price :
item.commodity_goods_info.sales_price }} item.commodity_goods_info.sales_price }} -->
<span>/{{ item.commodity_goods_info.goods_unit }}</span> <span>/{{ item.commodity_goods_info.goods_unit }}</span>
</view> </view>
<view class="goodsItem_msg_right_msg_right"> <view class="goodsItem_msg_right_msg_right">
@ -457,15 +459,20 @@ export default {
// //
calcTotal() { calcTotal() {
let total = 0; let total = 0;
const currentTime = new Date().getTime();
// //
this.isDayCarList.forEach(carItem => { this.isDayCarList.forEach(carItem => {
carItem.commodity_cart_and_goods_model.forEach(goods => { carItem.commodity_cart_and_goods_model.forEach(goods => {
if (goods.checked) { if (goods.checked) {
const price = goods.commodity_goods_info.group_buy_price !== undefined && goods.commodity_goods_info.group_buy_price !== null ? //
goods.commodity_goods_info.group_buy_price : const startTime = new Date(goods.commodity_goods_info.group_buy_activity_info.start_time).getTime();
goods.commodity_goods_info.sales_price; const endTime = new Date(goods.commodity_goods_info.group_buy_activity_info.end_time).getTime();
total += price * goods.count; if (currentTime >= startTime && currentTime <= endTime) {
total += goods.commodity_goods_info.group_buy_price * goods.count;
} else {
total += goods.commodity_goods_info.sales_price * goods.count;
}
} }
}); });
}); });
@ -474,10 +481,14 @@ export default {
this.shopCarList.forEach(carItem => { this.shopCarList.forEach(carItem => {
carItem.commodity_cart_and_goods_model.forEach(goods => { carItem.commodity_cart_and_goods_model.forEach(goods => {
if (goods.checked) { if (goods.checked) {
const price = goods.commodity_goods_info.group_buy_price !== undefined && goods.commodity_goods_info.group_buy_price !== null ? //
goods.commodity_goods_info.group_buy_price : const startTime = new Date(goods.commodity_goods_info.group_buy_activity_info.start_time).getTime();
goods.commodity_goods_info.sales_price; const endTime = new Date(goods.commodity_goods_info.group_buy_activity_info.end_time).getTime();
total += price * goods.count; if (currentTime >= startTime && currentTime <= endTime) {
total += goods.commodity_goods_info.group_buy_price * goods.count;
} else {
total += goods.commodity_goods_info.sales_price * goods.count;
}
} }
}); });
}); });
@ -486,24 +497,15 @@ export default {
}, },
// //
minus(carItem, goodsIndex, item) { //
let that = this; deleteCarItem(carItem, goodsIndex, item) {
const that = this;
if (carItem.count > 0) {
if (carItem.count == carItem.commodity_goods_info.min_order_quantity) {
uni.showToast({
title: '最少购买' + carItem.commodity_goods_info.min_order_quantity + '件',
icon: 'none'
});
request(apiArr.deleteCar, "POST", { request(apiArr.deleteCar, "POST", {
ids: [carItem.id], ids: [carItem.id],
}).then((res) => { }).then((res) => {
// //
item.splice(goodsIndex, 1); item.splice(goodsIndex, 1);
// API
that.shopCarTotal = that.shopCarTotal - carItem.commodity_goods_info.min_order_quantity;
// //
if (item.length === 0) { if (item.length === 0) {
// //
@ -531,18 +533,61 @@ export default {
} }
that.calcTotal(); that.calcTotal();
}).catch(error => {
console.error('删除商品失败:', error);
uni.showToast({
title: '删除失败,请重试',
icon: 'none'
}); });
});
},
//
minus(carItem, goodsIndex, item) {
const that = this;
const currentTime = new Date().getTime();
//
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.end_time).getTime();
if (carItem.count > 0) {
if (isGroupBuyActive && carItem.count === carItem.commodity_goods_info.min_order_quantity) {
//
uni.showToast({
title: '最少购买' + carItem.commodity_goods_info.min_order_quantity + '件',
icon: 'none'
});
//
that.shopCarTotal = Math.max(0, that.shopCarTotal - carItem.commodity_goods_info.min_order_quantity);
//
that.deleteCarItem(carItem, goodsIndex, item);
} else { } else {
this.shopCarTotal = this.shopCarTotal - 1; //
this.shopCarTotal = Math.max(0, this.shopCarTotal - 1);
carItem.count = carItem.count - 1; carItem.count = carItem.count - 1;
this.handleQuantityChange(carItem.count, carItem); this.handleQuantityChange(carItem.count, carItem);
}
// 0
if (carItem.count === 0) {
that.deleteCarItem(carItem, goodsIndex, item);
} else {
// 0
this.calcTotal(); this.calcTotal();
} }
}
}
}, },
// //
add(carItem, goodsIndex) { add(carItem, goodsIndex) {
const currentTime = new Date().getTime();
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.end_time).getTime();
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
this.shopCarTotal += carItem.commodity_goods_info.min_order_quantity; this.shopCarTotal += carItem.commodity_goods_info.min_order_quantity;
@ -564,6 +609,10 @@ export default {
carItem.count++; carItem.count++;
this.shopCarTotal++; this.shopCarTotal++;
} }
} else {
carItem.count++;
this.shopCarTotal++;
}
const item = carItem.commodity_cart_and_goods_model; const item = carItem.commodity_cart_and_goods_model;
this.handleQuantityChange(carItem.count, carItem); this.handleQuantityChange(carItem.count, carItem);
@ -647,6 +696,17 @@ export default {
return Promise.resolve(); return Promise.resolve();
}); });
}, },
// -
getPrice(item) {
const currentTime = new Date().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();
if (currentTime >= startTime && currentTime <= endTime) {
return item.commodity_goods_info.group_buy_price;
} else {
return item.commodity_goods_info.sales_price;
}
},
}, },
onLoad(options) { onLoad(options) {
@ -655,6 +715,9 @@ export default {
this.localHeight = meun.height; this.localHeight = meun.height;
this.getShopCar(); this.getShopCar();
}, },
onShow() {
this.getShopCar();
},
onReachBottom() { }, onReachBottom() { },