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" > -
里海收银系统
+
泸优采收银系统
{ + + const orderCount = ref(localStorage.getItem('orderCount')||0); + + + const setOrderCount = (e)=>{ + orderCount.value = e; + localStorage.setItem('orderCount',e); + } + + return { + orderCount, + setOrderCount + } +}) \ No newline at end of file diff --git a/src/utils/EscPos.js b/src/utils/EscPos.js new file mode 100644 index 0000000..588b5f9 --- /dev/null +++ b/src/utils/EscPos.js @@ -0,0 +1,70 @@ +import * as Esc from "@/utils/EscPostUtils.js"; + +const testObj = { + mer_name: "莲花农贸市场", //商户名称 + service_phone: "0830-2669767", //客服电话 + number: "PF171568087790938356", //单号 + create_time: "2024-5-15 18:00:32", //下单时间 + total_price: "29.96", //总价 + pay_price: "29.96", //实付 + pay_type: "微信支付", //支付方式 + pay_number: "4200002159202405159003084211", //支付单号 + goods: [ + { + name: "白菜 大白菜", //商品名称 + sell: "236.60", //单价 + nums: "13", //数量 + unit_name: "kg", //单位 + total: "2896.34" //小计 + }, + { + name: "小黄鸭", //商品名称 + sell: "9.56", //单价 + nums: "2", //数量 + unit_name: "只", //单位 + total: "19.38" //小计 + }, + { + name: "卷心菜", //商品名称 + sell: "15.37", //单价 + nums: "8", //数量 + unit_name: "斤", //单位 + total: "134.38" //小计 + } + ] +} + +export const printTicket = (obj = {}, test = false) => { + let str = ""; + if(!obj || !obj.number) obj = testObj; + str += Esc.Size2(0) + Esc.Center() + Esc.boldFontOn() + obj.mer_name + "\n"; + str += Esc.fillLine(" ") + Esc.boldFontOff() + "\n"; + str += Esc.Left() + "单号: " + obj.number + "\n"; + str += Esc.Left() + "下单时间: " + obj.create_time + "\n"; + + // 商品信息 + str += Esc.fillLine("=") + "\n"; + + str += Esc.inline3("单价", "数量", "小计", " ", 1) + "\n"; + obj.goods.forEach(item => { + str += Esc.Left() + item.name + "\n"; + str += Esc.inline3(`${item.sell}元`, `${item.nums}${item.unit_name}`, `${item.total}元`, " ", 1) + "\n"; + }) + + str += Esc.fillLine("=") + "\n"; + + str += Esc.Left() + "应付款: " + obj.total_price + "元" + "\n"; + str += Esc.Left() + "实付款: " + obj.pay_price + "元" + "\n"; + str += Esc.Left() + "支付方式: " + obj.pay_type + "\n"; + str += Esc.Left() + "支付单号: " + obj.pay_number + "\n"; + str += Esc.Left() + "联系电话: " + obj.service_phone + "\n"; + str += Esc.fillLine("=") + "\n"; + + // 票尾 + str += Esc.fillLine(" ") + "\n"; + str += Esc.Center() + "欢迎下次光临!" + "\n"; + str += Esc.feedLines(" ") + "\n"; + // 切纸 + str += Esc.cutPaper(); + return str; +} \ No newline at end of file diff --git a/src/utils/EscPostUtils.js b/src/utils/EscPostUtils.js index 82f2b02..f85e439 100644 --- a/src/utils/EscPostUtils.js +++ b/src/utils/EscPostUtils.js @@ -1,3 +1,5 @@ +// 此为指令集, 如非必要请不要进行修改操作, 以免打印效果异常 + // 打印机纸宽58mm,页的宽度384,字符宽度为1,每行最多盛放32个字符 // 打印机纸宽80mm,页的宽度576,字符宽度为1,每行最多盛放48个字符 const PAGE_WIDTH = 384; @@ -238,39 +240,19 @@ export function inline(str1, str2, fillWith = ' ', fontWidth = 1) { * @param {string} fillWith 列之间的填充字符 * @param {number} fontWidth 字符宽度(默认为1) */ -export function inlineThreeColumns(str1, str2, str3, fillWith = ' ', fontWidth = 1) { - const lineWidth = MAX_CHAR_COUNT_EACH_LINE / fontWidth; - - // 计算每列的宽度(假设三列等宽) - const columnWidth = Math.floor(lineWidth / 3); - - // 计算每列的实际宽度 - const width1 = getStringWidth(str1); - const width2 = getStringWidth(str2); - const width3 = getStringWidth(str3); - - // 计算每列需要的填充数量 - let fillCount1 = columnWidth - width1; - let fillCount2 = columnWidth - width2; - let fillCount3 = lineWidth - columnWidth - (width1 + fillCount1 * fontWidth + width2 + fillCount2 * fontWidth + width3); - - // 创建填充字符串 - let fillStr1 = new Array(fillCount1).fill(fillWith.charAt(0)).join(''); - let fillStr2 = new Array(fillCount2).fill(fillWith.charAt(0)).join(''); - let fillStr3 = new Array(fillCount3).fill(fillWith.charAt(0)).join(''); - - // 拼接字符串 - return str1 + fillStr1 + str2 + fillStr2 + str3 + fillStr3; -} - export function inline3(str1, str2, str3, fillWith = ' ', fontWidth = 1) { const lineWidth = MAX_CHAR_COUNT_EACH_LINE / fontWidth; // 需要填充的字符数量 let fillCount = lineWidth - (getStringWidth(str1) + getStringWidth(str2) + getStringWidth(str3)) % lineWidth; - console.log("=",lineWidth, getStringWidth(str1) + getStringWidth(str2) + getStringWidth(str3), fillCount); - fillCount = Math.floor(fillCount / 2); - let fillStr = new Array(fillCount).fill(fillWith.charAt(0)).join(''); - return str1 + fillStr + str2 + fillStr + str3; + let count2 = Math.floor(fillCount / 2); //分别计算出两边各自需要填充的数量 + let count1 = fillCount - count2; + if(fillCount>2){ //往左偏移两位, 防止打印时,小计与数量重叠 + count1 -= 2; + count2 += 2; + } + let fillStr1 = new Array(count1).fill(fillWith.charAt(0)).join(''); + let fillStr2 = new Array(count2).fill(fillWith.charAt(0)).join(''); + return str1 + fillStr1 + str2 + fillStr2 + str3; } /** diff --git a/src/views/order/component/detail.vue b/src/views/order/component/detail.vue index 2e53cc6..740a19f 100644 --- a/src/views/order/component/detail.vue +++ b/src/views/order/component/detail.vue @@ -175,8 +175,8 @@ onUnmounted(() => {
支付方式:
微信收款 - 余额支付 - 微信支付 + 余额支付 + 微信支付
diff --git a/src/views/order/component/order.vue b/src/views/order/component/order.vue index b18012d..059f348 100644 --- a/src/views/order/component/order.vue +++ b/src/views/order/component/order.vue @@ -51,7 +51,7 @@ const where = ref({ page_size: 20, number: "", date: moment(new Date()).format("YYYY-MM-DD"), - source: props.source, + // source: props.source, }); const loading = ref(false); @@ -86,6 +86,7 @@ const getOrderList = (reload = false) => { const submitOrder = ()=>{ createOrderApi().then(res=>{ ElMessage.success("提交成功"); + getOrderList(true); }) } @@ -203,8 +204,8 @@ onUnmounted(()=>{
已支付 (微信收款) - (余额支付) - (微信支付) + (余额支付) + (微信支付)
未支付
diff --git a/src/views/order/index.vue b/src/views/order/index.vue index b48a3c9..14e3e84 100644 --- a/src/views/order/index.vue +++ b/src/views/order/index.vue @@ -31,13 +31,18 @@ const rules = ref({ detail: [{ required: true, message: "请输入地址", trigger: "blur" }], }); +const formRef = ref(null); + const submit = () => { - merchantCreateApi(form.value).then((res) => { - dialogFormVisible.value = false; - orderRef.value?.getOrderList(true); + formRef.value?.validate((valid) => { + if (valid) { + merchantCreateApi(form.value).then((res) => { + dialogFormVisible.value = false; + orderRef.value?.getOrderList(true); + }); + } }); }; -