lilei 3 роки тому
батько
коміт
ca4698edd5

+ 52 - 0
src/libs/JGPrint.js

@@ -1,5 +1,8 @@
 import confirm from 'ant-design-vue/es/modal/confirm'
+import notification from 'ant-design-vue/es/notification'
 import { getLodop } from '@/libs/LodopFuncs'
+import moment from 'moment'
+// 打印控件
 export const JGPrint = function(data, type, printerType){
   if (!data) {
     return
@@ -45,4 +48,53 @@ export const JGPrint = function(data, type, printerType){
       window.frames['printfsqd'].print()
     }
   }
+}
+
+// 导出下载excel
+export const downloadExcel = function (data,fileName){
+   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 = fileName + a
+   link.setAttribute('download', fname + '.xlsx')
+   document.body.appendChild(link)
+   link.click()
+}
+
+/*
+  *printerType: 打印机类型
+  *type: 打印预览,打印,导出
+  *url: 数据请求接口
+  *params: 请求参数
+  *fileName: 导出文件名称
+  *callback: 回调函数
+*/
+export const hdPrint = function (printerType,type,url,params,fileName,callback){
+  // 打印时需要传打印机类型
+  if(type !== 'export'){
+    params.type = printerType
+  }
+  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 {
+      if (type == 'export') { //  导出
+        downloadExcel(res, fileName)
+      } else { // 打印
+        JGPrint(res, type, printerType)
+      }
+    }
+    callback()
+  })
 }

+ 49 - 0
src/views/common/print.vue

@@ -0,0 +1,49 @@
+<template>
+  <div class="print-page-header">
+    <a-radio-group key="4" id="print-printerType" v-model="printerType">
+      <a-radio value="NEEDLE">针式</a-radio>
+      <a-radio value="INK">喷墨</a-radio>
+    </a-radio-group>
+    <a-button key="3" id="print-preview-btn" :disabled="disabled" @click="handlePrint('preview')">打印预览</a-button>
+    <a-button key="2" type="primary" id="print-print-btn" :disabled="disabled" @click="handlePrint('print')">快捷打印</a-button>
+    <a-button
+      key="1"
+      type="primary"
+      class="button-warning"
+      id="print-export-btn"
+      :disabled="disabled"
+      @click="handlePrint('export')">导出Excel</a-button>
+    <!-- 打印 -->
+    <div id="print"></div>
+  </div>
+</template>
+
+<script>
+export default {
+  name: 'Print',
+  props: {
+    disabled: {
+      type: Boolean,
+      default: true
+    }
+  },
+  data () {
+    return {
+      printerType: 'NEEDLE' // 打印机类型
+    }
+  },
+  methods: {
+    handlePrint (type) {
+      this.$emit('handlePrint', type, this.printerType)
+    }
+  }
+}
+</script>
+
+<style lang="less">
+  .print-page-header{
+    > *{
+      margin-left: 5px;
+    }
+  }
+</style>

+ 19 - 63
src/views/salesManagement/salesQuery/detail.vue

@@ -13,19 +13,7 @@
             @click.stop="handleEdit">编辑</a-button>
         </template>
         <template slot="extra" v-if="outBizSn ? $hasPermissions('B_outboundOrderDetail') : $hasPermissions('B_salesPrint')">
-          <a-radio-group key="4" v-model="printerType">
-            <a-radio value="NEEDLE">针式</a-radio>
-            <a-radio value="INK">喷墨</a-radio>
-          </a-radio-group>
-          <a-button key="3" id="salesDetail-preview-btn" :disabled="localDataSource.length==0" @click="handlePrint('preview')">打印预览</a-button>
-          <a-button key="2" type="primary" id="salesDetail-print-btn" :disabled="localDataSource.length==0" @click="handlePrint('print')">快捷打印</a-button>
-          <a-button
-            key="1"
-            type="primary"
-            class="button-warning"
-            id="salesDetail-export-btn"
-            :disabled="localDataSource.length==0"
-            @click="handlePrint('export')">导出Excel</a-button>
+          <Print :disabled="localDataSource.length==0" @handlePrint="handlePrint"></Print>
         </template>
       </a-page-header>
       <!-- 基础信息 -->
@@ -87,21 +75,19 @@
         </s-table>
       </a-card>
     </a-spin>
-    <!-- 打印 -->
-    <div id="print"></div>
   </div>
 </template>
 
 <script>
-import moment from 'moment'
 import { getOperationalPrecision } from '@/libs/tools.js'
 import { STable, VSelect } from '@/components'
 import { salesDetailBySn, salesDetailPrint, salesDetailExport } from '@/api/sales'
 import { salesDetailList } from '@/api/salesDetail'
-import { JGPrint } from '@/libs/JGPrint'
+import Print from '@/views/common/print.vue'
+import { hdPrint } from '@/libs/JGPrint'
 export default {
   name: 'SalesDetail',
-  components: { STable, VSelect },
+  components: { STable, VSelect, Print },
   props: {
     outBizSn: { //  有值则为弹框,无值则为页面
       type: [Number, String],
@@ -157,11 +143,24 @@ export default {
         })
       },
       localDataSource: [],
-      detailData: null, //  详情数据
-      printerType: 'NEEDLE' //  打印机类型
+      detailData: null //  详情数据
     }
   },
   methods: {
+    // 打印预览/快捷打印
+    handlePrint (type, printerType) {
+      const _this = this
+      _this.spinning = true
+      let url = salesDetailPrint
+      const params = { sn: this.outBizSn || this.$route.params.sn }
+      if (type == 'export') { //  导出
+        url = salesDetailExport
+      }
+      // 打印或导出
+      hdPrint(printerType, type, url, params, '销售单', function () {
+        _this.spinning = false
+      })
+    },
     //  返回
     handleBack () {
       this.$router.push({ path: '/salesManagement/salesQuery/list', query: { closeLastOldTab: true } })
@@ -180,49 +179,6 @@ export default {
           this.detailData = null
         }
       })
-    },
-    // 打印预览/快捷打印
-    handlePrint (type) {
-      const _this = this
-      _this.spinning = true
-      let url = salesDetailPrint
-      let params = { sn: this.outBizSn || this.$route.params.sn, type: this.printerType }
-      if (type == 'export') { //  导出
-        url = salesDetailExport
-        params = { sn: this.outBizSn || this.$route.params.sn }
-      }
-      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 (type == 'export') { //  导出
-            this.download(res)
-          } else {
-            JGPrint(res, type, this.printerType)
-          }
-        }
-      })
-    },
-    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 () {

+ 18 - 60
src/views/salesManagement/salesQuery/edit.vue

@@ -9,19 +9,7 @@
         </template>
         <!-- 操作区,位于 title 行的行尾 -->
         <template slot="extra" v-if="$hasPermissions('B_salesPrint')">
-          <a-radio-group key="4" v-model="printerType">
-            <a-radio value="NEEDLE">针式</a-radio>
-            <a-radio value="INK">喷墨</a-radio>
-          </a-radio-group>
-          <a-button key="3" id="salesEdit-preview-btn" :disabled="dataSource.length==0" @click="handlePrint('preview')">打印预览</a-button>
-          <a-button key="2" type="primary" id="salesEdit-print-btn" :disabled="dataSource.length==0" @click="handlePrint('print')">快捷打印</a-button>
-          <a-button
-            key="1"
-            type="primary"
-            class="button-warning"
-            id="salesEdit-export-btn"
-            :disabled="dataSource.length==0"
-            @click="handlePrint('export')">导出Excel</a-button>
+          <Print :disabled="dataSource.length==0" @handlePrint="handlePrint"></Print>
         </template>
       </a-page-header>
       <a-card size="small" :bordered="false" class="salesEdit-cont">
@@ -173,23 +161,22 @@
     </div>
     <!-- 选择客户弹框 -->
     <choose-custom-modal ref="custModal" :show="openModal" @updateData="updateData" @cancel="openModal=false" />
-    <!-- 打印 -->
-    <div id="print"></div>
   </div>
 </template>
 
 <script>
 import moment from 'moment'
 import { STable, VSelect } from '@/components'
-import { JGPrint } from '@/libs/JGPrint'
 import queryPart from './queryPart.vue'
 import chooseCustomModal from './chooseCustomModal.vue'
 import { stockByProductSn } from '@/api/stock'
 import { salesDetail, salesWriteSubmit, salesWriteDiscount, salesDetailPrint, salesDetailExport } from '@/api/sales'
 import { salesDetailList, salesDetailInsert, salesDetailUpdatePrice, salesDetailUpdateQty, salesDetailDel, salesDetailDelAll } from '@/api/salesDetail'
+import Print from '@/views/common/print.vue'
+import { hdPrint } from '@/libs/JGPrint'
 export default {
   name: 'SalesDetail',
-  components: { STable, VSelect, queryPart, chooseCustomModal },
+  components: { STable, VSelect, queryPart, chooseCustomModal, Print },
   data () {
     return {
       spinning: false,
@@ -243,6 +230,20 @@ export default {
     }
   },
   methods: {
+    // 打印预览/快捷打印
+    handlePrint (type, printerType) {
+      const _this = this
+      _this.spinning = true
+      let url = salesDetailPrint
+      const params = { sn: this.outBizSn || this.$route.params.sn }
+      if (type == 'export') { //  导出
+        url = salesDetailExport
+      }
+      // 打印或导出
+      hdPrint(printerType, type, url, params, '销售单', function () {
+        _this.spinning = false
+      })
+    },
     // 已选产品 销售数量  blur
     qtyBlur (val, record) {
       const _this = this
@@ -316,49 +317,6 @@ export default {
     isCost (val) {
       this.isCosts = val
     },
-    // 打印预览/快捷打印
-    handlePrint (type) {
-      const _this = this
-      _this.spinning = true
-      let url = salesDetailPrint
-      let params = { sn: this.$route.params.sn, type: this.printerType }
-      if (type == 'export') { //  导出
-        url = salesDetailExport
-        params = { sn: this.$route.params.sn }
-      }
-      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 (type == 'export') { //  导出
-            this.download(res)
-          } else {
-            JGPrint(res, type, this.printerType)
-          }
-        }
-      })
-    },
-    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()
-    },
     // 更新产品列表
     updateData (priceType) {
       // 价格类型变更