1
xuxueyang
2024-07-31 fba19090a86a4821fd70c301a5a0cd1e4b7f3244
sub_pages/supplier/print/print-list.vue
@@ -64,11 +64,12 @@
            </view>
         </view>
      </view>
   </view>
</template>
<script>
   var tsc = require("@/plugins/tsc.js");
   export default {
      data() {
         return {
@@ -93,7 +94,7 @@
            printNum: [],
            printNumIndex: 0,
            printerNum: 1,
            currentPrint:1,
            currentPrint: 1,
            isReceiptSend: false,
            isLabelSend: false
         }
@@ -409,87 +410,87 @@
            //   }
            // })
         },
         prepareSend: function(buff) {  //准备发送,根据每次发送字节数来处理分包数量
           console.log(buff)
           var that = this
           var time = that.data.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.Send(buff)
         prepareSend: function(buff) { //准备发送,根据每次发送字节数来处理分包数量
            console.log(buff)
            var that = this
            var time = that.data.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.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 buf
           var dataView
           if (currentTime < loopTime) {
             buf = new ArrayBuffer(onTimeData)
             dataView = new DataView(buf)
             for (var i = 0; i < onTimeData; ++i) {
               dataView.setUint8(i, buff[(currentTime - 1) * onTimeData + i])
             }
           } else {
             buf = new ArrayBuffer(lastData)
             dataView = new DataView(buf)
             for (var i = 0; i < lastData; ++i) {
               dataView.setUint8(i, buff[(currentTime - 1) * onTimeData + i])
             }
           }
           console.log("第" + currentTime + "次发送数据大小为:" + buf.byteLength)
           wx.writeBLECharacteristicValue({
             deviceId: app.BLEInformation.deviceId,
             serviceId: app.BLEInformation.writeServiceId,
             characteristicId: app.BLEInformation.writeCharaterId,
             value: buf,
             success: function(res) {
               console.log(res)
             },
             fail: function(e) {
               console.log(e)
             },
             complete: function() {
               currentTime++
               if (currentTime <= loopTime) {
                 that.setData({
                   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
                   })
                 }else{
                   currentPrint++
                   that.setData({
                     currentPrint:currentPrint,
                     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 buf
            var dataView
            if (currentTime < loopTime) {
               buf = new ArrayBuffer(onTimeData)
               dataView = new DataView(buf)
               for (var i = 0; i < onTimeData; ++i) {
                  dataView.setUint8(i, buff[(currentTime - 1) * onTimeData + i])
               }
            } else {
               buf = new ArrayBuffer(lastData)
               dataView = new DataView(buf)
               for (var i = 0; i < lastData; ++i) {
                  dataView.setUint8(i, buff[(currentTime - 1) * onTimeData + i])
               }
            }
            console.log("第" + currentTime + "次发送数据大小为:" + buf.byteLength)
            wx.writeBLECharacteristicValue({
               deviceId: app.BLEInformation.deviceId,
               serviceId: app.BLEInformation.writeServiceId,
               characteristicId: app.BLEInformation.writeCharaterId,
               value: buf,
               success: function(res) {
                  console.log(res)
               },
               fail: function(e) {
                  console.log(e)
               },
               complete: function() {
                  currentTime++
                  if (currentTime <= loopTime) {
                     that.setData({
                        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
                        })
                     } else {
                        currentPrint++
                        that.setData({
                           currentPrint: currentPrint,
                           currentTime: 1,
                        })
                        that.Send(buff)
                     }
                  }
               }
            })
         },
      }
   }