修改易购模块部分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;
margin-left: 30rpx;
padding-bottom: 4rpx;
text-decoration: line-through;
}
.GGBox {

View File

@ -43,7 +43,7 @@
<view class="group-price">
<view>{{ item.commodity_goods_info.sales_price }}/{{
item.commodity_goods_info.goods_unit
}}</view>
}}</view>
<!-- 运费 -->
<view class="goods-desc" style="margin-top: 10rpx;">运费 {{
item.commodity_goods_info.freight }}</view>
@ -240,7 +240,7 @@
</view>
<view @click.stop="changeShadow">
<view class="shadowBox1">
<button class="shadowBox1Item_btn" open-type="share" bindtap="onShareButtonClick"/>
<button class="shadowBox1Item_btn" open-type="share" bindtap="onShareButtonClick" />
<view class="shadowBox1Item" @click="shareFriend">
<image
src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_WX.png"
@ -301,7 +301,7 @@ export default {
activeTab: 'pickup', //
quantity: 1, //
selectedPayment: 'wechat',
boxshadow1: true,
boxshadow1: false,
boxshadow2: false,
defAddress: {},
defZTAddress: [],
@ -345,7 +345,8 @@ export default {
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) {
this.orderList2.push(item)
} else {
@ -368,36 +369,59 @@ export default {
NavgateTo('../ztLocation/index?item=' + JSON.stringify(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 == item.commodity_goods_info.min_order_quantity) {
uni.showToast({
title: '最少购买' + item.commodity_goods_info.min_order_quantity + '件',
icon: 'none'
});
item.count = 0
if (currentTime >= startTime && currentTime <= endTime) {
if (item.count == item.commodity_goods_info.min_order_quantity) {
uni.showToast({
title: '最少购买' + item.commodity_goods_info.min_order_quantity + '件',
icon: 'none'
});
item.count = 0
} else {
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)
}
},
increaseQuantity(item) {
if (item.count == 0) {
item.count += item.commodity_goods_info.min_order_quantity
} else {
if (item.count == item.commodity_goods_info.total_stock) {
uni.showToast({
title: '库存不足',
icon: 'none'
});
return
}
if (item.count == item.commodity_goods_info.max_limit_quantity) {
uni.showToast({
title: '一次最多购买' + item.commodity_goods_info.max_limit_quantity + '件',
icon: 'none'
});
return
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) {
item.count += item.commodity_goods_info.min_order_quantity
} else {
if (item.count == item.commodity_goods_info.total_stock) {
uni.showToast({
title: '库存不足',
icon: 'none'
});
return
}
if (item.count == item.commodity_goods_info.max_limit_quantity) {
uni.showToast({
title: '一次最多购买' + item.commodity_goods_info.max_limit_quantity + '件',
icon: 'none'
});
return
}
}
}
item.count++;
@ -423,17 +447,32 @@ export default {
//
calculateTotal(order) {
const currentTime = new Date().getTime();
if (order === 'order1') {
let total = 0;
this.orderList1.forEach(item => {
total += item.commodity_goods_info.sales_price * item.count + item.commodity_goods_info.freight;
this.orderList1.forEach(goods => {
//
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;
} else {
let total = 0;
this.orderList2.forEach(item => {
total += item.commodity_goods_info.group_buy_price * item.count + item.commodity_goods_info.freight;
this.orderList2.forEach(goods => {
//
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;

View File

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

View File

@ -46,7 +46,7 @@
<view class="slide">
<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">
<image :src="picUrl + item.category_pic" mode="aspectFill"></image>
<text>{{ item.category_name }}</text>
@ -227,6 +227,7 @@ export default {
search: "",
value: "1",
cateListShow: false,
conRightElement: null,
iconList: [
{
icon: "https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_icon1.png",
@ -296,15 +297,45 @@ export default {
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) {
// id
const category = this.CateList.find((item) => item.id === id);
if (category) {
// leftCateListnull
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.topShow = false;
},
//
changeCateListShow() {
@ -440,10 +471,39 @@ export default {
this.localHeight = meun.height;
this.getCateList();
// this.getShopCarList();
//
this.hideShopCarTimer = null;
},
onShow() {
this.getShopCarList();
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() {
if (this.flag) {

View File

@ -70,9 +70,10 @@
</view>
<view class="goodsItem_msg_right_msg">
<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.sales_price }}
item.commodity_goods_info.sales_price }} -->
<span>/{{ item.commodity_goods_info.goods_unit }}</span>
</view>
<view class="goodsItem_msg_right_msg_right">
@ -148,9 +149,10 @@
</view>
<view class="goodsItem_msg_right_msg">
<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.sales_price }}
item.commodity_goods_info.sales_price }} -->
<span>/{{ item.commodity_goods_info.goods_unit }}</span>
</view>
<view class="goodsItem_msg_right_msg_right">
@ -457,15 +459,20 @@ export default {
//
calcTotal() {
let total = 0;
const currentTime = new Date().getTime();
//
this.isDayCarList.forEach(carItem => {
carItem.commodity_cart_and_goods_model.forEach(goods => {
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 :
goods.commodity_goods_info.sales_price;
total += price * goods.count;
//
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;
} else {
total += goods.commodity_goods_info.sales_price * goods.count;
}
}
});
});
@ -474,10 +481,14 @@ export default {
this.shopCarList.forEach(carItem => {
carItem.commodity_cart_and_goods_model.forEach(goods => {
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 :
goods.commodity_goods_info.sales_price;
total += price * goods.count;
//
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;
} else {
total += goods.commodity_goods_info.sales_price * goods.count;
}
}
});
});
@ -486,81 +497,119 @@ export default {
},
//
minus(carItem, goodsIndex, item) {
let that = this;
//
deleteCarItem(carItem, goodsIndex, item) {
const that = this;
request(apiArr.deleteCar, "POST", {
ids: [carItem.id],
}).then((res) => {
//
item.splice(goodsIndex, 1);
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", {
ids: [carItem.id],
}).then((res) => {
//
item.splice(goodsIndex, 1);
//
if (item.length === 0) {
//
const dayCarIndex = that.isDayCarList.findIndex(dayItem =>
dayItem.commodity_cart_and_goods_model === item
);
const normalCarIndex = that.shopCarList.findIndex(normalItem =>
normalItem.commodity_cart_and_goods_model === item
);
// API
that.shopCarTotal = that.shopCarTotal - carItem.commodity_goods_info.min_order_quantity;
//
if (item.length === 0) {
//
const dayCarIndex = that.isDayCarList.findIndex(dayItem =>
dayItem.commodity_cart_and_goods_model === item
);
const normalCarIndex = that.shopCarList.findIndex(normalItem =>
normalItem.commodity_cart_and_goods_model === item
);
if (dayCarIndex !== -1) {
that.isDayCarList.splice(dayCarIndex, 1);
//
if (that.isDayCarList.length === 0) {
that.isDayshow = false;
}
}
if (normalCarIndex !== -1) {
that.shopCarList.splice(normalCarIndex, 1);
//
if (that.shopCarList.length === 0) {
that.parcelPostshow = false;
}
}
}
that.calcTotal();
});
} else {
this.shopCarTotal = this.shopCarTotal - 1;
carItem.count = carItem.count - 1;
this.handleQuantityChange(carItem.count, carItem);
if (dayCarIndex !== -1) {
that.isDayCarList.splice(dayCarIndex, 1);
//
if (that.isDayCarList.length === 0) {
that.isDayshow = false;
}
}
if (normalCarIndex !== -1) {
that.shopCarList.splice(normalCarIndex, 1);
//
if (that.shopCarList.length === 0) {
that.parcelPostshow = false;
}
}
this.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 {
//
this.shopCarTotal = Math.max(0, this.shopCarTotal - 1);
carItem.count = carItem.count - 1;
this.handleQuantityChange(carItem.count, carItem);
// 0
if (carItem.count === 0) {
that.deleteCarItem(carItem, goodsIndex, item);
} else {
// 0
this.calcTotal();
}
}
}
},
//
add(carItem, goodsIndex) {
if (carItem.count == 0) {
carItem.count = carItem.commodity_goods_info.min_order_quantity
this.shopCarTotal += carItem.commodity_goods_info.min_order_quantity;
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) {
carItem.count = carItem.commodity_goods_info.min_order_quantity
this.shopCarTotal += carItem.commodity_goods_info.min_order_quantity;
} else {
if (carItem.count == carItem.commodity_goods_info.total_stock) {
uni.showToast({
title: '库存不足',
icon: 'none'
});
return
}
if (carItem.count == carItem.commodity_goods_info.max_limit_quantity) {
uni.showToast({
title: '一次最多购买' + carItem.commodity_goods_info.max_limit_quantity + '件',
icon: 'none'
});
return
}
carItem.count++;
this.shopCarTotal++;
}
} else {
if (carItem.count == carItem.commodity_goods_info.total_stock) {
uni.showToast({
title: '库存不足',
icon: 'none'
});
return
}
if (carItem.count == carItem.commodity_goods_info.max_limit_quantity) {
uni.showToast({
title: '一次最多购买' + carItem.commodity_goods_info.max_limit_quantity + '件',
icon: 'none'
});
return
}
carItem.count++;
this.shopCarTotal++;
}
@ -647,6 +696,17 @@ export default {
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) {
@ -655,6 +715,9 @@ export default {
this.localHeight = meun.height;
this.getShopCar();
},
onShow() {
this.getShopCar();
},
onReachBottom() { },