<template>
|
<!-- 显示要打印的东西 -->
|
<view class="list-container order-delivery-print supplier">
|
<view class="p15">
|
<view class="m-b-24 order-sale-list list-container">
|
<view class="order-sale-item list-item">
|
<view class="title flex">
|
<view>订单单号:{{item.orderNo}}</view>
|
<view class="m-l-a m-r-0 status">{{item.statusStr}}</view>
|
</view>
|
<view class="line"></view>
|
<view class="flower flex">
|
<image class="image img100 m-r-6" :src="item.flowerCover" @click="previewImg(item.flowerCover)">
|
</image>
|
<view class="flex1">
|
<view class=" flex">
|
<view class="title">{{item.flowerName }}
|
</view>
|
</view>
|
<view class="each-list flex">
|
<view class="each-item">
|
<view class="label">颜色</view>
|
<view class="value">{{ item.flowerColor || '-' }}</view>
|
|
</view>
|
<view class="each-item">
|
<view class="label">规格</view>
|
<view class="value">{{ item.flowerUnit || '-' }}</view>
|
</view>
|
</view>
|
</view>
|
<view class="each-list price">
|
<view class="each-item">
|
<view class="value">¥{{ item.price || '-' }}</view>
|
</view>
|
<view class="each-item">
|
<view class="value">x {{ item.num || 0 }}</view>
|
</view>
|
</view>
|
|
</view>
|
<view class="line"></view>
|
<view class="delivery-form">
|
<view class="form-item">
|
<view class="label">仓库名称</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>
|
|
</view>
|
</view>
|
</view>
|
</view>
|
|
<view class="print-container m-t-12">
|
<button class="btn" type="primary" @click="startSearch" :loading="isScanning"> 开始搜索 </button>
|
<view v-for="(device,index) of list" :key="device.deviceId" @click="bindViewTap(device)">
|
<view class="item">
|
<div class="deviceId block">{{device.deviceId}}</div>
|
<div class="name block">{{device.name}}</div>
|
</view>
|
</view>
|
</view>
|
</view>
|
</template>
|
|
<script>
|
var tsc = require("@/plugins/tsc.js");
|
|
export default {
|
data() {
|
return {
|
item: {},
|
services: [],
|
serviceId: 0,
|
writeCharacter: false,
|
readCharacter: false,
|
notifyCharacter: false,
|
isScanning: false,
|
//打印的
|
sendContent: "",
|
looptime: 0,
|
currentTime: 1,
|
lastData: 0,
|
oneTimeData: 0,
|
returnResult: "",
|
canvasWidth: 80,
|
canvasHeight: 80,
|
buffSize: [],
|
buffIndex: 0,
|
printNum: [],
|
printNumIndex: 0,
|
printerNum: 1,
|
currentPrint: 1,
|
isReceiptSend: false,
|
isLabelSend: false
|
}
|
},
|
onLoad() {
|
var t = this.$storage.getItem('cache_delivery_order_print') || ''
|
if (t)
|
this.item = JSON.parse(t)
|
},
|
methods: {
|
/**
|
* 蓝牙初始化,检查是否已经开启蓝牙
|
*/
|
startSearch: function() {
|
var that = this
|
wx.openBluetoothAdapter({
|
success: function(res) {
|
wx.getBluetoothAdapterState({
|
success: function(res) {
|
if (res.available) {
|
if (res.discovering) {
|
wx.stopBluetoothDevicesDiscovery({
|
success: function(res) {
|
console.log(res)
|
}
|
})
|
}
|
that.checkPemission()
|
} else {
|
wx.showModal({
|
title: '提示',
|
content: '本机蓝牙不可用',
|
})
|
}
|
},
|
})
|
},
|
fail: function() {
|
wx.showModal({
|
title: '提示',
|
content: '蓝牙初始化失败,请打开蓝牙',
|
})
|
}
|
})
|
},
|
/**
|
* 区分平台开放蓝牙权限
|
*/
|
checkPemission: function() { //android 6.0以上需授权地理位置权限
|
var that = this
|
var platform = app.BLEInformation.platform
|
if (platform == "ios") {
|
app.globalData.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)
|
if (systemVersion > 5) {
|
wx.getSetting({
|
success: function(res) {
|
console.log(res) //
|
if (!res.authSetting['scope.userLocation']) {
|
wx.authorize({
|
scope: 'scope.userLocation',
|
complete: function(res) {
|
that.getBluetoothDevices()
|
}
|
})
|
} else {
|
that.getBluetoothDevices()
|
}
|
}
|
})
|
}
|
}
|
},
|
|
/**
|
* 获取蓝牙设备列表
|
*/
|
getBluetoothDevices: function() {
|
var that = this
|
console.log("开始查找可被使用发现的蓝牙设备")
|
wx.showLoading({
|
title: '获取蓝牙设备中',
|
})
|
that.setData({
|
isScanning: true
|
})
|
wx.startBluetoothDevicesDiscovery({
|
success: function(res) {
|
console.log(res) //输出蓝牙设备列表查找的结果,是否成功
|
setTimeout(function() { //三秒后进行蓝牙设备的获取
|
wx.getBluetoothDevices({
|
success: function(res) {
|
console.log(res)
|
var devices = []
|
var num = 0
|
for (var i = 0; i < res.devices.length; ++i) {
|
if (res.devices[i].name != "未知设备") {
|
//筛选去除名字为未知设备的蓝牙设备
|
devices[num] = res.devices[i]
|
num++
|
}
|
}
|
that.setData({
|
list: devices,
|
isScanning: false
|
}) // 数据赋值 关闭刷新
|
wx.hideLoading()
|
wx.stopPullDownRefresh()
|
},
|
})
|
}, 3000) //到这里 都是三秒后执行的内容
|
},
|
})
|
},
|
|
/**
|
* 链接到某一个蓝牙设备上
|
*/
|
bindViewTap: function(device) {
|
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)
|
// console.log(e.currentTarget.dataset.title)
|
wx.showLoading({
|
title: '正在建立连接',
|
})
|
// 与蓝牙设备建立链接
|
wx.createBLEConnection({
|
deviceId: e.deviceId,
|
success: function(res) {
|
console.log('连接蓝牙设备成功', res)
|
app.BLEInformation.deviceId = e.deviceId
|
that.getSeviceId() //获取服务ID
|
},
|
fail: function(e) {
|
wx.showModal({
|
title: '提示',
|
content: '连接失败',
|
})
|
console.log('蓝牙设备链接失败', e)
|
wx.hideLoading()
|
},
|
complete: function(e) {
|
console.log(e)
|
}
|
})
|
},
|
|
getSeviceId: function() {
|
var that = this
|
var platform = app.BLEInformation.platform //获取平台信息
|
console.log(app.BLEInformation.deviceId) // 获取设备ID
|
wx.getBLEDeviceServices({
|
deviceId: app.BLEInformation.deviceId,
|
success: function(res) {
|
console.log(res)
|
// 注释内容为方便调试特意直接赋值的一些信息,可以跳过
|
var realId = ''
|
if (platform == 'android') {
|
// for(var i=0;i<res.services.length;++i){
|
// var item = res.services[i].uuid
|
// if (item == "0000FEE7-0000-1000-8000-00805F9B34FB"){
|
realId = "0000FEE7-0000-1000-8000-00805F9B34FB"
|
// break;
|
// }
|
// }
|
} else if (platform == 'ios') {
|
// for(var i=0;i<res.services.length;++i){
|
// var item = res.services[i].uuid
|
// if (item == "49535343-FE7D-4AE5-8FA9-9FAFD205E455"){
|
realId = "49535343-FE7D-4AE5-8FA9-9FAFD205E455"
|
// break
|
// }
|
// }
|
}
|
app.BLEInformation.serviceId = realId
|
that.setData({
|
services: res.services
|
}) //将服务信息赋值到公共数据缓存
|
that.getCharacteristics() //获取特征
|
},
|
fail: function(e) {
|
console.log(e)
|
},
|
complete: function(e) {
|
console.log(e)
|
}
|
})
|
},
|
|
/**
|
* 获取特征信息
|
*/
|
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
|
wx.getBLEDeviceCharacteristics({ //获取蓝牙设备的特征信息
|
deviceId: app.BLEInformation.deviceId,
|
serviceId: list[num].uuid,
|
success: function(res) {
|
console.log('获取特征成功的结果', res)
|
for (var i = 0; i < res.characteristics.length; ++i) {
|
var properties = res.characteristics[i].properties
|
var item = res.characteristics[i].uuid
|
if (!notify) {
|
if (properties.notify) {
|
app.BLEInformation.notifyCharaterId = item
|
app.BLEInformation.notifyServiceId = list[num].uuid
|
notify = true
|
}
|
}
|
if (!write) {
|
if (properties.write) {
|
app.BLEInformation.writeCharaterId = item
|
app.BLEInformation.writeServiceId = list[num].uuid
|
write = true
|
}
|
}
|
if (!read) {
|
if (properties.read) {
|
app.BLEInformation.readCharaterId = item
|
app.BLEInformation.readServiceId = list[num].uuid
|
read = true
|
}
|
}
|
}
|
if (!write || !notify || !read) {
|
num++
|
that.setData({
|
writeCharacter: write,
|
readCharacter: read,
|
notifyCharacter: notify,
|
serviceId: num
|
})
|
if (num == list.length) {
|
wx.showModal({
|
title: '提示',
|
content: '找不到该读写的特征值',
|
})
|
} else {
|
that.getCharacteristics()
|
}
|
} else {
|
that.openControl()
|
}
|
},
|
fail: function(e) {
|
console.log(e)
|
},
|
complete: function(e) {
|
console.log("write:" + app.BLEInformation.writeCharaterId)
|
console.log("read:" + app.BLEInformation.readCharaterId)
|
console.log("notify:" + app.BLEInformation.notifyCharaterId)
|
}
|
})
|
},
|
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())
|
|
// wx.canvasGetImageData({
|
// canvasId: 'edit_area_canvas',
|
// x: 0,
|
// y: 0,
|
// width: canvasWidth,
|
// height: canvasHeight,
|
// success: function(res) {
|
// command.setBitmap(60, 0, 0, res)
|
// },
|
// complete: function() {
|
|
// }
|
// })
|
},
|
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)
|
}
|
}
|
}
|
})
|
|
},
|
}
|
}
|
</script>
|
|
<style lang="scss" scoped>
|
.order-delivery-print {
|
.print-container {
|
.btn {
|
margin-top: 50rpx;
|
height: 40px;
|
width: 600rpx;
|
line-height: 40px;
|
}
|
|
/* .item {
|
padding-top: 10px;
|
padding-bottom: 10px;
|
height: 130rpx;
|
width: 100%;
|
} */
|
.item {
|
display: block;
|
font-family: Arial, Helvetica, sans-serif;
|
font-size: 14px;
|
margin: 0 30px;
|
margin-top: 10px;
|
background-color: #FFA850;
|
border-radius: 5px;
|
border-bottom: 2px solid #68BAEA;
|
}
|
|
.block {
|
display: block;
|
color: #ffffff;
|
padding: 5px;
|
}
|
|
/* pages/bleConnect/bleConnect.wxss */
|
}
|
|
.order-sale-list {
|
.order-sale-item {
|
background-color: #fff;
|
margin-bottom: 20rpx;
|
padding: 22rpx;
|
|
.buttons {
|
display: flex;
|
margin-left: auto;
|
width: fit-content;
|
|
.button {
|
// width: 216rpx;
|
padding: 10rpx 20rpx;
|
line-height: 34rpx;
|
font-size: 24rpx;
|
height: 34rpx;
|
background: #20613D;
|
text-align: center;
|
border-radius: 30rpx;
|
|
}
|
|
.button-1 {
|
background: #fff;
|
color: #333;
|
border: 2rpx solid #333;
|
|
}
|
|
.button-0 {
|
color: #fff;
|
border: 2rpx solid #20613D;
|
}
|
}
|
|
.title {
|
font-weight: 600;
|
font-size: 28rpx;
|
color: #000000;
|
line-height: 40rpx;
|
}
|
|
.status {
|
color: #20613D;
|
}
|
|
.line {
|
min-height: 2rpx;
|
background-color: #EEEEEE;
|
margin-top: 16rpx;
|
margin-bottom: 16rpx;
|
}
|
|
.flower {
|
font-weight: 400;
|
font-size: 24rpx;
|
color: #666666;
|
line-height: 40rpx;
|
|
.image {
|
width: 115rpx;
|
height: 106rpx;
|
}
|
|
.title {
|
font-weight: 600;
|
font-size: 28rpx;
|
color: #000000;
|
line-height: 40rpx;
|
}
|
|
.desc {}
|
|
.price {
|
color: #CF0000;
|
}
|
}
|
|
.form {
|
.form-item {
|
height: unset;
|
// min-height: ;
|
}
|
}
|
|
.delivery-form {
|
display: flex;
|
flex-wrap: wrap;
|
|
.form-item {
|
flex: 1;
|
min-width: 40%;
|
max-width: 50%;
|
display: flex;
|
|
.label {
|
font-weight: 400;
|
font-size: 22rpx;
|
color: #666666;
|
line-height: 34rpx;
|
min-width: 120rpx
|
}
|
|
.label::after {
|
content: ":";
|
font-weight: 400;
|
font-size: 24rpx;
|
color: #666666;
|
line-height: 34rpx;
|
}
|
|
.value {
|
font-weight: 400;
|
font-size: 22rpx;
|
color: #333;
|
line-height: 34rpx;
|
}
|
|
.value.red {
|
color: #CF0000;
|
}
|
}
|
|
.form-item.width100 {
|
max-width: unset;
|
}
|
}
|
}
|
}
|
|
}
|
</style>
|