fix: 订单管理页面调整增加退款功能,代客下单调整
This commit is contained in:
@@ -1,20 +1,38 @@
|
||||
import { store } from "@/store";
|
||||
import WebSocketManager, { type ApifoxModel, msgType } from "@/utils/websocket";
|
||||
import orderApi from "@/api/order/order";
|
||||
import { useUserStore } from "@/store/modules/user";
|
||||
|
||||
const shopUser = useUserStore();
|
||||
export interface CartsState {
|
||||
id: string | number;
|
||||
[property: string]: any;
|
||||
}
|
||||
|
||||
export const useCartsStore = defineStore("carts", () => {
|
||||
//选择用户
|
||||
const vipUser = ref<{ id?: string | number, isVip?: boolean }>({});
|
||||
function changeUser(user: any) {
|
||||
vipUser.value = user;
|
||||
}
|
||||
|
||||
|
||||
//是否启用会员价
|
||||
const useVipPrice = computed(() => {
|
||||
return shopUser.userInfo.isMemberPrice && vipUser.value.id && vipUser.value.isVip
|
||||
})
|
||||
|
||||
//台桌id
|
||||
const table_code = ref('');
|
||||
|
||||
|
||||
//当前购物车数据
|
||||
const list = useStorage<any[]>("carts", []);
|
||||
//历史订单数据
|
||||
const oldOrder = useStorage<any>("Instead_olold_order", {
|
||||
detailMap: [],
|
||||
originAmount: 0
|
||||
});
|
||||
|
||||
//代客下单页面商品缓存
|
||||
const goods = useStorage<any[]>("Instead_goods", []);
|
||||
//赠菜
|
||||
@@ -22,8 +40,13 @@ export const useCartsStore = defineStore("carts", () => {
|
||||
let goodsMap: { [key: string]: any } = useStorage('Instead_goods_map', {});
|
||||
//当前选中cart
|
||||
let selListIndex = ref(-1);
|
||||
|
||||
//当前选中商品是否是赠菜
|
||||
const isSelGift = ref(false);
|
||||
//当前选中是否是历史订单
|
||||
const isOldOrder = ref(false);
|
||||
//选中历史订单中的第几次下单
|
||||
const selPlaceNum = ref(-1);
|
||||
const defaultCart = {
|
||||
id: '',
|
||||
number: 0,
|
||||
@@ -34,6 +57,9 @@ export const useCartsStore = defineStore("carts", () => {
|
||||
})
|
||||
//当前购物车选中数据
|
||||
const selCart = computed(() => {
|
||||
if (isOldOrder.value && selPlaceNum.value >= 0) {
|
||||
return oldOrder.value.detailMap[selPlaceNum.value][selListIndex.value]
|
||||
}
|
||||
if (isSelGift.value) {
|
||||
return giftList.value[selListIndex.value] || defaultCart
|
||||
}
|
||||
@@ -56,6 +82,29 @@ export const useCartsStore = defineStore("carts", () => {
|
||||
return acc + cur.number * cur.salePrice
|
||||
}, 0)
|
||||
})
|
||||
//打包数量
|
||||
const packNum = computed(() => {
|
||||
const nowCartNumber = list.value.reduce((acc: number, cur: any) => {
|
||||
return acc + cur.pack_number * 1
|
||||
}, 0)
|
||||
const giftNumber = giftList.value.reduce((acc: number, cur: any) => {
|
||||
return acc + cur.pack_number * 1
|
||||
}, 0)
|
||||
return nowCartNumber + giftNumber
|
||||
})
|
||||
//打包费
|
||||
const packFee = computed(() => {
|
||||
const nowPackFee = list.value.reduce((acc: number, cur: any) => {
|
||||
return acc + (cur.packFee || 0) * cur.pack_number
|
||||
}, 0)
|
||||
const giftPackFee = giftList.value.reduce((acc: number, cur: any) => {
|
||||
return acc + (cur.packFee || 0) * cur.pack_number
|
||||
}, 0)
|
||||
return nowPackFee + giftPackFee
|
||||
})
|
||||
|
||||
|
||||
// 优惠
|
||||
const yiyouhui = computed(() => {
|
||||
const youhui = giftMoney.value
|
||||
if (youhui > 0) {
|
||||
@@ -67,14 +116,11 @@ export const useCartsStore = defineStore("carts", () => {
|
||||
//支付总价
|
||||
const payMoney = computed(() => {
|
||||
const money = list.value.reduce((acc: number, cur: any) => {
|
||||
if (cur.is_temporary) {
|
||||
//临时菜
|
||||
return acc + cur.number * (cur.discount_sale_amount)
|
||||
} else {
|
||||
return acc + cur.number * (cur.salePrice)
|
||||
}
|
||||
const memberPrice = cur.skuData ? (cur.skuData.memberPrice || cur.skuData.salePrice) : 0
|
||||
const price = (cur.discount_sale_amount * 1 || cur.salePrice || 0)
|
||||
return acc + cur.number * (useVipPrice.value ? memberPrice : price)
|
||||
}, 0)
|
||||
return money.toFixed(2)
|
||||
return (money + packFee.value).toFixed(2)
|
||||
})
|
||||
//总计数量
|
||||
const totalNumber = computed(() => {
|
||||
@@ -102,6 +148,21 @@ export const useCartsStore = defineStore("carts", () => {
|
||||
if (!cart.id) {
|
||||
return
|
||||
}
|
||||
if (cart.placeNum) {
|
||||
selPlaceNum.value = cart.placeNum
|
||||
isOldOrder.value = true
|
||||
console.log(oldOrder.value.detailMap[cart.placeNum])
|
||||
selListIndex.value = oldOrder.value.detailMap[cart.placeNum].findIndex((item: CartsState) => {
|
||||
return item.id == cart.id
|
||||
})
|
||||
return
|
||||
}
|
||||
if (cart.is_gift) {
|
||||
isSelGift.value = true
|
||||
} else {
|
||||
isSelGift.value = false
|
||||
}
|
||||
|
||||
if (cart.is_gift) {
|
||||
isSelGift.value = true
|
||||
selListIndex.value = giftList.value.findIndex((item: CartsState) => item.id === cart.id);
|
||||
@@ -119,7 +180,8 @@ export const useCartsStore = defineStore("carts", () => {
|
||||
is_temporary: 0,
|
||||
discount_sale_amount: 0,
|
||||
discount_sale_note: "",
|
||||
is_print: 0,
|
||||
is_print: 1,
|
||||
pro_group_info: '',
|
||||
is_wait_call: 0,
|
||||
product_name: "",
|
||||
remark: "",
|
||||
@@ -156,6 +218,8 @@ export const useCartsStore = defineStore("carts", () => {
|
||||
new_table_code: newVal,
|
||||
id: list.value[0].id
|
||||
});
|
||||
} else {
|
||||
table_code.value = `${newVal}`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,9 +240,19 @@ export const useCartsStore = defineStore("carts", () => {
|
||||
}
|
||||
sendMessage('edit', { ...cart, [key]: val });
|
||||
}
|
||||
|
||||
function clear() {
|
||||
sendMessage('cleanup', {});
|
||||
}
|
||||
function dataReset() {
|
||||
list.value = [];
|
||||
giftList.value = [];
|
||||
selListIndex.value = -1
|
||||
selPlaceNum.value = 1
|
||||
isOldOrder.value = false
|
||||
selListIndex.value = -1;
|
||||
isSelGift.value = false
|
||||
}
|
||||
|
||||
// 寻找套餐商品sku
|
||||
interface GroupSnap {
|
||||
@@ -200,19 +274,25 @@ export const useCartsStore = defineStore("carts", () => {
|
||||
return undefined
|
||||
}
|
||||
let skuData = undefined;
|
||||
if (goods.type == 'package') {
|
||||
//套餐商品
|
||||
const SnapSku = findInGroupSnapSku(goods.groupSnap, v.sku_id)
|
||||
skuData = { ...SnapSku, salePrice: SnapSku ? SnapSku.price : 0 }
|
||||
} else {
|
||||
skuData = goods?.skuList.find((sku: { id: string, salePrice: number }) => sku.id == v.sku_id);
|
||||
}
|
||||
skuData = goods?.skuList.find((sku: { id: string, salePrice: number }) => sku.id == v.sku_id);
|
||||
|
||||
// if (goods.type == 'package') {
|
||||
// //套餐商品
|
||||
// const SnapSku = findInGroupSnapSku(goods.groupSnap, v.sku_id)
|
||||
// skuData = { ...SnapSku, salePrice: SnapSku ? SnapSku.price : 0 }
|
||||
// } else {
|
||||
// skuData = goods?.skuList.find((sku: { id: string, salePrice: number }) => sku.id == v.sku_id);
|
||||
// }
|
||||
skuData = goods?.skuList.find((sku: { id: string, salePrice: number }) => sku.id == v.sku_id);
|
||||
|
||||
if (skuData) {
|
||||
return {
|
||||
salePrice: skuData ? skuData.salePrice : 0,
|
||||
memberPrice: skuData ? skuData.memberPrice : 0,
|
||||
coverImg: goods.coverImg,
|
||||
name: goods.name,
|
||||
specInfo: skuData.specInfo,
|
||||
packFee: goods.packFee || 0,
|
||||
skuData
|
||||
}
|
||||
} else {
|
||||
@@ -220,10 +300,42 @@ export const useCartsStore = defineStore("carts", () => {
|
||||
}
|
||||
}
|
||||
|
||||
function init(initParams: ApifoxModel, $goodsMap: any) {
|
||||
function returnDetailMap(data: any) {
|
||||
const newData: { [key: string]: any } = {}
|
||||
for (let i in data) {
|
||||
newData[i] = data[i].map((v: any) => {
|
||||
|
||||
const skuData = getProductDetails({ product_id: v.productId, sku_id: v.skuId })
|
||||
|
||||
return {
|
||||
...skuData,
|
||||
placeNum: v.placeNum,
|
||||
number: v.num,
|
||||
id: v.id
|
||||
}
|
||||
})
|
||||
}
|
||||
return newData
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param initParams 购物车初始化参数
|
||||
* @param $goodsMap 商品id对应的map
|
||||
* @param oldOrder 历史订单数据
|
||||
*/
|
||||
|
||||
function init(initParams: ApifoxModel, $goodsMap: any, $oldOrder: any) {
|
||||
// 商品id对应的数据map
|
||||
goodsMap = $goodsMap
|
||||
|
||||
oldOrder.value = {
|
||||
...$oldOrder,
|
||||
detailMap: returnDetailMap($oldOrder.detailMap)
|
||||
}
|
||||
console.log('initParams', initParams)
|
||||
|
||||
table_code.value = initParams && initParams.table_code ? initParams.table_code : '';
|
||||
|
||||
WebSocketManager.subscribeToTopic(initParams, (msg) => {
|
||||
console.log("收到消息:", msg);
|
||||
if (msg.hasOwnProperty('status') && msg.status != 1) {
|
||||
@@ -236,11 +348,17 @@ export const useCartsStore = defineStore("carts", () => {
|
||||
if (msg.data.table_code) {
|
||||
table_code.value = table_code.value ? table_code.value : msg.data.table_code
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 初始化
|
||||
if (msg.operate_type === "manage_init") {
|
||||
// 设置单价
|
||||
list.value = msg.data.filter((v: Record<string, any>) => {
|
||||
if (v.is_temporary) {
|
||||
return v
|
||||
}
|
||||
const skuData = getProductDetails({ product_id: v.product_id, sku_id: v.sku_id })
|
||||
if (skuData) {
|
||||
(Object.keys(skuData) as (keyof typeof skuData)[]).forEach((key) => {
|
||||
@@ -253,6 +371,9 @@ export const useCartsStore = defineStore("carts", () => {
|
||||
return !v.is_gift
|
||||
})
|
||||
giftList.value = msg.data.filter((v: Record<string, any>) => {
|
||||
if (v.is_temporary) {
|
||||
return v && v.is_gift
|
||||
}
|
||||
const skuData = getProductDetails({ product_id: v.product_id, sku_id: v.sku_id })
|
||||
if (skuData) {
|
||||
(Object.keys(skuData) as (keyof typeof skuData)[]).forEach((key) => {
|
||||
@@ -335,13 +456,17 @@ export const useCartsStore = defineStore("carts", () => {
|
||||
if (msg.operate_type === "manage_cleanup") {
|
||||
list.value = []
|
||||
giftList.value = []
|
||||
oldOrder.value = {
|
||||
detailMap: [],
|
||||
originAmount: 0
|
||||
}
|
||||
table_code.value = ''
|
||||
}
|
||||
console.log(list.value)
|
||||
});
|
||||
}
|
||||
|
||||
const delArr = ['skuData', 'coverImg', 'specInfo']
|
||||
const delArr = ['skuData', 'coverImg', 'specInfo', 'placeNum', 'update_time', 'create_time', 'packFee', 'memberPrice']
|
||||
function sendMessage(operate_type: msgType, message: any) {
|
||||
const msg = { ...message, operate_type: operate_type, table_code: table_code.value }
|
||||
if (operate_type == 'edit') {
|
||||
@@ -349,9 +474,16 @@ export const useCartsStore = defineStore("carts", () => {
|
||||
delete msg[delArr[i]]
|
||||
}
|
||||
}
|
||||
console.log('send msg', msg)
|
||||
WebSocketManager.sendMessage(msg);
|
||||
}
|
||||
return {
|
||||
dataReset,
|
||||
useVipPrice,
|
||||
changeUser,
|
||||
packNum, packFee,
|
||||
isOldOrder,
|
||||
oldOrder,
|
||||
isCanSelectGroup,
|
||||
goods,
|
||||
selGoods,
|
||||
|
||||
Reference in New Issue
Block a user