Ver código fonte

打印优化

lilei 2 anos atrás
pai
commit
2054fc1e02

+ 20 - 5
src/libs/JGPrint.js

@@ -142,6 +142,23 @@ export const jGPrint = function (data, type, callback, printLogParams, printPage
   }
 }
 
+// 自动排版, 遍历数组,将数组中每一个数值加起来,如果和小于某个数,则将这些数值存放到一个新数组中。
+export const groupLessThan = function(numbers, targetSum) {
+  let currentSum = 0;
+  let result = [];
+  for (let i = 0; i < numbers.length; i++) {
+    currentSum += numbers[i].h;
+    if (currentSum <= targetSum) {
+      result.push(numbers[i].t);
+    } else {
+      result.push('&-NEWPAGE-&'); // 用'&-NEWPAGE-&'作为分页符
+      currentSum = numbers[i].h; // 重新计算当前总和
+      result.push(numbers[i].t);
+    }
+  }
+  return result;
+}
+
 // 批量打印销售收款单html
 export const jGPlPrint = function (data, type, callback, printLogParams, taskName) {
   if (!data) {
@@ -189,11 +206,9 @@ export const jGPlPrint = function (data, type, callback, printLogParams, taskNam
   LODOP.SET_PRINT_PAGESIZE(1,'210mm','297mm',"");
   LODOP.SET_SHOW_MODE('BKIMG_PRINT', 0)
   // 循环页
-  for(var i=0;i<data.length;i=i+2){
-     if(i%2==0){
-       LODOP.NewPage();
-     }
-     LODOP.ADD_PRINT_HTM(0, 0, '100%', '99%', data[i]+(data[i+1]||''))
+  for(var i=0;i<data.length;i++){
+    LODOP.NewPage();
+    LODOP.ADD_PRINT_HTM(0, 0, '100%', '99%', data[i])
   }
   
   if (type == 'preview') { //  预览

+ 6 - 11
src/views/expenseManagement/expenseReimbursement/previewModal.vue

@@ -125,7 +125,8 @@
 
 <script>
 import { commonMixin } from '@/utils/mixin'
-import { jGPlPrint } from '@/libs/JGPrint.js'
+import { jGPlPrint, groupLessThan } from '@/libs/JGPrint.js'
+
 export default {
   mixins: [commonMixin],
   data () {
@@ -154,19 +155,13 @@ export default {
       printCons.sort((a, b) => {
         return a['h'] - b['h']
       })
-
-      const htmlStr = []
-      for (let i = 0; i < printCons.length; i++) {
-        if (printCons[i].h > 560) {
-          htmlStr.push('')
-        }
-        printCons[i].t = '<div style="height:530px;margin:0 auto;">' +printCons[i].t+'</div>'
-        htmlStr.push(printCons[i].t)
-      }
+      // 自动排版
+      const htmlStr = groupLessThan(printCons, 560*2)
+      // console.log(htmlStr.join('').split('&-NEWPAGE-&'))
       this.$store.state.app.curActionPermission = 'B_eRPrint'
       // html, type, callback, printLogParams
       // console.log(htmlStr)
-      jGPlPrint(htmlStr, 'print', function (res) {
+      jGPlPrint(htmlStr.join('').split('&-NEWPAGE-&'), 'print', function (res) {
         _this.$store.state.app.curActionPermission = ''
         _this.$emit('printOk', res)
       },null,'费用报销单')

+ 5 - 11
src/views/salesManagement/receiptPrint/printModel.vue

@@ -82,7 +82,7 @@
 </template>
 
 <script>
-import { jGPlPrint } from '@/libs/JGPrint.js'
+import { jGPlPrint, groupLessThan } from '@/libs/JGPrint.js'
 import moment from 'moment'
 export default {
   data () {
@@ -120,19 +120,13 @@ export default {
         return a['h'] - b['h']
       })
 
-      const htmlStr = []
-      for (let i = 0; i < printCons.length; i++) {
-        if (printCons[i].h > 560) {
-          htmlStr.push('')
-        }else{
-          printCons[i].t = '<div style="width:564pt;margin:0 auto;height:535px;">' +printCons[i].t+'</div>'
-        }
-        htmlStr.push(printCons[i].t)
-      }
+      // 自动排版
+      const htmlStr = groupLessThan(printCons, 1120)
+      // console.log(htmlStr.join('').split('&-NEWPAGE-&'))
       this.$store.state.app.curActionPermission = 'B_SkPrint'
       // html, type, callback, printLogParams
       this.spinning = true
-      jGPlPrint(htmlStr, 'print', function (res) {
+      jGPlPrint(htmlStr.join('').split('&-NEWPAGE-&'), 'print', function (res) {
         if(res){
           _this.handleCommonCancel()
         }