1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060 |
- <template>
- <view>
- <u-navbar :title="headline" autoBack placeholder></u-navbar>
- <view class="card_stamp">
- <view class="title_bluetooth">匹配蓝牙设备</view>
- <view class="center_in">
- <x-radar :BlueState="BlueState"></x-radar>
- </view>
- <view class="nearby_title">{{nearbyTitle}}</view>
- <view class="search_card">
- <u-button style="width: 200rpx;" size="small" type="warning" :text="searchTitle"
- @click="openBluetoothAdapter(searchType)"></u-button>
- </view>
- <view class="space_between">
- <view class="waybill_num">运单号: {{waybillNo}}</view>
- <view style="font-size: 28rpx;margin-top: 20rpx;" v-if="printType == 'barCode'">
- x{{waybillList.quantity}}</view>
- </view>
- <view class="waybill_numil" v-if="printType == 'record'">请选择运单温湿度时间段</view>
- <view class="card_waybill" v-for="(item,index) in timeQuantumList" :key="index" @click="selectChange(item)">
- <view @click="selectChangeil(item)">
- <x-checkbox :label="item.title" :isChecked="item.isChecked"></x-checkbox>
- </view>
- <!-- <view class="time_title">{{item.startTime}}</view>
- <view class="time_title">{{item.endTime}}</view> -->
- <view class="dateTime_card" style="margin-top: 20rpx;">
- <uni-datetime-picker v-model="item.datetimeRange" type="datetimerange"
- @change="changeDatetime($event,item)" />
- </view>
- </view>
- <view class="card_waybill" style="margin-top: 20rpx;">
- <u-radio-group v-model="printerValue" placement="row">
- <u-radio name="default" label="默认打印机设备"></u-radio>
- <u-radio name="zicox" style="margin-left: 30rpx;" label="芝柯打印机设备"></u-radio>
- </u-radio-group>
- </view>
- <view class="card_bluetooth" v-if="pairedDeviceList.length > 0">
- <view class="equipment_title">已配对设备</view>
- <view class="card_equipment">
- <x-bluetooth :reconnectionFlag="true" :list="pairedDeviceList" text="打印" btnType="success"
- @connect="getPrint" @reconnection="reconnection"></x-bluetooth>
- </view>
- </view>
- <view class="card_bluetooth">
- <view class="equipment_title">可连接设备</view>
- <view class="card_equipment">
- <x-bluetooth :list="devices" @connect="connect"></x-bluetooth>
- </view>
- </view>
- </view>
- </view>
- </template>
- <script>
- import {
- printList
- } from './waybill.js'
- import PrinterJobs from './gprint/printerjobs.js'
- import printerUtil from './gprint/printerutil.js'
- import util from './gprint/util.js'
- import drawQrcode from './gprint/weapp.qrcode.esm.js'
- import getCode128 from './gprint/code128'
- import * as blesdk from './gprint/bluetoolth.js'
- import gbk from './gprint/printUtil-GBK.js'
- export default {
- data() {
- return {
- headline: '',
- barCodeShow: false,
- pairedDeviceList: [],
- matchingUnit: {},
- BlueState: true,
- nearbyTitle: '使用蓝牙设备打印...',
- searchTitle: '开始搜索',
- searchType: false,
- devices: [],
- deviceId: null,
- serviceId: null,
- characteristicId: null,
- waybillNo: '',
- printType: '',
- waybillList: {},
- humitureData: [],
- maxData: [],
- timeQuantumList: [],
- checkboxValue: [],
- userInfo: {},
- disqualification: true,
- connectBluetooth: {},
- breakTime: null,
- printerValue: 'default',
- }
- },
- beforeDestroy() {
- this.closeBLEConnectionil(this.connectBluetooth)
- },
- onLoad(value) {
- const arr = this.$cache.getCache('commodity')
- this.waybillList = JSON.parse(arr)
- // console.log(this.waybillList, 14)
- var userInfo = this.$cache.getCache('userInfo')
- this.userInfo = userInfo
- if (value.printType == 'barCode') {
- this.headline = '条码打印'
- } else if (value.printType == 'record') {
- this.headline = '温湿度记录打印'
- this.getHumiture(value.waybillNo)
- }
- this.waybillNo = value.waybillNo
- this.printType = value.printType
- },
- methods: {
- openBluetoothAdapter(value) {
- var that = this
- if (value) {
- that.BlueState = true
- that.searchTitle = '开始搜索'
- that.nearbyTitle = '已停止蓝牙查找附近设备...'
- that.searchType = false
- } else {
- that.BlueState = false
- // console.log('开始搜索')
- that.searchTitle = '停止搜索'
- that.nearbyTitle = '正通过蓝牙查找附近设备...'
- that.searchType = true
- uni.openBluetoothAdapter({ //打开蓝牙适配器接口
- success: (res) => { //已打开
- that.onDevice() //监听寻找到新设备的事件
- uni.getBluetoothAdapterState({ //获取本机蓝牙适配器状态
- success: function(res) {
- // console.log(res)
- if (res.available) {
- //搜索蓝牙
- //开始搜寻附近的蓝牙外围设备
- console.log("开始搜寻附近的蓝牙外围设备")
- uni.startBluetoothDevicesDiscovery({
- success(res) {
- console.log(res)
- }
- })
- } else {
- console.log('本机蓝牙不可用')
- }
- },
- })
- },
- fail: err => { //未打开
- uni.showToast({
- icon: 'none',
- title: '查看手机蓝牙是否打开'
- });
- }
- })
- }
- },
- onDevice() {
- var that = this
- //监听寻找到新设备的事件
- uni.onBluetoothDeviceFound(function(devices) {
- var re = JSON.parse(JSON.stringify(devices))
- if (re.devices[0].name != '') {
- let deviceId = re.devices[0].deviceId
- let name = re.devices[0].name
- that.devices.push({
- name: name,
- deviceId: deviceId,
- services: []
- })
- for (let i = 0; i < that.devices.length; i++) {
- for (let j = i + 1; j < that.devices.length; j++) {
- if (that.devices[i].deviceId == that.devices[j].deviceId) {
- that.devices.splice(j, 1);
- j--;
- }
- }
- }
- that.devices = that.devices
- }
- })
- },
- stopFindBule() {
- const that = this
- uni.stopBluetoothDevicesDiscovery({
- success: e => {
- that.searchTitle = '开始搜索'
- that.nearbyTitle = '已停止蓝牙查找附近设备...'
- that.searchType = false
- that.BlueState = true
- console.log('停止搜索蓝牙设备:' + e.errMsg);
- },
- fail: e => {
- console.log('停止搜索蓝牙设备失败,错误码:' + e.errCode);
- }
- });
- },
- // 连接
- async connect(value) {
- const arr = await this.closeBLEConnectionil(this.connectBluetooth)
- this.connectBluetooth = value
- await this.createBLEConnectionil(value)
- },
- // 重连
- async reconnection(event) {
- const arr = await this.closeBLEConnectionil(this.connectBluetooth)
- this.connectBluetooth = event
- await this.createBLEConnectionil(event)
- },
- // item 是要连接的设备数据
- createBLEConnectionil(item) {
- let that = this;
- that.matchingUnit.deviceId = item.deviceId
- uni.showLoading({
- title: "连接中,请稍等",
- mask: true,
- });
- uni.createBLEConnection({
- deviceId: item.deviceId,
- success(res) {
- that.stopFindBule(); // 停止搜索蓝牙
- setTimeout(function() {
- that.getBLEDeviceServicesil(item); // 获取蓝牙的服务
- }, 1000)
- },
- fail(res) {
- uni.showToast({
- title: item.name + "蓝牙连接失败",
- icon: "none",
- });
- uni.hideLoading()
- }
- });
- },
- getBLEDeviceServicesil(item) {
- const that = this
- setTimeout(() => {
- uni.getBLEDeviceServices({
- // 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
- deviceId: item.deviceId,
- complete(res) {
- console.log(res, '获取服务成功')
- // let serviceId = ""
- if (res.services.length > 0) {
- let finished = false;
- that.pairedDeviceList = []
- that.pairedDeviceList.push(item)
- that.uniAsyncPromise(item, res).then(flag => {
- // console.log(flag, 24)
- if (flag) {
- // console.log(that.matchingUnit, 326)
- uni.hideLoading()
- uni.showToast({
- icon: 'success',
- title: '连接成功',
- duration: 2000
- });
- } else {
- // console.log(3)
- that.pairedDeviceList = []
- uni.showToast({
- icon: 'none',
- title: '获取特征值失败!请重新连接',
- duration: 2000
- });
- uni.hideLoading()
- }
- })
- // const serviceId = res.services.shift().uuid;
- } else {
- uni.showToast({
- icon: 'none',
- title: '连接失败!请重新连接',
- duration: 2000
- });
- uni.hideLoading()
- console.log(item, '没有服务')
- setTimeout(() => {
- that.closeBLEConnectionil(item)
- }, 1000)
- }
- },
- fail(res) {
- console.log(res)
- },
- })
- }, 1000);
- },
- uniAsyncPromise(item, arr) {
- const that = this
- return new Promise(async (resolve, reject) => {
- for (var s = 0; s < arr.services.length; s++) {
- let serviceId = arr.services[s].uuid
- await uni.getBLEDeviceCharacteristics({ //获取蓝牙设备某个服务中所有特征值(characteristic)
- // 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
- deviceId: item.deviceId,
- // 这里的 serviceId 需要在 getBLEDeviceServices 接口中获取
- serviceId: serviceId,
- success(res) {
- var readId;
- var writeId;
- // console.log(res, serviceId, '获取特征值成功')
- // that.pairedDeviceList = []
- // that.pairedDeviceList.push(item)
- var arrList = JSON.parse(JSON.stringify(res))
- for (var i = 0; i < arrList.characteristics
- .length; i++) {
- let write = false;
- let notify = false;
- let indicate = false;
- if (!notify) {
- notify = arrList.characteristics[i]
- .properties
- .notify;
- if (notify) readId = arrList
- .characteristics[i]
- .uuid;
- }
- if (!indicate) {
- indicate = arrList.characteristics[i]
- .properties
- .indicate;
- if (indicate) readId = arrList
- .characteristics[
- i].uuid;
- }
- if (!write) {
- write = arrList.characteristics[i]
- .properties
- .write;
- writeId = arrList.characteristics[i].uuid;
- }
- if ((notify || indicate) && write) {
- /* 获取蓝牙特征值uuid */
- let uuid = arrList.characteristics[i].uuid
- that.matchingUnit.characteristicId = uuid
- that.matchingUnit.serviceId = serviceId
- // console.log(that.matchingUnit, 'matchingUnit')
- resolve(true);
- break;
- }
- }
- }
- })
- }
- });
- },
- // 断开连接
- async closeBLEConnectionil(event) {
- if (event.deviceId) {
- let that = this
- return new Promise((resolve, reject) => {
- uni.closeBLEConnection({
- deviceId: event.deviceId,
- success: (res) => {
- console.log(res, '断开连接')
- if (that.breakTime) {
- clearTimeout(that.breakTime)
- }
- that.breakTime = setTimeout(() => {
- resolve(true)
- }, 1000)
- },
- fail: (res) => {
- console.log(res, '断开失败')
- reject(false)
- },
- })
- })
- }
- },
- // 配对设备打印
- async getPrint(value) {
- this.deviceId = this.matchingUnit.deviceId
- this.serviceId = this.matchingUnit.serviceId
- this.characteristicId = this.matchingUnit.characteristicId
- if (this.printType == 'barCode') {
- const showFirstName = (name) => {
- let newStr;
- if (name.length === 2) {
- newStr = name.substr(0, 1) + '*';
- } else if (name.length > 2) {
- let char = '';
- for (let i = 0, len = name.length - 1; i < len; i++) {
- char += '*';
- }
- newStr = name.substr(0, 1) + char;
- } else {
- newStr = name;
- }
- return newStr;
- }
- const shippingAddress = (addres) => {
- let title;
- if (addres.length < 16) {
- title = addres + ' \n'
- } else {
- title = addres
- }
- return title
- }
- let printerJobs = new PrinterJobs();
- let codeValue = this.waybillNo
- const ENV = require('../../.env.js')
- let logistics = ENV.APP_LINK_URL + '/WaybillInquiry?waybillNo=' + codeValue
- let code128 = getCode128(codeValue);
- if (this.printerValue == 'zicox') {
- let strCmd = blesdk.CreatCPCLPage(384, 820 * this.waybillList.quantity, 1, 0);
- for (var i = 0; i < this.waybillList.quantity; i++) {
- let numa = i + 1
- let name = showFirstName(this.waybillList.senderAddressName)
- let phone = this.waybillList.senderAddressPhone.substr(0, 3) + "****" + this
- .waybillList
- .senderAddressPhone.substr(7)
- let name1 = showFirstName(this.waybillList.consigneeAddressName)
- let phone1 = this.waybillList.consigneeAddressPhone.substr(0, 3) + "****" + this
- .waybillList
- .consigneeAddressPhone.substr(7)
- strCmd += blesdk.addCPCLLocation(0);
- strCmd += blesdk.addCPCLSETMAG(0, 0);
- strCmd += blesdk.addCPCLText(0, 0 + 820 * i, '24', '0', 0, `#${this.userInfo.dept.name}`);
- strCmd += blesdk.addCPCLText(0, 30 + 820 * i, '24', '0', 0, numa + '/' + this.waybillList
- .quantity);
- strCmd += blesdk.addCPCLLocation(2);
- strCmd += blesdk.addCPCLBarCode(0, 50 + 820 * i, '128', 80, 0, 1, 1, '202405131452870423');
- strCmd += blesdk.addCPCLText(0, 130 + 820 * i, '7', '2', 0, '202405131452870423');
- strCmd += blesdk.addCPCLLocation(0);
- strCmd += blesdk.addCPCLSETMAG(2, 2);
- strCmd += blesdk.addCPCLText(0, 160 + 820 * i, '24', '0', 0, '收:');
- strCmd += blesdk.addCPCLSETMAG(0, 0);
- strCmd += blesdk.addCPCLText(90, 180 + 820 * i, '24', '0', 0, `${name}`);
- strCmd += blesdk.addCPCLText(150, 180 + 820 * i, '24', '0', 0, `${phone}`);
- strCmd += blesdk.addCPCLTextil(0, 210 + 820 * i, '24', '0', 0, this.waybillList
- .senderAddressDetails);
- strCmd += blesdk.addCPCLSETMAG(2, 2);
- strCmd += blesdk.addCPCLText(0, 270 + 820 * i, '24', '0', 0, '寄:');
- strCmd += blesdk.addCPCLSETMAG(0, 0);
- strCmd += blesdk.addCPCLText(90, 290 + 820 * i, '24', '0', 0, `${name1}`);
- strCmd += blesdk.addCPCLText(150, 290 + 820 * i, '24', '0', 0, `${phone1}`);
- strCmd += blesdk.addCPCLTextil(0, 320 + 820 * i, '24', '0', 0, this.waybillList
- .consigneeAddressDetails);
- // strCmd += blesdk.addCPCLLine(0, 380, 384, 380, 1);
- strCmd += blesdk.addCPCLText(0, 390 + 820 * i, '3', '0', 0, '下单时间:' + this.waybillList
- .orderTime);
- strCmd += blesdk.addCPCLText(0, 420 + 820 * i, '3', '0', 0, '备注:货物类型:' + this.waybillList
- .cargoType);
- strCmd += blesdk.addCPCLText(60, 450 + 820 * i, '3', '0', 0, '温度需求:' + this.waybillList
- .temperatureInterval);
- strCmd += blesdk.addCPCLText(60, 480 + 820 * i, '3', '0', 0, '配送要求:' + this.waybillList
- .deliveryCondition);
- strCmd += blesdk.addCPCLLocation(2);
- strCmd += blesdk.addCPCLQRCode(0, 510 + 820 * i, 'M', 3, 5, `${logistics}`);
- strCmd += blesdk.addCPCLText(0, 700 + 820 * i, '24', '0', 0, '扫码查询物流温湿度信息');
- }
- strCmd += blesdk.addCPCLPrint();
- uni.hideLoading()
- let buffer = gbk.strToGBKByte(strCmd)
- // this.printbuffs(buffer);
- let opt = {
- deviceId: this.deviceId,
- serviceId: this.serviceId,
- characteristicId: this.characteristicId,
- value: buffer,
- onceLength: 20
- }
- blesdk.sendDataToDevice(opt);
- } else {
- let numArr = []
- for (var i = 0; i < this.waybillList.quantity; i++) {
- let numa = i + 1
- numArr.push(numa)
- }
- numArr.forEach((numitem, indexnum) => {
- printerJobs
- .setSize(1, 1)
- .setAlign('LT')
- .print('#' + this.userInfo.dept.name)
- .print(numitem + '/' + this.waybillList.quantity)
- .setAlign('CT')
- .printBarcode(code128)
- .setSize(1, 1)
- .setAlign('CT')
- .text(codeValue + ' \n')
- .setAlign('LT')
- .setSize(1, 2)
- .setSize(2, 1)
- .setBold()
- .text('收:')
- .setSize(1, 1)
- .setBold(false)
- .text(' ' + showFirstName(this.waybillList.senderAddressName))
- .text(' ' + this.waybillList.senderAddressPhone.substr(0, 3) + "****" + this
- .waybillList
- .senderAddressPhone.substr(7) + ' \n')
- .print(shippingAddress(this.waybillList.senderAddressDetails))
- .setSize(1, 2)
- .setSize(2, 1)
- .setBold()
- .text('寄:')
- .setSize(1, 1)
- .setBold(false)
- .text(' ' + showFirstName(this.waybillList.consigneeAddressName))
- .text(' ' + this.waybillList.consigneeAddressPhone.substr(0, 3) + "****" + this
- .waybillList
- .consigneeAddressPhone.substr(7) + ' \n')
- .print(shippingAddress(this.waybillList.consigneeAddressDetails))
- .print(printerUtil.fillLine())
- .print('下单时间:' + this.waybillList.orderTime)
- .text('备注:')
- .text('货物类型:' + this.waybillList.cargoType + ' \n')
- .print(' 温度需求:' + this.waybillList.temperatureInterval)
- .print(' 配送要求:' + this.waybillList.deliveryCondition)
- .setAlign('CT')
- .printQrcode(logistics)
- .print('扫码查询物流温湿度信息 \n')
- .println()
- })
- let buffer = printerJobs.buffer();
- // this.printbuffs(buffer);
- let opt = {
- deviceId: this.deviceId,
- serviceId: this.serviceId,
- characteristicId: this.characteristicId,
- value: buffer,
- onceLength: 20
- }
- blesdk.sendDataToDevice(opt);
- }
- } else {
- var flag = true;
- for (let i = 0, len = this.humitureData.length; i < len; i++) {
- if (!this.humitureData[i].belowStandard) {
- flag = false;
- uni.$u.toast('数据不合格,无法打印!')
- return false;
- }
- }
- // 选择项全部合格
- if (flag) {
- // if (this.printerValue == 'zicox') {
- // let strHum = blesdk.CreatCPCLPage(384, 300, 1, 0);
- // strHum += blesdk.addCPCLText(0, 0, '24', '0', 0, `#${this.userInfo.dept.name}`);
- // strHum += blesdk.addCPCLText(0, 0, '24', '0', 0, `运单号:${this.waybillList.waybillNo}`);
- // strHum += blesdk.addCPCLText(0, 0, '24', '0', 0, `货物类型:${this.waybillList.cargoType}`);
- // strHum += blesdk.addCPCLText(0, 0, '24', '0', 0, `温度需求:${this.waybillList.temperatureInterval}`);
- // strHum += blesdk.addCPCLText(0, 0, '24', '0', 0, `配送要求:${this.waybillList.deliveryCondition}`);
- // strHum += blesdk.addCPCLText(0, 0, '24', '0', 0, `寄件人:${this.waybillList.senderAddressName}`);
- // strHum += blesdk.addCPCLText(0, 0, '24', '0', 0, `收件人:${this.waybillList.consigneeAddressName}`);
- // } else {
- // }
- let printerJobs = new PrinterJobs();
- printerJobs
- .setSize(1, 1)
- .setAlign('lt')
- .print('#' + this.userInfo.dept.name)
- .print('运单号:' + this.waybillList.waybillNo)
- .print('货物类型:' + this.waybillList.cargoType)
- .print('温度需求:' + this.waybillList.temperatureInterval)
- .print('配送要求:' + this.waybillList.deliveryCondition)
- .print('寄件人:' + this.waybillList.senderAddressName)
- .print('收件人:' + this.waybillList.consigneeAddressName)
- .print(printerUtil.fillLine())
- this.humitureData.forEach((item, index) => {
- // console.log(item,123)
- const exists = this.checkboxValue.some(Tid => Tid === item.id);
- if (item.isChecked) {
- // printerJobs
- // .print('设备号:' + item.sn)
- // .print('标识名:' + item.title)
- // .print('开始时间:' + item.startTime)
- // .print('结束时间:' + item.endTime)
- // .print(printerUtil.fillLine())
- item.arr.forEach((item1, index1) => {
- if (item1.arrNum < 2) {
- printerJobs
- .print('日期:' + item1.time + '单位℃ ')
- .text('时间 ')
- .text('|')
- .text(' ')
- .text('T1 ')
- .text(' ')
- .text('|')
- .text(' ')
- .text('T2 ')
- .text(' ')
- .text('|')
- .text(' ')
- .text('T3 ')
- .text(' ')
- .text('|')
- .text(' ')
- .text('T4 \n')
- item1.arr.forEach((item2, index2) => {
- printerJobs
- .text(`${item2[0].time}`)
- .text('|')
- .text(' ')
- .text(
- `${item2[0] == '---' ? '----' : character(item2[0].T_t) }`
- )
- .text(' ')
- .text('|')
- .text(' ')
- .text(
- `${item2[1] == '---' ? '----' : character(item2[1].T_t) }`
- )
- .text(' ')
- .text('|')
- .text(' ')
- .text(
- `${item2[2] == '---' ? '----' : character(item2[2].T_t) }`
- )
- .text(' ')
- .text('|')
- .text(' ')
- .text(
- `${item2[3] == '---' ? '----' : character(item2[3].T_t) }`
- )
- function character(value) {
- var arr = value.toFixed(1)
- if (arr.length == 3) {
- var arr1 = arr + ' '
- return arr1
- } else {
- return arr
- }
- }
- })
- } else {
- printerJobs
- .print('日期:' + item1.time + '单位℃ ')
- .text('时间')
- .text('|')
- .text('温度(℃)')
- .text(' ')
- .text('时间')
- .text('|')
- .text('温度(℃) \n')
- item1.arr.forEach((item2, index2) => {
- printerJobs
- .text(`${item2[0].time}`)
- .text('|')
- .text(
- `${item2[0] == '---' ? '----' : character(item2[0].T_t) }`
- )
- .text('|')
- .text(
- `${item2[1] == '---' ? '----' : character(item2[1].T_t) }`
- )
- .text(' ')
- // if (isEven(index2 + 1)) {
- // printerJobs.text(' \n')
- // }
- function isEven(num) {
- return num % 2 === 0;
- }
- function character(value) {
- var arr = value.toFixed(1)
- if (arr.length == 3) {
- var arr1 = arr + ' '
- return arr1
- } else {
- return arr
- }
- }
- })
- function isLengthOdd(array) {
- return array.length % 2 === 1;
- }
- if (isLengthOdd(item1.arr)) {
- printerJobs.text(' \n')
- }
- }
- })
- // printerJobs.println()
- }
- })
- printerJobs.println()
- let buffer = printerJobs.buffer();
- // this.printbuffs(buffer);
- let opt = {
- deviceId: this.deviceId,
- serviceId: this.serviceId,
- characteristicId: this.characteristicId,
- value: buffer,
- onceLength: 20
- }
- blesdk.sendDataToDevice(opt);
- }
- }
- },
- async printbuffs(buffer) {
- uni.hideLoading()
- uni.showLoading({
- title: '打印中,请稍等',
- mask: true,
- });
- // 1.并行调用多次会存在写失败的可能性
- // 2.建议每次写入不超过20字节
- // 分包处理,延时调用
- const maxChunk = 20;
- const delay = 20;
- for (let i = 0, j = 0, length = buffer.byteLength; i < length; i += maxChunk, j++) {
- let subPackage = buffer.slice(i, i + maxChunk <= length ? (i + maxChunk) : length);
- setTimeout(await this.printbuff, j * delay, subPackage);
- }
- uni.showToast({
- title: '打印完成',
- icon: 'none',
- duration: 2000
- })
- },
- printbuff(buffer) {
- let deviceId = this.deviceId;
- let serviceId = this.serviceId;
- let characteristicId = this.characteristicId;
- // console.log(deviceId, serviceId, characteristicId, 333)
- return new Promise((resolve, reject) => {
- uni.writeBLECharacteristicValue({
- deviceId,
- serviceId,
- characteristicId,
- value: buffer,
- success(res) {
- //console.log('message发送成功', JSON.stringify(res));
- resolve(res);
- },
- fail(err) {
- console.log('message发送失败', JSON.stringify(err));
- reject(err);
- }
- });
- });
- },
- // 获取设备信息探头
- getHumiture(waybillNo) {
- this.checkboxValue = []
- this.$api.get('/api/waybill-task', {
- waybillNo: waybillNo,
- }).then(res => {
- if (res.code == 200) {
- const arrlsist = res.data.list
- let arrList = []
- arrlsist.forEach((item, index) => {
- let dataList = {}
- dataList.id = item.id
- dataList.sn = item.sn
- dataList.deviceSensorList = item.deviceSensorList
- dataList.startTime = item.startTime
- dataList.endTime = item.endTime
- if (item.car.id) {
- dataList.title = item.car.carNo
- } else if (item.warehouse.id) {
- dataList.title = item.warehouse.name
- } else if (item.coolerBox.id) {
- dataList.title = item.coolerBox.name
- }
- arrList.push(dataList)
- })
- this.timeQuantumList = arrList
- this.timeQuantumList.forEach((item1, index1) => {
- item1.datetimeRange = []
- item1.datetimeRange.push(item1.startTime)
- item1.datetimeRange.push(item1.endTime)
- item1.isChecked = true
- this.checkboxValue.push(item1.id)
- })
- this.humitureInfo(arrList)
- }
- })
- },
- // 选择打印
- selectChange(value) {
- this.timeQuantumList.forEach((item, index) => {
- if (item.isChecked) {
- this.checkboxValue = []
- this.checkboxValue.push(item.id)
- }
- })
- // console.log(this.humitureData,'------')
- this.$forceUpdate()
- },
- selectChangeil(value) {
- this.timeQuantumList.forEach((item, index) => {
- if (value.id == item.id) {
- if (value.isChecked) {
- item.isChecked = false
- } else {
- item.isChecked = true
- }
- }
- })
- },
- // 获取温湿度信息
- humitureInfo(value) {
- let arrData = value
- let arrData1 = printList()
- arrData.forEach((item, index) => {
- let arr = []
- item.deviceSensorList.forEach((ote, te) => {
- arr.push(ote.T_id)
- })
- let params = {
- t_ids: arr,
- taskId: item.id,
- waybillNo: this.waybillNo,
- page: 1,
- pageSize: 9999,
- startTime: item.startTime,
- endTime: item.endTime,
- }
- item.arr = []
- this.getWaybillTask(params).then(res => {
- if (!res) {
- item.belowStandard = false
- } else {
- item.belowStandard = true
- const arrL = JSON.parse(JSON.stringify(res))
- const timeList = JSON.parse(JSON.stringify(res))
- const arrLil = res
- for (let i = 0; i < arrLil.length; i++) {
- for (let j = i + 1; j < arrLil.length; j++) {
- if (arrLil[i].T_time == arrLil[j].T_time) {
- arrLil.splice(j, 1);
- j--;
- }
- }
- }
- var resultArr = arrLil
- let list1 = []
- resultArr.forEach(k => {
- let arr1 = {
- T_sn: k.T_sn,
- time: k.T_time,
- arr: [],
- }
- list1.push(arr1)
- })
- this.maxData = list1
- for (let i = 0; i < timeList.length; i++) {
- for (let j = i + 1; j < timeList.length; j++) {
- if (timeList[i].time == timeList[j].time) {
- timeList.splice(j, 1);
- j--;
- }
- }
- }
- this.maxData.forEach((item3, index3) => {
- timeList.forEach((item2, index2) => {
- const result1 = arrL.find(fruit => fruit.T_id === 1 &&
- fruit.time === item2.time && fruit.T_time ===
- item3
- .time)
- const result2 = arrL.find(fruit => fruit.T_id === 2 &&
- fruit.time === item2.time && fruit.T_time ===
- item3
- .time)
- const result3 = arrL.find(fruit => fruit.T_id === 3 &&
- fruit.time === item2.time && fruit.T_time ===
- item3
- .time)
- const result4 = arrL.find(fruit => fruit.T_id === 4 &&
- fruit.time === item2.time && fruit.T_time ===
- item3
- .time)
- const flag = areAllUndefined(result1, result2, result3,
- result4)
- if (!flag) {
- function countFalseObjects(objects) {
- let count = 0;
- for (let i = 0; i < objects.length; i++) {
- if (objects[i] === undefined) {
- count++;
- }
- }
- return count;
- }
- const arrNum = countFalseObjects([result1, result2,
- result3, result4
- ])
- let list2 = []
- if (arrNum < 2) {
- list2.push(result1 == undefined ? '---' :
- result1)
- list2.push(result2 == undefined ? '---' :
- result2)
- list2.push(result3 == undefined ? '---' :
- result3)
- list2.push(result4 == undefined ? '---' :
- result4)
- } else {
- list2.push(result1 == undefined ? '---' :
- result1)
- list2.push(result2 == undefined ? '---' :
- result2)
- }
- // let list2 = [
- // result1 == undefined ? '---' : result1,
- // result2 == undefined ? '---' : result2,
- // result3 == undefined ? '---' : result3,
- // result4 == undefined ? '---' : result4,
- // ]
- item3.arrNum = arrNum
- item3.arr.push(list2)
- }
- function areAllUndefined(...args) {
- return args.every(arg => arg === undefined);
- }
- })
- })
- item.arr = this.maxData
- }
- })
- })
- this.humitureData = arrData
- // console.log(this.humitureData, 26)
- },
- getWaybillTask(params) {
- return new Promise((resolve, reject) => {
- setTimeout(() => {
- this.$api.post('/api/waybill-task/print-data', params).then(res => {
- if (res.code == 200) {
- let arr1 = res.data.list
- if (arr1) {
- let arr2 = []
- arr1.forEach(item1 => {
- const dateString = item1.T_time;
- const parts = dateString.split(" ")[0].split("-");
- const extractedDate = parts[0] + "-" + parts[1] +
- "-" + parts[
- 2];
- const parts1 = dateString.split(" ")[1].split(":");
- const extractedTime = parts1[0] + ":" + parts1[1];
- let arr3 = {
- T_sn: item1.T_sn,
- T_id: item1.T_id,
- T_time: extractedDate,
- T_t: item1.T_t,
- T_rh: item1.T_rh,
- time: extractedTime
- }
- arr2.push(arr3)
- })
- resolve(arr2)
- }
- this.disqualification = true
- } else if (res.code == 5000) {
- // this.disqualification = false
- // let arr2 = []
- // resolve(arr2)
- resolve(false)
- }
- })
- }, 300)
- });
- },
- changeDatetime(value, data) {
- this.timeQuantumList.forEach((item, index) => {
- if (data.id == item.id) {
- item.datetimeRange = value
- item.startTime = value[0]
- item.endTime = value[1]
- }
- })
- this.humitureData = []
- this.humitureInfo(this.timeQuantumList)
- }
- }
- }
- </script>
- <style lang="scss">
- page {
- background-color: #fff;
- }
- .title_bluetooth {
- display: flex;
- justify-content: center;
- align-items: center;
- font-size: 40rpx;
- margin: 20rpx;
- font-weight: 600;
- }
- .nearby_title {
- display: flex;
- justify-content: center;
- align-items: center;
- font-size: 30rpx;
- margin: 20rpx;
- font-weight: 600;
- }
- .card_stamp {
- display: flex;
- flex-direction: column;
- padding: 30rpx 20rpx;
- }
- .search_card {
- display: flex;
- justify-content: center;
- align-items: center;
- }
- .card_bluetooth {
- margin-top: 20rpx;
- }
- .equipment_title {
- font-size: 28rpx;
- font-weight: 600;
- }
- .card_equipment {
- margin-top: 20rpx;
- min-height: 90rpx;
- box-shadow: 0 4rpx 24rpx 0 rgba(0, 0, 0, 0.1);
- padding: 10rpx 20rpx;
- border-radius: 10rpx;
- }
- .waybill_num {
- margin-top: 20rpx;
- font-size: 30rpx;
- font-weight: 600;
- }
- .waybill_numil {
- margin-top: 10rpx;
- font-size: 28rpx;
- color: #767a82;
- }
- .time_title {
- margin-top: 5rpx;
- font-size: 28rpx;
- }
- .card_waybill {
- display: flex;
- flex-direction: column;
- box-shadow: 1rpx 2rpx 14rpx rgba(0, 0, 0, .12);
- padding: 20rpx;
- border-radius: 10rpx;
- margin-top: 20rpx;
- }
- .dateTime_card ::v-deep .icon-calendar {
- display: none;
- }
- </style>
|