规格数量处理

This commit is contained in:
GaoHao
2024-08-03 11:19:44 +08:00
parent 0e3e975627
commit 520d791326
2 changed files with 31 additions and 42 deletions

View File

@@ -350,6 +350,7 @@
socketTicket: null,
amountcartNumber: 0,
skuNumber: 0,
skuSuit: 0,
salePrice: '', //钱数
cartListsdatashow: false, //是否显示购物车
showCart: false,
@@ -526,20 +527,22 @@
*/
shopAdd(item, index, index1, a, b) {
let flag = true;
if ( this.cartLists.data.length > 0) {
this.cartLists.data.forEach((v,e)=>{
if ( v.productId == item.id) {
flag = false;
}
console.log(v)
})
}
// if ( this.cartLists.data.length > 0) {
// this.cartLists.data.forEach((v,e)=>{
// if ( v.productId == item.id) {
// flag = false;
// }
// console.log(v)
// })
// }
console.log(a)
console.log(this.amountcartNumber)
console.log(this.skuNumber)
console.log(this.skuSuit)
console.log(flag)
console.log(item)
if ( a == "+" ){
if ( this.amountcartNumber <= 0 && flag) {
if ( this.skuNumber < this.skuSuit) {
this.amountcartNumber = this.amountcartNumber + (item.suit==0?1:item.suit);
}else {
this.amountcartNumber++;
@@ -548,7 +551,7 @@
if (this.amountcartNumber > 0) {
console.log(item)
if ( this.amountcartNumber <= item.suit && flag) {
if ( this.skuNumber < this.skuSuit) {
this.amountcartNumber = this.amountcartNumber - (item.suit==0?1:item.suit);
} else {
this.amountcartNumber = this.amountcartNumber - 1;
@@ -738,33 +741,26 @@
productId: item.id, //商品id
spec_tag: this.skuidname.join(",")
})
if (res.data.stockNumber == 0) {
uni.showToast({
title: '暂无库存',
icon: "none",
})
} else {
this.skuidsearch = res.data.id // 储存skuid 用于筛选数量
this.salePrice = res.data.salePrice // 价格
let data = null;
if (a == 1) { //1添加购物车 2是websocket返回这个商品的价格(应为不同的多规格商品返回不同的价格)
let params = {
"skuId": res.data.id,
"num": num, //数量
"type": c == '+' ? 1 : 0,
"productId": item.id, //商品id
"shopId": uni.cache.get('shopUser'),
"userId": uni.cache.get('userInfo').id,
"tableId": uni.cache.get('tableCode'),
}
this.addCart(params);
} else {
this.skuId = res.data.id;
this.skuNumber = res.data.number;
this.showShopsku = true //打开弹框
this.salePrice = res.data.salePrice // 价格
let data = null;
if (a == 1) { //1添加购物车 2是websocket返回这个商品的价格(应为不同的多规格商品返回不同的价格)
let params = {
"skuId": res.data.id,
"num": num, //数量
"type": c == '+' ? 1 : 0,
"productId": item.id, //商品id
"shopId": uni.cache.get('shopUser'),
"userId": uni.cache.get('userInfo').id,
"tableId": uni.cache.get('tableCode'),
}
this.$set(this, 'amountcartNumber', 0)
this.addCart(params);
} else {
this.skuId = res.data.id;
this.skuNumber = res.data.number;
this.skuSuit = res.data.suit;
this.showShopsku = true //打开弹框
}
this.$set(this, 'amountcartNumber', 0)
} catch (e) {}
},