fix: 修改优化转桌功能

This commit is contained in:
2025-03-18 10:20:42 +08:00
parent 90dc61dee8
commit cefabae276
3 changed files with 88 additions and 30 deletions

View File

@@ -327,15 +327,17 @@ export const useCartsStore = defineStore("carts", () => {
// 换桌 // 换桌
function changeTable(newVal: string | number) { function changeTable(newVal: string | number) {
if (table_code.value) { table_code.value = `${newVal}`;
sendMessage('rottable', {
new_table_code: newVal,
table_code: table_code.value
});
} else {
table_code.value = `${newVal}`;
}
} }
//转桌
function rotTable(newVal: string | number, cart_id = []) {
sendMessage('rottable', {
new_table_code: newVal,
table_code: table_code.value,
cart_id
});
}
function del(data: any) { function del(data: any) {
sendMessage('del', { id: data.id }); sendMessage('del', { id: data.id });
@@ -684,7 +686,8 @@ export const useCartsStore = defineStore("carts", () => {
selCart, totalNumber, selCart, totalNumber,
changeSelCart, payMoney, changeSelCart, payMoney,
clear, yiyouhui, giftList, clear, yiyouhui, giftList,
changeTable changeTable,
rotTable
}; };
}); });

View File

@@ -17,14 +17,25 @@
<el-radio value="1" border>并桌(并台会将全部购物车商品转入)</el-radio> <el-radio value="1" border>并桌(并台会将全部购物车商品转入)</el-radio>
</el-radio-group> </el-radio-group>
</el-form-item> </el-form-item>
<el-form-item label="购物车商品" v-if="rottableType == 0"> <el-form-item label="购物车商品" v-if="rottableType == 0" label-position="top">
<el-table border :data="cartGoods" ref="refTable"> <el-table border :data="nowCartGoods" ref="refTable">
<el-table-column type="selection" width="55" /> <el-table-column type="selection" width="55" />
<el-table-column label="商品" prop="name"></el-table-column> <el-table-column label="商品" prop="name"></el-table-column>
<el-table-column label="数量" prop="number"></el-table-column> <el-table-column label="数量" prop="number"></el-table-column>
<el-table-column label="商品" prop="name"></el-table-column> <el-table-column label="商品" prop="name"></el-table-column>
</el-table> </el-table>
</el-form-item> </el-form-item>
<el-form-item label="历史订单商品" v-if="rottableType == 0" label-position="top">
<div v-for="(oldGoods, index) in oldCartGoods" :key="index" style="width: 100%">
<h4>{{ index }} 次下单</h4>
<el-table border :data="oldGoods" ref="oldTableRef">
<el-table-column type="selection" width="55" />
<el-table-column label="商品" prop="name"></el-table-column>
<el-table-column label="数量" prop="number"></el-table-column>
<el-table-column label="商品" prop="name"></el-table-column>
</el-table>
</div>
</el-form-item>
</el-form> </el-form>
<template #footer> <template #footer>
<el-button @click="close">取消</el-button> <el-button @click="close">取消</el-button>
@@ -37,14 +48,10 @@
import tableApi from "@/api/account/table"; import tableApi from "@/api/account/table";
import orderApi from "@/api/order/order"; import orderApi from "@/api/order/order";
const props = defineProps({
cartGoods: {
type: Array,
default: () => [],
},
});
const refForm = ref(); const refForm = ref();
// 历史订单table
const oldTableRef = ref([]);
let rottableType = ref("0"); let rottableType = ref("0");
const basicForm = { const basicForm = {
@@ -61,12 +68,18 @@ const rules = {
}; };
function reset() { function reset() {
Object.assign(form, basicForm); Object.assign(form, basicForm);
nowCartGoods.value = [];
oldCartGoods.value = {};
} }
const show = ref(false); const show = ref(false);
function open(obj) { const nowCartGoods = ref([]);
const oldCartGoods = ref({});
function open(obj, nowCart, oldCart) {
Object.assign(form, obj); Object.assign(form, obj);
show.value = true; show.value = true;
nowCartGoods.value = nowCart;
oldCartGoods.value = oldCart;
} }
function close() { function close() {
show.value = false; show.value = false;
@@ -78,14 +91,44 @@ function getTableList() {
tableList.value = res.records.filter((v) => v.tableCode); tableList.value = res.records.filter((v) => v.tableCode);
}); });
} }
const emits = defineEmits(["success"]); const emits = defineEmits(["success", "confirm"]);
function confirm() { function confirm() {
refForm.value.validate((valid, fields) => { refForm.value.validate((valid, fields) => {
if (valid) { if (valid) {
console.log("submit!"); console.log("submit!");
const detailIds = !rottableType.value let detailIds = [];
? refTable.value.getSelectionRows().map((v) => v.id) let cart_id = [];
: props.cartGoods.map((v) => v.id); cart_id =
rottableType.value == 0
? refTable.value.getSelectionRows().map((v) => v.id)
: nowCartGoods.value.map((v) => v.id);
if (rottableType.value == 0) {
for (let i = 0; i < oldTableRef.value.length; i++) {
const table = oldTableRef.value[i];
const detailId = table.getSelectionRows().map((v) => v.id);
detailIds.push(...detailId);
}
} else {
for (let i in oldCartGoods.value) {
detailIds.push(...oldCartGoods.value[i].map((v) => v.id));
}
}
if (detailIds.length == 0 && cart_id.length == 0) {
return ElNotification({
title: "失败",
message: "请选择商品",
type: "error",
});
}
emits(
"confirm",
{
...form,
detailIds,
},
cart_id
);
return;
orderApi orderApi
.mergeOrder({ .mergeOrder({
...form, ...form,

View File

@@ -217,7 +217,7 @@
<!-- 美团抖音核销 --> <!-- 美团抖音核销 -->
<quan-hexiao ref="refQuanHexiao"></quan-hexiao> <quan-hexiao ref="refQuanHexiao"></quan-hexiao>
<!-- 转桌 --> <!-- 转桌 -->
<rottable ref="refRotTable" :cartGoods="carts.list" @success="rottableSuccess"></rottable> <rottable ref="refRotTable" @confirm="rottableConfirm"></rottable>
</div> </div>
</template> </template>
<script setup> <script setup>
@@ -267,13 +267,25 @@ function refChangeNumberConfirm(cart, num) {
//转桌 //转桌
const refRotTable = ref(); const refRotTable = ref();
function rottableShow() { function rottableShow() {
refRotTable.value.open({ refRotTable.value.open(
sourceOrderId: carts.oldOrder.id, {
}); sourceOrderId: carts.oldOrder.id,
},
carts.list,
carts.oldOrder.detailMap
);
} }
async function rottableSuccess(tableCode) { async function rottableConfirm(form, cart_id) {
const res = await getTableDetail({ tableCode: tableCode }); carts.rotTable(form.targetTableCode, cart_id);
tableClick(res); const res = await orderApi.mergeOrder(form);
ElNotification({
title: "成功",
message: "合并成功",
type: "success",
});
refRotTable.value.close();
const res1 = await getTableDetail({ tableCode: form.targetTableCode });
tableClick(res1);
} }
//美团抖音核销 //美团抖音核销