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