优化标签小票打印
This commit is contained in:
parent
87627e7b35
commit
f3dfd4a121
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "vite-electron",
|
"name": "vite-electron",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "1.3.18",
|
"version": "1.3.21",
|
||||||
"main": "dist-electron/main.js",
|
"main": "dist-electron/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "chcp 65001 && vite",
|
"dev": "chcp 65001 && vite",
|
||||||
|
|
|
||||||
|
|
@ -7,12 +7,26 @@
|
||||||
color: #000;
|
color: #000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
html,
|
||||||
|
body {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
padding: 2mm;
|
padding: 2mm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#app {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
.print_view {
|
.print_view {
|
||||||
position: relative;
|
position: relative;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
.print_view .ewm {
|
.print_view .ewm {
|
||||||
width: 50px;
|
width: 50px;
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,23 @@
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
color: #000;
|
color: #000;
|
||||||
}
|
}
|
||||||
|
html,
|
||||||
|
body {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
body {
|
body {
|
||||||
padding: 2mm;
|
padding: 2mm;
|
||||||
}
|
}
|
||||||
|
#app{
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
.print_view {
|
.print_view {
|
||||||
position: relative;
|
position: relative;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
overflow: hidden;
|
||||||
.ewm {
|
.ewm {
|
||||||
$size: 50px;
|
$size: 50px;
|
||||||
width: $size;
|
width: $size;
|
||||||
|
|
|
||||||
141
src/App.vue
141
src/App.vue
|
|
@ -28,15 +28,15 @@ import { useRouter, useRoute } from "vue-router";
|
||||||
import leftMenu from "@/components/leftMenu.vue";
|
import leftMenu from "@/components/leftMenu.vue";
|
||||||
import useStorage from '@/utils/useStorage'
|
import useStorage from '@/utils/useStorage'
|
||||||
import { useUser } from "@/store/user.js";
|
import { useUser } from "@/store/user.js";
|
||||||
import { bySubType } from "@/api/device";
|
|
||||||
import { dayjs, ElMessage } from "element-plus";
|
import { dayjs, ElMessage } from "element-plus";
|
||||||
import { ipcRenderer } from 'electron'
|
|
||||||
import { scanSendMessage } from '@/api/order/index'
|
import { scanSendMessage } from '@/api/order/index'
|
||||||
import { useGlobal } from '@/store/global.js'
|
import { useGlobal } from '@/store/global.js'
|
||||||
import { useSocket } from '@/store/socket.js'
|
import { useSocket } from '@/store/socket.js'
|
||||||
|
import { usePrint } from '@/store/print.js'
|
||||||
|
|
||||||
const global = useGlobal()
|
const global = useGlobal()
|
||||||
const socketStore = useSocket()
|
const socketStore = useSocket()
|
||||||
|
const printStore = usePrint()
|
||||||
|
|
||||||
const leftMenuRef = ref(null)
|
const leftMenuRef = ref(null)
|
||||||
|
|
||||||
|
|
@ -78,16 +78,15 @@ watch(route, (to) => {
|
||||||
} else {
|
} else {
|
||||||
// 打开ws
|
// 打开ws
|
||||||
openWs()
|
openWs()
|
||||||
// setTimeout(() => {
|
|
||||||
// }, 1000)
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 登录成功后开始连接ws
|
// 登录成功后开始连接ws
|
||||||
function openWs() {
|
function openWs() {
|
||||||
if (store.userInfo && store.userInfo.shopId && ws.value == null) {
|
if (store.userInfo && store.userInfo.shopId && ws.value == null) {
|
||||||
bySubTypeAjax();
|
|
||||||
initWebSocket()
|
initWebSocket()
|
||||||
|
// 更新print
|
||||||
|
printStore.init()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -106,134 +105,6 @@ router.beforeEach((to, from) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 小票打印机列表
|
|
||||||
const printList = ref([]);
|
|
||||||
// 标签打印机列表
|
|
||||||
const printLabelList = ref([]);
|
|
||||||
const localPrintList = ref([])
|
|
||||||
|
|
||||||
// 获取打印机状态
|
|
||||||
async function bySubTypeAjax() {
|
|
||||||
try {
|
|
||||||
const res1 = await bySubType({
|
|
||||||
shopId: store.userInfo.shopId,
|
|
||||||
contentType: "local",
|
|
||||||
subType: "cash",
|
|
||||||
});
|
|
||||||
const res2 = await bySubType({
|
|
||||||
shopId: store.userInfo.shopId,
|
|
||||||
contentType: "local",
|
|
||||||
subType: "label",
|
|
||||||
});
|
|
||||||
printList.value = res1;
|
|
||||||
printLabelList.value = res2;
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取本地打印机列表
|
|
||||||
function getPrintList() {
|
|
||||||
ipcRenderer.send("getPrintList");
|
|
||||||
ipcRenderer.on("printList", (event, arg) => {
|
|
||||||
localPrintList.value = arg;
|
|
||||||
// console.log(localPrintList.value);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查本地打印机是否能正常使用
|
|
||||||
function checkLocalPrint(deviceName) {
|
|
||||||
let print = ''
|
|
||||||
for (let item of localPrintList.value) {
|
|
||||||
if (item.name == deviceName) {
|
|
||||||
print = item
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!print.name) {
|
|
||||||
return false
|
|
||||||
} else {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 打印小票
|
|
||||||
function printBill(props) {
|
|
||||||
if (!checkLocalPrint(printLabelList.value[0].config.deviceName)) {
|
|
||||||
ElMessage.error("本地打印机无法使用,请检查打印机是否正确连接");
|
|
||||||
} else {
|
|
||||||
const data = {
|
|
||||||
shop_name: store.userInfo.merchantName,
|
|
||||||
carts: props.carts,
|
|
||||||
amount: props.amount,
|
|
||||||
remark: props.remark,
|
|
||||||
orderInfo: props.orderInfo,
|
|
||||||
deviceName: printList.value[0].config.deviceName,
|
|
||||||
createdAt: dayjs(props.orderInfo.createdAt).format(
|
|
||||||
"YYYY-MM-DD HH:mm:ss"
|
|
||||||
),
|
|
||||||
printTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
|
|
||||||
};
|
|
||||||
ipcRenderer.send("printerInfoSync", JSON.stringify(data));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检测是否打印标签小票
|
|
||||||
function checkLabelPrint(props) {
|
|
||||||
if (!checkLocalPrint(printLabelList.value[0].config.deviceName)) {
|
|
||||||
ElMessage.error("本地打印机无法使用,请检查打印机是否正确连接");
|
|
||||||
} else {
|
|
||||||
let pids = printLabelList.value[0].config.categoryList.map(item => item.id)
|
|
||||||
let labelList = []
|
|
||||||
|
|
||||||
// let count = 0
|
|
||||||
// let sum = 0
|
|
||||||
|
|
||||||
// props.carts.map(item => {
|
|
||||||
// if (pids.some(el => el == item.categoryId)) {
|
|
||||||
// for (let i = 0; i < item.number; i++) {
|
|
||||||
// sum++
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
|
|
||||||
props.carts.map(item => {
|
|
||||||
if (pids.some(el => el == item.categoryId)) {
|
|
||||||
for (let i = 0; i < item.number; i++) {
|
|
||||||
// count++
|
|
||||||
labelList.push(
|
|
||||||
{
|
|
||||||
outNumber: props.outNumber,
|
|
||||||
name: item.name,
|
|
||||||
skuName: item.skuName,
|
|
||||||
masterId: props.orderInfo.tableName,
|
|
||||||
deviceName: printLabelList.value[0].config.deviceName,
|
|
||||||
createdAt: dayjs(props.createdAt).format('YYYY-MM-DD HH:mm:ss'),
|
|
||||||
// count: `${count}/${sum}`
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
printLabel(labelList)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 打印标签
|
|
||||||
function printLabel(list) {
|
|
||||||
// console.log(list);
|
|
||||||
if (!checkLocalPrint(printLabelList.value[0].config.deviceName)) {
|
|
||||||
ElMessage.error("本地打印机无法使用,请检查打印机是否正确连接");
|
|
||||||
} else {
|
|
||||||
for (let i = 0; i <= list.length - 1; i++) {
|
|
||||||
// ipcRenderer.send('printerTagSync', JSON.stringify(list[i]))
|
|
||||||
setTimeout(() => {
|
|
||||||
ipcRenderer.send('printerTagSync', JSON.stringify(list[i]))
|
|
||||||
}, i * 800)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let ws = ref(null)
|
let ws = ref(null)
|
||||||
let wsIsClose = ref(false)
|
let wsIsClose = ref(false)
|
||||||
|
|
@ -276,7 +147,8 @@ function initWebSocket(wsUrl = import.meta.env.VITE_API_WSS) {
|
||||||
// printBill(data)
|
// printBill(data)
|
||||||
|
|
||||||
// 检测是否需要打印标签小票
|
// 检测是否需要打印标签小票
|
||||||
checkLabelPrint(data)
|
// checkLabelPrint(data)
|
||||||
|
printStore.labelPrint(data)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -430,7 +302,6 @@ async function getBarCode(e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
getPrintList()
|
|
||||||
document.addEventListener('keydown', (e) => {
|
document.addEventListener('keydown', (e) => {
|
||||||
getBarCode(e)
|
getBarCode(e)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,44 @@
|
||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
|
import { ipcRenderer } from "electron";
|
||||||
|
import { bySubType } from "@/api/device";
|
||||||
|
import { useUser } from "@/store/user.js";
|
||||||
|
import dayjs from "dayjs";
|
||||||
|
|
||||||
export const usePrint = defineStore({
|
export const usePrint = defineStore({
|
||||||
id: "print",
|
id: "print",
|
||||||
state: () => ({
|
state: () => ({
|
||||||
localDevices: [], // 本地打印机列表
|
localDevices: [], // 本地打印机列表
|
||||||
deviceList: [], // 添加的打印机
|
deviceNoteList: [], // 添加的打印机
|
||||||
data: "", // 要打印的数据
|
deviceLableList: [], // 添加的打印机
|
||||||
|
labelList: [], // 要打印的队列数据
|
||||||
|
printTimer: null,
|
||||||
}),
|
}),
|
||||||
actions: {
|
actions: {
|
||||||
// 更新本地打印机列表
|
// 获取本地打印机和已添加的可以用打印机列表
|
||||||
updateLocalDevice(list) {
|
async init() {
|
||||||
this.localDevices = list;
|
const store = useUser();
|
||||||
},
|
|
||||||
// 更新已添加的打印机
|
// 获取本地打印机
|
||||||
updateDevice(list) {
|
ipcRenderer.send("getPrintList");
|
||||||
this.deviceList = list;
|
ipcRenderer.on("printList", (event, arg) => {
|
||||||
|
// localPrintList.value = arg;
|
||||||
|
// console.log(localPrintList.value);
|
||||||
|
this.localDevices = arg;
|
||||||
|
});
|
||||||
|
|
||||||
|
// 获取已添加的小票打印机
|
||||||
|
this.deviceNoteList = await bySubType({
|
||||||
|
shopId: store.userInfo.shopId,
|
||||||
|
contentType: "local",
|
||||||
|
subType: "cash",
|
||||||
|
});
|
||||||
|
|
||||||
|
// 获取已添加的标签打印机
|
||||||
|
this.deviceLableList = await bySubType({
|
||||||
|
shopId: store.userInfo.shopId,
|
||||||
|
contentType: "local",
|
||||||
|
subType: "label",
|
||||||
|
});
|
||||||
},
|
},
|
||||||
// 检查本地打印机是否能正常使用
|
// 检查本地打印机是否能正常使用
|
||||||
checkLocalPrint(deviceName) {
|
checkLocalPrint(deviceName) {
|
||||||
|
|
@ -31,10 +55,62 @@ export const usePrint = defineStore({
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// 执行打印操作
|
// 打印标签小票
|
||||||
printHandle(state, type = "label") {
|
labelPrint(props) {
|
||||||
if (type == "label") {
|
if (this.checkLocalPrint(this.deviceLableList[0].config.deviceName)) {
|
||||||
|
let pids = this.deviceLableList[0].config.categoryList.map(
|
||||||
|
(item) => item.id
|
||||||
|
);
|
||||||
|
|
||||||
|
let count = 0;
|
||||||
|
let sum = 0;
|
||||||
|
|
||||||
|
props.carts.map((item) => {
|
||||||
|
if (pids.some((el) => el == item.categoryId)) {
|
||||||
|
for (let i = 0; i < item.number; i++) {
|
||||||
|
sum++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
props.carts.map((item) => {
|
||||||
|
if (pids.some((el) => el == item.categoryId)) {
|
||||||
|
for (let i = 0; i < item.number; i++) {
|
||||||
|
count++;
|
||||||
|
this.labelList.push({
|
||||||
|
outNumber: props.outNumber,
|
||||||
|
name: item.name,
|
||||||
|
skuName: item.skuName,
|
||||||
|
masterId: props.orderInfo.tableName,
|
||||||
|
deviceName: this.deviceLableList[0].config.deviceName,
|
||||||
|
createdAt: dayjs(props.createdAt).format("YYYY-MM-DD HH:mm:ss"),
|
||||||
|
isPrint: false,
|
||||||
|
count: `${count}/${sum}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// 执行打印操作
|
||||||
|
this.startLabelPrint();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
// 开始打印标签数据
|
||||||
|
startLabelPrint() {
|
||||||
|
if (this.printTimer != null) return;
|
||||||
|
this.printTimer = setInterval(() => {
|
||||||
|
let item = "";
|
||||||
|
if (!this.labelList.length) {
|
||||||
|
clearInterval(this.printTimer);
|
||||||
|
this.printTimer = null;
|
||||||
|
} else {
|
||||||
|
item = this.labelList[0];
|
||||||
|
if (!item.isPrint) {
|
||||||
|
ipcRenderer.send("printerTagSync", JSON.stringify(item));
|
||||||
|
this.labelList[0].isPrint = true;
|
||||||
|
this.labelList.splice(0, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 800);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -111,6 +111,7 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
|
import _ from 'lodash'
|
||||||
import { ipcRenderer } from "electron";
|
import { ipcRenderer } from "electron";
|
||||||
import { onMounted, ref } from "vue";
|
import { onMounted, ref } from "vue";
|
||||||
import { useRouter, useRoute } from "vue-router";
|
import { useRouter, useRoute } from "vue-router";
|
||||||
|
|
@ -170,7 +171,7 @@ function getPrintList() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 测试打印
|
// 测试打印
|
||||||
function printHandle() {
|
const printHandle = _.throttle(function () {
|
||||||
if (!form.value.config.deviceName) {
|
if (!form.value.config.deviceName) {
|
||||||
ElMessage.warning("请选择打印设备");
|
ElMessage.warning("请选择打印设备");
|
||||||
return;
|
return;
|
||||||
|
|
@ -179,7 +180,7 @@ function printHandle() {
|
||||||
"printerTagSync",
|
"printerTagSync",
|
||||||
JSON.stringify(printData.value)
|
JSON.stringify(printData.value)
|
||||||
);
|
);
|
||||||
}
|
}, 1500, { leading: true, trailing: false })
|
||||||
|
|
||||||
// 提交打印机
|
// 提交打印机
|
||||||
async function submitHandle() {
|
async function submitHandle() {
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,8 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="search_wrap">
|
<div class="search_wrap">
|
||||||
<div class="input">
|
<div class="input">
|
||||||
<el-input placeholder="请输入商品名称查询" v-model="commdityName" clearable @input="inputChange"></el-input>
|
<el-input placeholder="请输入商品名称查询" v-model="commdityName" clearable @focus="
|
||||||
|
global.updateData(false)" @blur="global.updateData(true)" @input="inputChange"></el-input>
|
||||||
</div>
|
</div>
|
||||||
<el-button :loading="searchLoading" :icon="Search" @click="searchHandle">搜索</el-button>
|
<el-button :loading="searchLoading" :icon="Search" @click="searchHandle">搜索</el-button>
|
||||||
<!-- <el-button :icon="shopListType == 'text' ? 'PictureRounded' : 'PriceTag'"
|
<!-- <el-button :icon="shopListType == 'text' ? 'PictureRounded' : 'PriceTag'"
|
||||||
|
|
@ -76,6 +77,10 @@ import { Swiper, SwiperSlide } from 'swiper/vue'
|
||||||
import "swiper/swiper-bundle.css";
|
import "swiper/swiper-bundle.css";
|
||||||
|
|
||||||
|
|
||||||
|
import { useGlobal } from '@/store/global.js'
|
||||||
|
const global = useGlobal()
|
||||||
|
|
||||||
|
|
||||||
const store = useUser()
|
const store = useUser()
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
|
|
|
||||||
|
|
@ -72,13 +72,14 @@ import { onMounted, ref } from "vue";
|
||||||
import { useUser } from "@/store/user.js";
|
import { useUser } from "@/store/user.js";
|
||||||
import payCard from "@/components/payCard/payCard.vue";
|
import payCard from "@/components/payCard/payCard.vue";
|
||||||
import { print } from "@/api/pay";
|
import { print } from "@/api/pay";
|
||||||
import { bySubType } from "@/api/device";
|
|
||||||
import { ElMessage } from "element-plus";
|
import { ElMessage } from "element-plus";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import useStorage from '@/utils/useStorage'
|
import useStorage from '@/utils/useStorage'
|
||||||
|
|
||||||
import { ipcRenderer } from "electron";
|
import { ipcRenderer } from "electron";
|
||||||
|
|
||||||
|
import { usePrint } from '@/store/print.js'
|
||||||
|
const printStore = usePrint()
|
||||||
|
|
||||||
const store = useUser();
|
const store = useUser();
|
||||||
|
|
||||||
const emit = defineEmits("paySuccess");
|
const emit = defineEmits("paySuccess");
|
||||||
|
|
@ -115,157 +116,40 @@ const props = defineProps({
|
||||||
|
|
||||||
const isPrint = ref(true);
|
const isPrint = ref(true);
|
||||||
|
|
||||||
// 小票打印机列表
|
|
||||||
const printList = ref([]);
|
|
||||||
|
|
||||||
// 标签打印机列表
|
|
||||||
const printLabelList = ref([]);
|
|
||||||
const localPrintList = ref([])
|
|
||||||
|
|
||||||
// 获取打印机状态
|
|
||||||
async function bySubTypeAjax() {
|
|
||||||
try {
|
|
||||||
const res1 = await bySubType({
|
|
||||||
shopId: store.userInfo.shopId,
|
|
||||||
contentType: "local",
|
|
||||||
subType: "cash",
|
|
||||||
});
|
|
||||||
const res2 = await bySubType({
|
|
||||||
shopId: store.userInfo.shopId,
|
|
||||||
contentType: "local",
|
|
||||||
subType: "label",
|
|
||||||
});
|
|
||||||
printList.value = res1;
|
|
||||||
printLabelList.value = res2;
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取本地打印机列表
|
|
||||||
function getPrintList() {
|
|
||||||
ipcRenderer.send("getPrintList");
|
|
||||||
ipcRenderer.on("printList", (event, arg) => {
|
|
||||||
localPrintList.value = arg;
|
|
||||||
// console.log(localPrintList.value);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查本地打印机是否能正常使用
|
|
||||||
function checkLocalPrint(deviceName) {
|
|
||||||
let print = ''
|
|
||||||
for (let item of localPrintList.value) {
|
|
||||||
if (item.name == deviceName) {
|
|
||||||
print = item
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!print.name) {
|
|
||||||
return false
|
|
||||||
} else {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检测是否打印标签小票
|
|
||||||
function checkLabelPrint(props) {
|
|
||||||
// console.log(props);
|
|
||||||
if (!checkLocalPrint(printLabelList.value[0].config.deviceName)) {
|
|
||||||
ElMessage.error("本地打印机无法使用,请检查打印机是否正确连接1");
|
|
||||||
} else {
|
|
||||||
let pids = printLabelList.value[0].config.categoryList.map(item => item.id)
|
|
||||||
let labelList = []
|
|
||||||
// let count = 0
|
|
||||||
// let sum = 0
|
|
||||||
|
|
||||||
// props.carts.map(item => {
|
|
||||||
// if (pids.some(el => el == item.categoryId)) {
|
|
||||||
// for (let i = 0; i < item.number; i++) {
|
|
||||||
// sum++
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
|
|
||||||
props.carts.map(item => {
|
|
||||||
if (pids.some(el => el == item.categoryId)) {
|
|
||||||
for (let i = 0; i < item.number; i++) {
|
|
||||||
// count++
|
|
||||||
labelList.push(
|
|
||||||
{
|
|
||||||
outNumber: props.outNumber,
|
|
||||||
name: item.name,
|
|
||||||
skuName: item.skuName,
|
|
||||||
masterId: props.orderInfo.tableName,
|
|
||||||
deviceName: printLabelList.value[0].config.deviceName,
|
|
||||||
createdAt: dayjs(props.createdAt).format('YYYY-MM-DD HH:mm:ss'),
|
|
||||||
// count: `${count}/${sum}`
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
printLabel(labelList)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 打印标签
|
|
||||||
const printLabel = _.throttle(function (list) {
|
|
||||||
if (!checkLocalPrint(printLabelList.value[0].config.deviceName)) {
|
|
||||||
ElMessage.error("本地打印机无法使用,请检查打印机是否正确连接");
|
|
||||||
} else {
|
|
||||||
for (let i = 0; i <= list.length - 1; i++) {
|
|
||||||
// ipcRenderer.send('printerTagSync', JSON.stringify(list[i]))
|
|
||||||
setTimeout(() => {
|
|
||||||
ipcRenderer.send('printerTagSync', JSON.stringify(list[i]))
|
|
||||||
}, i * 800)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 1500, { leading: true, trailing: false })
|
|
||||||
|
|
||||||
// 打印操作
|
// 打印操作
|
||||||
async function printHandle() {
|
const printHandle = _.throttle(async function () {
|
||||||
try {
|
try {
|
||||||
if (!isPrint.value) return;
|
if (!isPrint.value) return;
|
||||||
if (printLabelList.value.length) {
|
const data = {
|
||||||
const data = {
|
shop_name: store.userInfo.merchantName,
|
||||||
shop_name: store.userInfo.merchantName,
|
carts: props.cart,
|
||||||
carts: props.cart,
|
amount: props.amount,
|
||||||
amount: props.amount,
|
remark: props.remark,
|
||||||
remark: props.remark,
|
orderInfo: props.orderInfo,
|
||||||
orderInfo: props.orderInfo,
|
createdAt: dayjs(props.orderInfo.createdAt).format(
|
||||||
deviceName: printLabelList.value[0].config.deviceName,
|
"YYYY-MM-DD HH:mm:ss"
|
||||||
createdAt: dayjs(props.orderInfo.createdAt).format(
|
),
|
||||||
"YYYY-MM-DD HH:mm:ss"
|
printTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
|
||||||
),
|
};
|
||||||
printTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
|
printStore.labelPrint(data)
|
||||||
};
|
|
||||||
checkLabelPrint(data)
|
try {
|
||||||
// if (!checkLocalPrint(printList.value[0].config.deviceName)) {
|
printLoading.value = true;
|
||||||
// ElMessage.error("本地小票打印机无法使用,请检查打印机是否正确连接3");
|
await print({
|
||||||
// } else {
|
type: "normal",
|
||||||
// ipcRenderer.send("printerInfoSync", JSON.stringify(data));
|
ispre: true,
|
||||||
// }
|
orderId: props.orderInfo.id,
|
||||||
} else {
|
});
|
||||||
// ElMessage.error("您还没有添加本地打印设备,将使用网络打印");
|
printLoading.value = false;
|
||||||
try {
|
// ElMessage.success("打印成功");
|
||||||
printLoading.value = true;
|
} catch (error) {
|
||||||
await print({
|
printLoading.value = false;
|
||||||
type: "normal",
|
console.log(error);
|
||||||
ispre: true,
|
|
||||||
orderId: props.orderInfo.id,
|
|
||||||
});
|
|
||||||
printLoading.value = false;
|
|
||||||
// ElMessage.success("打印成功");
|
|
||||||
} catch (error) {
|
|
||||||
printLoading.value = false;
|
|
||||||
console.log(error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
}
|
}, 1500, { leading: true, trailing: false })
|
||||||
|
|
||||||
// 订单已支付
|
// 订单已支付
|
||||||
function paySuccess() {
|
function paySuccess() {
|
||||||
|
|
@ -297,8 +181,6 @@ function getLocalMemberInfo() {
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
getPrintList();
|
|
||||||
bySubTypeAjax();
|
|
||||||
getLocalMemberInfo()
|
getLocalMemberInfo()
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,9 @@
|
||||||
<el-tabs v-model="ordereData.status" class="demo-tabs" @tab-click="handleClick">
|
<el-tabs v-model="ordereData.status" class="demo-tabs" @tab-click="handleClick">
|
||||||
<el-tab-pane label="全部" name="">
|
<el-tab-pane label="全部" name="">
|
||||||
<div class="demo_tabs_div">
|
<div class="demo_tabs_div">
|
||||||
<el-input v-model="ordereData.orderNo" placeholder="请输入订单号查询" @input="inputChange" clearable />
|
<el-input v-model="ordereData.orderNo" placeholder="请输入订单号查询" @input="inputChange" clearable
|
||||||
|
@focus="
|
||||||
|
global.updateData(false)" @blur="global.updateData(true)" />
|
||||||
<!-- <el-button style="margin-left: 10px;" type="primary" @click="onSubmit">搜索</el-button> -->
|
<!-- <el-button style="margin-left: 10px;" type="primary" @click="onSubmit">搜索</el-button> -->
|
||||||
</div>
|
</div>
|
||||||
<add :loading="loadingboxshow" :ordereData="ordereData" @emititemboxshow="emititemboxshow"
|
<add :loading="loadingboxshow" :ordereData="ordereData" @emititemboxshow="emititemboxshow"
|
||||||
|
|
@ -157,7 +159,9 @@
|
||||||
<el-dialog v-model="recharge" title="退单" width="800" :before-close="handlerecharge">
|
<el-dialog v-model="recharge" title="退单" width="800" :before-close="handlerecharge">
|
||||||
<div class="recharge_footer">
|
<div class="recharge_footer">
|
||||||
<div class="recharge_footer_item">
|
<div class="recharge_footer_item">
|
||||||
<el-input v-model="remark" style="width: 100%" :rows="2" type="textarea" placeholder="请输入退单原因" />
|
<el-input v-model="remark" style="width: 100%" :rows="2" type="textarea" placeholder="请输入退单原因"
|
||||||
|
@focus="
|
||||||
|
global.updateData(false)" @blur="global.updateData(true)" />
|
||||||
<div class="recharge_footer_items" @click="remark = '顾客取消'">
|
<div class="recharge_footer_items" @click="remark = '顾客取消'">
|
||||||
<div>顾客取消</div>
|
<div>顾客取消</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -209,7 +213,9 @@
|
||||||
<!-- {{ item.num }} -->
|
<!-- {{ item.num }} -->
|
||||||
<el-input-number v-model="item.num" :min="1" size="small"
|
<el-input-number v-model="item.num" :min="1" size="small"
|
||||||
:disabled="item.status == 'refund' ? true : false" :max="item.maxnum"
|
:disabled="item.status == 'refund' ? true : false" :max="item.maxnum"
|
||||||
@change="(currentValue, oldValue) => changezong(item, index, 1, 'num', currentValue, oldValue)" />
|
@change="(currentValue, oldValue) => changezong(item, index, 1, 'num', currentValue, oldValue)"
|
||||||
|
@focus="
|
||||||
|
global.updateData(false)" @blur="global.updateData(true)" />
|
||||||
<!-- @change="changezong(item, index, 1, 'num')" -->
|
<!-- @change="changezong(item, index, 1, 'num')" -->
|
||||||
</div>
|
</div>
|
||||||
<div class="recharge_footer_itemright_botton_itemthere">
|
<div class="recharge_footer_itemright_botton_itemthere">
|
||||||
|
|
@ -246,126 +252,20 @@ import { orderfindOrder, orderorderDetail, payreturnOrder, cloudPrinterprint, se
|
||||||
import add from '@/views/order/components/add.vue'
|
import add from '@/views/order/components/add.vue'
|
||||||
import cashTable from '@/views/order/components/cashTable.vue'
|
import cashTable from '@/views/order/components/cashTable.vue'
|
||||||
import { clearNoNum } from '@/utils'
|
import { clearNoNum } from '@/utils'
|
||||||
|
|
||||||
|
import { useGlobal } from '@/store/global.js'
|
||||||
|
const global = useGlobal()
|
||||||
|
|
||||||
const store = useUser()
|
const store = useUser()
|
||||||
const itemboxshow = ref(false)
|
const itemboxshow = ref(false)
|
||||||
|
|
||||||
|
import { usePrint } from '@/store/print.js'
|
||||||
|
const printStore = usePrint()
|
||||||
|
|
||||||
import { ipcRenderer } from 'electron'
|
import { ipcRenderer } from 'electron'
|
||||||
|
|
||||||
const reforderboxrightbutton = ref(null);//定义ref
|
const reforderboxrightbutton = ref(null);//定义ref
|
||||||
const reforderboxrightbuttonheight = ref(null)//获取元素高度
|
const reforderboxrightbuttonheight = ref(null)//获取元素高度
|
||||||
import { bySubType } from "@/api/device";
|
|
||||||
|
|
||||||
|
|
||||||
// 小票打印机列表
|
|
||||||
const printList = ref([]);
|
|
||||||
// 标签打印机列表
|
|
||||||
const printLabelList = ref([]);
|
|
||||||
const localPrintList = ref([])
|
|
||||||
|
|
||||||
// 获取打印机状态
|
|
||||||
async function bySubTypeAjax() {
|
|
||||||
try {
|
|
||||||
const res1 = await bySubType({
|
|
||||||
shopId: store.userInfo.shopId,
|
|
||||||
contentType: "local",
|
|
||||||
subType: "cash",
|
|
||||||
});
|
|
||||||
const res2 = await bySubType({
|
|
||||||
shopId: store.userInfo.shopId,
|
|
||||||
contentType: "local",
|
|
||||||
subType: "label",
|
|
||||||
});
|
|
||||||
printList.value = res1;
|
|
||||||
printLabelList.value = res2;
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取本地打印机列表
|
|
||||||
function getPrintList() {
|
|
||||||
ipcRenderer.send("getPrintList");
|
|
||||||
ipcRenderer.on("printList", (event, arg) => {
|
|
||||||
localPrintList.value = arg;
|
|
||||||
// console.log(localPrintList.value);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查本地打印机是否能正常使用
|
|
||||||
function checkLocalPrint(deviceName) {
|
|
||||||
let print = ''
|
|
||||||
for (let item of localPrintList.value) {
|
|
||||||
if (item.name == deviceName) {
|
|
||||||
print = item
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!print.name) {
|
|
||||||
return false
|
|
||||||
} else {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// 检测是否打印标签小票
|
|
||||||
function checkLabelPrint(props) {
|
|
||||||
// console.log(props);
|
|
||||||
// console.log(printLabelList.value);
|
|
||||||
if (!checkLocalPrint(printLabelList.value[0].config.deviceName)) {
|
|
||||||
ElMessage.error("本地打印机无法使用,请检查打印机是否正确连接");
|
|
||||||
} else {
|
|
||||||
let pids = printLabelList.value[0].config.categoryList.map(item => item.id)
|
|
||||||
let labelList = []
|
|
||||||
// let count = 0
|
|
||||||
// let sum = 0
|
|
||||||
|
|
||||||
// props.skuInfos.map(item => {
|
|
||||||
// if (pids.some(el => el == item.categoryId)) {
|
|
||||||
// for (let i = 0; i < item.num; i++) {
|
|
||||||
// sum++
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
|
|
||||||
props.skuInfos.map(item => {
|
|
||||||
if (pids.some(el => el == item.categoryId)) {
|
|
||||||
for (let i = 0; i < item.num; i++) {
|
|
||||||
// count++
|
|
||||||
labelList.push(
|
|
||||||
{
|
|
||||||
outNumber: props.outNumber,
|
|
||||||
name: item.productName,
|
|
||||||
skuName: item.productSkuName,
|
|
||||||
masterId: props.tableName,
|
|
||||||
deviceName: printLabelList.value[0].config.deviceName,
|
|
||||||
createdAt: dayjs(props.createAt).format('YYYY-MM-DD HH:mm:ss'),
|
|
||||||
// count: `${count}/${sum}`
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
if (labelList.length) printLabel(labelList)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 打印标签
|
|
||||||
const printLabel = lodash.throttle(function (list) {
|
|
||||||
if (!checkLocalPrint(printLabelList.value[0].config.deviceName)) {
|
|
||||||
ElMessage.error("本地打印机无法使用,请检查打印机是否正确连接");
|
|
||||||
} else {
|
|
||||||
console.log(list.length);
|
|
||||||
for (let i = 0; i <= list.length - 1; i++) {
|
|
||||||
// console.log(list[i]);
|
|
||||||
// ipcRenderer.send('printerTagSync', JSON.stringify(list[i]))
|
|
||||||
setTimeout(() => {
|
|
||||||
ipcRenderer.send('printerTagSync', JSON.stringify(list[i]))
|
|
||||||
}, i * 800)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 1500, { leading: true, trailing: false })
|
|
||||||
|
|
||||||
|
|
||||||
const handleClick = (Name) => {//切换teb
|
const handleClick = (Name) => {//切换teb
|
||||||
ordereData.status = Name.props.name
|
ordereData.status = Name.props.name
|
||||||
|
|
@ -416,15 +316,37 @@ const payreturnOrderclick = lodash.debounce(async () => { //搜索手机号
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
buttonloading.value = false
|
buttonloading.value = false
|
||||||
|
|
||||||
}
|
}
|
||||||
}, 500)
|
}, 500)
|
||||||
|
|
||||||
|
|
||||||
const print = async (e) => {
|
// 重新打印标签/小票
|
||||||
|
const print = lodash.throttle(async function (e) {
|
||||||
try {
|
try {
|
||||||
if (e == 'label' && printLabelList.value.length) {
|
if (e == 'label') {
|
||||||
checkLabelPrint(printLabelOrder.value)
|
// checkLabelPrint(printLabelOrder.value)
|
||||||
|
const data = {
|
||||||
|
shop_name: store.userInfo.merchantName,
|
||||||
|
carts: [],
|
||||||
|
orderInfo: printLabelOrder.value,
|
||||||
|
outNumber: printLabelOrder.value.outNumber,
|
||||||
|
createdAt: dayjs(printLabelOrder.value.createdAt).format(
|
||||||
|
"YYYY-MM-DD HH:mm:ss"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
printLabelOrder.value.skuInfos.map(item => {
|
||||||
|
data.carts.push(
|
||||||
|
{
|
||||||
|
categoryId: item.categoryId,
|
||||||
|
name: item.productName,
|
||||||
|
number: item.num,
|
||||||
|
skuName: item.productSkuName
|
||||||
|
}
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
// console.log('重打标签小票', data);
|
||||||
|
printStore.labelPrint(data)
|
||||||
} else {
|
} else {
|
||||||
await cloudPrinterprint({
|
await cloudPrinterprint({
|
||||||
type: e,
|
type: e,
|
||||||
|
|
@ -439,7 +361,7 @@ const print = async (e) => {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
}
|
}, 1500, { leading: true, trailing: false })
|
||||||
|
|
||||||
const loadingboxshow = ref(false);
|
const loadingboxshow = ref(false);
|
||||||
// 要打印标签的订单数据
|
// 要打印标签的订单数据
|
||||||
|
|
@ -585,9 +507,6 @@ const callNumberHandle = async () => {
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
// resetMembrform.value = { ...membrform.value }
|
// resetMembrform.value = { ...membrform.value }
|
||||||
asyncorderfindOrder()
|
asyncorderfindOrder()
|
||||||
|
|
||||||
getPrintList();
|
|
||||||
bySubTypeAjax();
|
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue