优化订单小票打印
This commit is contained in:
@@ -262,11 +262,12 @@ import { inputFilterFloat, formatDecimal, getOrderByIdAjax, commOrderPrintData }
|
||||
import { refundOrder } from '@/api/order.js'
|
||||
import { useSocket } from '@/store/socket.js'
|
||||
import { usePrint } from '@/store/print.js'
|
||||
import { useUser } from '@/store/user.js'
|
||||
|
||||
const goodsStore = useGoods()
|
||||
const socket = useSocket()
|
||||
const printStore = usePrint()
|
||||
|
||||
const store = useUser()
|
||||
const tableMergingRef = ref(null)
|
||||
|
||||
const props = defineProps({
|
||||
@@ -337,7 +338,9 @@ async function returnOrderItemAjax(num = 1) {
|
||||
returnAmount: goodsStore.cartOrderItem.lowPrice,
|
||||
num: num
|
||||
}
|
||||
]
|
||||
],
|
||||
operator: store.userInfo.name || store.shopInfo.shopName,
|
||||
print: printStore.deviceNoteList.length ? false : true
|
||||
}
|
||||
await refundOrder(data)
|
||||
goodsStore.cartOrderItem.returnNum += num
|
||||
@@ -345,19 +348,13 @@ async function returnOrderItemAjax(num = 1) {
|
||||
|
||||
getOrderByIdAjax(goodsStore.orderListInfo.id).then(res => {
|
||||
let originOrderInfo = res
|
||||
console.log('originOrderInfo1===', originOrderInfo);
|
||||
|
||||
console.log('goodsStore.cartOrderItem.id', goodsStore.cartOrderItem.id);
|
||||
|
||||
let index = originOrderInfo.cartList.findIndex(item => item.id == goodsStore.cartOrderItem.id)
|
||||
|
||||
console.log('index===', index);
|
||||
|
||||
originOrderInfo.cartList = _.at(originOrderInfo.cartList, index);
|
||||
console.log('originOrderInfo2===', originOrderInfo);
|
||||
// return
|
||||
originOrderInfo.cartList[0].num = num
|
||||
originOrderInfo.cartList[0].returnNum = 0
|
||||
originOrderInfo.cartList[0].payAmount = num * originOrderInfo.cartList[0].price
|
||||
|
||||
printStore.printRefund(commOrderPrintData({ ...originOrderInfo, isGuest: false, isBefore: false, title: '退菜单' }));
|
||||
printStore.printRefundDish(commOrderPrintData({ ...originOrderInfo, isRefundDish: true }));
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
})
|
||||
|
||||
@@ -204,14 +204,55 @@ const printHandle = _.throttle(async function () {
|
||||
await printOrderLable(true)
|
||||
}, 1500, { leading: true, trailing: false })
|
||||
|
||||
|
||||
// 在 usePrint 的 actions 中添加(比如放在 pushReceiptData 方法下方)
|
||||
function calcAllCartsTotalSum(cartObj) {
|
||||
// 初始化总和为0
|
||||
let totalSum = 0;
|
||||
// 遍历原始对象的所有键(0、1、2...)
|
||||
Object.keys(cartObj).forEach(key => {
|
||||
const carts = cartObj[key] || [];
|
||||
// 累加当前分类下的菜品总价(num × unitPrice)
|
||||
carts.forEach(item => {
|
||||
const num = Number(item.num) - Number(item.returnNum) || 0; // 防错:非数字转0
|
||||
const unitPrice = Number(item.unitPrice) || 0;
|
||||
totalSum += num * unitPrice;
|
||||
});
|
||||
});
|
||||
return totalSum; // 返回所有菜品的总价总和
|
||||
}
|
||||
|
||||
// 打印订单标签
|
||||
async function printOrderLable(isBefore = false) {
|
||||
try {
|
||||
let orderId = goodsStore.orderListInfo.id
|
||||
const data = await getOrderByIdAjax(orderId);
|
||||
let data = await getOrderByIdAjax(orderId);
|
||||
|
||||
console.log(`打印订单标签数据${isBefore}===`, data);
|
||||
|
||||
if (isBefore) {
|
||||
data.originAmount = calcAllCartsTotalSum(data.detailMap)
|
||||
}
|
||||
|
||||
if (data.seatAmount > 0 && data.dineMode == 'dine-in' && isBefore) {
|
||||
data.originAmount += data.seatAmount
|
||||
}
|
||||
|
||||
let packFee = 0
|
||||
|
||||
data.cartList.forEach(item => {
|
||||
packFee += item.num - item.returnNum * item.packAmount
|
||||
})
|
||||
|
||||
if (packFee > 0 && isBefore) {
|
||||
data.originAmount += packFee
|
||||
data.packFee = packFee
|
||||
}
|
||||
|
||||
let printList = useStorage.get("printList") || [];
|
||||
|
||||
console.log('printStore.deviceNoteList.length:', printStore.deviceNoteList.length);
|
||||
|
||||
// 防止重复打印
|
||||
if (!printList.some((el) => el == orderId)) {
|
||||
if (!isBefore) {
|
||||
@@ -225,7 +266,7 @@ async function printOrderLable(isBefore = false) {
|
||||
printStore.labelPrint(commOrderPrintData(data))
|
||||
}
|
||||
}
|
||||
|
||||
console.log('printStore.deviceNoteList', printStore.deviceNoteList);
|
||||
if (printStore.deviceNoteList.length) {
|
||||
// 使用本地打印机打印
|
||||
printStore.pushReceiptData(commOrderPrintData({ ...data, isBefore: isBefore }));
|
||||
@@ -248,7 +289,7 @@ async function printOrderLable(isBefore = false) {
|
||||
|
||||
// 订单已支付
|
||||
function paySuccess() {
|
||||
// if (isPrint.value) printOrderLable()
|
||||
if (isPrint.value) printOrderLable()
|
||||
emits('success')
|
||||
dialogVisible.value = false;
|
||||
ElMessage.success('支付成功')
|
||||
|
||||
@@ -189,7 +189,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<!-- 备注 -->
|
||||
<remarkModal ref="remarkRef" @success="(e) => (remark = e)" />
|
||||
<remarkModal ref="remarkRef" @success="(e) => (goodsStore.remark = e)" />
|
||||
<!-- 修改取餐号 -->
|
||||
<takeFoodCode />
|
||||
<el-drawer v-model="membershow" :with-header="true" size="90%" title="选择会员">
|
||||
@@ -197,7 +197,7 @@
|
||||
</el-drawer>
|
||||
<!-- <takeFoodCode ref="takeFoodCodeRef" title="修改取餐号" placeholder="请输入取餐号" @success="takeFoodCodeSuccess" /> -->
|
||||
<!-- 结算订单 -->
|
||||
<settleAccount ref="settleAccountRef" :cart="cartList" :amount="cartInfo.totalAmount" :remark="remark"
|
||||
<settleAccount ref="settleAccountRef" :cart="cartList" :amount="cartInfo.totalAmount" :remark="goodsStore.remark"
|
||||
:orderInfo="orderInfo" @success="" />
|
||||
<!-- 快捷收银 -->
|
||||
<fastCashier ref="fastCashierRef" type="0" />
|
||||
@@ -253,7 +253,6 @@ const pendingCartModalRef = ref(null);
|
||||
const settleAccountRef = ref(null);
|
||||
const fastCashierRef = ref(null);
|
||||
const tableMergingRef = ref(null)
|
||||
const remark = ref("");
|
||||
const cartListActive = ref(0);
|
||||
const cartListActiveItem = ref({})
|
||||
const cartList = ref([]);
|
||||
@@ -310,7 +309,7 @@ async function createOrderHandle(t = 0) {
|
||||
originAmount: goodsStore.cartInfo.costSummary.goodsOriginalAmount,
|
||||
tableCode: goodsStore.cartList[0].table_code, // 台桌号
|
||||
dineMode: goodsStore.allSelected ? store.shopInfo.eatModel.split(',')[1] : store.shopInfo.eatModel.split(',')[0], // 用餐方式
|
||||
remark: remark.value, // 备注
|
||||
remark: goodsStore.remark, // 备注
|
||||
placeNum: placeNum + 1, // 下单次数
|
||||
waitCall: 0, // 是否叫号
|
||||
userId: goodsStore.vipUserInfo.userId || '', // 会员用户id
|
||||
@@ -331,16 +330,31 @@ async function createOrderHandle(t = 0) {
|
||||
} else {
|
||||
goodsStore.clearCart()
|
||||
// 开始打印客看单,可看单需要剔除其他历史下单
|
||||
getOrderByIdAjax(res.id).then(res => {
|
||||
let originOrderInfo = res
|
||||
originOrderInfo.detailMap = _.at(originOrderInfo.detailMap, placeNum + 1);
|
||||
// getOrderByIdAjax(res.id).then(res => {
|
||||
// let originOrderInfo = res
|
||||
// originOrderInfo.detailMap = _.at(originOrderInfo.detailMap, placeNum + 1);
|
||||
|
||||
console.log('originOrderInfo', originOrderInfo);
|
||||
// console.log('originOrderInfo', originOrderInfo);
|
||||
|
||||
printStore.pushReceiptData(commOrderPrintData({ ...originOrderInfo, isGuest: true, isBefore: true }));
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
})
|
||||
// let amout = 0
|
||||
// originOrderInfo.detailMap.flat().forEach(item => {
|
||||
// amout += item.num * item.unitPrice
|
||||
// });
|
||||
|
||||
// originOrderInfo.originAmount = amout
|
||||
|
||||
// if (originOrderInfo.placeNum == 1 && originOrderInfo.dineMode == 'dine-in') {
|
||||
// originOrderInfo.originAmount += originOrderInfo.seatAmount
|
||||
// }
|
||||
|
||||
// if (originOrderInfo.packFee > 0) {
|
||||
// originOrderInfo.originAmount += originOrderInfo.packFee
|
||||
// }
|
||||
|
||||
// printStore.pushReceiptData(commOrderPrintData({ ...originOrderInfo, isGuest: true, isBefore: false }));
|
||||
// }).catch(err => {
|
||||
// console.log(err);
|
||||
// })
|
||||
}
|
||||
// 清除购物车,更新历史订单
|
||||
goodsStore.updateOrderList()
|
||||
|
||||
@@ -30,11 +30,16 @@
|
||||
<el-table :data="list" height="100%" border stripe>
|
||||
<el-table-column label="记录" prop="name"></el-table-column>
|
||||
<el-table-column label="数量" prop="num"></el-table-column>
|
||||
<el-table-column label="操作时间" prop="expTime"></el-table-column>
|
||||
<el-table-column label="操作" width="150">
|
||||
<el-table-column label="到期时间" prop="expTime"></el-table-column>
|
||||
<el-table-column label="操作" width="250">
|
||||
<template #default="{ row }">
|
||||
<el-button type="danger" :disabled="row.num <= 0"
|
||||
@click="takeWineDialogVisible = true; maxTakeNum = row.num; takeWineForm.id = row.id;">取酒</el-button>
|
||||
<el-button type="primary" @click="viewRecord(row)">查看记录</el-button>
|
||||
<el-button type="danger" :disabled="isExpired(row.expTime) || row.num <= 0"
|
||||
@click="takeWineDialogVisible = true; maxTakeNum = row.num; takeWineForm.id = row.id;">
|
||||
<span v-if="isExpired(row.expTime) || row.status == 2">已过期</span>
|
||||
<span v-else-if="row.num <= 0">已取完</span>
|
||||
<span v-else>取酒</span>
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
@@ -85,12 +90,19 @@
|
||||
</div>
|
||||
</div>
|
||||
</el-dialog>
|
||||
<!-- 存取酒记录弹窗 -->
|
||||
<el-dialog title="记录" width="600px" v-model="showRecordDialogVisible">
|
||||
<el-table :data="recordList" border stripe>
|
||||
<el-table-column label="记录" prop="content"></el-table-column>
|
||||
<el-table-column label="操作时间" prop="time"></el-table-column>
|
||||
</el-table>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted } from "vue";
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { shopStoragePost, storageGoodGet, shopStorageGet, shopStoragePut } from '@/api/product_new'
|
||||
import { shopStoragePost, storageGoodGet, shopStorageGet, shopStoragePut, shopStorageRecord } from '@/api/product_new'
|
||||
|
||||
const props = defineProps({
|
||||
userInfo: {
|
||||
@@ -214,6 +226,30 @@ function init() {
|
||||
list.value = [];
|
||||
}
|
||||
|
||||
function isExpired(expTime) {
|
||||
if (!expTime) return false;
|
||||
const now = new Date();
|
||||
const expDate = new Date(expTime);
|
||||
return expDate < now;
|
||||
}
|
||||
|
||||
// 查看记录
|
||||
const showRecordDialogVisible = ref(false);
|
||||
const recordList = ref([]);
|
||||
async function viewRecord(row) {
|
||||
try {
|
||||
showRecordDialogVisible.value = true;
|
||||
const res = await shopStorageRecord({
|
||||
id: row.id,
|
||||
page: 1,
|
||||
size: 999,
|
||||
});
|
||||
recordList.value = res || [];
|
||||
} catch (error) {
|
||||
console.error('获取存取酒记录失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
function show() {
|
||||
init();
|
||||
drawerVisible.value = true;
|
||||
|
||||
@@ -174,15 +174,15 @@ async function passwordSuccess(e = '') {
|
||||
loading.value = true
|
||||
let rows = tableRef.value.getSelectionRows()
|
||||
let refundDetails = []
|
||||
if (refundType.value != 1) {
|
||||
refundDetails = tableRef.value.getSelectionRows().map(val => {
|
||||
return {
|
||||
id: val.id,
|
||||
returnAmount: val.payAmount,
|
||||
num: val.refund_number
|
||||
}
|
||||
})
|
||||
}
|
||||
// if (refundType.value != 1) {
|
||||
refundDetails = tableRef.value.getSelectionRows().map(val => {
|
||||
return {
|
||||
id: val.id,
|
||||
returnAmount: val.payAmount,
|
||||
num: val.refund_number
|
||||
}
|
||||
})
|
||||
// }
|
||||
|
||||
let data = {
|
||||
orderId: item.value.id,
|
||||
@@ -192,6 +192,8 @@ async function passwordSuccess(e = '') {
|
||||
refundReason: remark.value,
|
||||
refundDetails: refundDetails,
|
||||
pwd: e,
|
||||
operator: store.userInfo.name || store.shopInfo.shopName,
|
||||
print: printStore.deviceNoteList.length ? false : true
|
||||
};
|
||||
|
||||
await refundOrder(data)
|
||||
@@ -269,7 +271,7 @@ async function printRefund(rows) {
|
||||
orderInfo: item.value,
|
||||
outNumber: item.value.id,
|
||||
createdAt: item.value.createTime,
|
||||
refundMethod: cash.value ? '现金' : '原路退回',
|
||||
refundMethod: cash.value ? '线下退款' : '原路退回',
|
||||
printTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
|
||||
}
|
||||
|
||||
@@ -277,10 +279,10 @@ async function printRefund(rows) {
|
||||
data.carts.push(
|
||||
{
|
||||
name: item.productName,
|
||||
number: item.num,
|
||||
number: item.refund_number,
|
||||
skuName: item.skuName,
|
||||
salePrice: formatDecimal(+item.unitPrice),
|
||||
totalAmount: formatDecimal(+item.payAmount)
|
||||
totalAmount: formatDecimal(+item.unitPrice * item.refund_number)
|
||||
}
|
||||
)
|
||||
})
|
||||
@@ -288,8 +290,8 @@ async function printRefund(rows) {
|
||||
printStore.printRefund(data);
|
||||
} else {
|
||||
// 云打印
|
||||
await orderPrint({ id: item.value.id, type: 2 })
|
||||
ElMessage.success('云打印退款单成功')
|
||||
// await orderPrint({ id: item.value.id, type: 2 })
|
||||
// ElMessage.success('云打印退款单成功')
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
</div>
|
||||
<div class="box_content_left_top_item_top">
|
||||
<div style="color:#ff5252; font-size: 30px;">
|
||||
¥{{ formatDecimal(infoData.handAmount || 0) }}
|
||||
¥{{ formatDecimal(infoData.orderTurnover || 0) }}
|
||||
</div>
|
||||
<div style="margin-top: 6px; color: #666;">
|
||||
营业额
|
||||
@@ -36,7 +36,7 @@
|
||||
<div class="box_content_left_top_item">
|
||||
<div class="box_content_left_top_item_botton">
|
||||
<div style=" font-size: 20px;">
|
||||
¥{{ formatDecimal(infoData.cashAmount || 0) }}
|
||||
¥{{ formatDecimal(infoData.cash || 0) }}
|
||||
</div>
|
||||
<div style="margin-top: 6px;">
|
||||
现金支付
|
||||
@@ -179,26 +179,18 @@ const exit = async () => {
|
||||
if (loading.value) return
|
||||
loading.value = true;
|
||||
// await staffPermission('yun_xu_jiao_ban')
|
||||
|
||||
// const res = await handover(isPrint.value)
|
||||
// const data = await handoverData(res)
|
||||
|
||||
const res = '136'
|
||||
const data = { "accountType": "merchant", "alipayAmount": 0, "cashAmount": 38.5, "categoryDataList": [{ "amount": 8.7, "categoryId": "614", "categoryName": "主食", "num": 3, "quantity": 1 }, { "amount": 29.8, "categoryId": "615", "categoryName": "炒菜", "num": 5, "quantity": 4 }], "creditAmount": 0, "handAmount": 38.5, "handoverTime": "2026-04-02 18:19:45", "id": "136", "loginTime": "2026-04-02 18:17:57", "orderCount": 1, "productDataList": [{ "amount": 8.7, "num": 3, "productId": "4037", "productName": "金镶白玉板", "skuId": "6727", "skuName": "" }, { "amount": 8.8, "num": 1, "productId": "4039", "productName": "雪底红梅", "skuId": "6729", "skuName": "" }, { "amount": 1.2, "num": 1, "productId": "4045", "productName": "清蒸鲈鱼", "skuId": "6738", "skuName": "微辣,中度酸" }, { "amount": 2, "num": 1, "productId": "4046", "productName": "四喜丸子", "skuId": "6741", "skuName": "" }, { "amount": 17.8, "num": 2, "productId": "4295", "productName": "小烤串", "skuId": "6990", "skuName": "" }], "quickInAmount": 0, "refundAmount": 0, "shopId": "151", "shopName": "高歌的小店", "staffId": "151", "staffName": "高歌的小店", "vipPay": 0, "vipRecharge": 0, "wechatAmount": 0 }
|
||||
|
||||
// console.log('res===', JSON.stringify(res));
|
||||
// console.log('data===', JSON.stringify(data));
|
||||
|
||||
await handover(printStore.deviceNoteList.length ? 0 : 1)
|
||||
if (printStore.deviceNoteList.length) {
|
||||
printStore.printWork(infoData.value)
|
||||
// 使用本地打印机 打印交班数据
|
||||
data.printTime = dayjs().format('YYYY-MM-DD HH:mm:ss')
|
||||
data.printShop = isPrint.value
|
||||
printStore.printWork(data)
|
||||
} else {
|
||||
// 使用云打印机 打印交班数据
|
||||
await handoverNetworkPrint(data.id)
|
||||
// data.printTime = dayjs().format('YYYY-MM-DD HH:mm:ss')
|
||||
// data.printShop = isPrint.value
|
||||
}
|
||||
// logoutHandle()
|
||||
// else {
|
||||
// // 使用云打印机 打印交班数据
|
||||
// await handoverNetworkPrint(data.id)
|
||||
// }
|
||||
logoutHandle()
|
||||
loading.value = false;
|
||||
} catch (error) {
|
||||
loading.value = false;
|
||||
|
||||
Reference in New Issue
Block a user