xuxueyang
2024-09-13 731b3a23a6369aaef5c4fdc0ff4524eb6a7f3642
sub_pages/supplier/print/print-list.vue
@@ -1,7 +1,7 @@
<template>
   <!-- 显示要打印的东西 -->
   <view class="list-container order-delivery-print supplier">
      <view class="p15">
      <view class="p15" v-if="false">
         <view class="m-b-24 order-sale-list list-container">
            <view class="order-sale-item list-item">
               <view class="title flex">
@@ -70,6 +70,7 @@
      <view class="print-container m-t-12">
         <button class="btn" type="primary" @click="startSearch" :loading="isScanning"> 开始搜索 </button>
         <button class="btn m-t-12" type="default" @click="breakPrint=true"> 中断打印 </button>
         <view v-for="(device,index) of list" :key="device.deviceId" @click="bindViewTap(device)">
            <view class="item">
               <div class="deviceId block">{{device.deviceId}}</div>
@@ -87,7 +88,8 @@
   export default {
      data() {
         return {
            item: {},
            // item: {},
            items: [],
            services: [],
            serviceId: 0,
            writeCharacter: false,
@@ -119,6 +121,7 @@
            notifyServiceId: '',
            BserviceId: '',
            buffs: [],
            breakPrint: false
         }
      },
      /**
@@ -144,7 +147,7 @@
      async onLoad() {
         var t = this.$storage.getItem('cache_delivery_order_print') || ''
         if (t) {
            this.item = JSON.parse(t)
            this.items = JSON.parse(t)
            var apitype = ''
            // #ifdef PUB_SUPPLIER
            apitype = '/supplier'
@@ -153,21 +156,36 @@
            // apitype = '/supplier'
            // #endif
            //获取详情接口
            var ids = []
            for (var item of this.items) {
               ids.push(item.id)
            }
            this.$message.showLoading()
            // const {
            //    code,
            //    data
            // } = await this.$http.request('get', `/api${apitype}/delivery/list/items/view`, {
            //    params: {
            //       id: this.item.id,
            //       ids: ids
            //    }
            // })
            const {
               code,
               data
            } = await this.$http.request('get', `/api${apitype}/delivery/list/items/view`, {
               params: {
                  id: this.item.id
            } = await this.$http.request('post', `/api${apitype}/delivery/list/items/views`, {
               data: {
                  // id: this.item.id,
                  ids: ids
               }
            })
            this.$message.hideLoading()
            if (code == 0 && data) {
               this.item = {
                  ...this.item,
                  ...data
               }
               // this.item = {
               //    ...this.item,
               //    ...data
               // }
               this.items = data || []
            }
         } else {
            this.$message.showToast('获取详情失败')
@@ -336,11 +354,11 @@
          * 链接到某一个蓝牙设备上
          */
         bindViewTap: function(device) {
            if (this.isLabelSend) {
               this.$message.showToast('正在打印中')
               return
            }
            this.breakPrint = false
            var that = this
            wx.stopBluetoothDevicesDiscovery({ //关闭发现蓝牙设备
@@ -498,18 +516,25 @@
            //打印
            var that = this;
            if (that.item.num < 0) {
            if (that.items.num <= 0) {
               that.$message.showToast('打印数目不能小于0')
               return
            }
            if (that.item.num > 3) {
               await that.$message.confirm(`打印数目为${that.item.num}张,确定打印吗`)
            var totalnum = 0
            for (var each of that.items) {
               totalnum += each.num
            }
            if (totalnum > 3) {
               await that.$message.confirm(`打印数目为${totalnum}张,确定打印吗`)
            }
            if (totalnum <= 0) {
               that.$message.showToast('打印数目不能小于0')
               return
            }
            that.buffs = []
            for (var i = 0; i < that.item.num; i++) {
            for (var each of that.items) {
               for (var i = 0; i < each.num; i++) {
               var command = tsc.jpPrinter.createNew()
               //根据数目不同,打印不同数目
@@ -519,21 +544,21 @@
               command.setCls()
               // command.setText(0, 30, "TSS24.BF2", 1, 1, "图片")
               // command.setQR(40, 120, "L", 5, "A", "www.smarnet.cc佳博智汇")
               // command.setText(60, 20, "TSS24.BF2", 1, 1, "单号:" + (that.item.orderNo || '-'))
                  // command.setText(60, 20, "TSS24.BF2", 1, 1, "单号:" + (each.orderNo || '-'))
               // 仓库:
               // if (that.item.warehouseName)
                  // if (each.warehouseName)
               var paramsmap = {}
               if (that.item.params) {
                  for (var p of that.item.params) {
                  if (each.params) {
                     for (var p of each.params) {
                     if (p.name !== '枝长' && p.name !== '成熟度') {
                        continue
                     }
                     paramsmap[p.name] = p.value || ''
                  }
               }
               command.setText(30, 40, "TSS24.BF2", 1, 1, "" + (that.item.supplierName || '-'))
               command.setText(200, 40, "TSS24.BF2", 1, 1, "" + (that.item.warehouseName || '待分配'))
               var flowerCategory = that.item.flowerCategory
                  command.setText(30, 40, "TSS24.BF2", 1, 1, "" + (each.supplierName || '-'))
                  command.setText(200, 40, "TSS24.BF2", 1, 1, "" + (each.warehouseName || '待分配'))
                  var flowerCategory = each.flowerCategory
               if (flowerCategory) {
                  //只取二级分类
                  var tarr = flowerCategory.split("/")
@@ -542,12 +567,12 @@
                  }
               }
               command.setText(30, 80, "TSS24.BF2", 1, 1, "" + (flowerCategory || ''))
               command.setText(200, 80, "TSS24.BF2", 1, 1, "库位:" + (that.item.warehouseLocationCode || ''))
                  command.setText(200, 80, "TSS24.BF2", 1, 1, "库位:" + (each.warehouseLocationCode || ''))
               command.setText(30, 120, "TSS24.BF2", 1, 1, "等级:" + (that.item.flowerLevelStr || ''))
               command.setText(200, 120, "TSS24.BF2", 1, 1, "" + (that.item.flowerColor || ''))
                  command.setText(30, 120, "TSS24.BF2", 1, 1, "等级:" + (each.flowerLevelStr || ''))
                  command.setText(200, 120, "TSS24.BF2", 1, 1, "" + (each.flowerColor || ''))
               // 规格: 
               command.setText(30, 160, "TSS24.BF2", 1, 1, "" + (that.item.flowerUnit || '-'))
                  command.setText(30, 160, "TSS24.BF2", 1, 1, "" + (each.flowerUnit || '-'))
               // 成熟度: 
               command.setText(200, 160, "TSS24.BF2", 1, 1, "" + (paramsmap['成熟度'] || '-'))
               // 枝长: 
@@ -557,7 +582,7 @@
               command.setText(60, 230, "TSS24.BF2", 1, 1, "————————————")
               command.setText(30, 260, "TSS24.BF2", 1, 1, "花满芫")
               command.setText(200, 260, "TSS24.BF2", 1, 1, `数目: ${i+1}/${that.item.num}`)
                  command.setText(200, 260, "TSS24.BF2", 1, 1, `数目: ${i+1}/${each.num}`)
               // command.setText(20, 40, "TSS24.BF2", 1, 1, "" + (that.item.warehouseName || '待分配'))
               // // 库位: 
@@ -611,6 +636,8 @@
               command.setPagePrint()
               that.buffs.push(command.getData())
               }
            }
            that.isLabelSend = true
            // that.prepareSend(command.getData())
@@ -692,8 +719,13 @@
                     wx.showToast({
                        title: '已打印第' + currentPrint + '张',
                     })
                     if (currentPrint == that.buffs.length) {
                     if (currentPrint == that.buffs.length || that.breakPrint) {
                        if (that.breakPrint) {
                           wx.showToast({
                              title: '中断成功',
                           })
                           that.breakPrint = false
                        }
                        that.looptime = 0
                        that.lastData = 0
                        that.currentTime = 1