feat:在线商城
This commit is contained in:
1 parent
bc24d80a33
commit
391bf62d9c
14 files changed
+165
-353
No files matched your search
@@ -3,11 +3,11 @@ import { foodApi } from "../api"
|
||||
|
||||
export const useCartStore = defineStore("cartStore", {
|
||||
state: () => ({
|
||||
cart: JSON.parse(uni.getStorageSync("cart") || "[]"),
|
||||
shopMerchantId: uni.getStorageSync("shopMerchantId") || "",
|
||||
cart: JSON.parse(uni.getStorageSync("onlineShopCart") || "[]"),
|
||||
shopMerchantId: uni.getStorageSync("onlineShopMerchantId") || "",
|
||||
}),
|
||||
getters: {
|
||||
totCount(state) {
|
||||
totalCount(state) {
|
||||
return state.cart.reduce((prev: string, cur: any) => {
|
||||
return prev + cur.productCount
|
||||
}, 0)
|
||||
@@ -22,14 +22,11 @@ export const useCartStore = defineStore("cartStore", {
|
||||
actions: {
|
||||
saveShopMerchantId(shopMerchantId: string) {
|
||||
this.shopMerchantId = shopMerchantId
|
||||
uni.setStorageSync("shopMerchantId", this.shopMerchantId)
|
||||
uni.setStorageSync("onlineShopMerchantId", this.shopMerchantId)
|
||||
},
|
||||
saveToStorage() {
|
||||
uni.setStorageSync("cart", JSON.stringify(this.cart))
|
||||
},
|
||||
saveShoppingCart(cartList: any) {
|
||||
saveShopCart(cartList: any) {
|
||||
this.cart = cartList
|
||||
this.saveToStorage()
|
||||
uni.setStorageSync("onlineShopCart", JSON.stringify(this.cart))
|
||||
},
|
||||
addGoodsItemToCart(goodsItem: any) {
|
||||
const findResult = this.cart.find((item: any) => {
|
||||
@@ -40,7 +37,7 @@ export const useCartStore = defineStore("cartStore", {
|
||||
} else {
|
||||
findResult.productCount++
|
||||
}
|
||||
this.saveToStorage()
|
||||
uni.setStorageSync("onlineShopCart", JSON.stringify(this.cart))
|
||||
},
|
||||
async addProductCount(productId: string) {
|
||||
this.cart.forEach((item: any) => {
|
||||
@@ -62,7 +59,7 @@ export const useCartStore = defineStore("cartStore", {
|
||||
},
|
||||
async getShopCart() {
|
||||
const { data } = await foodApi.getShopCar({ merchantId: this.shopMerchantId, hardType: "SUPERMARKET" })
|
||||
this.saveShoppingCart(data ?? [])
|
||||
this.saveShopCart(data ?? [])
|
||||
},
|
||||
async updateShopCart() {
|
||||
const list = this.cart
|
||||
|
||||
Reference in new issue
Block a user