From 3f0a509bba98151a08f5abd057c7a6f77064f5bc Mon Sep 17 00:00:00 2001 From: lkk <364857242@qq.com> Date: 星期二, 29 十月 2024 11:31:21 +0800 Subject: [PATCH] 2024.10.29 --- src/views/sampling/sampling/index.vue | 382 +++++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 291 insertions(+), 91 deletions(-) diff --git a/src/views/sampling/sampling/index.vue b/src/views/sampling/sampling/index.vue index c4f2d65..5d4f164 100644 --- a/src/views/sampling/sampling/index.vue +++ b/src/views/sampling/sampling/index.vue @@ -274,7 +274,12 @@ <!-- 鍔ㄦ�佺敓鎴愬涓潯褰㈢爜鐨勫鍣� --> <div v-for="(item, index) in selectList" :key="index"> <svg :id="'barcode' + index"></svg> - <div class="name">{{ item.proName }}</div> + <!-- <div class="name">{{ item.proName }}</div> + <div class="name1">{{ item.proName }}</div> --> + <div class="name">{{ getTruncatedName(item.proName).truncated }}</div> + <div class="name1"> + {{ getTruncatedName(item.proName).remaining }} + </div> <div class="last"> <p>{{ item.cusName }}</p> <div> @@ -347,10 +352,11 @@ getCusCyList, mergeCaiYang, chexiaoCaiYang, + getTxmmccd, + getTxmkd, } from "@/api/sampling/sampling"; import { getNewDateList } from "@/api/hosp/order"; import moment from "moment"; -import ItemVue from "../../../layout/components/Sidebar/Item.vue"; export default { dicts: [ @@ -462,7 +468,80 @@ ); }, }, + methods: { + async getTruncatedName(proName) { + try { + const res = await getTxmmccd(); // 纭繚浣跨敤 async/await + console.log(res, 4545); + + // 鍘绘帀鎵�鏈夌┖鏍� + const trimmedProName = proName.replace(/\s+/g, ""); + + // 妫�鏌� res 鏄惁鏈夋晥 + if (res && res.msg) { + const number = Number(res.msg); + console.log(number, 4444); + + const truncated = + trimmedProName.length > number + ? trimmedProName.slice(0, number) + : trimmedProName; + const remaining = + trimmedProName.length > number ? trimmedProName.slice(number) : ""; + + return { truncated, remaining }; // 杩斿洖缁撴灉 + } else { + // 濡傛灉 res 鏃犳晥锛屼娇鐢ㄩ粯璁ゅ�� + const truncated = + trimmedProName.length > 35 + ? trimmedProName.slice(0, 35) + : trimmedProName; + const remaining = + trimmedProName.length > 35 ? trimmedProName.slice(35) : ""; + + return { truncated, remaining }; // 纭繚杩斿洖 + } + } catch (error) { + console.error("Error fetching data:", error); + return { truncated: "", remaining: "" }; // 鎹曡幏閿欒鏃剁殑杩斿洖鍊� + } + }, + /* getTruncatedName(proName) { + getTxmmccd().then((res) => { + console.log(res, 4545); + const number = Number(res.msg); + console.log(number, 4444); + if (res) { + const trimmedProName = proName.replace(/\s+/g, ""); // 鍘绘帀鎵�鏈夌┖鏍� + const truncated = + trimmedProName.length > res.msg + ? trimmedProName.slice(0, res.msg) + : trimmedProName; + const remaining = + trimmedProName.length > res.msg + ? trimmedProName.slice(res.msg) + : ""; + return { truncated, remaining }; + } else { + res.msg == "35"; + } + }); */ + + /* const trimmedProName = proName.replace(/\s+/g, ""); // 鍘绘帀鎵�鏈夌┖鏍� + const truncated = + trimmedProName.length > 35 + ? trimmedProName.slice(0, 35) + : trimmedProName; + const remaining = + trimmedProName.length > 35 ? trimmedProName.slice(35) : ""; + return { truncated, remaining }; */ + // }, + // 绀轰緥鐨勬棩鏈熸牸寮忓寲鏂规硶 + formatDate(date) { + const options = { year: "numeric", month: "2-digit", day: "2-digit" }; + return new Date(date).toLocaleDateString(undefined, options); + }, getdate() { getNewDateList().then((res) => { this.createTimeList = [ @@ -784,20 +863,21 @@ .catch((error) => { this.$message.error("璇锋眰澶辫触锛岃閲嶈瘯锛�"); }); - - // chexiaoCaiYang(data).then((res) => {}); }, /** 鐐瑰嚮琛ユ墦鏉$爜鎸夐挳 **/ - Collection() { - const jyxh = this.selectList.map((item) => item.jyxh); - // const selectedData = this.selectList.map((item) => ({ - // jyxh: item.jyxh, - // })); - console.log(this.selectList, 999); - // console.log(selectedData, 888); + async Collection() { + try { + // 璇锋眰鎺ュ彛骞惰幏鍙栧搴﹀�� + const widthResponse = await getTxmkd(); + console.log("浠� getTxmkd 杩斿洖鐨勫搷搴�:", widthResponse); // 鎵撳嵃鍚庣杩斿洖鍊� + const barcodeWidth = `${Number(widthResponse.msg)}%` || "70%"; // 鑾峰彇瀹藉害鍊硷紝榛樿浣跨敤 70% - this.$nextTick(() => { + const jyxh = this.selectList.map((item) => item.jyxh); + console.log(this.selectList, 999); + + await this.$nextTick(); // 纭繚 DOM 鏇存柊 + jyxh.forEach((number, index) => { const barcodeContent = number; // 纭繚 jyxh 鏄湁鏁堢殑 if (barcodeContent && barcodeContent !== "鏈彁渚涗綋妫�鍙�") { @@ -811,9 +891,125 @@ console.log(`鏉″舰鐮佸唴瀹规棤鏁�: ${barcodeContent}`); // 璋冭瘯杈撳嚭 } }); - }); - this.$nextTick(() => { + await this.$nextTick(); // 纭繚鏉″舰鐮佺敓鎴愬畬鎴� + + const barcodeElements = jyxh.map((_, index) => + document.querySelector(`#barcode${index}`) + ); + + if (barcodeElements) { + barcodeElements.forEach((element) => { + if (element) { + console.log(element.innerHTML); // 鎵撳嵃鏉″舰鐮佺殑鍐呭锛岀湅鐪嬫槸鍚︾敓鎴愭垚鍔� + } + }); + } else { + console.log("鏉″舰鐮佸厓绱犳湭鎵惧埌"); + } + + const newWindow = window.open("", "_blank", "width=800,height=600"); + const printContents = document.getElementById("printSection").innerHTML; + + console.log(printContents); + newWindow.document.write(` + <html> + <head> + <title>Print Barcode</title> + <style> + @media print { + * { + margin: 0; + padding: 0; /* 閲嶇疆鎵�鏈夊厓绱犵殑 margin 鍜� padding */ + box-sizing: border-box; /* 浣垮唴杈硅窛鍜岃竟妗嗗寘鍚湪鍏冪礌鐨勬�诲搴﹀拰楂樺害鍐� */ + } + body { + margin: 0; + padding: 0; + } + .barcode-container { + // width: 100%; /* 鏍规嵁闇�瑕佽皟鏁� */ + // text-align: center; /* 纭繚鏉″舰鐮佸眳涓� */ + } + .name, .name1 { + padding: 0; + font-size: 18px; + width: 70%; + } + p { + margin: 0; + padding: 0; + } + svg { + display: block; + width: ${barcodeWidth}; /* 浣跨敤浠庢帴鍙h幏鍙栫殑瀹藉害 */ + margin-left: 10mm; + height: auto; + margin-bottom: 0; + } + .last { + width: 66%; + display: flex; + font-size: 19px; + justify-content: space-between; + font-family: "Arial Black", sans-serif; /* 璁剧疆榛戜綋 */ + } + .last div span { + margin-left: 10px; + } + .last p { + margin-left: 10px; + } + .tj { + width: 70%; + display: flex; + font-size: 19px; + justify-content: space-between; + font-family: "Arial Black", sans-serif; /* 璁剧疆榛戜綋 */ + } + .tj span { + margin-left: 10px; + } + } + </style> + </head> + <body>${printContents}</body> + </html> + `); + newWindow.document.close(); + newWindow.focus(); + newWindow.print(); + newWindow.close(); + } catch (error) { + console.error("鑾峰彇瀹藉害鏃跺嚭閿�:", error); // 鎹曡幏閿欒 + } + }, + + // Collection() { + // const jyxh = this.selectList.map((item) => item.jyxh); + // const selectedData = this.selectList.map((item) => ({ + // jyxh: item.jyxh, + // })); + // console.log(this.selectList, 999); + // console.log(selectedData, 888); + + /* this.$nextTick(() => { + jyxh.forEach((number, index) => { + const barcodeContent = number; // 纭繚 jyxh 鏄湁鏁堢殑 + if (barcodeContent && barcodeContent !== "鏈彁渚涗綋妫�鍙�") { + JsBarcode(`#barcode${index}`, barcodeContent, { + format: "CODE128", + width: 2, + height: 50, + displayValue: false, + }); + } else { + console.log(`鏉″舰鐮佸唴瀹规棤鏁�: ${barcodeContent}`); // 璋冭瘯杈撳嚭 + } + }); + }); */ + + /* this.$nextTick(() => { const barcodeElement = document.querySelector("#barcode"); // const barcodeElements = selectedData.map((_, index) => // document.querySelector(`#barcode${index}`) @@ -831,81 +1027,86 @@ const newWindow = window.open("", "_blank", "width=800,height=600"); const printContents = document.getElementById("printSection").innerHTML; - console.log(printContents); - newWindow.document.write(` - <html> - <head> - <title>Print Barcode</title> - <style> - @media print { - * { - margin: 0; - padding: 0; /* 閲嶇疆鎵�鏈夊厓绱犵殑 margin 鍜� padding */ - box-sizing: border-box; /* 浣垮唴杈硅窛鍜岃竟妗嗗寘鍚湪鍏冪礌鐨勬�诲搴﹀拰楂樺害鍐� */ - } - body { - margin: 0; - padding: 0; - } - .barcode-container { - width: 100%; /* 鏍规嵁闇�瑕佽皟鏁� */ - text-align: center; /* 纭繚鏉″舰鐮佸眳涓� */ - } - .name { - padding: 0; - margin: -5px auto 0; - padding-left: 20px; - font-size: 18px; - width: 90%; - display: -webkit-box; - -webkit-box-orient: vertical; - -webkit-line-clamp: 2; - overflow: hidden; - white-space: normal; - } - p { - margin: 0; - padding: 0; - } - svg { - display: block; - width: 70%; - margin: 0 auto; - height: auto; - margin-bottom: 0; - } - .last { - width: 66%; - display: flex; - font-size: 19px; - margin-left: 20px; - justify-content: space-between; - } - .last div span{ - margin-left: 10px - } - .tj{ - width: 70%; - display: flex; - font-size: 19px; - margin-left: 10px; - justify-content: space-between; - } - .tj span{ - margin-left:10px; - } - } - </style> - </head> - <body>${printContents}</body> - </html> - `); - newWindow.document.close(); - newWindow.focus(); - newWindow.print(); - newWindow.close(); - }); - }, + console.log(printContents); */ + // newWindow.document.write(` + // <html> + // <head> + // <title>Print Barcode</title> + // <style> + // @media print { + // * { + // margin: 0; + // padding: 0; /* 閲嶇疆鎵�鏈夊厓绱犵殑 margin 鍜� padding */ + // box-sizing: border-box; /* 浣垮唴杈硅窛鍜岃竟妗嗗寘鍚湪鍏冪礌鐨勬�诲搴﹀拰楂樺害鍐� */ + // } + // body { + // margin: 0; + // padding: 0; + // } + // .barcode-container { + // // width: 100%; /* 鏍规嵁闇�瑕佽皟鏁� */ + // // text-align: center; /* 纭繚鏉″舰鐮佸眳涓� */ + // } + // .name,.name1 { + // padding: 0; + // // margin: -5px auto 0; + // // padding-left: 20px; + // font-size: 18px; + // width: 70%; + // // max-height: 3.6em; + // // display: -webkit-box; + // // -webkit-box-orient: vertical; + // // -webkit-line-clamp: 2; + // // overflow: hidden; + // // white-space: normal; + // } + // p { + // margin: 0; + // padding: 0; + // } + // svg { + // display: block; + // width: 70%; + // margin-left: 10mm; + // // margin: 0 auto; + // height: auto; + // margin-bottom: 0; + // } + // .last { + // width: 66%; + // display: flex; + // font-size: 19px; + // // margin-left: 20px; + // justify-content: space-between; + // } + // .last div span{ + // margin-left: 10px + // } + // .last p{ + // margin-left: 10px + // } + // .tj{ + // width: 70%; + // display: flex; + // font-size: 19px; + // // margin-left: 10px; + // justify-content: space-between; + // } + // .tj span{ + // margin-left:10px; + // } + // } + // </style> + // </head> + // <body>${printContents}</body> + // </html> + // `); + // newWindow.document.close(); + // newWindow.focus(); + // newWindow.print(); + // newWindow.close(); + // }); + // }, tableRowClassName({ row, rowIndex }) { for (let i = 0; i < this.selectList.length; i++) { @@ -917,7 +1118,7 @@ handleChange(selection) { console.log(selection); - + this.selectList = selection; this.ids = selection.map((item) => item.id); @@ -1015,5 +1216,4 @@ .el-table .warning-row { background-color: #e5f3ff !important; } - </style> -- Gitblit v1.8.0