Browse Source

打印优化

lilei 3 years ago
parent
commit
287548857b

+ 121 - 7
src/libs/JGPrint.js

@@ -34,8 +34,26 @@ export const JGPrintTag = function (html, width, height, data) {
   LODOP.SET_PRINT_PAGESIZE(1, width, height)
   LODOP.PRINT()
 }
- 
-// 导出下载excel
+// 导出文件
+export const exportExcel = function(url,params,fileName,callback){
+  url(params).then(res => {
+    if (res.type == 'application/json') {
+      var reader = new FileReader()
+      reader.addEventListener('loadend', function () {
+        const obj = JSON.parse(reader.result)
+        notification.error({
+          message: '提示',
+          description: obj.message
+        })
+      })
+      reader.readAsText(res)
+    } else {
+       downloadExcel(res,fileName)
+    }
+    callback()
+  })
+}
+// 下载excel
 export const downloadExcel = function (data, fileName) {
   if (!data) { return }
   const a = moment().format('YYYYMMDDHHmmss')
@@ -56,7 +74,16 @@ export const downloadExcel = function (data, fileName) {
   }
 }
 
-// 打印控件
+// pdf blob 转 base64
+export const blobToBaseByPdf = function(data,callback){
+  const reader = new FileReader()
+  reader.readAsDataURL(new Blob([data], { type: 'application/pdf' }))
+  reader.addEventListener('load', () => {
+    callback(reader.result)
+  })
+}
+
+// 打印html
 export const jGPrint = function (data, type) {
     if (!data) {
       return
@@ -81,13 +108,100 @@ export const jGPrint = function (data, type) {
       return
     }
     LODOP.SET_SHOW_MODE('HIDE_PAPER_BOARD', 1) //  隐藏底图上有模拟走纸板的条纹线
-    // LODOP.SET_PRINT_MODE('POS_BASEON_PAPER', true) // 可使输出以纸张边缘为基点
-    // LODOP.SET_PRINT_STYLEA(0,"TableRowThickNess",50)
+    //执行该语句之后,PRINT指令不再返回那个所谓“打印成功”,才能获取到打印状态
+    LODOP.SET_PRINT_MODE("CATCH_PRINT_STATUS",true);
+    //TaskID:任务id,Value:job代码
+    LODOP.On_Return=function(TaskID,Value){
+       console.log(TaskID,Value)
+       // 已打印
+       if(Value){
+         console.log('已打印,统计打印次数')
+       }
+    };
     LODOP.ADD_PRINT_HTM(10, 2, '98%', '100%', data)
     LODOP.SET_PRINT_PAGESIZE(1,2100,0,"");
     if (type == 'preview') { //  预览
       LODOP.PREVIEW()
     } else if (type == 'print') { //  打印
-      LODOP.PRINT()
+      LODOP.PRINTA()
+    }
+}
+
+// 打印
+export const printFun = function(url,params,type,taskName,callback){
+  url(params).then(res => {
+    if (res.type == 'application/json') {
+      var reader = new FileReader()
+      reader.addEventListener('loadend', function () {
+        const obj = JSON.parse(reader.result)
+        notification.error({
+          message: '提示',
+          description: obj.message
+        })
+      })
+      reader.readAsText(res)
+    } else {
+       jGPrintPdf(res,type,taskName)
+    }
+    callback()
+  })
+}
+// 打印pdf
+export const jGPrintPdf = function (data, type, taskName) {
+    if (!data) {
+      return
+    }
+    const LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'))
+    if (!LODOP) {
+      confirm({
+        title: '提示?',
+        content: h => <div>打印控件未安装,请先下载并安装。安装完成后,刷新页面即可打印。</div>,
+        okText: '立即下载',
+        okType: 'danger',
+        cancelText: '暂不打印',
+        onOk () {
+          var agent = navigator.userAgent.toLowerCase();
+          if (agent.indexOf("win32") >= 0 || agent.indexOf("wow32") >= 0) {
+              window.open('http://www.lodop.net/demolist/CLodop_Setup_for_Win32NT.zip')
+          }else if (agent.indexOf("win64") >= 0 || agent.indexOf("wow64") >= 0) {
+              window.open('http://www.lodop.net/download/CLodop_Setup_for_Win64NT_4.155EN.zip')
+          }
+        }
+      })
+      return
+    }
+    blobToBaseByPdf(data, function (dataurl) {
+      console.log(dataurl)
+      LODOP.PRINT_INIT(taskName)
+      LODOP.SET_SHOW_MODE('HIDE_PAPER_BOARD', 1) //  隐藏底图上有模拟走纸板的条纹线
+      //执行该语句之后,PRINT指令不再返回那个所谓“打印成功”,才能获取到打印状态
+      LODOP.SET_PRINT_MODE("CATCH_PRINT_STATUS",true);
+      //TaskID:任务id,Value:job代码
+      LODOP.On_Return=function(TaskID,Value){
+         console.log(TaskID,Value)
+         // 已打印
+         if(Value){
+           console.log('已打印,统计打印次数')
+         }
+      };
+      LODOP.ADD_PRINT_PDF(0, 0, '100%', '100%', dataurl.replace('data:application/pdf;base64,', ''))
+      LODOP.SET_PRINT_PAGESIZE(3,2090,30,"");
+      if (type == 'preview') { //  预览
+        LODOP.PREVIEW()
+      } else if (type == 'print') { //  打印
+        LODOP.PRINTA()
+      }
+    })
+}
+
+// 获取打印机状态
+export const getStatusValue = function (ValueType,ValueIndex,callback){
+		const LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'))
+		if (LODOP.CVERSION) {
+      LODOP.On_Return=function(TaskID,Value){
+        callback(Value)
+      };
     }
-}
+		var strResult=LODOP.GET_VALUE(ValueType,ValueIndex);
+		if (!LODOP.CVERSION) return callback(strResult); else return callback('');
+	}

+ 11 - 0
src/views/dealerManagement/merchantInfoManagement/edit.vue

@@ -146,6 +146,16 @@
                       placeholder="请输入经营项目(最多100个字符)" />
                   </a-form-model-item>
                 </a-col>
+                <a-col :xs="24" :sm="24" :md="12" :lg="8" :xl="8">
+                  <a-form-model-item label="营业执照名称" prop="licenseName">
+                    <a-input
+                      v-model.trim="form.licenseName"
+                      id="merchantInfoManagementEdit-licenseName"
+                      :maxLength="100"
+                      allowClear
+                      placeholder="请输入营业执照名称(最多100个字符)" />
+                  </a-form-model-item>
+                </a-col>
                 <a-col :xs="24" :sm="24" :md="12" :lg="8" :xl="8">
                   <a-form-model-item label="公司规模" prop="busniessScope" help="(例:100-999人)">
                     <a-input-number
@@ -429,6 +439,7 @@ export default {
         dealerTelephone: '',
         busniessMode: '',
         busniessItmes: '',
+        licenseName: '',
         busniessScope: '',
         buildDate: '',
         isTaxpayer: undefined,

+ 0 - 5
src/views/expenseManagement/expenseReimbursement/detail.vue

@@ -163,11 +163,6 @@ export default {
     // 打印
     handlePrint (type) {
       const html = document.getElementById('printTest').innerHTML
-      // var iframe = document.getElementById('printfsqd')
-      // var iframedoc = iframe.contentDocument || iframe.contentWindow.document
-      // iframedoc.body.innerHTML = html
-      // window.frames['printfsqd'].focus()
-      // window.frames['printfsqd'].print()
       jGPrint(html, type)
     },
     //  详情

+ 8 - 37
src/views/salesManagement/pushOrderManagement/detail.vue

@@ -90,8 +90,8 @@
         </s-table>
       </a-card>
     </a-spin>
-    <!-- 分类打印 -->
-    <sendTypeModal ref="typePrint" :openModal="openModal" @ok="handleOk" @close="openModal=false" />
+    <!-- 发货分类打印 -->
+    <sendTypeModal ref="typePrint" :openModal="openModal" @ok="requestFun" @close="openModal=false" />
     <!-- 导出Excel -->
     <export-excel-modal :openModal="openExcelModal" :itemData="detailData" @ok="handleExcelOk" @close="openExcelModal=false" />
     <!-- 打印 -->
@@ -104,7 +104,7 @@ import { commonMixin } from '@/utils/mixin'
 import { STable, VSelect } from '@/components'
 import sendTypeModal from './sendTypeModal.vue'
 import exportExcelModal from './exportExcelModal.vue'
-import { hdExportExcel } from '@/libs/exportExcel'
+import { printFun, exportExcel } from '@/libs/JGPrint.js'
 import { dispatchDetaillList, dispatchFindBySn, dispatchDetailPrint, dispatchDetailExcel } from '@/api/dispatch'
 export default {
   name: 'PushOrderDetail',
@@ -213,58 +213,29 @@ export default {
         printType: priceType
       }
       this.spinning = true
-      hdExportExcel(dispatchDetailExcel, params, '下推产品', function () {
+      exportExcel(dispatchDetailExcel, params, '下推产品', function () {
         _this.spinning = false
       })
     },
-    // 分类选择
-    handleOk (obj) {
-      this.requestFun(obj)
-    },
     // 打印预览/快捷打印
     handlePrint (type) {
       this.nowPrintType = type
       if (type == 'DISPATCH_BILL') { // 发货打印
-        this.requestFun()
+        this.requestFun(null, '发货')
       } else if (type == 'DISPATCH_BILL_TYPE') { // 发货分类打印
         this.openModal = true
         this.$refs.typePrint.setData(this.detailData, this.outBizSubSn || this.$route.params.sn)
       }
     },
-    // 打印
-    requestFun (obj) {
+    // 发货分类打印
+    requestFun (obj, taskName) {
       const _this = this
       const params = {
         type: this.nowPrintType,
         dispatchBillSn: this.outBizSubSn || this.$route.params.sn
       }
       _this.spinning = true
-      dispatchDetailPrint(Object.assign(params, obj || {})).then(res => {
-        _this.spinning = false
-        if (res.type == 'application/json') {
-          var reader = new FileReader()
-          reader.addEventListener('loadend', function () {
-            const obj = JSON.parse(reader.result)
-            _this.$notification.error({
-              message: '提示',
-              description: obj.message
-            })
-          })
-          reader.readAsText(res)
-        } else {
-          this.print(res)
-        }
-      })
-    },
-    print (data) {
-      this.spinLoading = false
-      if (!data) {
-        return
-      }
-      const url = window.URL.createObjectURL(new Blob([data], { type: 'application/pdf' }))
-      document.getElementById('print').innerHTML = '<iframe id="printfpmd" name="printfpmd" src="' + url + '" hidden></iframe>'
-      window.frames['printfpmd'].focus()
-      window.frames['printfpmd'].print()
+      printFun(dispatchDetailPrint, Object.assign(params, obj || {}), 'print', taskName, () => { _this.spinning = false })
     }
   },
   mounted () {

+ 1 - 1
src/views/salesManagement/pushOrderManagement/sendTypeModal.vue

@@ -93,7 +93,7 @@ export default {
               productTypeSn: item.productTypeSn,
               dispatchBillSn: this.detailData.dispatchBillSn
             }
-            _this.$emit('ok', obj)
+            _this.$emit('ok', obj, '发货分类')
           }
           _this.isShow = false
         } else {

+ 16 - 66
src/views/salesManagement/salesQuery/detail.vue

@@ -189,6 +189,7 @@
 </template>
 
 <script>
+import { printFun, exportExcel } from '@/libs/JGPrint.js'
 import { commonMixin } from '@/utils/mixin'
 import moment from 'moment'
 import { STable, VSelect } from '@/components'
@@ -383,83 +384,32 @@ export default {
     },
     // 打印导出
     handlePrint (type) {
+      const _this = this
+      // 销售分类导出
       if (type == 'typeExport') {
-        this.nowType = type
-        this.handleOk()
+        const params = {
+          salesBillSn: this.$route.params.sn,
+          showCostFlag: this.$hasPermissions('B_isShowCost')
+        }
+        _this.spinning = true
+        exportExcel(salesDetailTypeExcel, params, '销售分类' + moment().format('YYYYMMDDHHmmss'), () => { _this.spinning = false })
       } else {
         this.nowType = type
         this.openModal = true
       }
     },
+    // 确定打印或预览
     handleOk (objs) {
       const _this = this
-      let params
-      let url = salesDetailPrint //  打印
+      const params = JSON.parse(JSON.stringify(objs))
+      delete params.type
+      _this.spinning = true
       if (this.nowType == 'export') { //  导出
-        url = salesDetailExcel
-        params = JSON.parse(JSON.stringify(objs))
-        delete params.type
-      } else if (this.nowType == 'typeExport') { //  分类导出
-        url = salesDetailTypeExcel
-        params = {
-          salesBillSn: this.$route.params.sn,
-          showCostFlag: this.$hasPermissions('B_isShowCost')
-        }
+        exportExcel(salesDetailExcel, params, '销售' + moment().format('YYYYMMDDHHmmss'), () => { _this.spinning = false })
       } else { //  打印
-        params = JSON.parse(JSON.stringify(objs))
-        delete params.type
-      }
-      _this.spinning = true
-      url(params).then(res => {
-        _this.spinning = false
-        if (res.type == 'application/json') {
-          var reader = new FileReader()
-          reader.addEventListener('loadend', function () {
-            const obj = JSON.parse(reader.result)
-            _this.$notification.error({
-              message: '提示',
-              description: obj.message
-            })
-          })
-          reader.readAsText(res)
-        } else {
-          if (this.nowType == 'export' || this.nowType == 'typeExport') {
-            this.download(res)
-          } else {
-            this.print(res, objs.type)
-          }
-        }
-      })
-    },
-    print (data, type) {
-      if (!data) {
-        return
-      }
-      const url = window.URL.createObjectURL(new Blob([data], { type: 'application/pdf' }))
-      document.getElementById('print').innerHTML = '<iframe id="printfsqd" name="printfsqd" src="' + url + '" hidden></iframe>'
-      if (type == 'preview') { //  预览
-        window.open(url)
-      } else if (type == 'print') { //  打印
-        window.frames['printfsqd'].focus()
-        window.frames['printfsqd'].print()
-      }
-    },
-    download (data) {
-      if (!data) { return }
-      const url = window.URL.createObjectURL(new Blob([data]))
-      const link = document.createElement('a')
-      link.style.display = 'none'
-      link.href = url
-      const a = moment().format('YYYYMMDDHHmmss')
-      let fname = ''
-      if (this.nowType == 'typeExport') {
-        fname = '销售分类' + a
-      } else {
-        fname = '销售' + a
+        const taskName = this.nowType == 'SALES_BILL' ? '销售单' : '销售分类'
+        printFun(salesDetailPrint, params, objs.type, taskName, () => { _this.spinning = false })
       }
-      link.setAttribute('download', fname + '.xlsx')
-      document.body.appendChild(link)
-      link.click()
     }
   },
   mounted () {

+ 9 - 47
src/views/salesManagement/salesReturn/detail.vue

@@ -107,6 +107,7 @@ import { commonMixin } from '@/utils/mixin'
 import moment from 'moment'
 import { getOperationalPrecision } from '@/libs/tools.js'
 import { STable, VSelect } from '@/components'
+import { printFun, exportExcel } from '@/libs/JGPrint.js'
 import auditModal from '@/views/common/auditModal.vue'
 import { salesReturnDetail, salesReturnAudit, salesReturnPrint, salesReturnExport } from '@/api/salesReturn'
 import { salesReturnDetailList } from '@/api/salesReturnDetail'
@@ -206,56 +207,17 @@ export default {
     // 打印预览/快捷打印
     handlePrint (type) {
       const _this = this
+      const params = { sn: this.$route.params.sn }
       _this.spinning = true
-      let url = salesReturnPrint
+      // 导出
       if (type == 'export') {
-        url = salesReturnExport
-      }
-      url({ sn: this.$route.params.sn }).then(res => {
-        _this.spinning = false
-        if (res.type == 'application/json') {
-          var reader = new FileReader()
-          reader.addEventListener('loadend', function () {
-            const obj = JSON.parse(reader.result)
-            _this.$notification.error({
-              message: '提示',
-              description: obj.message
-            })
-          })
-          reader.readAsText(res)
-        } else {
-          if (type == 'export') {
-            this.download(res)
-          } else {
-            this.print(res, type)
-          }
-        }
-      })
-    },
-    print (data, type) {
-      if (!data) {
-        return
-      }
-      const url = window.URL.createObjectURL(new Blob([data], { type: 'application/pdf' }))
-      document.getElementById('print').innerHTML = '<iframe id="printfsrd" name="printfsrd" src="' + url + '" hidden></iframe>'
-      if (type == 'preview') { //  预览
-        window.open(url)
-      } else if (type == 'print') { //  打印
-        window.frames['printfsrd'].focus()
-        window.frames['printfsrd'].print()
+        exportExcel(salesReturnExport, params, '销售退货', function () {
+          _this.spinning = false
+        })
+      } else {
+        // 打印或预览
+        printFun(salesReturnPrint, params, type, '销售退货', () => { _this.spinning = false })
       }
-    },
-    download (data) {
-      if (!data) { return }
-      const url = window.URL.createObjectURL(new Blob([data]))
-      const link = document.createElement('a')
-      link.style.display = 'none'
-      link.href = url
-      const a = moment().format('YYYYMMDDHHmmss')
-      const fname = '销售退货' + a
-      link.setAttribute('download', fname + '.xlsx')
-      document.body.appendChild(link)
-      link.click()
     }
   },
   mounted () {