瀏覽代碼

调拨列表 打印预览 对接

chenrui 4 年之前
父節點
當前提交
479ffc4087

+ 8 - 0
src/api/allocateBill.js

@@ -103,3 +103,11 @@ export const allocateBillDetailSave = params => {
     method: 'post'
   })
 }
+// 调拨管理 详情  打印
+export const allocateBillDetailPrint = params => {
+  return axios.request({
+    url: `allocateBill/print/${params.sn}`,
+    method: 'get',
+    responseType: 'blob'
+  })
+}

+ 40 - 4
src/views/allocationManagement/transferOut/detail.vue

@@ -14,8 +14,8 @@
       </template>
       <!-- 操作区,位于 title 行的行尾 -->
       <template slot="extra">
-        <a-button key="2" id="allocateBillDetail-preview-btn">打印预览</a-button>
-        <a-button key="1" type="primary" id="allocateBillDetail-print-btn">快速打印</a-button>
+        <a-button key="2" id="allocateBillDetail-preview-btn" :disabled="localDataSource.length==0" @click="handlePrint('preview')">打印预览</a-button>
+        <a-button key="1" type="primary" id="allocateBillDetail-print-btn" :disabled="localDataSource.length==0" @click="handlePrint('print')">快捷打印</a-button>
       </template>
     </a-page-header>
     <a-card size="small" :bordered="false" class="allocateBillDetail-cont">
@@ -48,13 +48,15 @@
         bordered>
       </s-table>
     </a-card>
+    <!-- 打印 -->
+    <div id="print"></div>
   </div>
 </template>
 
 <script>
 import { STable, VSelect } from '@/components'
 import { getOperationalPrecision } from '@/libs/tools.js'
-import { allocateBillDetailList, allocateBillDetail, allocateBillDetailCount } from '@/api/allocateBill'
+import { allocateBillDetailList, allocateBillDetail, allocateBillDetailCount, allocateBillDetailPrint } from '@/api/allocateBill'
 export default {
   components: { STable, VSelect },
   data () {
@@ -83,11 +85,13 @@ export default {
             data.list[i].costSubtotal = getOperationalPrecision(data.list[i].cost, data.list[i].qty)
             data.list[i].priceSubtotal = getOperationalPrecision(data.list[i].price, data.list[i].qty)
           }
+          this.localDataSource = data.list
           return data
         })
       },
       basicInfoData: null, //  基本信息
-      productTotal: null //  合计
+      productTotal: null, //  合计
+      localDataSource: []
     }
   },
   computed: {
@@ -123,6 +127,38 @@ export default {
     //  编辑
     handleEdit () {
       this.$router.push({ path: `/allocationManagement/transferOut/edit/${this.basicInfoData.allocateSn}/${this.basicInfoData.targetName}` })
+    },
+    // 打印预览/快捷打印
+    handlePrint (type) {
+      const _this = this
+      allocateBillDetailPrint({ sn: this.$route.params.sn }).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) {

+ 38 - 4
src/views/allocationManagement/transferOut/edit.vue

@@ -8,8 +8,8 @@
       </template>
       <!-- 操作区,位于 title 行的行尾 -->
       <template slot="extra">
-        <a-button key="2" id="allocateBillEdit-preview-btn">打印预览</a-button>
-        <a-button key="1" type="primary" id="allocateBillEdit-print-btn">快速打印</a-button>
+        <a-button key="2" id="allocateBillEdit-preview-btn" :disabled="chooseLoadData.length==0" @click="handlePrint('preview')">打印预览</a-button>
+        <a-button key="1" type="primary" id="allocateBillEdit-print-btn" :disabled="chooseLoadData.length==0" @click="handlePrint('print')">快捷打印</a-button>
       </template>
     </a-page-header>
     <!-- 选择产品 -->
@@ -94,7 +94,7 @@
               </div>
             </a-col>
             <a-col :span="7" style="text-align: right;">
-              <a-button size="small" id="allocateBillEdit-import-btn">导入明细</a-button>
+              <!-- <a-button size="small" id="allocateBillEdit-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>
@@ -140,13 +140,15 @@
           style="padding: 0 60px;">提交</a-button>
       </div>
     </a-affix>
+    <!-- 打印 -->
+    <div id="print"></div>
   </div>
 </template>
 
 <script>
 import { STable, VSelect } from '@/components'
 import { queryStockProductPage } from '@/api/stock'
-import { allocateBillDetailList, allocateBillDetailCount, allocateBillDetailSave, allocateBillSubmit, allocateBillDetailDel, allocateBillDetailDelAll } from '@/api/allocateBill'
+import { allocateBillDetailList, allocateBillDetailCount, allocateBillDetailSave, allocateBillSubmit, allocateBillDetailDel, allocateBillDetailDelAll, allocateBillDetailPrint } from '@/api/allocateBill'
 export default {
   components: { STable, VSelect },
   data () {
@@ -375,6 +377,38 @@ export default {
       if (val != record.qtyBackups) {
         this.handleAdd(record, 'edit')
       }
+    },
+    // 打印预览/快捷打印
+    handlePrint (type) {
+      const _this = this
+      allocateBillDetailPrint({ sn: this.$route.params.sn }).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) {