From 745b8675ea837af25581a2064024e07bdad63e85 Mon Sep 17 00:00:00 2001
From: gyq <875626088@qq.com>
Date: Thu, 13 Mar 2025 18:54:10 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=B0=8F=E7=A5=A8=E6=89=93?=
=?UTF-8?q?=E5=8D=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/store/goods.js | 65 ++++++++++++++-
src/store/socket.js | 44 +++-------
src/views/home/components/cartOperation.vue | 80 +++++++++----------
.../home/components/pendingCartModal.vue | 38 +++------
src/views/home/components/tableMerging.vue | 61 +++++++-------
src/views/home/index.vue | 31 ++++---
src/views/order/components/refundDrawer.vue | 20 +++--
src/views/table/index.vue | 35 +++++---
8 files changed, 207 insertions(+), 167 deletions(-)
diff --git a/src/store/goods.js b/src/store/goods.js
index 2900306..e75cd58 100644
--- a/src/store/goods.js
+++ b/src/store/goods.js
@@ -1,4 +1,5 @@
import _ from "lodash";
+import dayjs from "dayjs";
import { defineStore } from "pinia";
import { productPage, categoryList } from "@/api/product_new.js";
import { historyOrder } from "@/api/order.js";
@@ -6,6 +7,7 @@ import { useUser } from "@/store/user.js";
import { useSocket } from "@/store/socket.js";
import useStorage from "@/utils/useStorage.js";
import { formatDecimal } from "@/utils/index.js";
+import { ElMessage } from "element-plus";
// 商品store + 购物车store
export const useGoods = defineStore("goods", {
@@ -45,8 +47,58 @@ export const useGoods = defineStore("goods", {
orderListInfo: "", // 历史订单信息
cartType: "cart", // cart order
cartOrderItem: "",
+ pendingList: useStorage.get("pendingList") || [],
}),
actions: {
+ // 恢复挂单
+ async recoverPending(item) {
+ let socket = useSocket();
+
+ if (this.cartList.length || this.orderList.length) {
+ this.pendingCart();
+ }
+
+ if (item.orderId) {
+ await this.historyOrderAjax(item.tableCode);
+ }
+
+ let pendingList = useStorage.get("pendingList");
+ let index = pendingList.findIndex(
+ (val) => val.tableCode == item.tableCode
+ );
+
+ pendingList.splice(index, 1);
+ useStorage.set("pendingList", pendingList);
+ this.pendingList = useStorage.get("pendingList");
+ useStorage.set("tableCode", item.tableCode);
+ socket.cartInit();
+ },
+ // 开始挂单
+ pendingCart() {
+ let cart = this.cartList;
+ let order = this.orderList;
+
+ if (cart.length || order.length) {
+ let pendingList = useStorage.get("pendingList") || [];
+ pendingList.push({
+ tableCode: cart[0].table_code || this.orderListInfo.tableCode,
+ productName: [
+ ...cart.map((item) => item.product_name),
+ ...order
+ .map((item) => item.goods)
+ .flat()
+ .map((item) => item.product_name),
+ ].join("、"),
+ orderId: order.length && this.orderListInfo.id,
+ totalAmount: this.cartInfo.totalAmount,
+ pendingAt: dayjs().format("YYYY-MM-DD HH:mm:ss"),
+ });
+
+ useStorage.set("pendingList", pendingList);
+ this.pendingList = useStorage.get("pendingList");
+ useStorage.del("tableCode");
+ }
+ },
// 选中订单中的商品
selectOrderItem(index = null, i) {
this.orderList.map((item) => {
@@ -220,7 +272,12 @@ export const useGoods = defineStore("goods", {
async getCartList(arr) {
const store = useUser();
+ let numCount = 0;
+ let packCount = 0;
+
arr.map((val, index) => {
+ numCount += +val.number;
+ packCount += +val.pack_number;
val = this.completeGoodsInfo(val);
val.active = false;
if (!this.isCartInit && index == 0) {
@@ -228,6 +285,12 @@ export const useGoods = defineStore("goods", {
}
});
+ if (packCount > 0 && packCount == numCount) {
+ this.allSelected = 1;
+ } else {
+ this.allSelected = 0;
+ }
+
this.cartList = arr;
this.isCartInit = true;
@@ -267,7 +330,7 @@ export const useGoods = defineStore("goods", {
product_id: params.productId || "",
sku_id: params.id || "",
number: params.number || 1,
- pack_number: params.is_pack || 0,
+ pack_number: this.allSelected ? params.number : 0,
is_gift: params.is_gift || 0,
is_temporary: params.is_temporary || 0,
discount_sale_amount: params.discount_sale_amount || 0,
diff --git a/src/store/socket.js b/src/store/socket.js
index 1938e9b..8941af6 100644
--- a/src/store/socket.js
+++ b/src/store/socket.js
@@ -119,6 +119,10 @@ export const useSocket = defineStore("socket", {
// 清空购物车
goodsStore.successClearCart();
break;
+ case "batch":
+ // 打包
+ this.cartInit();
+ break;
default:
break;
}
@@ -127,37 +131,12 @@ export const useSocket = defineStore("socket", {
}
} else if (data.data_type == "order") {
// 收到订单消息,打印订单小票
- // this.orderList.push(data.data);
- // this.startPrintInterval();
+ if (!this.orderList.some((el) => el == data.data)) {
+ // 防止重复打印
+ this.orderList.push(data.data);
+ this.startPrintInterval();
+ }
}
-
- // if (data.data_type == "cart" && data.operate_type == "init") {
- // // 购物车消息
- // goodsStore.getCartList(data.data);
- // } else if (data.data_type == "order") {
- // // 接收订单消息,打印小票
- // if (this.log) console.log("接收消息", data);
- // this.ws.send(
- // JSON.stringify({
- // type: "send",
- // orderNo: data.orderInfo.orderNo,
- // })
- // );
- // // 接收订单消息,打印小票
- // // printBill(data)
- // // 打印标签小票
- // if (!this.orderList.some((el) => el == data.orderInfo.orderNo)) {
- // // console.log("打印", data);
- // printStore.labelPrint(data);
- // printStore.pushReceiptData(data);
- // this.orderList.push(data.orderInfo.orderNo);
- // if (this.orderList.length > 30) {
- // this.orderList.splice(0, 1);
- // }
- // }
- // } else if (data.data_type == "heartbeat") {
- // if (this.log) console.log("接收心跳");
- // }
});
this.ws.addEventListener("error", () => {
@@ -190,14 +169,15 @@ export const useSocket = defineStore("socket", {
const printStore = usePrint();
if (this.orderListTimer !== null) return;
this.orderListTimer = setInterval(async () => {
- console.log("隔2秒执行===", this.orderList);
try {
if (!this.orderList.length) {
clearInterval(this.orderListTimer);
this.orderListTimer = null;
} else {
const orderInfo = await getOrderByIdAjax(this.orderList[0]);
- printStore.pushReceiptData(commOrderPrintData(orderInfo));
+ if (orderInfo.status == "done" && orderInfo.platformType != "PC") {
+ printStore.pushReceiptData(commOrderPrintData(orderInfo));
+ }
this.orderList.splice(0, 1);
}
} catch (error) {
diff --git a/src/views/home/components/cartOperation.vue b/src/views/home/components/cartOperation.vue
index 7939ada..46ba763 100644
--- a/src/views/home/components/cartOperation.vue
+++ b/src/views/home/components/cartOperation.vue
@@ -68,12 +68,12 @@