xuxueyang
2024-08-31 32526e5bddb7b14328b2467cd18783f480b33f3b
sub_pages/supplier/print/print-list.vue
@@ -14,26 +14,30 @@
                  </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 flex">
                        <view class="each-item">
                     <view class="each-list ">
                        <view class="each-item flex1 flex">
                           <view class="label">颜色</view>
                           <view class="value">{{ item.flowerColor || '-' }}</view>
                        </view>
                        <view class="each-item">
                        <view class="each-item flex1 flex">
                           <view class="label">规格</view>
                           <view class="value">{{ item.flowerUnit || '-' }}</view>
                        </view>
                     </view>
                  </view>
                  <view class="each-list price">
                     <view class="each-item">
                     <view class="each-item flex1">
                        <view class="value">¥{{ item.price || '-' }}</view>
                     </view>
                     <view class="each-item">
                     <view class="each-item flex1">
                        <view class="value">x {{ item.num || 0 }}</view>
                     </view>
                  </view>
@@ -43,14 +47,23 @@
               <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>
               <!-- 罗列详细参数 -->
               <view class="line" v-if="item.params"></view>
               <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>
            </view>
         </view>
      </view>
@@ -68,7 +81,8 @@
</template>
<script>
   var tsc = require("@/plugins/tsc.js");
   var tsc = require("@/sub_pages/supplier/plugins/tsc.js");
   // var app = uni.getApp()
   export default {
      data() {
@@ -80,6 +94,7 @@
            readCharacter: false,
            notifyCharacter: false,
            isScanning: false,
            deviceId: '',
            //打印的
            sendContent: "",
            looptime: 0,
@@ -96,13 +111,79 @@
            printerNum: 1,
            currentPrint: 1,
            isReceiptSend: false,
            isLabelSend: false
            isLabelSend: false,
            //写入的
            writeServiceId: '',
            writeCharaterId: '',
            notifyCharaterId: {},
            notifyServiceId: '',
            BserviceId: '',
            buffs: [],
         }
      },
      onLoad() {
      /**
       * 生命周期函数--监听页面初次渲染完成
       */
      onReady: function() {
         var list = []
         var numList = []
         var j = 0
         for (var i = 20; i < 200; i += 10) {
            list[j] = i;
            j++
         }
         for (var i = 1; i < 10; i++) {
            numList[i - 1] = i
         }
         let that = this
         that.buffSize = list
         that.oneTimeData = list[0]
         that.printNum = numList
         that.printerNum = numList[0]
      },
      async onLoad() {
         var t = this.$storage.getItem('cache_delivery_order_print') || ''
         if (t)
         if (t) {
            this.item = JSON.parse(t)
            var apitype = ''
            // #ifdef PUB_SUPPLIER
            apitype = '/supplier'
            // #endif
            // #ifdef PUB_PARTNER
            // apitype = '/supplier'
            // #endif
            //获取详情接口
            this.$message.showLoading()
            const {
               code,
               data
            } = await this.$http.request('get', `/api${apitype}/delivery/list/items/view`, {
               params: {
                  id: this.item.id
               }
            })
            this.$message.hideLoading()
            if (code == 0 && data) {
               this.item = {
                  ...this.item,
                  ...data
               }
            }
         } else {
            this.$message.showToast('获取详情失败')
         }
      },
      onUnload() {
         try {
            wx.closeBLEConnection({
               deviceId: that.deviceId,
               success: function(res) {
                  console.log("关闭蓝牙成功")
               },
            })
         } catch (e) {
         }
      },
      methods: {
         /**
@@ -130,6 +211,12 @@
                           })
                        }
                     },
                     fail: function() {
                        wx.showModal({
                           title: '提示',
                           content: '蓝牙状态获取失败',
                        })
                     }
                  })
               },
               fail: function() {
@@ -145,17 +232,26 @@
          */
         checkPemission: function() { //android 6.0以上需授权地理位置权限
            var that = this
            var platform = app.BLEInformation.platform
            var platform = uni.getDeviceInfo().platform
            if (platform == "ios") {
               app.globalData.platform = "ios"
               // uni.getDeviceInfo().platform = "ios"
               that.getBluetoothDevices()
            } else if (platform == "android") {
               app.globalData.platform = "android"
               console.log(app.getSystem()) //这里是拿到安卓的系统版本名 如:Android 9
               console.log('输出系统版本号', app.getSystem().substring(app.getSystem().length - (app.getSystem().length -
                  8), app.getSystem().length - (app.getSystem().length - 8) + 1)) //这里为了获取到系统的版本号,如 9
               var systemVersion = app.getSystem().substring(app.getSystem().length - (app.getSystem().length -
                  8), app.getSystem().length - (app.getSystem().length - 8) + 1)
               // uni.getDeviceInfo().platform = "android"
               console.log(uni.getDeviceInfo()) //这里是拿到安卓的系统版本名 如:Android 9
               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) {
@@ -165,14 +261,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 || '-'))
            }
         },
@@ -185,9 +294,7 @@
            wx.showLoading({
               title: '获取蓝牙设备中',
            })
            that.setData({
               isScanning: true
            })
            that.isScanning = true
            wx.startBluetoothDevicesDiscovery({
               success: function(res) {
                  console.log(res) //输出蓝牙设备列表查找的结果,是否成功
@@ -204,16 +311,24 @@
                                 num++
                              }
                           }
                           that.setData({
                              list: devices,
                              isScanning: false
                           }) // 数据赋值 关闭刷新
                           // 数据赋值 关闭刷新
                           that.list = devices || []
                           that.isScanning = false
                           wx.hideLoading()
                           wx.stopPullDownRefresh()
                        },
                        fail(e) {
                           that.$message.showToast('获取蓝牙设备出错:' + (e || ''))
                        }
                     })
                  }, 3000) //到这里 都是三秒后执行的内容
               },
               fail(e) {
                  that.$message.showToast('扫描蓝牙报错:' + (e || ''))
               }
            })
         },
@@ -221,29 +336,35 @@
          * 链接到某一个蓝牙设备上
          */
         bindViewTap: function(device) {
            if (this.isLabelSend) {
               this.$message.showToast('正在打印中')
               return
            }
            var that = this
            wx.stopBluetoothDevicesDiscovery({ //关闭发现蓝牙设备
               success: function(res) {
                  console.log(res)
               },
            })
            that.setData({
               serviceId: 0,
               writeCharacter: false,
               readCharacter: false,
               notifyCharacter: false
            })
            console.log("e", e)
            that.serviceId = 0
            that.writeCharacter = false
            that.readCharacter = false
            that.notifyCharacter = false
            console.log("e", device)
            // console.log(e.currentTarget.dataset.title)
            wx.showLoading({
               title: '正在建立连接',
            })
            // 与蓝牙设备建立链接
            wx.createBLEConnection({
               deviceId: e.deviceId,
               deviceId: device.deviceId,
               success: function(res) {
                  console.log('连接蓝牙设备成功', res)
                  app.BLEInformation.deviceId = e.deviceId
                  that.deviceId = device.deviceId
                  that.getSeviceId() //获取服务ID
               },
               fail: function(e) {
@@ -262,10 +383,11 @@
         getSeviceId: function() {
            var that = this
            var platform = app.BLEInformation.platform //获取平台信息
            console.log(app.BLEInformation.deviceId) // 获取设备ID
            var platform = uni.getDeviceInfo().platform //获取平台信息
            console.log(that.deviceId) // 获取设备ID
            console.log('info getSeviceId', uni.getDeviceInfo())
            wx.getBLEDeviceServices({
               deviceId: app.BLEInformation.deviceId,
               deviceId: that.deviceId,
               success: function(res) {
                  console.log(res)
                  // 注释内容为方便调试特意直接赋值的一些信息,可以跳过
@@ -287,10 +409,9 @@
                     // }
                     // }
                  }
                  app.BLEInformation.serviceId = realId
                  that.setData({
                     services: res.services
                  }) //将服务信息赋值到公共数据缓存
                  that.BserviceId = realId
                  that.services = res.services
                  that.getCharacteristics() //获取特征
               },
               fail: function(e) {
@@ -307,13 +428,13 @@
          */
         getCharacteristics: function() {
            var that = this
            var list = that.data.services
            var num = that.data.serviceId
            var write = that.data.writeCharacter
            var read = that.data.readCharacter
            var notify = that.data.notifyCharacter
            var list = that.services
            var num = that.serviceId
            var write = that.writeCharacter
            var read = that.readCharacter
            var notify = that.notifyCharacter
            wx.getBLEDeviceCharacteristics({ //获取蓝牙设备的特征信息
               deviceId: app.BLEInformation.deviceId,
               deviceId: that.deviceId,
               serviceId: list[num].uuid,
               success: function(res) {
                  console.log('获取特征成功的结果', res)
@@ -322,34 +443,35 @@
                     var item = res.characteristics[i].uuid
                     if (!notify) {
                        if (properties.notify) {
                           app.BLEInformation.notifyCharaterId = item
                           app.BLEInformation.notifyServiceId = list[num].uuid
                           that.notifyCharaterId = item
                           that.notifyServiceId = list[num].uuid
                           notify = true
                        }
                     }
                     if (!write) {
                        if (properties.write) {
                           app.BLEInformation.writeCharaterId = item
                           app.BLEInformation.writeServiceId = list[num].uuid
                           that.writeCharaterId = item
                           that.writeServiceId = list[num].uuid
                           write = true
                        }
                     }
                     if (!read) {
                        if (properties.read) {
                           app.BLEInformation.readCharaterId = item
                           app.BLEInformation.readServiceId = list[num].uuid
                           that.readCharaterId = item
                           that.readServiceId = list[num].uuid
                           read = true
                        }
                     }
                  }
                  if (!write || !notify || !read) {
                     num++
                     that.setData({
                        writeCharacter: write,
                        readCharacter: read,
                        notifyCharacter: notify,
                        serviceId: num
                     })
                     that.writeCharacter = write
                     that.readCharacter = read
                     that.notifyCharacter = notify
                     that.serviceId = num
                     if (num == list.length) {
                        wx.showModal({
                           title: '提示',
@@ -366,35 +488,134 @@
                  console.log(e)
               },
               complete: function(e) {
                  console.log("write:" + app.BLEInformation.writeCharaterId)
                  console.log("read:" + app.BLEInformation.readCharaterId)
                  console.log("notify:" + app.BLEInformation.notifyCharaterId)
                  console.log("write:" + that.writeCharaterId)
                  console.log("read:" + that.readCharaterId)
                  console.log("notify:" + that.notifyCharaterId)
               }
            })
         },
         openControl() {
         async openControl() {
            //打印
            var that = this;
            // var canvasWidth = that.data.canvasWidth
            // var canvasHeight = that.data.canvasHeight
            var command = tsc.jpPrinter.createNew()
            command.setSize(48, 40)
            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, 90, "TSS24.BF2", 1, 1, "佳博智汇")
            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.setBar(170, 180, "EAN8", 64, 1, 3, 3, "1234567")
            command.setPagePrint()
            that.setData({
               isLabelSend: true
            })
            that.prepareSend(command.getData())
            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, 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
                     }
                     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())
            }
            that.isLabelSend = true
            // that.prepareSend(command.getData())
            that.prepareSend(that.buffs[0])
            // wx.canvasGetImageData({
            //   canvasId: 'edit_area_canvas',
@@ -413,25 +634,24 @@
         prepareSend: function(buff) { //准备发送,根据每次发送字节数来处理分包数量
            console.log(buff)
            var that = this
            var time = that.data.oneTimeData
            var time = that.oneTimeData
            var looptime = parseInt(buff.length / time);
            var lastData = parseInt(buff.length % time);
            console.log(looptime + "---" + lastData)
            that.setData({
               looptime: looptime + 1,
               lastData: lastData,
               currentTime: 1,
            })
            that.looptime = looptime + 1
            that.lastData = lastData
            that.currentTime = 1
            that.Send(buff)
         },
         Send: function(buff) { //分包发送
            var that = this
            var currentTime = that.data.currentTime
            var loopTime = that.data.looptime
            var lastData = that.data.lastData
            var onTimeData = that.data.oneTimeData
            var printNum = that.data.printerNum
            var currentPrint = that.data.currentPrint
            var currentTime = that.currentTime
            var loopTime = that.looptime
            var lastData = that.lastData
            var onTimeData = that.oneTimeData
            var printNum = that.printerNum
            var currentPrint = that.currentPrint
            var buf
            var dataView
            if (currentTime < loopTime) {
@@ -449,9 +669,9 @@
            }
            console.log("第" + currentTime + "次发送数据大小为:" + buf.byteLength)
            wx.writeBLECharacteristicValue({
               deviceId: app.BLEInformation.deviceId,
               serviceId: app.BLEInformation.writeServiceId,
               characteristicId: app.BLEInformation.writeCharaterId,
               deviceId: that.deviceId,
               serviceId: that.writeServiceId,
               characteristicId: that.writeCharaterId,
               value: buf,
               success: function(res) {
                  console.log(res)
@@ -462,31 +682,46 @@
               complete: function() {
                  currentTime++
                  if (currentTime <= loopTime) {
                     that.setData({
                        currentTime: currentTime
                     })
                     that.currentTime = currentTime
                     that.Send(buff)
                  } else {
                     wx.showToast({
                        title: '已打印第' + currentPrint + '张',
                     })
                     if (currentPrint == printNum) {
                        that.setData({
                           looptime: 0,
                           lastData: 0,
                           currentTime: 1,
                           isReceiptSend: false,
                           isLabelSend: false,
                           currentPrint: 1
                        })
                     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.setData({
                           currentPrint: currentPrint,
                           currentTime: 1,
                        })
                        that.Send(buff)
                        that.currentPrint = currentPrint
                        that.currentTime = 1
                        that.Send(that.buffs[that.currentPrint - 1])
                     }
                     // } else {
                     //    currentPrint++
                     //    that.currentPrint = currentPrint
                     //    that.currentTime = 1
                     //    that.Send(buff)
                     // }
                  }
               }
            })
@@ -538,6 +773,18 @@
            margin-bottom: 20rpx;
            padding: 22rpx;
            .each-item {
               .label {
                  min-width: 120rpx;
               }
               .label:after {
                  content: ":";
                  margin-right: 10rpx;
               }
            }
            .buttons {
               display: flex;
               margin-left: auto;
@@ -573,6 +820,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 {
@@ -602,6 +857,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 {}