Procházet zdrojové kódy

连锁调出 打印预览 对接

chenrui před 4 roky
rodič
revize
a8d06e9ffb

+ 8 - 0
src/api/allocLinkageOut.js

@@ -102,3 +102,11 @@ export const getTenantList = (params) => {
     method: 'get'
   })
 }
+// 连锁调拨调出 详情  打印
+export const allocLinkageOutDetailPrint = params => {
+  return axios.request({
+    url: `allocLinkageOut/print/${params.sn}/${params.type}`,
+    method: 'get',
+    responseType: 'blob'
+  })
+}

+ 45 - 4
src/views/allocationManagement/chainTransferOut/detail.vue

@@ -14,8 +14,12 @@
       </template>
       <!-- 操作区,位于 title 行的行尾 -->
       <template slot="extra">
-        <a-button key="2" id="chainTransferOutDetail-preview-btn">打印预览</a-button>
-        <a-button key="1" type="primary" id="chainTransferOutDetail-print-btn">快速打印</a-button>
+        <a-radio-group key="3" v-model="printerType">
+          <a-radio value="INK">针式</a-radio>
+          <a-radio value="NEEDLE">喷墨</a-radio>
+        </a-radio-group>
+        <a-button key="2" id="chainTransferOutDetail-preview-btn" :disabled="localDataSource.length==0" @click="handlePrint('preview')">打印预览</a-button>
+        <a-button key="1" type="primary" id="chainTransferOutDetail-print-btn" :disabled="localDataSource.length==0" @click="handlePrint('print')">快捷打印</a-button>
       </template>
     </a-page-header>
     <!-- 基础信息 -->
@@ -54,13 +58,15 @@
         </a-collapse-panel>
       </a-collapse>
     </a-card>
+    <!-- 打印 -->
+    <div id="print"></div>
   </div>
 </template>
 
 <script>
 import { STable, VSelect } from '@/components'
 import { getOperationalPrecision } from '@/libs/tools.js'
-import { allocLinkageOutDetailSn, allocLinkageOutDetailList, allocLinkageOutDetailCount } from '@/api/allocLinkageOut'
+import { allocLinkageOutDetailSn, allocLinkageOutDetailList, allocLinkageOutDetailCount, allocLinkageOutDetailPrint } from '@/api/allocLinkageOut'
 export default {
   components: { STable, VSelect },
   data () {
@@ -90,11 +96,14 @@ export default {
           }
           this.disabled = false
           this.getDetailCount(params)
+          this.localDataSource = data.list
           return data
         })
       },
       basicInfoData: null, //  基本信息
-      productTotal: null //  合计
+      productTotal: null, //  合计
+      localDataSource: [],
+      printerType: 'INK' //  打印机类型
     }
   },
   computed: {
@@ -130,6 +139,38 @@ export default {
     //  编辑
     handleEdit () {
       this.$router.push({ path: `/allocationManagement/chainTransferOut/edit/${this.basicInfoData.id}/${this.basicInfoData.allocationLinkageOutSn}` })
+    },
+    // 打印预览/快捷打印
+    handlePrint (type) {
+      const _this = this
+      allocLinkageOutDetailPrint({ sn: this.$route.params.sn, type: this.printerType }).then(res => {
+        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, type)
+        }
+      })
+    },
+    print (data, type) {
+      if (!data) {
+        return
+      }
+      const url = window.URL.createObjectURL(new Blob([data], { type: 'application/pdf' }))
+      document.getElementById('print').innerHTML = '<iframe id="printf" name="printf" src="' + url + '" hidden></iframe>'
+      if (type == 'preview') { //  预览
+        window.open(url)
+      } else if (type == 'print') { //  打印
+        window.frames['printf'].focus()
+        window.frames['printf'].print()
+      }
     }
   },
   beforeRouteEnter (to, from, next) {

+ 46 - 5
src/views/allocationManagement/chainTransferOut/edit.vue

@@ -8,8 +8,12 @@
       </template>
       <!-- 操作区,位于 title 行的行尾 -->
       <template slot="extra">
-        <a-button key="2" id="chainTransferOutEdit-preview-btn">打印预览</a-button>
-        <a-button key="1" type="primary" id="chainTransferOutEdit-print-btn">快速打印</a-button>
+        <a-radio-group key="3" v-model="printerType">
+          <a-radio value="INK">针式</a-radio>
+          <a-radio value="NEEDLE">喷墨</a-radio>
+        </a-radio-group>
+        <a-button key="2" id="chainTransferOutEdit-preview-btn" :disabled="localDataSource.length==0" @click="handlePrint('preview')">打印预览</a-button>
+        <a-button key="1" type="primary" id="chainTransferOutEdit-print-btn" :disabled="localDataSource.length==0" @click="handlePrint('print')">快捷打印</a-button>
       </template>
     </a-page-header>
     <!-- 选择产品 -->
@@ -146,7 +150,7 @@
               </div>
             </a-col>
             <a-col :span="7" style="text-align: right;">
-              <a-button size="small" style="margin-left: 8px" id="chainTransferOutEdit-import-btn">导入明细</a-button>
+              <!-- <a-button size="small" style="margin-left: 8px" id="chainTransferOutEdit-import-btn">导入明细</a-button> -->
               <a-button size="small" type="danger" style="margin-left: 8px" @click.stop="handleDel('', 'all')" id="chainTransferOutEdit-del-all-btn">整单删除</a-button>
             </a-col>
           </a-row>
@@ -179,13 +183,15 @@
           style="padding: 0 60px;">提交</a-button>
       </div>
     </a-affix>
+    <!-- 打印 -->
+    <div id="print"></div>
   </div>
 </template>
 
 <script>
 import { STable, VSelect } from '@/components'
 import { getOperationalPrecision } from '@/libs/tools.js'
-import { allocLinkageOutDetailSn, allocLinkageOutDetailList, allocLinkageOutDetailSave, allocLinkageOutDetailDel, allocLinkageOutDetailCount, allocLinkageOutSubmit, allocLinkageOutDetailDelAll } from '@/api/allocLinkageOut'
+import { allocLinkageOutDetailSn, allocLinkageOutDetailList, allocLinkageOutDetailSave, allocLinkageOutDetailDel, allocLinkageOutDetailCount, allocLinkageOutSubmit, allocLinkageOutDetailDelAll, allocLinkageOutDetailPrint } from '@/api/allocLinkageOut'
 import { productQuery } from '@/api/allocWarehouse'
 import { dealerProductBrandQuery } from '@/api/dealerProductBrand'
 import { dealerProductTypeList } from '@/api/dealerProductType'
@@ -269,11 +275,14 @@ export default {
           }
           this.chooseDisabled = false
           this.getDetailCount(params)
+          this.localDataSource = data.list
           return data
         })
       },
       basicInfoData: null, //  基本信息
-      productTotal: null //  合计
+      productTotal: null, //  合计
+      localDataSource: [],
+      printerType: 'INK' //  打印机类型
     }
   },
   methods: {
@@ -468,6 +477,38 @@ export default {
           this.warehouseList = []
         }
       })
+    },
+    // 打印预览/快捷打印
+    handlePrint (type) {
+      const _this = this
+      allocLinkageOutDetailPrint({ sn: this.$route.params.sn, type: this.printerType }).then(res => {
+        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, type)
+        }
+      })
+    },
+    print (data, type) {
+      if (!data) {
+        return
+      }
+      const url = window.URL.createObjectURL(new Blob([data], { type: 'application/pdf' }))
+      document.getElementById('print').innerHTML = '<iframe id="printf" name="printf" src="' + url + '" hidden></iframe>'
+      if (type == 'preview') { //  预览
+        window.open(url)
+      } else if (type == 'print') { //  打印
+        window.frames['printf'].focus()
+        window.frames['printf'].print()
+      }
     }
   },
   beforeRouteEnter (to, from, next) {