You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2 lines
1.4 KiB

"use strict";const c=require("../../common/vendor.js"),s=require("../api/trade/cart.js"),a=c.defineStore({id:"cart",state:()=>({list:[],selectedIds:[],isAllSelected:!1,totalPriceSelected:0}),actions:{async getList(){const{data:t,code:e}=await s.CartApi.getCartList();e===0&&(this.list=t.validList,this.selectedIds=[],this.isAllSelected=!0,this.totalPriceSelected=0,this.list.forEach(i=>{i.selected?(this.selectedIds.push(i.id),this.totalPriceSelected+=i.count*i.sku.price):this.isAllSelected=!1}))},async add(t){const{code:e}=await s.CartApi.addCart({skuId:t.id,count:t.goods_num});e===0&&await this.getList()},async update(t){const{code:e}=await s.CartApi.updateCartCount({id:t.goods_id,count:t.goods_num});e===0&&await this.getList()},async delete(t){const{code:e}=await s.CartApi.deleteCart(t.join(","));e===0&&await this.getList()},async selectSingle(t){const{code:e}=await s.CartApi.updateCartSelected({ids:[t],selected:!this.selectedIds.includes(t)});e===0&&await this.getList()},async selectAll(t){const{code:e}=await s.CartApi.updateCartSelected({ids:this.list.map(i=>i.id),selected:t});e===0&&await this.getList()},emptyList(){this.list=[],this.selectedIds=[],this.isAllSelected=!0,this.totalPriceSelected=0}},persist:{enabled:!0,strategies:[{key:"cart-store"}]}}),d=Object.freeze(Object.defineProperty({__proto__:null,default:a},Symbol.toStringTag,{value:"Module"}));exports.__vite_glob_0_1=d;exports.cart=a;