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

@@ -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
? refTable.value.getSelectionRows().map((v) => v.id)
: props.cartGoods.map((v) => v.id);
let detailIds = [];
let cart_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
.mergeOrder({
...form,