index.c4829cd7.js 4.1 KB

1
  1. import{C as n}from"./index.8f85fe36.js";import{s as i}from"./index.module.3bc378ff.js";import{d as h,D as d,b as a,a2 as u,G as r,a3 as m,Y as p,I as f,v as g,a0 as l,j as c,F as C}from"./vendor.2bcdc9cf.js";/* empty css *//* empty css *//* empty css *//* empty css *//* empty css *//* empty css *//* empty css */import{r as o,m as b,C as y}from"./index.f45ba589.js";import{f as I}from"./cart.2a3b730f.js";import{g as x}from"./shop-mall.789d0e66.js";function k(e){return typeof e=="function"||Object.prototype.toString.call(e)==="[object Object]"&&!g(e)}var P=h({name:"cart",data(){return{loading:!0,dataShow:!1,isManage:!1,cartList:[],selectItems:[]}},computed:{checkAll(){const e=this.selectItems.length,t=this.cartList.length;return t?e===t:!1},len(){return this.selectItems.length},totalPrice(){let e=0;const t=this.selectItems;return this.cartList.forEach(s=>{t.includes(s.id)&&typeof s.price=="number"&&(e+=s.price*s.quantity)}),e*100}},mounted(){this.getCartList()},methods:{async getCartList(){this.loading=!0,this.cartList=[];try{const{code:e,data:t}=await o.get("/api-mall-portal/cart/list");e===200&&(this.cartList=t.map(s=>s)),this.$nextTick(()=>{setTimeout(()=>{this.cartList=t.map(s=>(s.stock=s.stock-s.lockStock,s.stock=s.stock<=0?0:s.stock,s))},0)})}catch{}this.dataShow=!0,this.loading=!1},setCheckAll(){const e=[];this.checkAll||this.cartList.forEach(t=>{e.push(t.id)}),this.selectItems=e},async setCartItem(e){try{const{code:t,data:s}=await o.get("/api-mall-portal/cart/update/quantity",{params:{id:e.id,quantity:e.quantity}})}catch{}},onChecked(e){const t=this.selectItems;t.includes(e)?t.splice(t.indexOf(e),1):t.push(e),this.selectItems=t},async onDeleteCartItem(){d.confirm({message:"\u662F\u5426\u786E\u8BA4\u5220\u9664\u9009\u4E2D\u7684\u5546\u54C1?",confirmButtonColor:"var(--van-primary)"}).then(async()=>{const e=this.selectItems.join(",");try{const{code:t,data:s}=await o.post("/api-mall-portal/cart/delete?ids="+e);t===200&&(this.getCartList(),this.selectItems=[],this.isManage=!1,x())}catch{}})},async generateConfirmOrder(){this.$router.push({path:"/cartConfirm",query:{cartIds:this.selectItems.join(",")}})},gotoShopMall(){this.$router.replace("/")}},render(){let e;return a(C,null,[this.dataShow?a("div",null,[a(n,{onClickRight:()=>{this.isManage=!this.isManage,this.isManage||this.cartList.forEach(t=>{t.stock<=0&&(this.selectItems=this.selectItems.filter(s=>s!=t.id))})}},{right:()=>a("span",{class:i.rightText},[this.isManage?"\u5B8C\u6210":"\u7BA1\u7406"])}),a("div",{class:[i.cartBox]},[this.cartList.length?a(u,{modelValue:this.selectItems,"onUpdate:modelValue":t=>this.selectItems=t},k(e=this.cartList.map(t=>a("div",{class:i.cartItem},[a(r,{name:t.id},{default:()=>[a(m,{price:b(t.price),desc:I(t.productAttr),title:t.productName,thumb:t.productPic},{num:()=>a(p,{modelValue:t.quantity,"onUpdate:modelValue":s=>t.quantity=s,onClick:s=>{s.stopPropagation()},onChange:()=>{console.log(1),t.quantity&&this.setCartItem(t)},inputWidth:"50px",buttonSize:"24px",min:1,max:200,integer:!0},null),thumb:()=>a("div",null,[a(f,{src:t.productPic},null)])})]})])))?e:{default:()=>[e]}):null,!this.loading&&!this.cartList.length&&a(y,{tips:"\u8D2D\u7269\u8F66\u7A7A\u7A7A\u5982\u4E5F",buttonText:"\u53BB\u5546\u57CE\u901B\u901B",classImgSize:"GOODS",type:"goods",onClick:()=>this.gotoShopMall()},null),a("div",{style:{height:"var(--van-submit-bar-height)"}},null),this.isManage?a("div",{class:i.delete},[a(l,{buttonText:"\u5220\u9664",buttonColor:"var(--van-primary)",disabled:this.len===0,safeAreaInsetBottom:!1,onSubmit:()=>this.onDeleteCartItem()},{default:()=>[a(r,{modelValue:this.checkAll,onClick:t=>this.setCheckAll()},{default:()=>[c("\u5168\u9009")]})]})]):a("div",{class:i.submit},[a(l,{price:this.totalPrice,buttonText:`\u7ED3\u7B97(${this.len})`,buttonColor:"var(--van-primary)",safeAreaInsetBottom:!1,disabled:this.len===0,onSubmit:()=>this.generateConfirmOrder()},{default:()=>[a(r,{modelValue:this.checkAll,onClick:t=>this.setCheckAll()},{default:()=>[c("\u5168\u9009")]})]})])])]):null])}});export{P as default};