uni-购物车之批量删除

tech2023-08-23  112

delSelect(){//删除选中的商品 var delectArry=[] this.goodlist.forEach((item,index)=>{ var arry ={}// 确保每次循环都创建一个新对象 var agoods=item.good var good=agoods.filter(function(goodsitem){ // console.log(goodsitem); if(goodsitem.select===true){ arry['storeName']=item.storeName arry['storeID']=item.storeID } return goodsitem.select===true }) if(good.length!=0){ arry['goods']=good delectArry.push(arry) } }) // console.log(delectArry); if(delectArry.length){ console.log('选中了商品',delectArry); var delnum=0;//待删除商品总数 delectArry.forEach(delShop=>{ // console.log(delShop); delnum+=delShop.goods.length }) uni.showModal({ content: '确认将这'+delnum+'个宝贝删除?', showCancel: true, cancelText: '我再想想', confirmText: '删除', success: res => { if(res.confirm){ //删除页面购物车商品 delectArry.forEach(delShop=>{ // console.log(delShop); delnum+=delShop.goods.length this.goodlist.forEach((item,shopindex)=>{ // console.log(item); if(delShop.storeID==item.storeID){ //待删除店铺的商品数与购物车店铺的商品数相等时,删除整个店的购物车商品 if(delShop.goods.length==item.good.length){ this.goodlist.splice(shopindex,1) }else{ delShop.goods.forEach(delGoods=>{ console.log(delGoods); item.good.forEach((goods,goodsindex)=>{ //如果待删除商品存在店铺商品,删除该商品 if(delGoods.goodid==goods.goodid){ console.log(goods); item.good.splice(goodsindex,1) } }) }) } } }) }) }else{ } }, fail: () => {}, complete: () => {} }); }else{ uni.showToast({ title: '您还没有选择宝贝哦', icon:'none' }); } }
最新回复(0)