diff --git a/.env.development b/.env.development index 6a0e204..8a2f4db 100644 --- a/.env.development +++ b/.env.development @@ -1,7 +1,7 @@ VITE_NOW_TYPE = 'dist' VITE_PUSH_URL = 'ws://192.168.1.22:8787' +VITE_BASE_URL = 'http://192.168.1.22:8546' - -# VITE_BASE_URL = 'http://192.168.1.22:8546' -VITE_BASE_URL = 'https://erp.lihaink.cn' \ No newline at end of file +# VITE_PUSH_URL ='wss://erp.lihaink.cn/pull' +# VITE_BASE_URL = 'https://erp.lihaink.cn' \ No newline at end of file diff --git a/src/api/store.js b/src/api/store.js index c53cdee..a4f83ba 100644 --- a/src/api/store.js +++ b/src/api/store.js @@ -147,4 +147,11 @@ export function opurchaseOrderApi(data) { */ export function subOrdersListApi(data) { return request.get(`/order/OpurchaseOrder/sub_orders`, { params: data }) +} + +/** + * @description 摊贩订单数量统计 + */ +export function merchantOrderCountApi(data) { + return request.get(`/order/retailOrder/merchant_order_count`, { params: data }) } \ No newline at end of file diff --git a/src/assets/order.mp3 b/src/assets/order.mp3 new file mode 100644 index 0000000..3cc3499 Binary files /dev/null and b/src/assets/order.mp3 differ diff --git a/src/components/pay.vue b/src/components/pay.vue index eb5736c..d52f4ac 100644 --- a/src/components/pay.vue +++ b/src/components/pay.vue @@ -110,22 +110,36 @@ const handleEnter = () => { message: res.data.trade_state_desc || '支付成功', type: "success", }); - if(res.data.message) audioplay(res.data.message); - beforeClose(); + // if(res.data.message) audioplay(res.data.message); + beforeClose(res.data); } else { - if (!res.data.group_order_sn) { - order_id.value = res.data.result.order_id; - loading.value = false; - return ElMessage({ - message: res.message, - type: "error", - }); - } else { - order_id.value = res.data.group_order_id; - count.value = 0; - timecount = 0; - getOrderStatus(res.data.group_order_sn); + if(res.msg=='用户支付中'&&res.code==1){ + ElMessage.warning(res.msg); + mitt.on('pay_success', (e)=>{ + ElMessage({ + message: '支付成功', + type: "success", + }); + setTimeout(()=>{ + mitt.off('pay_success'); + }, 200); + drawer.value = false; + beforeClose(e); + }) } + // if (!res.data.group_order_sn) { + // order_id.value = res.data.result.order_id; + // loading.value = false; + // return ElMessage({ + // message: res.message, + // type: "error", + // }); + // } else { + // order_id.value = res.data.group_order_id; + // count.value = 0; + // timecount = 0; + // getOrderStatus(res.data.group_order_sn); + // } } }) .catch((err) => { @@ -165,8 +179,8 @@ const orderPay = (id) => { message: res.message=='success'?'支付成功':res.message, type: "success", }); - if(res.data.message) audioplay(res.data.message); - beforeClose(); + // if(res.data.message) audioplay(res.data.message); + beforeClose(res.data); } else { order_id.value = res.data.group_order_id; count.value = 0; @@ -197,7 +211,7 @@ const getOrderStatus = (id) => { message: res.message, type: "success", }); - if(res.data.message) audioplay(res.data.message); + // if(res.data.message) audioplay(res.data.message); beforeClose(); } else { ElMessage({ @@ -229,7 +243,7 @@ const getOrderStatus = (id) => { }); }; -const beforeClose = () => { +const beforeClose = (data) => { window.removeEventListener("keydown", keyboard); reLoad.value = false; loading.value = false; @@ -237,7 +251,7 @@ const beforeClose = () => { collection.value = ""; collectionArray.value = []; codeRef.value?.blur(); - emit("paySuccess"); + emit("paySuccess", data); drawer.value = false; }; @@ -314,7 +328,7 @@ const cashBnt = () => { type: "success", }); changeActive(1); - if(res.data.message) audioplay(res.data.message); + // if(res.data.message) audioplay(res.data.message); beforeClose(); } else { if (!res.data.group_order_sn) { diff --git a/src/layout/index.vue b/src/layout/index.vue index cfe940d..7c067ea 100644 --- a/src/layout/index.vue +++ b/src/layout/index.vue @@ -12,14 +12,23 @@ const connection = new Push({ app_key: '2ce3ce22329517213caa7dad261f5695', }); - // 浏览器监听user-1 const user_channel = connection.subscribe(`store_merchant_${userStore.userInfo.merchant.mer_id}`); // const user_channel = connection.subscribe(`store_merchant_${1}`); // 当user-2频道有message事件的消息时 user_channel.on('message', function (data) { - console.log("收到消息--",data, JSON.parse(data.content)); + console.log("收到消息--",data); + try { + if(data?.content?.type=='cash_register'&&data?.content?.msg=="您有一笔订单已支付"){ + mitt.emit('pay_success', data?.content?.data); + } + if(data?.content?.type=='store_merchant'&&data?.content?.msg=="您有一笔新的订单"){ + mitt.emit('new_order', data?.content); + } + } catch (error) { + + } }); // 断线事件 user_channel.on('close', function () { diff --git a/src/layout/myAside.vue b/src/layout/myAside.vue index bebc25f..3f41d55 100644 --- a/src/layout/myAside.vue +++ b/src/layout/myAside.vue @@ -2,18 +2,56 @@ import { useRoute, useRouter } from "vue-router"; import { ref, onMounted, onUnmounted } from "vue"; import mitt from "@/utils/mitt.js"; +import { useOrderStore } from "@/store/order.js"; +import { merchantOrderCountApi } from "@/api/store.js"; +import { ElMessage } from "element-plus"; const router = useRouter(); const route = useRoute(); +const orderStore = useOrderStore(); +// setInterval(()=>{ +// setOrderCount(+orderStore.orderCount + 1) +// }, 2000) + +const setOrderCount = (e = 1) => { + orderStore.setOrderCount(e) + list.value.forEach(item=>{ + if(item.name == "order") item.count = e; + }) +}; + +const newOrder = (e) => { + merchantOrderCountApi().then((res) => { + setOrderCount(res?.data?.order_count || 0); + }); + ElMessage.success('您有新的订单') + // 创建音频对象 + var audio = new Audio("/src/assets/order.mp3"); + // 播放音频 + audio.play(); +}; + +// setTimeout(() => { +// newOrder({ +// msg: "您有一笔新的订单", +// }); +// }, 3000); + const navTo = (name) => { router.push({ name }); }; const list = ref([ { name: "saleHome", title: "收银", ico: "Sell", count: 0 }, { name: "saleOrder", title: "收银订单", ico: "DataLine", count: 0 }, - { name: "order", title: "摊贩订单", ico: "DataAnalysis", count: 2 }, - { name: "purchaseOrder", title: "采购订单", ico: "Tickets", count: 0 }, + { + name: "order", + title: "摊贩订单", + ico: "DataAnalysis", + count: +orderStore.orderCount, + }, + { name: "purchaseOrder", title: "采购订单", ico: "Van", count: 0 }, + { name: "orderCount", title: "订单统计", ico: "DocumentRemove", count: 0 }, // { name: "test", title: "打印", ico: "Tickets", count: 0 }, ]); const aup = () => { @@ -29,11 +67,16 @@ const adown = () => { onMounted(() => { mitt.on("up", aup); mitt.on("down", adown); + mitt.on("new_order", newOrder); + merchantOrderCountApi().then((res) => { + setOrderCount(res?.data?.order_count || 0); + }); }); onUnmounted(() => { mitt.off("aup", aup); mitt.off("adown", adown); + mitt.off("new_order", newOrder); }); @@ -80,14 +123,14 @@ onUnmounted(() => { background-color: #1890ff; transition: 300ms; } - .badge{ - position: absolute; - top: -0.5rem; - right: -0.5rem; - background-color: #ff4a00; - font-size: 0.7rem; - padding: 0.2rem 0.5rem; - border-radius: 2rem; + .badge { + position: absolute; + top: -0.5rem; + right: -0.5rem; + background-color: #ff4a00; + font-size: 0.7rem; + padding: 0.2rem 0.5rem; + border-radius: 2rem; } } } diff --git a/src/layout/myHeader.vue b/src/layout/myHeader.vue index 5f80401..fb31978 100644 --- a/src/layout/myHeader.vue +++ b/src/layout/myHeader.vue @@ -6,7 +6,7 @@ import { ElMessage } from "element-plus"; import { useRouter } from "vue-router"; import mitt from "@/utils/mitt.js"; import { usePrintStore } from "@/store/print.js"; -import * as Esc from "@/utils/EscPostUtils.js"; +import { printTicket } from "@/utils/EscPos.js"; const userStore = useUserStore(); const printStore = usePrintStore(); @@ -48,9 +48,7 @@ let isPrint = false; //是否正在打印小票 // 预打印 const printReceipt = (content = "") => { console.log("预打印"); - // console.log(Esc.inline3("单价 ", "数量", "小计", " ", 1) + "\n"); - // console.log(Esc.inline3("2.36元 ", "10包", "30.00元", " ", 1) + "\n"); - // return ; + console.log(printTicket(content, true)); if (isPrint) return; isPrint = true; uni.getEnv((res) => { @@ -70,46 +68,7 @@ const printReceipt = (content = "") => { const APPprint = (content = "") => { let str = ""; if (content === "") { - // str += "********************************\n"; - // str += "莲花农贸市场\n"; - // str += "单号: PF171568087790938356\n"; - // str += "测试商品 0.01元/kg\n"; - // str += "x 3 \t\t 0.10 \n"; - // str += "测试商品白菜 1.33元/kg\n"; - // str += "x 10 \t\t 13.30元\n"; - // str += "测试商品小黄鸭 36.59元/只\n"; - // str += "x 3 \t\t 106.97元\n"; - // str += " \t 合计: ¥235.36\n"; - // str += "\n"; - // str += "--------------------------------\n"; - // str += "\n"; - str += Esc.Size2(0) + Esc.Center() + Esc.boldFontOn() + "莲花农贸市场" + "\n"; - str += Esc.fillLine(" ") + Esc.boldFontOff() + "\n"; - str += Esc.Left() + "单号: PF171568087790938356" + "\n"; - str += Esc.Left() + "下单时间: 2024-5-15 18:00:32" + "\n"; - // 商品信息 - str += Esc.fillLine("=") + "\n"; - str += Esc.inline3("单价 ", "数量", "小计", " ", 1) + "\n"; - str += Esc.Left() + "白菜 大白菜" + "\n"; - str += Esc.inline3("206.36元 ", "10包", "3600.00元", " ", 1) + "\n"; - str += Esc.Left() + "白菜 大白菜" + "\n"; - str += Esc.inline3("206.36元 ", "10包", "3600.00元", " ", 1) + "\n"; - str += Esc.Left() + "白菜 大白菜" + "\n"; - str += Esc.inline3("206.36元 ", "10包", "3600.00元", " ", 1) + "\n"; - str += Esc.fillLine("=") + "\n"; - - str += Esc.Left() + "应付款: " + "29.96元" + "\n"; - str += Esc.Left() + "实付款: " + "29.96元" + "\n"; - str += Esc.Left() + "支付方式: " + "微信支付" + "\n"; - str += Esc.Left() + "支付单号: " + "4200002159202405159003084211" + "\n"; - str += Esc.fillLine("=") + "\n"; - - // 票尾 - str += Esc.fillLine(" ") + "\n"; - str += Esc.Center() + "欢迎下次光临!" + "\n"; - str += Esc.feedLines(" ") + "\n"; - // 切纸 - str += Esc.cutPaper(); + str = printTicket({}, true); //打印自检 console.log(str); } else str = content; uni.postMessage({ @@ -150,7 +109,7 @@ onUnmounted(() => { src="https://lihai001.oss-cn-chengdu.aliyuncs.com/def/12c93202404101530591311.png" > -