修改易购模块部分bug
This commit is contained in:
parent
567af67ef1
commit
6d0a011836
@ -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 {
|
||||||
|
|||||||
@ -43,7 +43,7 @@
|
|||||||
<view class="group-price">
|
<view class="group-price">
|
||||||
<view>¥{{ item.commodity_goods_info.sales_price }}/{{
|
<view>¥{{ item.commodity_goods_info.sales_price }}/{{
|
||||||
item.commodity_goods_info.goods_unit
|
item.commodity_goods_info.goods_unit
|
||||||
}}</view>
|
}}</view>
|
||||||
<!-- 运费 -->
|
<!-- 运费 -->
|
||||||
<view class="goods-desc" style="margin-top: 10rpx;">运费 ¥{{
|
<view class="goods-desc" style="margin-top: 10rpx;">运费 ¥{{
|
||||||
item.commodity_goods_info.freight }}</view>
|
item.commodity_goods_info.freight }}</view>
|
||||||
@ -240,7 +240,7 @@
|
|||||||
</view>
|
</view>
|
||||||
<view @click.stop="changeShadow">
|
<view @click.stop="changeShadow">
|
||||||
<view class="shadowBox1">
|
<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">
|
<view class="shadowBox1Item" @click="shareFriend">
|
||||||
<image
|
<image
|
||||||
src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_WX.png"
|
src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_WX.png"
|
||||||
@ -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,36 +369,59 @@ 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 (item.count == item.commodity_goods_info.min_order_quantity) {
|
if (currentTime >= startTime && currentTime <= endTime) {
|
||||||
uni.showToast({
|
if (item.count == item.commodity_goods_info.min_order_quantity) {
|
||||||
title: '最少购买' + item.commodity_goods_info.min_order_quantity + '件',
|
uni.showToast({
|
||||||
icon: 'none'
|
title: '最少购买' + item.commodity_goods_info.min_order_quantity + '件',
|
||||||
});
|
icon: 'none'
|
||||||
item.count = 0
|
});
|
||||||
|
item.count = 0
|
||||||
|
} else {
|
||||||
|
item.count--
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
item.count--
|
item.count--
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 当数量减到0时,从carList中删除该商品
|
||||||
|
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) {
|
||||||
if (item.count == 0) {
|
const currentTime = new Date().getTime();
|
||||||
item.count += item.commodity_goods_info.min_order_quantity
|
const startTime = new Date(item.commodity_goods_info.group_buy_activity_info.start_time).getTime();
|
||||||
} else {
|
const endTime = new Date(item.commodity_goods_info.group_buy_activity_info.end_time).getTime();
|
||||||
if (item.count == item.commodity_goods_info.total_stock) {
|
if (currentTime >= startTime && currentTime <= endTime) {
|
||||||
uni.showToast({
|
if (item.count == 0) {
|
||||||
title: '库存不足',
|
item.count += item.commodity_goods_info.min_order_quantity
|
||||||
icon: 'none'
|
} else {
|
||||||
});
|
if (item.count == item.commodity_goods_info.total_stock) {
|
||||||
return
|
uni.showToast({
|
||||||
}
|
title: '库存不足',
|
||||||
if (item.count == item.commodity_goods_info.max_limit_quantity) {
|
icon: 'none'
|
||||||
uni.showToast({
|
});
|
||||||
title: '一次最多购买' + item.commodity_goods_info.max_limit_quantity + '件',
|
return
|
||||||
icon: 'none'
|
}
|
||||||
});
|
if (item.count == item.commodity_goods_info.max_limit_quantity) {
|
||||||
return
|
uni.showToast({
|
||||||
|
title: '一次最多购买' + item.commodity_goods_info.max_limit_quantity + '件',
|
||||||
|
icon: 'none'
|
||||||
|
});
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
item.count++;
|
item.count++;
|
||||||
@ -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;
|
||||||
|
|||||||
@ -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;
|
||||||
@ -511,7 +515,7 @@ page {
|
|||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
.GGItem_Image image{
|
.GGItem_Image image {
|
||||||
border-radius: 20rpx;
|
border-radius: 20rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
@ -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) {
|
||||||
// 将leftCateList设置为该分类的二级分类,若为null则设为空数组
|
// 将leftCateList设置为该分类的二级分类,若为null则设为空数组
|
||||||
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();
|
||||||
|
|
||||||
|
// 添加滚动事件监听 - 使用nextTick确保DOM已渲染
|
||||||
|
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) {
|
||||||
|
|||||||
@ -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,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) {
|
if (item.length === 0) {
|
||||||
uni.showToast({
|
// 分别检查并移除当日达和普通购物车中的商家
|
||||||
title: '最少购买' + carItem.commodity_goods_info.min_order_quantity + '件',
|
const dayCarIndex = that.isDayCarList.findIndex(dayItem =>
|
||||||
icon: 'none'
|
dayItem.commodity_cart_and_goods_model === item
|
||||||
});
|
);
|
||||||
request(apiArr.deleteCar, "POST", {
|
const normalCarIndex = that.shopCarList.findIndex(normalItem =>
|
||||||
ids: [carItem.id],
|
normalItem.commodity_cart_and_goods_model === item
|
||||||
}).then((res) => {
|
);
|
||||||
// 从商品列表中移除该商品
|
|
||||||
item.splice(goodsIndex, 1);
|
|
||||||
|
|
||||||
// 更新购物车总数(API删除成功后再更新)
|
if (dayCarIndex !== -1) {
|
||||||
that.shopCarTotal = that.shopCarTotal - carItem.commodity_goods_info.min_order_quantity;
|
that.isDayCarList.splice(dayCarIndex, 1);
|
||||||
|
// 如果当日达购物车为空,更新显示状态
|
||||||
// 如果商家没有商品了,移除该商家
|
if (that.isDayCarList.length === 0) {
|
||||||
if (item.length === 0) {
|
that.isDayshow = false;
|
||||||
// 分别检查并移除当日达和普通购物车中的商家
|
}
|
||||||
const dayCarIndex = that.isDayCarList.findIndex(dayItem =>
|
}
|
||||||
dayItem.commodity_cart_and_goods_model === item
|
if (normalCarIndex !== -1) {
|
||||||
);
|
that.shopCarList.splice(normalCarIndex, 1);
|
||||||
const normalCarIndex = that.shopCarList.findIndex(normalItem =>
|
// 如果普通购物车为空,更新显示状态
|
||||||
normalItem.commodity_cart_and_goods_model === item
|
if (that.shopCarList.length === 0) {
|
||||||
);
|
that.parcelPostshow = false;
|
||||||
|
}
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
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) {
|
add(carItem, goodsIndex) {
|
||||||
if (carItem.count == 0) {
|
const currentTime = new Date().getTime();
|
||||||
carItem.count = carItem.commodity_goods_info.min_order_quantity
|
|
||||||
this.shopCarTotal += carItem.commodity_goods_info.min_order_quantity;
|
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 {
|
} 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++;
|
carItem.count++;
|
||||||
this.shopCarTotal++;
|
this.shopCarTotal++;
|
||||||
}
|
}
|
||||||
@ -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() { },
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user