index.218f1201.js 3.6 KB

1
  1. import{C as h}from"./index.59a5f083.js";import{s as i}from"./index.cb7eaf1d.js";import{d as m,a,F as c,a0 as u,a1 as l,an as p,O as f,x as C,ao as n,b as d}from"./vendor.acdd8727.js";/* empty css *//* empty css *//* empty css *//* empty css *//* empty css *//* empty css */import{r,m as g}from"./index.0b78728c.js";import{c as o}from"./cart.68dd4bdf.js";import{C as b}from"./index.8335e6dc.js";function x(e){return typeof e=="function"||Object.prototype.toString.call(e)==="[object Object]"&&!C(e)}var w=m({name:"cart",data(){return{dataShow:!1,isManage:!1,cartList:[],selectItems:[]}},computed:{checkAll(){let e=this.selectItems.length,t=this.cartList.length;return e===t},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.cartList=[];try{let{code:e,data:t}=await r.get("/api-mall-portal/cart/list");e===200&&(this.cartList=t)}catch{}this.dataShow=!0},setCheckAll(){const e=[];this.checkAll||this.cartList.forEach(t=>{e.push(t.id)}),this.selectItems=e},async setCartItem(e){try{let{code:t,data:s}=await r.get("/api-mall-portal/cart/update/quantity",{params:{id:e.id,quantity:e.quantity},hideLoading:!0})}catch{}},onChecked(e){const t=this.selectItems;t.includes(e)?t.splice(t.indexOf(e),1):t.push(e),this.selectItems=t},async onDeleteCartItem(){const e=this.selectItems.join(",");try{let{code:t,data:s}=await r.post("/api-mall-portal/cart/delete?ids="+e);t===200&&(this.getCartList(),this.selectItems=[],this.isManage=!1)}catch{}},async generateConfirmOrder(){const e=[...this.selectItems];try{let{code:t,data:s}=await r.post("/api-mall-portal/order/generateConfirmOrder",{params:{cartIds:e.join(",")}});t===200&&(o.calcAmount=s.calcAmount,o.cartPromotionItemList=s.cartPromotionItemList,o.memberReceiveAddressList=s.memberReceiveAddressList,this.$router.push({path:"/cartConfirm"}))}catch{}},gotoShopMall(){this.$router.push({path:"/shopMall"})}},render(){let e;return a(c,null,[this.dataShow?a("div",null,[this.cartList.length?a(c,null,[a(h,{onClickRight:()=>this.isManage=!this.isManage},{right:()=>a("span",{style:{color:"#333",fontSize:"14px"}},[this.isManage?"\u5B8C\u6210":"\u7BA1\u7406"])}),a("div",{class:i.cartBox},[a(u,{modelValue:this.selectItems,"onUpdate:modelValue":t=>this.selectItems=t},x(e=this.cartList.map(t=>a("div",{class:i.cartItem},[a(l,{name:t.id},{default:()=>[a(p,{price:g(t.price),desc:t.productAttr,title:t.productName,thumb:t.productPic},{num:()=>a(f,{modelValue:t.quantity,"onUpdate:modelValue":s=>t.quantity=s,onClick:s=>{s.stopPropagation()},onChange:()=>this.setCartItem(t),inputWidth:"50px",buttonSize:"24px",min:1},null)})]})])))?e:{default:()=>[e]}),a("div",{style:{height:"var(--van-submit-bar-height)"}},null),this.isManage?a("div",{class:i.delete},[a(n,{buttonText:"\u5220\u9664",buttonColor:"var(--van-primary)",disabled:this.totalPrice===0,onSubmit:()=>this.onDeleteCartItem()},{default:()=>[a(l,{modelValue:this.checkAll,onClick:t=>this.setCheckAll()},{default:()=>[d("\u5168\u9009")]})]})]):a("div",{class:i.submit},[a(n,{price:this.totalPrice,buttonText:`\u7ED3\u7B97(${this.len})`,buttonColor:"var(--van-primary)",disabled:this.totalPrice===0,onSubmit:()=>this.generateConfirmOrder()},{default:()=>[a(l,{modelValue:this.checkAll,onClick:t=>this.setCheckAll()},{default:()=>[d("\u5168\u9009")]})]})])])]):a(b,{tips:"\u8D2D\u7269\u8F66\u7A7A\u7A7A\u5982\u4E5F",buttonText:"\u53BB\u5546\u57CE\u901B\u901B",onClick:()=>this.gotoShopMall()},null)]):null])}});export{w as default};