fix: 修改优化转桌功能

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

View File

@ -327,16 +327,18 @@ export const useCartsStore = defineStore("carts", () => {
// 换桌
function changeTable(newVal: string | number) {
if (table_code.value) {
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) {
sendMessage('del', { id: data.id });
}
@ -684,7 +686,8 @@ export const useCartsStore = defineStore("carts", () => {
selCart, totalNumber,
changeSelCart, payMoney,
clear, yiyouhui, giftList,
changeTable
changeTable,
rotTable
};
});

View File

@ -17,14 +17,25 @@
<el-radio value="1" border>并桌(并台会将全部购物车商品转入)</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="购物车商品" v-if="rottableType == 0">
<el-table border :data="cartGoods" ref="refTable">
<el-form-item label="购物车商品" v-if="rottableType == 0" label-position="top">
<el-table border :data="nowCartGoods" ref="refTable">
<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>
</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>
<template #footer>
<el-button @click="close">取消</el-button>
@ -37,14 +48,10 @@
import tableApi from "@/api/account/table";
import orderApi from "@/api/order/order";
const props = defineProps({
cartGoods: {
type: Array,
default: () => [],
},
});
const refForm = ref();
// table
const oldTableRef = ref([]);
let rottableType = ref("0");
const basicForm = {
@ -61,12 +68,18 @@ const rules = {
};
function reset() {
Object.assign(form, basicForm);
nowCartGoods.value = [];
oldCartGoods.value = {};
}
const show = ref(false);
function open(obj) {
const nowCartGoods = ref([]);
const oldCartGoods = ref({});
function open(obj, nowCart, oldCart) {
Object.assign(form, obj);
show.value = true;
nowCartGoods.value = nowCart;
oldCartGoods.value = oldCart;
}
function close() {
show.value = false;
@ -78,14 +91,44 @@ function getTableList() {
tableList.value = res.records.filter((v) => v.tableCode);
});
}
const emits = defineEmits(["success"]);
const emits = defineEmits(["success", "confirm"]);
function confirm() {
refForm.value.validate((valid, fields) => {
if (valid) {
console.log("submit!");
const detailIds = !rottableType.value
let detailIds = [];
let cart_id = [];
cart_id =
rottableType.value == 0
? refTable.value.getSelectionRows().map((v) => v.id)
: props.cartGoods.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
.mergeOrder({
...form,

View File

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