12 |
- "use strict";const c=require("../common/vendor.js"),n=require("../api/order.js"),a=require("../common/assets.js"),l={data(){return{shopList:[],totalMoney:0,checkAll:!1,orderKey:""}},onLoad(){this.queryLiveCart()},methods:{getKey(){n.liveOrderKey().then(e=>{e.code==200?(this.orderKey=e.orderKey,c.index.navigateTo({url:"/pages_shop/confirmCreateOrder?type=cart&orderKey="+this.orderKey})):c.index.showToast({title:e.msg,icon:"none"})})},modifyLiveCart(e){let t={checked:e.checked?1:0,cartId:e.cartId,cartNum:e.cartNum};n.modifyLiveCart(t).then(d=>{d.code==200?this.computedMoney():c.index.showToast({icon:"none",title:d.msg})})},queryLiveCart(){n.queryLiveCartList().then(e=>{e.code==200?(this.shopList=e.rows,this.shopList.forEach(t=>{t.checked=t.checked==1}),this.updateCheckAllState(),this.computedMoney()):c.index.showToast({icon:"none",title:"请求失败"})})},delCart(){const e=this.shopList.filter(t=>t.checked).map(t=>t.cartId);if(e.length===0){c.index.showToast({icon:"none",title:"请选择商品删除"});return}n.delLiveCart(e).then(t=>{t.code===200?(c.index.showToast({icon:"success",title:"操作成功"}),this.queryLiveCart()):c.index.showToast({icon:"none",title:t.msg})})},computedMoney(){this.totalMoney=this.shopList.reduce((e,t)=>e+(t.checked?t.price*t.cartNum:0),0)},updateCheckAllState(){if(this.shopList.length===0){this.checkAll=!1;return}this.checkAll=this.shopList.every(e=>e.checked)},handleCheckAll(){this.checkAll=!this.checkAll,this.shopList.forEach(e=>{e.checked=this.checkAll,this.modifyLiveCart(e)}),this.computedMoney()},checkChange(e){e.checked=!e.checked,this.updateCheckAllState(),this.computedMoney(),this.modifyLiveCart(e)},changeNum(e,t){if(t.cartNum=e.detail.value.replace(/\D/g,""),t.cartNum<=1){c.index.showToast({title:"已经是底线啦!",icon:"none",duration:2e3});return}t.cartNum<1&&(t.cartNum=1),t.cartNum>=t.stock&&(t.cartNum=t.stock),this.modifyLiveCart(t)},delNum(e){if(e.cartNum<=1){c.index.showToast({title:"已经是底线啦!",icon:"none",duration:2e3});return}e.cartNum--,e.cartNum<1&&(e.cartNum=1),this.modifyLiveCart(e)},addNum(e){e.cartNum++,e.cartNum>=e.stock&&(e.cartNum=e.stock),this.modifyLiveCart(e)},submit(){if(this.shopList.filter(t=>t.checked).length===0){c.index.showToast({icon:"none",title:"请选择商品"});return}this.getKey()},showProduct(e){c.index.navigateTo({url:"./goods?productId="+e.productId})}}};function u(e,t,d,p,r,s){return c.e({a:r.shopList.length!==0},r.shopList.length!==0?{b:c.f(r.shopList,(o,h,k)=>c.e({a:o.checked,b:o.checked,c:c.o(i=>s.checkChange(o),h),d:c.o(i=>s.showProduct(o),h),e:o.imgUrl,f:c.t(o.productName),g:c.t(o.price),h:o.cartNum<=1},o.cartNum<=1?{i:a._imports_0$3}:{j:a._imports_1$4},{k:c.o(i=>s.delNum(o),h),l:c.o(i=>s.changeNum(i,o),h),m:o.cartNum,n:c.o(i=>s.addNum(o),h),o:h})),c:a._imports_2$2}:{},{d:r.shopList.length==0},r.shopList.length==0?{e:a._imports_2$1}:{},{f:r.checkAll,g:c.o(o=>s.handleCheckAll()),h:c.o(o=>s.delCart()),i:c.t(r.totalMoney.toFixed(2)),j:c.o((...o)=>s.submit&&s.submit(...o))})}const f=c._export_sfc(l,[["render",u]]);wx.createPage(f);
- //# sourceMappingURL=../../.sourcemap/mp-weixin/pages_shop/cart.js.map
|