feat: 增加代课下单收到商品信息变动时重新获取商品信息初始化购物车数据
This commit is contained in:
@@ -3,6 +3,7 @@ import WebSocketManager, { type ApifoxModel, msgType } from "@/utils/websocket";
|
||||
import orderApi from "@/api/order/order";
|
||||
import { useUserStoreHook } from "@/store/modules/user";
|
||||
import { customTruncateToTwoDecimals } from '@/utils/tools'
|
||||
import productApi from "@/api/product/index";
|
||||
|
||||
const shopUser = useUserStoreHook();
|
||||
export interface CartsState {
|
||||
@@ -43,6 +44,24 @@ export const useCartsStore = defineStore("carts", () => {
|
||||
|
||||
//代客下单页面商品缓存
|
||||
const goods = useStorage<any[]>("Instead_goods", []);
|
||||
async function getGoods(query: any) {
|
||||
const res = await productApi.getPage({
|
||||
page: 1,
|
||||
size: 999,
|
||||
status: "on_sale",
|
||||
...query,
|
||||
});
|
||||
goods.value = res.records;
|
||||
setGoodsMap(goods.value)
|
||||
}
|
||||
|
||||
function setGoodsMap(goods: any[]) {
|
||||
for (let item of goods) {
|
||||
goodsMap[item.id] = item;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//赠菜
|
||||
const giftList = useStorage<any[]>("giftList", []);
|
||||
let goodsMap: { [key: string]: any } = useStorage('Instead_goods_map', {});
|
||||
@@ -326,8 +345,10 @@ export const useCartsStore = defineStore("carts", () => {
|
||||
}
|
||||
|
||||
// 换桌
|
||||
function changeTable(newVal: string | number) {
|
||||
function changeTable(newVal: string | undefined) {
|
||||
table_code.value = `${newVal}`;
|
||||
$initParams.table_code = newVal
|
||||
concocatSocket()
|
||||
}
|
||||
//转桌
|
||||
function rotTable(newVal: string | number, cart_id = []) {
|
||||
@@ -415,7 +436,9 @@ export const useCartsStore = defineStore("carts", () => {
|
||||
//获取历史订单
|
||||
async function getOldOrder(table_code: string | number) {
|
||||
const res = await orderApi.getHistoryList({ tableCode: table_code })
|
||||
setOldOrder(res)
|
||||
if (res) {
|
||||
setOldOrder(res)
|
||||
}
|
||||
}
|
||||
|
||||
function getProductDetails(v: { product_id: string, sku_id: string }) {
|
||||
@@ -497,13 +520,14 @@ export const useCartsStore = defineStore("carts", () => {
|
||||
|
||||
|
||||
|
||||
function init(initParams: ApifoxModel, $goodsMap: any, $oldOrder: any) {
|
||||
async function init(initParams: ApifoxModel, $oldOrder: any | undefined) {
|
||||
// 商品id对应的数据map
|
||||
if ($goodsMap) {
|
||||
goodsMap = $goodsMap
|
||||
}
|
||||
await getGoods({})
|
||||
|
||||
if ($oldOrder) {
|
||||
setOldOrder($oldOrder)
|
||||
} else {
|
||||
oldOrder.value = { detailMap: [] }
|
||||
}
|
||||
|
||||
// console.log('oldOrder.detailMap', oldOrder.value.detailMap)
|
||||
@@ -639,6 +663,10 @@ export const useCartsStore = defineStore("carts", () => {
|
||||
if (msg.operate_type === "batch") {
|
||||
concocatSocket({ ...$initParams, table_code: table_code.value })
|
||||
}
|
||||
if (msg.operate_type === "product_update") {
|
||||
console.log('商品更新')
|
||||
init($initParams, oldOrder.value)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -687,7 +715,9 @@ export const useCartsStore = defineStore("carts", () => {
|
||||
changeSelCart, payMoney,
|
||||
clear, yiyouhui, giftList,
|
||||
changeTable,
|
||||
rotTable
|
||||
rotTable,
|
||||
getGoods,
|
||||
setGoodsMap
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user