增加培训班管理,增加购物车功能

This commit is contained in:
liuyuan
2025-07-01 16:35:55 +08:00
parent 06340ad137
commit 249b4b93f6
25 changed files with 4428 additions and 1764 deletions

View File

@@ -234,7 +234,7 @@
</view>
<view class="goods_nav_box" v-if="!this.$store.state.loadingShow">
<uni-goods-nav :fill="true" :options="buyOptions" :button-group="customButtonGroup1"
@click="onHandleClickBuy" @buttonClick="onHandleClickBuy1" />
@click="onHandleClick" @buttonClick="onHandleClickBuy1" />
</view>
<common-select-goods ref="commonSelectGoods" :selectGoodsData="selectGoodsData" :goodsList="goodsList"
:buyOptions="buyOptions" :customButtonGroup1="customButtonGroup1" @selectGoods="selectGoods"
@@ -303,8 +303,11 @@
parameterList: [],
booksList: [],
coursesList: [],
buyOptions: [],
buyOptions: [{
icon: "cart",
text: "购物车",
}],
swiperList: [],
goodsList: [],
options: {},
@@ -347,12 +350,20 @@
goodsList: "book/shopproduct/getGlProductList",
},
customButtonGroup1: [{
with: 200,
customButtonGroup1: [
{
text: "加入购物车",
backgroundColor: "linear-gradient(90deg, #FFCD1E, #FF8A18)",
color: "#fff",
},
{
text: "立即购买",
backgroundColor: "linear-gradient(90deg, #FE6035, #EF1224)",
color: "#fff",
}, ],
buttonType: '', //点击的是加入购物车还是购买
cartList: [], // 购物车列表
productAmount: 1, // 商品数量
};
},
onLoad(options) {
@@ -413,8 +424,17 @@
this.$refs.commonSelectGoods.open();
this.$forceUpdate();
},
onHandleClickBuy1() {
//点击购物车
onHandleClick(){
console.log('点击购物车')
uni.navigateTo({
url: "/pages/goods/shopping",
});
},
//点击筛选商品
onHandleClickBuy1(e) {
this.buttonType = e.index;
if (this.options.type == "visitor") {
uni.showModal({
content: "登陆后可购买本商品",
@@ -433,22 +453,115 @@
}
this.$refs.commonSelectGoods.open();
},
//点击下单按钮
onHandleClickBuy() {
var mynavData = {
goods: [{
productImages: this.selectGoodsData.productImages,
productId: this.selectGoodsData.productId,
productName: this.selectGoodsData.productName,
goodsType: this.selectGoodsData.goodsType,
}],
navTitle: this.options.navTitle,
title: this.options.title,
typeId: 0
};
uni.setStorageSync('mynavData', mynavData);
uni.navigateTo({
url: '/pages/goods/order',
});
if(this.buttonType==0){ //如果是加入购物车
console.log('剩余', this.selectGoodsData.productStock)
if(this.selectGoodsData.productStock==0){
uni.showToast({
title: "商品库存不足",
icon: "none",
duration: 1000,
});
}else{
this.$http.post(`book/ordercart/getCartList?userId=${this.userInfo.id}`)
.then((res) => {
this.cartList = res.cartList;
this.isAddLink(this.selectGoodsData);
});
}
}else{ //如果是正常下单
var mynavData = JSON.stringify({
goods: [{
productImages: this.selectGoodsData.productImages,
productId: this.selectGoodsData.productId,
productName: this.selectGoodsData.productName,
goodsType: this.selectGoodsData.goodsType,
}],
typeId: 0
});
uni.navigateTo({
url: `/pages/goods/order?data=${mynavData}`,
});
}
},
//统计商品信息
isAddLink(item) {
let data = {
userId: this.userInfo.id,
productId: item.productId,
productAmount: this.productAmount,
price: item.price,
};
// 判断列表是否为空
if (this.cartList.length > 0) {
let flag = "";
let shagnpin = {};
// 循环购物车列表
flag = this.cartList.some((item, index) => {
if (item.productId == data.productId) {
shagnpin = item;
shagnpin.productAmount = item.productAmount + 1;
return true;
}
});
if (flag) {
// 已在购物车中添加
$http.request({
url: "book/ordercart/update",
method: "POST",
data: shagnpin,
header: {
"Content-Type": "application/json",
},
})
.then((res) => {
if (res.code == 0) {
uni.showToast({
title: "加入购物车成功",
duration: 1000,
});
}
});
} else {
// 加入购物车
$http.request({
url: "book/ordercart/save",
method: "POST",
data,
header: {
"Content-Type": "application/json",
},
})
.then((res) => {
if (res.code == 0) {
uni.showToast({
title: "加入购物车成功",
duration: 1000,
});
}
});
}
} else {
// 购物车列表为空时直接加入购物车
$http.request({
url: "book/ordercart/save",
method: "POST",
data,
header: {
"Content-Type": "application/json",
},
})
.then((res) => {
if (res.code == 0) {
uni.showToast({
title: "加入购物车成功",
duration: 1000,
});
}
});
}
this.$refs.commonSelectGoods.close();
},
buttonClick(e) {
console.log(e);
@@ -1276,4 +1389,9 @@
align-items: center;
justify-content: space-between;
}
/deep/.uni-tab__text{
font-size: 26rpx;
line-height: 28rpx;
}
</style>