浏览代码

lodop打印flex布局失效问题

zengfanwei 1 月之前
父节点
当前提交
7ea16c6f75
共有 1 个文件被更改,包括 106 次插入27 次删除
  1. 106 27
      src/views/hospitalization/nurse-module/PrintInfusionCard.vue

+ 106 - 27
src/views/hospitalization/nurse-module/PrintInfusionCard.vue

@@ -87,14 +87,38 @@
               :id="item.patInfo.patNo+'-'+index"
               style="margin: 0px 12px"
           >
-            <div style="margin-bottom: 10px;">
               <bottle-card
                 :drugs="item.bottleCardDrugs"
                 :pat-info="item.patInfo"
                 :yz-date="queryParams.executeDate"
+                style="margin-bottom: 10px;"
               >
               </bottle-card>
-            </div>
+          </div>
+        </div>
+        <div class="print-hiden-area" style="margin: 0px 12px" id="print-test">
+          <div
+              class="print-bottle-card-area"
+              style="margin: 0px 12px;"
+          >
+              <div 
+                v-for="(item,index) in printPatientBottleInfos"
+                :id="item.patInfo.patNo+'-'+index"
+                style="width:260px;"
+              >
+                  <bottle-card
+                  :drugs="item.bottleCardDrugs"
+                  :pat-info="item.patInfo"
+                  :yz-date="queryParams.executeDate"
+                  style="margin-bottom: 10px;"
+              >
+                  </bottle-card>
+              </div>
+              <div 
+                v-if="printPatientBottleInfos.length!= 0 && printPatientBottleInfos.length % 2 !=0"
+                style="width: 260px;"
+              >
+              </div>
           </div>
         </div>
       </div>
@@ -152,6 +176,7 @@ const queryParams = reactive({
 })
 
 const patientInfusionInfos = ref([])
+const printPatientBottleInfos = ref([])
 
 const handleStartBedChange = (bed) => {
   queryParams.bedNoStart = bed.bedNoLabel
@@ -197,28 +222,13 @@ const execPrint = () => {
     })
     return
   }
-  let LODOP = getLodop();
-
-  const prntStyle = `<style>td{border: 1px solid black;
-  font-size: 12px;padding: 2px;}</style>`
-
-  // let cardLength = patientInfusionInfos.value.length
-  // for (let i = 0; i < cardLength; i++) {
-  //   let info = patientInfusionInfos.value[i]
-  //   let id = queryParams.cardType === 'INFUSION_CARD'
-  //       ? info.patInfo.patNo + 'a' + i : info.patInfo.patNo + '-' + i
-  //   const prntContent = document.getElementById(id).innerHTML
-  //   let pagePrint = prntStyle + '<body>' + prntContent + '</body>'
-  //   LODOP.PRINT_INIT('infusionCard')
-  //   LODOP.SET_PRINT_PAGESIZE(1, '210mm', '297mm', '')
-  //   LODOP.ADD_PRINT_TABLE('0mm', '0mm', '210mm', '230mm', pagePrint)
-  //   LODOP.SET_PRINT_STYLE('ItemType', 3)
-  //   LODOP.PREVIEW();
-  //   // LODOP.PRINT()
-  // }
-    let prntContent = document.getElementById("infusion_list").innerHTML
+    let LODOP = getLodop();
+    if(queryParams.cardType=='INFUSION_CARD'){
+          let prntContent = document.getElementById("infusion_list").innerHTML
     // console.log("prntContent",prntContent)
     let printHTML = ""
+    const prntStyle = `<style>td{border: 1px solid black;
+    font-size: 12px;padding: 2px;}</style>`
     if(patientInfusionInfos.value.length == 1){
       let id = queryParams.cardType === 'INFUSION_CARD'
           ? patientInfusionInfos.value[0].patInfo.patNo : patientInfusionInfos.value[0].patInfo.patNo + '-' + i
@@ -237,22 +247,44 @@ const execPrint = () => {
               ? 3 : 6
             // console.log("printCount",printCount)
             if(i !== 0 && ((i + 1) % printCount == 0 || i == patientInfusionInfos.value.length - 1)) {
-            // console.log("printHTML",printHTML)
             // console.log("printIndex",i)
+            let printFinal = prntStyle + '<body><div style:"width:600px;display: flex;justify-content: center;align-items: center;flex-wrap: wrap;">' + printHTML + '</div></body>' ;
+            console.log("printFinal",printFinal)
             printHTML += document.getElementById(id).innerHTML
             LODOP.PRINT_INIT('infusionCard')
             LODOP.SET_PRINT_PAGESIZE(1, '210mm', '297mm', '')
-            LODOP.ADD_PRINT_HTML('0mm', '0mm', '210mm', '297mm',prntStyle + '<body style:"display: flex;justify-content: center;align-items: center;">' + printHTML + '</body>' )
+            // LODOP.ADD_PRINT_HTML('0mm', '0mm', '210mm', '297mm',prntStyle + '<body style:"width:800px;display: flex;justify-content: center;align-items: center;flex-wrap: wrap;">' + printHTML + '</body>' )
+            LODOP.ADD_PRINT_HTML('0mm', '0mm', '210mm', '297mm',printFinal )
             LODOP.SET_PRINT_STYLE('ItemType', 3)
-            // LODOP.PREVIEW();  
-            LODOP.PRINT()
+            LODOP.PREVIEW();  
+            // LODOP.PRINT()
             printHTML = ""
             } else {
               printHTML += document.getElementById(id).innerHTML
             }
         }
+      }
+      updatePrintState()
+    } else {
+      printPatientBottleInfos.value = [...patientInfusionInfos.value ]
+      // console.log("patientInfusionInfos",patientInfusionInfos.value)
+      // console.log("printPatientBottleInfos",printPatientBottleInfos.value)
+      nextTick(() => {
+        let prntContent1 = document.getElementById("print-test").innerHTML
+        let flexStyles = getStyleText('.print-bottle-card-area');
+        const prntStyle = `<style>${flexStyles}td{border: 1px solid black;
+        font-size: 12px;padding: 2px;}</style>`
+        let printFinal = prntStyle + prntContent1
+        // console.log("prntContent1",prntContent1)
+        LODOP.PRINT_INIT('infusionCard')
+        LODOP.SET_PRINT_PAGESIZE(1, '210mm', '297mm', '')
+        LODOP.ADD_PRINT_HTML('0mm', '0mm', '210mm', '297mm',printFinal)
+        LODOP.SET_PRINT_STYLE('ItemType', 3)
+        LODOP.PREVIEW();
+        printPatientBottleInfos.value = []
+        updatePrintState()
+      });
     }
-  updatePrintState()
 }
 
 function updatePrintState() {
@@ -281,6 +313,24 @@ function updatePrintState() {
 
 }
 
+function getStyleText(selector) {
+    var sheets = document.styleSheets;
+    var styleText = '';
+    for (var i = 0; i < sheets.length; i++) {
+        try {
+            var rules = sheets[i].cssRules || sheets[i].rules;
+            if (rules) {
+                for (var j = 0; j < rules.length; j++) {
+                    if (rules[j].selectorText && rules[j].selectorText.includes(selector)) {
+                        styleText += rules[j].cssText + '\n';
+                    }
+                }
+            }
+        } catch(e) { /* 可能跨域安全错误 */ }
+    }
+    return styleText;
+}
+
 // J,S,JS,SJ
 // -- 小输液卡
 // -- 已打印:print_comment like '%S%'
@@ -319,4 +369,33 @@ onMounted(() => {
   justify-content: center;
   align-items: center;
 }
+.print-bottle-card-area{
+  width: 700px;
+  display: flex;
+  justify-content: space-between;
+  /* align-items: center; */
+  flex-wrap: wrap;
+  padding: 15px 5px;
+}
+.print-hiden-area{
+  display: none;
+}
+@media print {
+    .your-flex-container {
+        display: flex !important;
+        flex-direction: row !important;
+        /* 其他必要flex属性 */
+    }
+    
+    .flex-item {
+        flex: 1 !important;
+    }
+    .print-bottle-card-area{
+      width: 550px;
+      display: flex;
+      justify-content: center;
+      /* align-items: center; */
+      flex-wrap: wrap;
+    }
+}
 </style>