index.b792408f.js 3.4 KB

1
  1. import{C as n}from"./index.2c715c84.js";import{s as i,S as o}from"./index.4ac97166.js";import{d as h,b as r,i as a,bk as u,ak as d,C as m,w as c,F as p}from"./index.9a8e7555.js";import{C as l}from"./index.17575d3a.js";import"./index.df465582.js";import"./index.7f9087a9.js";import"./index.eefac611.js";import{C as f}from"./index.b2988de5.js";import{S as C}from"./index.851ca690.js";import{f as g}from"./cart.d351a25d.js";import{C as y}from"./index.4abed682.js";import"./use-height.5caa9b61.js";function b(e){return typeof e=="function"||Object.prototype.toString.call(e)==="[object Object]"&&!d(e)}var O=h({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(){this.$router.push({path:"/cartConfirm",query:{cartIds:this.selectItems.join(",")}})},gotoShopMall(){this.$router.push({path:"/shopMall"})}},render(){let e;return a(p,null,[this.dataShow?a("div",null,[a(n,{onClickRight:()=>this.isManage=!this.isManage},{right:()=>a("span",{style:{color:"#333",fontSize:"14px"}},[this.isManage?"\u5B8C\u6210":"\u7BA1\u7406"])}),a("div",{class:i.cartBox},[this.cartList.length?a(y,{modelValue:this.selectItems,"onUpdate:modelValue":t=>this.selectItems=t},b(e=this.cartList.map(t=>a("div",{class:i.cartItem},[a(l,{name:t.id},{default:()=>[a(f,{price:u(t.price),desc:g(t.productAttr),title:t.productName,thumb:t.productPic},{num:()=>a(C,{modelValue:t.quantity,"onUpdate:modelValue":s=>t.quantity=s,onClick:s=>{s.stopPropagation()},onChange:()=>{t.quantity&&this.setCartItem(t)},inputWidth:"50px",buttonSize:"24px",min:1},null)})]})])))?e:{default:()=>[e]}):a(m,{tips:"\u8D2D\u7269\u8F66\u7A7A\u7A7A\u5982\u4E5F",buttonText:"\u53BB\u5546\u57CE\u901B\u901B",onClick:()=>this.gotoShopMall()},null),a("div",{style:{height:"var(--van-submit-bar-height)"}},null),this.isManage?a("div",{class:i.delete},[a(o,{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:()=>[c("\u5168\u9009")]})]})]):a("div",{class:i.submit},[a(o,{price:this.totalPrice,buttonText:`\u7ED3\u7B97(${this.len})`,buttonColor:"var(--van-primary)",disabled:this.len===0,onSubmit:()=>this.generateConfirmOrder()},{default:()=>[a(l,{modelValue:this.checkAll,onClick:t=>this.setCheckAll()},{default:()=>[c("\u5168\u9009")]})]})])])]):null])}});export{O as default};