购物车列表数量处理
This commit is contained in:
@@ -369,7 +369,7 @@
|
|||||||
if (res.code == 0) {
|
if (res.code == 0) {
|
||||||
uni.cache.set('shopUser', res.data)
|
uni.cache.set('shopUser', res.data)
|
||||||
this.handlemessage() //监听websocket返回
|
this.handlemessage() //监听websocket返回
|
||||||
// this.productqueryProduct() //list 数据
|
this.productqueryProduct() //list 数据
|
||||||
} else {
|
} else {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
uni.pro.switchTab('index/index')
|
uni.pro.switchTab('index/index')
|
||||||
@@ -401,7 +401,7 @@
|
|||||||
switch (msg.type) {
|
switch (msg.type) {
|
||||||
case 'sku': // sku 数量 查询这个商品的价格和数量
|
case 'sku': // sku 数量 查询这个商品的价格和数量
|
||||||
this.$set(this, 'amountcartNumber', msg.amount)
|
this.$set(this, 'amountcartNumber', msg.amount)
|
||||||
this.productqueryProduct() //list 数据
|
// this.productqueryProduct() //list 数据
|
||||||
break;
|
break;
|
||||||
case 'clearCart':
|
case 'clearCart':
|
||||||
this.cartLists = msg
|
this.cartLists = msg
|
||||||
@@ -427,8 +427,7 @@
|
|||||||
break;
|
break;
|
||||||
case 'addcart':
|
case 'addcart':
|
||||||
this.cartLists = msg
|
this.cartLists = msg
|
||||||
// console.log(msg, 1111)
|
// this.productqueryProduct() //list 数据
|
||||||
this.productqueryProduct() //list 数据
|
|
||||||
try {
|
try {
|
||||||
if (msg.data.length != 0) {
|
if (msg.data.length != 0) {
|
||||||
let nums = 0
|
let nums = 0
|
||||||
@@ -453,10 +452,35 @@
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
//TODO handle the exception
|
//TODO handle the exception
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
// 处理购物车相同id的情况下 数量相加
|
||||||
|
var summedArray = msg.data.reduce((acc, current) => {
|
||||||
|
const existing = acc.find(item => item.productId === current.productId);
|
||||||
|
if (existing) {
|
||||||
|
existing.number += current.number;
|
||||||
|
} else {
|
||||||
|
acc.push({
|
||||||
|
...current
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return acc;
|
||||||
|
}, []);
|
||||||
|
// 购物车总数据与列表页面互通
|
||||||
|
this.shopList.productInfo.forEach((item) => {
|
||||||
|
return item.products.filter(e => {
|
||||||
|
return summedArray.find(i => {
|
||||||
|
if (e.id == i.productId) {
|
||||||
|
e.cartNumber = i.number
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
} catch (e) {}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// console.log(this.cartLists.data, 1111111)
|
// 判断是否显示购物车
|
||||||
this.cartListsdatashow = this.cartLists.data.length == 0 ? false : true
|
this.cartListsdatashow = this.cartLists.data.length == 0 ? false : true
|
||||||
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
//TODO handle the exception
|
//TODO handle the exception
|
||||||
@@ -667,7 +691,7 @@
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
// 点击菜单商品滚动到指定为止
|
// 点击菜单商品滚动到指定为止
|
||||||
titleClickHandle(id,index) {
|
titleClickHandle(id, index) {
|
||||||
this.titleTopNumIndexFalg = false;
|
this.titleTopNumIndexFalg = false;
|
||||||
this.titleTopNumIndex = index;
|
this.titleTopNumIndex = index;
|
||||||
uni.createSelectorQuery()
|
uni.createSelectorQuery()
|
||||||
@@ -719,7 +743,7 @@
|
|||||||
.select(`#title${i.id}`)
|
.select(`#title${i.id}`)
|
||||||
.boundingClientRect((res) => {
|
.boundingClientRect((res) => {
|
||||||
topNums.push(res.top - this.menuInfo.top - this.menuInfo.height - this
|
topNums.push(res.top - this.menuInfo.top - this.menuInfo.height - this
|
||||||
.paddingBtmSize*8 -
|
.paddingBtmSize * 8 -
|
||||||
this.tabHeadHeight + 40);
|
this.tabHeadHeight + 40);
|
||||||
})
|
})
|
||||||
.exec();
|
.exec();
|
||||||
|
|||||||
Reference in New Issue
Block a user