diff --git a/public/index.html b/public/index.html index c231a41..6823c82 100644 --- a/public/index.html +++ b/public/index.html @@ -60,7 +60,7 @@ <% if (process.env.VUE_APP_NODE_ENV === 'prod') { %> <% } %> diff --git a/src/components/PrintDom.vue b/src/components/PrintDom.vue index ebe064f..a153d4c 100644 --- a/src/components/PrintDom.vue +++ b/src/components/PrintDom.vue @@ -32,13 +32,21 @@ {{ datetime.toLocaleDateString() }} {{ datetime.toLocaleTimeString() }} -

884797

-

RX-GZ-CN

-

MGGZ 5725 KA

-

TG14/175

-

Po: 50024779

+ +

{{ dataForm.pdtCode }}

+ +

{{ dataForm.brand }}

+ +

{{ dataForm.bomCode }}

+ +

+ {{ dataForm.shapeCode }} +

+ +

{{ dataForm.orderCode }}

+

- chongqing linagyou k + {{ dataForm.customer }}

- 22301675 - 00006 + + {{ dataForm.code }} + + {{ dataForm.saleNo }}

-

2022.12.18

+ +

+ {{ + new Date(dataForm.deliveryTime).toLocaleDateString() + + " " + + new Date(dataForm.deliveryTime).toLocaleTimeString() + }} +

+

- Pallet 1 + {{ palletType }} +

+
+
-

2890

-

120

-

24x120

-

1x10

+ +

{{ dataForm.prodqty }}

+ +

{{ dataForm.realQty }}

+ +

{{ dataForm.fpText }}

+ +

{{ dataForm.tpText }}

@@ -97,33 +125,105 @@ export default { data() { return { lodop: null, - datetime: new Date() + datetime: new Date(), + dataForm: { + pdtCode: null, + brand: null, + bomCode: null, + shapeCode: null, + orderCode: null, + customer: null, + code: null, + saleNo: null, + deliveryTime: null, + typeDictValue: null, + prodqty: null, + realQty: null, + fpText: null, + tpText: null, + packTechCode: null, + hu: null, + }, + jobId: null, + palletId: null, }; }, - computed: {}, + computed: { + // comp120() { + // if (this.dataForm.realQty == null) return 0; + // return Math.floor(this.dataForm.realQty / 120); + // }, + // comp10() { + // if (this.dataForm.realQty == null) return 0; + // return Math.ceil((this.dataForm.realQty % 120) / 10); + // }, + palletType() { + switch (this.dataForm.typeDictValue?.toString()) { + case "0": + return "满 托"; + case "1": + return "尾 托"; + case "2": + return "余 托"; + default: + return "-"; + } + }, + }, methods: { - print(data) { - console.log("print data", data); + /** + * + * @param {string|object} data 当source为api时,data为id,当source为local时,data为对象 + * @param {'api'|'local'} source 数据来源 + */ + async print(data, source = "api") { // 初始化打印控件 if (!this.initPrintPlugin()) return this.close(); - - this.paintBarCode(); - this.paintQrCode(); - this.handlePrint(); + if (source === "api") { + this.palletId = data; + await this.printByApi(data); + } else { + this.printByLocalData(data); + } this.close(); }, + + async printByApi(id) { + const { data: res } = await this.$http.get("/pms/pallet/" + id); + + this.dataForm = res.data; + await this.printByLocalData(res.data); + }, + + async printByLocalData(data) { + // 绘制包装代码 + this.paintBarCode(data.packTechCode || "0000-0000-0000"); + // 绘制HU号 + await this.paintQrCode(data.hu || "- 无HU数据 -"); + await this.handlePrint(); + }, + initPrintPlugin() { this.lodop = getLodop(); if (!this.lodop) { - alert("请先安装打印控件"); - return false; + return this.$confirm("请先安装打印控件", "提示", { + confirmButtonText: "确定", + cancelButtonText: "取消", + type: "warning", + }) + .then(() => { + window.open("http://www.c-lodop.com/download.html"); + }) + .catch(() => { + return false; + }); } return true; }, + paintBarCode(data) { - console.log("JSBarcode", JsBarcode); - JsBarcode("#barcode", "S653", { + JsBarcode("#barcode", data, { format: "CODE128", width: 2.5, height: 48, @@ -131,31 +231,79 @@ export default { margin: 0, }); }, - paintQrCode(data) { - console.log("JSBarcode", QRCode); - QRCode.toDataURL( - "S653", - { + + async paintQrCode(data) { + try { + const url = await QRCode.toDataURL(data, { width: 128, height: 128, - }, - (err, url) => { - if (err) { - document.querySelector(".qrcode").innerHTML = "no QRCode"; - return; - } - console.log("url", url); - document.querySelector("#qrcode").src = url; - } - ); + }); + document.querySelector("#qrcode").src = url; + } catch (err) { + document.querySelector(".qrcode").innerHTML = "NO QRCode"; + } }, + handlePrint() { - this.lodop.PRINT_INIT("RGV小票打印"); - // 纵向打印,宽度60mm,高度150mm,定义纸张名称 - this.lodop.SET_PRINT_PAGESIZE(1, 600, 1500, "ZebraT231 Tag Paper"); - this.lodop.ADD_PRINT_HTM(0, 0, "100%", "100%", document.querySelector(".print-area").outerHTML); - this.lodop.PREVIEW(); + return new Promise((resolve, reject) => { + this.lodop.PRINT_INIT("RGV小票打印"); + // 捕获打印状态 + this.lodop.SET_PRINT_MODE("CATCH_PRINT_STATUS", true); + if (this.lodop.CVERSION) { + // 获取jobId + this.lodop.On_Return = (TaskID, Value) => { + this.jobId = Value; + this.$nextTick(() => { + this.getPrintStatus(resolve, reject); + }); + }; + } + // 纵向打印,宽度60mm,高度150mm,定义纸张名称 + this.lodop.SET_PRINT_PAGESIZE(1, 600, 1500, "ZebraT231 Tag Paper"); + this.lodop.ADD_PRINT_HTM(0, 0, "100%", "100%", document.querySelector(".print-area").outerHTML); + this.lodop.PRINT(); + }); }, + + getPrintStatus(resolve, reject) { + if (!this.jobId) return; + if (LODOP.CVERSION) { + LODOP.On_Return = (TaskID, Value) => { + // console.log("on return value: <", Value, ">"); + if (Value.toString() == "1") { + // 打印成功 + this.sendSuccess() + .then(() => { + this.$message.success("打印成功"); + this.$emit("refresh-list"); + resolve(); + }) + .catch((err) => { + this.$message.error(err); + reject(err); + }); + } else { + this.$message.error("打印失败"); + } + }; + } + LODOP.GET_VALUE("PRINT_STATUS_OK", this.jobId); + }, + + sendSuccess() { + return this.$http({ + url: "/pms/pallet/print", + method: "post", + data: this.palletId, + headers: { + "Content-Type": "application/json", + }, + }).then(({ data: res }) => { + if (res.code == 0) return; + else throw new Error(res.msg); + }); + }, + close() { this.$emit("destroy"); }, diff --git a/src/views/atomViews/ListViewWithHead.vue b/src/views/atomViews/ListViewWithHead.vue index 8268ce3..89f14fe 100644 --- a/src/views/atomViews/ListViewWithHead.vue +++ b/src/views/atomViews/ListViewWithHead.vue @@ -62,7 +62,7 @@ " /> - + @@ -620,12 +620,16 @@ export default { confirmButtonText: "确认", cancelButtonText: "我再想想", type: "warning", - }).then(() => { - this.printDOMmount = true; - this.$nextTick(() => { - this.$refs["print"].print(data); + }) + .then(() => { + this.printDOMmount = true; + this.$nextTick(() => { + this.$refs["print"].print(data); + }); + }) + .catch((err) => { + // console.log("cancel ", err); }); - }); } } },