2 lines
1.8 KiB
JavaScript
2 lines
1.8 KiB
JavaScript
|
"use strict";var t=(t,e,i)=>new Promise(((s,l)=>{var d=t=>{try{c(i.next(t))}catch(e){l(e)}},r=t=>{try{c(i.throw(t))}catch(e){l(e)}},c=t=>t.done?s(t.value):Promise.resolve(t.value).then(d,r);c((i=i.apply(t,e)).next())}));const e=require("../../common/vendor.js"),i=require("../api/trade/cart.js"),s=e.defineStore({id:"cart",state:()=>({list:[],selectedIds:[],isAllSelected:!1,totalPriceSelected:0}),actions:{getList(){return t(this,null,(function*(){const{data:t,code:e}=yield i.CartApi.getCartList();0===e&&(this.list=t.validList,this.selectedIds=[],this.isAllSelected=!0,this.totalPriceSelected=0,this.list.forEach((t=>{t.selected?(this.selectedIds.push(t.id),this.totalPriceSelected+=t.count*t.sku.price):this.isAllSelected=!1})))}))},add(e){return t(this,null,(function*(){const{code:t}=yield i.CartApi.addCart({skuId:e.id,count:e.goods_num});0===t&&(yield this.getList())}))},update(e){return t(this,null,(function*(){const{code:t}=yield i.CartApi.updateCartCount({id:e.goods_id,count:e.goods_num});0===t&&(yield this.getList())}))},delete(e){return t(this,null,(function*(){let t="";t=Array.isArray(e)?e.join(","):e;const{code:s}=yield i.CartApi.deleteCart(t);0===s&&(yield this.getList())}))},selectSingle(e){return t(this,null,(function*(){const{code:t}=yield i.CartApi.updateCartSelected({ids:[e],selected:!this.selectedIds.includes(e)});0===t&&(yield this.getList())}))},selectAll(e){return t(this,null,(function*(){const{code:t}=yield i.CartApi.updateCartSelected({ids:this.list.map((t=>t.id)),selected:e});0===t&&(yield this.getList())}))},emptyList(){this.list=[],this.selectedIds=[],this.isAllSelected=!0,this.totalPriceSelected=0}},persist:{enabled:!0,strategies:[{key:"cart-store"}]}}),l=Object.freeze(Object.defineProperty({__proto__:null,default:s},Symbol.toStringTag,{value:"Module"}));exports.__vite_glob_0_1=l,exports.cart=s;
|