index.888d2e67.js 4.2 KB

1
  1. import{C as h}from"./index.c5bf3ab5.js";import{s as i}from"./index.module.0e920025.js";import{d as u,e as l,T as d,D as m,p,i as a,by as f,C as g,A as o,F as C,$ as k}from"./index.7994470a.js";import{C as r}from"./index.29eb1675.js";import"./index.c9af17c2.js";import{S as c}from"./index.4d16ec29.js";import{I as n}from"./index.2fbdc579.js";import"./index.0262b810.js";import{C as y}from"./index.100c0398.js";import{S as b}from"./index.6dd38dfa.js";import{f as I}from"./cart.d2ad347e.js";import{i as v}from"./icon-sell-out.98742fd0.js";import{g as S}from"./shop-mall.8049f9da.js";import{C as L}from"./index.2e766b01.js";import"./index.0a2aeb2c.js";import"./use-height.ffa5a0f3.js";function x(e){return typeof e=="function"||Object.prototype.toString.call(e)==="[object Object]"&&!k(e)}var R=u({name:"cart",data(){return{loading:!0,dataShow:!1,isManage:!1,cartList:[],selectItems:[]}},computed:{checkAll(){let 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{let{code:e,data:t}=await l.get("/api-mall-portal/cart/list");e===200&&(this.cartList=t.map(s=>(s.stock=s.stock-s.lockStock,s.stock=s.stock<=0?0:s.stock,s)))}catch{}this.dataShow=!0,this.loading=!1},setCheckAll(){const e=[];this.checkAll||this.cartList.forEach(t=>{(this.isManage||t.stock>0)&&e.push(t.id)}),this.selectItems=e},async setCartItem(e){try{let{code:t,data:s}=await l.get("/api-mall-portal/cart/update/quantity",{params:{id:e.id,quantity:e.quantity}});e.stock=s,e.quantity>s&&(e.quantity=s,setTimeout(()=>{d("\u5E93\u5B58\u4E0D\u8DB3")},500))}catch{}},onChecked(e){const t=this.selectItems;t.includes(e)?t.splice(t.indexOf(e),1):t.push(e),this.selectItems=t},async onDeleteCartItem(){m.confirm({message:"\u662F\u5426\u786E\u8BA4\u5220\u9664\u9009\u4E2D\u7684\u5546\u54C1?"}).then(async()=>{const e=this.selectItems.join(",");try{let{code:t,data:s}=await l.post("/api-mall-portal/cart/delete?ids="+e);t===200&&(this.getCartList(),this.selectItems=[],this.isManage=!1,S())}catch{}})},async generateConfirmOrder(){this.$router.push({path:"/cartConfirm",query:{cartIds:this.selectItems.join(",")}})},gotoShopMall(){p({api:"back"})}},render(){let e;return a(C,null,[this.dataShow?a("div",null,[a(h,{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",{style:{color:"#333",fontSize:"14px"}},[this.isManage?"\u5B8C\u6210":"\u7BA1\u7406"])}),a("div",{class:i.cartBox},[this.cartList.length?a(L,{modelValue:this.selectItems,"onUpdate:modelValue":t=>this.selectItems=t},x(e=this.cartList.map(t=>a("div",{class:i.cartItem},[a(r,{name:t.id,disabled:t.stock<=0&&!this.isManage},{default:()=>[a(y,{price:f(t.price),desc:I(t.productAttr),title:t.productName,thumb:t.productPic},{num:()=>a(b,{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,max:t.stock>200?200:t.stock,integer:!0},null),thumb:()=>a("div",null,[a(n,{src:t.productPic},null),t.stock<=0&&a("div",{class:i.sellOut},[a(n,{src:v,fit:"cover",class:i.sellOutImg},null)])])})]})])))?e:{default:()=>[e]}):null,!this.loading&&!this.cartList.length&&a(g,{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(c,{buttonText:"\u5220\u9664",buttonColor:"var(--van-primary)",disabled:this.len===0,onSubmit:()=>this.onDeleteCartItem()},{default:()=>[a(r,{modelValue:this.checkAll,onClick:t=>this.setCheckAll()},{default:()=>[o("\u5168\u9009")]})]})]):a("div",{class:i.submit},[a(c,{price:this.totalPrice,buttonText:`\u7ED3\u7B97(${this.len})`,buttonColor:"var(--van-primary)",disabled:this.len===0,onSubmit:()=>this.generateConfirmOrder()},{default:()=>[a(r,{modelValue:this.checkAll,onClick:t=>this.setCheckAll()},{default:()=>[o("\u5168\u9009")]})]})])])]):null])}});export{R as default};