feat:共富商城订单

This commit is contained in:
weiwei committed 2025-10-28 18:23:16 +08:00
1 parent f8ee97f88a
commit 0fe72f08ae
8 files changed
+156 -91

No files matched your search

+22 -17
View File
@@ -1,8 +1,9 @@
import { defineStore } from "pinia"
import { orderApi } from "../api"
// 共富商城购物车
export const useProsperityCartStore = defineStore("prosperityCartStore", {
state: () => ({
state: (): any => ({
cartList: [],
}),
getters: {
@@ -19,6 +20,7 @@ export const useProsperityCartStore = defineStore("prosperityCartStore", {
},
},
actions: {
// 购物车添加商品项
addGoodsItemToCart(goodsItem: any) {
const findResult = this.cartList.find((item: any) => {
return item.productId === goodsItem.productId
@@ -28,17 +30,8 @@ export const useProsperityCartStore = defineStore("prosperityCartStore", {
} else {
findResult.productCount++
}
uni.setStorageSync("onlineShopCart", JSON.stringify(this.cartList))
},
async addProductCount(productId: string) {
this.cartList.forEach((item: any) => {
if (item.productId === productId) {
item.productCount++
}
})
await this.updateShopCart()
await this.getShopCart()
},
// 购物车商品项数量减一
async removeProductCount(productId: string) {
this.cartList.forEach((item: any) => {
if (item.productId === productId) {
@@ -48,11 +41,23 @@ export const useProsperityCartStore = defineStore("prosperityCartStore", {
await this.updateShopCart()
await this.getShopCart()
},
async getShopCart(merchantId: string) {
const { data } = await orderApi.getShopCar({ merchantId, hardType: "SUPERMARKET" })
this.cartList = data
// 购物车商品项数量加一
async addProductCount(productId: string) {
this.cartList.forEach((item: any) => {
if (item.productId === productId) {
item.productCount++
}
})
await this.updateShopCart()
await this.getShopCart()
},
async updateShopCart() {
// 获取购物车商品列表
async getShopCart(merchantId: string) {
const { data } = await orderApi.getShopCar({ merchantId, hardType: "FARMER" })
this.cartList = data ?? []
},
// 更新购物车商品列表
async updateShopCart(merchantId: string) {
const list = this.cartList
.filter((v) => v.productCount && v.productCount > 0)
.map((v) => {
@@ -61,8 +66,8 @@ export const useProsperityCartStore = defineStore("prosperityCartStore", {
productId: v.productId,
}
})
const { code }: any = await orderApi.updateShopCar({ merchantId: this.shopMerchantId, list, hardType: "SUPERMARKET" })
if (code == 0) return await this.getShopCart()
const { code }: any = await orderApi.updateShopCar({ merchantId, list, hardType: "FARMER" })
if (code == 0) return await this.getShopCart(merchantId)
uni.showToast({ title: "更新购物车失败", icon: "none" })
},
},