1
xuxueyang
2024-08-09 6e12337e17704d873d8954d80e4567a94e23d92d
sub_pages/supplier/print/print-list.vue
@@ -14,7 +14,11 @@
                  </image>
                  <view class="flex1">
                     <view class=" flex">
                        <view class="title">{{item.flowerName }}
                        <view class="title">
                           <span class="level"
                              v-if="item.flowerCategory">{{ item.flowerCategory || ''}}</span><span
                              class="level">{{ item.flowerLevelStr || ''}}</span>
                           {{item.flowerName }}
                        </view>
                     </view>
                     <view class="each-list ">
@@ -43,11 +47,11 @@
               <view class="delivery-form">
                  <view class="form-item">
                     <view class="label">仓库名称</view>
                     <view class="value red">{{item.warehouseName}}</view>
                     <view class="value red">{{item.warehouseName||'待分配'}}</view>
                  </view>
                  <view class="form-item">
                     <view class="label">库位名称</view>
                     <view class="value red">{{item.warehouseLocationCode}}</view>
                     <view class="value red">{{item.warehouseLocationCode||'待分配'}}</view>
                  </view>
               </view>
@@ -114,6 +118,7 @@
            notifyCharaterId: {},
            notifyServiceId: '',
            BserviceId: '',
            buffs: [],
         }
      },
      /**
@@ -199,6 +204,12 @@
                           })
                        }
                     },
                     fail: function() {
                        wx.showModal({
                           title: '提示',
                           content: '蓝牙状态获取失败',
                        })
                     }
                  })
               },
               fail: function() {
@@ -221,13 +232,19 @@
            } else if (platform == "android") {
               // uni.getDeviceInfo().platform = "android"
               console.log(uni.getDeviceInfo()) //这里是拿到安卓的系统版本名 如:Android 9
               console.log('输出系统版本号', uni.getDeviceInfo().system.substring(uni.getDeviceInfo().system.length - (
                     uni.getDeviceInfo().system.length -
                     8), uni.getDeviceInfo().system.length - (uni.getDeviceInfo().system.length - 8) +
                  1)) //这里为了获取到系统的版本号,如 9
               var systemVersion = uni.getDeviceInfo().system.substring(uni.getDeviceInfo().system.length - (uni
                  .getDeviceInfo().system.length -
                  8), uni.getDeviceInfo().system.length - (uni.getDeviceInfo().system.length - 8) + 1)
               var systemVersion = 10
               // try {
               //    var s = '' + (uni.getDeviceInfo().system || '')
               //    console.log('输出系统版本号', s.substring(s.length - (
               //          s.length -
               //          8), s.length - (s.length - 8) +
               //       1)) //这里为了获取到系统的版本号,如 9
               //    systemVersion = s.substring(s.length - (s.length -
               //       8), s.length - (s.length - 8) + 1)
               // } catch (e) {
               //    that.$message.showToast('获取系统版本错误,版本号:' + s)
               //    systemVersion = 10
               // }
               if (systemVersion > 5) {
                  wx.getSetting({
                     success: function(res) {
@@ -237,14 +254,27 @@
                              scope: 'scope.userLocation',
                              complete: function(res) {
                                 that.getBluetoothDevices()
                              }
                              },
                              fail: function(res) {
                                 that.$message.showToast('获取蓝牙系统位置信息错误')
                              },
                           })
                        } else {
                           that.getBluetoothDevices()
                        }
                     }
                     },
                     fail: function(res) {
                        that.$message.showToast('获取系统设置错误' + (res || ''))
                     },
                  })
               } else {
                  that.$message.showToast('获取系统版本过低,版本号:' + systemVersion)
               }
            } else {
               that.$message.showToast('未知平台:' + (platform || '-'))
            }
         },
@@ -275,15 +305,23 @@
                              }
                           }
                           // 数据赋值 关闭刷新
                           that.list = devices
                           that.list = devices || []
                           that.isScanning = false
                           wx.hideLoading()
                           wx.stopPullDownRefresh()
                        },
                        fail(e) {
                           that.$message.showToast('获取蓝牙设备出错:' + (e || ''))
                        }
                     })
                  }, 3000) //到这里 都是三秒后执行的内容
               },
               fail(e) {
                  that.$message.showToast('扫描蓝牙报错:' + (e || ''))
               }
            })
         },
@@ -291,6 +329,12 @@
          * 链接到某一个蓝牙设备上
          */
         bindViewTap: function(device) {
            if (this.isLabelSend) {
               this.$message.showToast('正在打印中')
               return
            }
            var that = this
            wx.stopBluetoothDevicesDiscovery({ //关闭发现蓝牙设备
               success: function(res) {
@@ -443,64 +487,128 @@
               }
            })
         },
         openControl() {
         async openControl() {
            //打印
            var that = this;
            if (that.item.num < 0) {
               that.$message.showToast('打印数目不能小于0')
               return
            }
            if (that.item.num > 3) {
               await that.$message.confirm(`打印数目为${that.item.num}张,确定打印吗`)
            }
            that.buffs = []
            for (var i = 0; i < that.item.num; i++) {
            var command = tsc.jpPrinter.createNew()
            command.setSize(48, 96)
            command.setGap(0)
            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 || '-'))
            if (that.item.warehouseName)
               command.setText(10, 60, "TSS24.BF2", 1, 1, "仓库: " + that.item.warehouseName)
            if (that.item.warehouseLocationCode)
               command.setText(200, 60, "TSS24.BF2", 1, 1, "库位: " + that.item.warehouseLocationCode)
            // command.setText(170, 50, "TSS24.BF2", 1, 1, "小程序测试")
            // command.setText(170, 90, "TSS24.BF2", 1, 1, "测试数字12345678")
            // command.setText(170, 120, "TSS24.BF2", 1, 1, "测试英文abcdefg")
            // command.setText(170, 150, "TSS24.BF2", 1, 1, "测试符号/*-+!@#$")
            command.setText(10, 100, "TSS24.BF2", 1, 1, "供应商: " + (that.item.supplierName || '-'))
            command.setText(10, 140, "TSS24.BF2", 1, 1, "商品名称: " + (that.item.flowerName || '-'))
            command.setText(10, 180, "TSS24.BF2", 1, 1, "等级: " + (that.item.flowerLevelStr || '-'))
            command.setText(200, 180, "TSS24.BF2", 1, 1, "颜色: " + (that.item.flowerColor || '-'))
            command.setText(10, 220, "TSS24.BF2", 1, 1, "价格: ¥ " + (that.item.price || '-'))
            command.setText(200, 220, "TSS24.BF2", 1, 1, "数目: x " + (that.item.num || '0'))
            command.setText(10, 260, "TSS24.BF2", 1, 1, "规格: " + (that.item.flowerUnit || '-'))
            command.setText(10, 300, "TSS24.BF2", 1, 1, "花满芫")
            command.setText(170, 300, "TSS24.BF2", 1, 1, that.$util.toDateMin(new Date()))
            if (that.item.params) {
               var addnum = 0
               var hlen = 300
               for (var p of that.item.params) {
                  if (p.value) {
                     var lef = 10
                     if (addnum % 2 == 1) {
                        lef = 190
                     } else {
                        lef = 10
                        hlen += 40
               var command = tsc.jpPrinter.createNew()
               //根据数目不同,打印不同数目
               command.setSize(48, 60)
               command.setGap(0)
               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 || '-'))
               // 仓库:
               // if (that.item.warehouseName)
               var paramsmap = {}
               if (that.item.params) {
                  for (var p of that.item.params) {
                     if (p.name !== '枝长' && p.name !== '成熟度') {
                        continue
                     }
                     command.setText(lef, hlen, "TSS24.BF2", 1, 1, "" + (p.name || '') + ':' + p.value)
                     addnum += 1
                     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
               if (flowerCategory) {
                  //只取二级分类
                  var tarr = flowerCategory.split("/")
                  if (tarr.length >= 2) {
                     flowerCategory = tarr[tarr.length - 1]
                  }
               }
               command.setText(30, 80, "TSS24.BF2", 1, 1, "" + (flowerCategory || ''))
               command.setText(200, 80, "TSS24.BF2", 1, 1, "库位:" + (that.item.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, 160, "TSS24.BF2", 1, 1, "" + (that.item.flowerUnit || '-'))
               // 成熟度:
               command.setText(200, 160, "TSS24.BF2", 1, 1, "" + (paramsmap['成熟度'] || '-'))
               // 枝长:
               command.setText(30, 200, "TSS24.BF2", 1, 1, "" + (paramsmap['枝长'] || '-'))
               command.setText(200, 200, "TSS24.BF2", 1, 1, that.$util.toDate(new Date()))
               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(20, 40, "TSS24.BF2", 1, 1, "" + (that.item.warehouseName || '待分配'))
               // // 库位:
               // // if (that.item.warehouseLocationCode)
               // command.setText(200, 40, "TSS24.BF2", 1, 1, "" + (that.item.warehouseLocationCode || '待分配'))
               // // command.setText(170, 50, "TSS24.BF2", 1, 1, "小程序测试")
               // // command.setText(170, 90, "TSS24.BF2", 1, 1, "测试数字12345678")
               // // command.setText(170, 120, "TSS24.BF2", 1, 1, "测试英文abcdefg")
               // // command.setText(170, 150, "TSS24.BF2", 1, 1, "测试符号/*-+!@#$")
               // // 供应商:
               // command.setText(20, 80, "TSS24.BF2", 1, 1, "" + (that.item.supplierName || '-'))
               // // 商品名称:
               // command.setText(20, 120, "TSS24.BF2", 1, 1, "" + (that.item.flowerName || '-'))
               // // 颜色:
               // command.setText(200, 120, "TSS24.BF2", 1, 1, "" + (that.item.flowerColor || '-'))
               // // command.setText(10, 220, "TSS24.BF2", 1, 1, "价格: ¥ " + (that.item.price || '-'))
               // command.setText(20, 160, "TSS24.BF2", 1, 1, "规格: " + (that.item.flowerUnit || '-'))
               // command.setText(200, 160, "TSS24.BF2", 1, 1, `数目: ${i+1}/${that.item.num}`)
               // // command.setText(10, 300, "TSS24.BF2", 1, 1, "花满芫")
               // command.setText(100, 200, "TSS24.BF2", 1, 1, that.$util.toDateMin(new Date()))
               // if (that.item.params) {
               //    var addnum = 0
               //    var hlen = 200
               //    for (var p of that.item.params) {
               //       if (p.name !== '枝长' && p.name !== '成熟度') {
               //          continue
               //       }
               //       if (p.value) {
               //          var lef = 20
               //          if (addnum % 2 == 1) {
               //             lef = 190
               //          } else {
               //             lef = 20
               //             hlen += 40
               //          }
               //          command.setText(lef, hlen, "TSS24.BF2", 1, 1, "" + (p.name || '') + ':' + p.value)
               //          addnum += 1
               //       }
               //    }
               // }
               // <view class="delivery-form" v-if="item.params">
               //    <view class="form-item" v-for="(p,k) of item.params" :key="k">
               //       <view class="label">{{p.name||'-'}}:</view>
               //       <view class="value red">{{p.value}}</view>
               //    </view>
               // </view>
               // command.setBar(170, 180, "EAN8", 64, 1, 3, 3, "1234567")
               command.setPagePrint()
               that.buffs.push(command.getData())
            }
            // <view class="delivery-form" v-if="item.params">
            //    <view class="form-item" v-for="(p,k) of item.params" :key="k">
            //       <view class="label">{{p.name||'-'}}:</view>
            //       <view class="value red">{{p.value}}</view>
            //    </view>
            // </view>
            // command.setBar(170, 180, "EAN8", 64, 1, 3, 3, "1234567")
            command.setPagePrint()
            that.isLabelSend = true
            that.prepareSend(command.getData())
            // that.prepareSend(command.getData())
            that.prepareSend(that.buffs[0])
            // wx.canvasGetImageData({
            //   canvasId: 'edit_area_canvas',
@@ -574,22 +682,39 @@
                     wx.showToast({
                        title: '已打印第' + currentPrint + '张',
                     })
                     if (currentPrint == printNum) {
                     if (currentPrint == that.buffs.length) {
                        that.looptime = 0
                        that.lastData = 0
                        that.currentTime = 1
                        that.isReceiptSend = false
                        that.isLabelSend = false
                        that.currentPrint = 1
                        try {
                           wx.closeBLEConnection({
                              deviceId: that.deviceId,
                              success: function(res) {
                                 console.log("关闭蓝牙成功")
                              },
                           })
                        } catch (e) {
                        }
                     } else {
                        currentPrint++
                        that.currentPrint = currentPrint
                        that.currentTime = 1
                        that.Send(buff)
                        that.Send(that.buffs[that.currentPrint - 1])
                     }
                     // } else {
                     //    currentPrint++
                     //    that.currentPrint = currentPrint
                     //    that.currentTime = 1
                     //    that.Send(buff)
                     // }
                  }
               }
            })
@@ -688,6 +813,14 @@
               font-size: 28rpx;
               color: #000000;
               line-height: 40rpx;
               .level {
                  font-weight: 400;
                  font-size: 28rpx;
                  color: #20613D;
                  line-height: 40rpx;
                  margin-right: 20rpx;
               }
            }
            .status {
@@ -717,6 +850,14 @@
                  font-size: 28rpx;
                  color: #000000;
                  line-height: 40rpx;
                  .level {
                     font-weight: 400;
                     font-size: 28rpx;
                     color: #20613D;
                     line-height: 40rpx;
                     margin-right: 20rpx;
                  }
               }
               .desc {}