quantum.vue 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051
  1. <template>
  2. <view>
  3. <u-navbar :title="headline" autoBack placeholder></u-navbar>
  4. <view class="card_stamp">
  5. <view class="title_bluetooth">匹配蓝牙设备</view>
  6. <view class="center_in">
  7. <x-radar :BlueState="BlueState"></x-radar>
  8. </view>
  9. <view class="nearby_title">{{nearbyTitle}}</view>
  10. <view class="search_card">
  11. <u-button style="width: 200rpx;" size="small" type="warning" :text="searchTitle"
  12. @click="openBluetoothAdapter(searchType)"></u-button>
  13. </view>
  14. <view class="space_between">
  15. <view class="waybill_num">运单号: {{waybillNo}}</view>
  16. <view style="font-size: 28rpx;margin-top: 20rpx;" v-if="printType == 'barCode'">
  17. x{{waybillList.quantity}}</view>
  18. </view>
  19. <view class="waybill_numil" v-if="printType == 'record'">请选择运单温湿度时间段</view>
  20. <view class="card_waybill" v-for="(item,index) in timeQuantumList" :key="index" @click="selectChange(item)">
  21. <view @click="selectChangeil(item)">
  22. <x-checkbox :label="item.title" :isChecked="item.isChecked"></x-checkbox>
  23. </view>
  24. <!-- <view class="time_title">{{item.startTime}}</view>
  25. <view class="time_title">{{item.endTime}}</view> -->
  26. <view class="dateTime_card" style="margin-top: 20rpx;">
  27. <uni-datetime-picker v-model="item.datetimeRange" type="datetimerange"
  28. @change="changeDatetime($event,item)" />
  29. </view>
  30. </view>
  31. <view class="card_waybill" style="margin-top: 20rpx;">
  32. <u-radio-group v-model="printerValue" placement="row">
  33. <u-radio name="default" label="默认打印机设备"></u-radio>
  34. <u-radio name="zicox" style="margin-left: 30rpx;" label="芝柯打印机设备"></u-radio>
  35. </u-radio-group>
  36. </view>
  37. <view class="card_bluetooth" v-if="pairedDeviceList.length > 0">
  38. <view class="equipment_title">已配对设备</view>
  39. <view class="card_equipment">
  40. <x-bluetooth :reconnectionFlag="true" :list="pairedDeviceList" text="打印" btnType="success"
  41. @connect="getPrint" @reconnection="reconnection"></x-bluetooth>
  42. </view>
  43. </view>
  44. <view class="card_bluetooth">
  45. <view class="equipment_title">可连接设备</view>
  46. <view class="card_equipment">
  47. <x-bluetooth :list="devices" @connect="connect"></x-bluetooth>
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. </template>
  53. <script>
  54. import {
  55. printList
  56. } from './waybill.js'
  57. import PrinterJobs from './gprint/printerjobs.js'
  58. import printerUtil from './gprint/printerutil.js'
  59. import util from './gprint/util.js'
  60. import drawQrcode from './gprint/weapp.qrcode.esm.js'
  61. import getCode128 from './gprint/code128'
  62. import * as blesdk from './gprint/bluetoolth.js'
  63. import gbk from './gprint/printUtil-GBK.js'
  64. export default {
  65. data() {
  66. return {
  67. headline: '',
  68. barCodeShow: false,
  69. pairedDeviceList: [],
  70. matchingUnit: {},
  71. BlueState: true,
  72. nearbyTitle: '使用蓝牙设备打印...',
  73. searchTitle: '开始搜索',
  74. searchType: false,
  75. devices: [],
  76. deviceId: null,
  77. serviceId: null,
  78. characteristicId: null,
  79. waybillNo: '',
  80. printType: '',
  81. waybillList: {},
  82. humitureData: [],
  83. maxData: [],
  84. timeQuantumList: [],
  85. checkboxValue: [],
  86. userInfo: {},
  87. disqualification: true,
  88. connectBluetooth: {},
  89. breakTime: null,
  90. printerValue: 'default',
  91. }
  92. },
  93. beforeDestroy() {
  94. this.closeBLEConnectionil(this.connectBluetooth)
  95. },
  96. onLoad(value) {
  97. const arr = this.$cache.getCache('commodity')
  98. this.waybillList = JSON.parse(arr)
  99. // console.log(this.waybillList, 14)
  100. var userInfo = this.$cache.getCache('userInfo')
  101. this.userInfo = userInfo
  102. if (value.printType == 'barCode') {
  103. this.headline = '条码打印'
  104. } else if (value.printType == 'record') {
  105. this.headline = '温湿度记录打印'
  106. this.getHumiture(value.waybillNo)
  107. }
  108. this.waybillNo = value.waybillNo
  109. this.printType = value.printType
  110. },
  111. methods: {
  112. openBluetoothAdapter(value) {
  113. var that = this
  114. if (value) {
  115. that.BlueState = true
  116. that.searchTitle = '开始搜索'
  117. that.nearbyTitle = '已停止蓝牙查找附近设备...'
  118. that.searchType = false
  119. } else {
  120. that.BlueState = false
  121. // console.log('开始搜索')
  122. that.searchTitle = '停止搜索'
  123. that.nearbyTitle = '正通过蓝牙查找附近设备...'
  124. that.searchType = true
  125. uni.openBluetoothAdapter({ //打开蓝牙适配器接口
  126. success: (res) => { //已打开
  127. that.onDevice() //监听寻找到新设备的事件
  128. uni.getBluetoothAdapterState({ //获取本机蓝牙适配器状态
  129. success: function(res) {
  130. // console.log(res)
  131. if (res.available) {
  132. //搜索蓝牙
  133. //开始搜寻附近的蓝牙外围设备
  134. console.log("开始搜寻附近的蓝牙外围设备")
  135. uni.startBluetoothDevicesDiscovery({
  136. success(res) {
  137. console.log(res)
  138. }
  139. })
  140. } else {
  141. console.log('本机蓝牙不可用')
  142. }
  143. },
  144. })
  145. },
  146. fail: err => { //未打开
  147. uni.showToast({
  148. icon: 'none',
  149. title: '查看手机蓝牙是否打开'
  150. });
  151. }
  152. })
  153. }
  154. },
  155. onDevice() {
  156. var that = this
  157. //监听寻找到新设备的事件
  158. uni.onBluetoothDeviceFound(function(devices) {
  159. var re = JSON.parse(JSON.stringify(devices))
  160. if (re.devices[0].name != '') {
  161. let deviceId = re.devices[0].deviceId
  162. let name = re.devices[0].name
  163. that.devices.push({
  164. name: name,
  165. deviceId: deviceId,
  166. services: []
  167. })
  168. for (let i = 0; i < that.devices.length; i++) {
  169. for (let j = i + 1; j < that.devices.length; j++) {
  170. if (that.devices[i].deviceId == that.devices[j].deviceId) {
  171. that.devices.splice(j, 1);
  172. j--;
  173. }
  174. }
  175. }
  176. that.devices = that.devices
  177. }
  178. })
  179. },
  180. stopFindBule() {
  181. const that = this
  182. uni.stopBluetoothDevicesDiscovery({
  183. success: e => {
  184. that.searchTitle = '开始搜索'
  185. that.nearbyTitle = '已停止蓝牙查找附近设备...'
  186. that.searchType = false
  187. that.BlueState = true
  188. console.log('停止搜索蓝牙设备:' + e.errMsg);
  189. },
  190. fail: e => {
  191. console.log('停止搜索蓝牙设备失败,错误码:' + e.errCode);
  192. }
  193. });
  194. },
  195. // 连接
  196. async connect(value) {
  197. const arr = await this.closeBLEConnectionil(this.connectBluetooth)
  198. this.connectBluetooth = value
  199. await this.createBLEConnectionil(value)
  200. },
  201. // 重连
  202. async reconnection(event) {
  203. const arr = await this.closeBLEConnectionil(this.connectBluetooth)
  204. this.connectBluetooth = event
  205. await this.createBLEConnectionil(event)
  206. },
  207. // item 是要连接的设备数据
  208. createBLEConnectionil(item) {
  209. let that = this;
  210. that.matchingUnit.deviceId = item.deviceId
  211. uni.showLoading({
  212. title: "连接中,请稍等",
  213. mask: true,
  214. });
  215. uni.createBLEConnection({
  216. deviceId: item.deviceId,
  217. success(res) {
  218. that.stopFindBule(); // 停止搜索蓝牙
  219. setTimeout(function() {
  220. that.getBLEDeviceServicesil(item); // 获取蓝牙的服务
  221. }, 1000)
  222. },
  223. fail(res) {
  224. uni.showToast({
  225. title: item.name + "蓝牙连接失败",
  226. icon: "none",
  227. });
  228. uni.hideLoading()
  229. }
  230. });
  231. },
  232. getBLEDeviceServicesil(item) {
  233. const that = this
  234. setTimeout(() => {
  235. uni.getBLEDeviceServices({
  236. // 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
  237. deviceId: item.deviceId,
  238. complete(res) {
  239. console.log(res, '获取服务成功')
  240. // let serviceId = ""
  241. if (res.services.length > 0) {
  242. let finished = false;
  243. that.pairedDeviceList = []
  244. that.pairedDeviceList.push(item)
  245. that.uniAsyncPromise(item, res).then(flag => {
  246. // console.log(flag, 24)
  247. if (flag) {
  248. // console.log(that.matchingUnit, 326)
  249. uni.hideLoading()
  250. uni.showToast({
  251. icon: 'success',
  252. title: '连接成功',
  253. duration: 2000
  254. });
  255. } else {
  256. // console.log(3)
  257. that.pairedDeviceList = []
  258. uni.showToast({
  259. icon: 'none',
  260. title: '获取特征值失败!请重新连接',
  261. duration: 2000
  262. });
  263. uni.hideLoading()
  264. }
  265. })
  266. // const serviceId = res.services.shift().uuid;
  267. } else {
  268. uni.showToast({
  269. icon: 'none',
  270. title: '连接失败!请重新连接',
  271. duration: 2000
  272. });
  273. uni.hideLoading()
  274. console.log(item, '没有服务')
  275. setTimeout(() => {
  276. that.closeBLEConnectionil(item)
  277. }, 1000)
  278. }
  279. },
  280. fail(res) {
  281. console.log(res)
  282. },
  283. })
  284. }, 1000);
  285. },
  286. uniAsyncPromise(item, arr) {
  287. const that = this
  288. return new Promise(async (resolve, reject) => {
  289. for (var s = 0; s < arr.services.length; s++) {
  290. let serviceId = arr.services[s].uuid
  291. await uni.getBLEDeviceCharacteristics({ //获取蓝牙设备某个服务中所有特征值(characteristic)
  292. // 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
  293. deviceId: item.deviceId,
  294. // 这里的 serviceId 需要在 getBLEDeviceServices 接口中获取
  295. serviceId: serviceId,
  296. success(res) {
  297. let write = false;
  298. let notify = false;
  299. let indicate = false;
  300. var readId;
  301. var writeId;
  302. console.log(res, serviceId, '获取特征值成功')
  303. // that.pairedDeviceList = []
  304. // that.pairedDeviceList.push(item)
  305. var arrList = JSON.parse(JSON.stringify(res))
  306. for (var i = 0; i < arrList.characteristics
  307. .length; i++) {
  308. if (!notify) {
  309. notify = arrList.characteristics[i]
  310. .properties
  311. .notify;
  312. if (notify) readId = arrList
  313. .characteristics[i]
  314. .uuid;
  315. }
  316. if (!indicate) {
  317. indicate = arrList.characteristics[i]
  318. .properties
  319. .indicate;
  320. if (indicate) readId = arrList
  321. .characteristics[
  322. i].uuid;
  323. }
  324. if (!write) {
  325. write = arrList.characteristics[i]
  326. .properties
  327. .write;
  328. writeId = arrList.characteristics[i].uuid;
  329. }
  330. if ((notify || indicate) && write) {
  331. // console.log(2)
  332. /* 获取蓝牙特征值uuid */
  333. let uuid = arrList.characteristics[i].uuid
  334. that.matchingUnit.characteristicId = uuid
  335. that.matchingUnit.serviceId = serviceId
  336. resolve(true);
  337. break;
  338. }
  339. }
  340. }
  341. })
  342. }
  343. });
  344. },
  345. // 断开连接
  346. async closeBLEConnectionil(event) {
  347. if (event.deviceId) {
  348. let that = this
  349. return new Promise((resolve, reject) => {
  350. uni.closeBLEConnection({
  351. deviceId: event.deviceId,
  352. success: (res) => {
  353. console.log(res, '断开连接')
  354. if (that.breakTime) {
  355. clearTimeout(that.breakTime)
  356. }
  357. that.breakTime = setTimeout(() => {
  358. resolve(true)
  359. }, 1000)
  360. },
  361. fail: (res) => {
  362. console.log(res, '断开失败')
  363. reject(false)
  364. },
  365. })
  366. })
  367. }
  368. },
  369. // 配对设备打印
  370. async getPrint(value) {
  371. this.deviceId = this.matchingUnit.deviceId
  372. this.serviceId = this.matchingUnit.serviceId
  373. this.characteristicId = this.matchingUnit.characteristicId
  374. if (this.printType == 'barCode') {
  375. const showFirstName = (name) => {
  376. let newStr;
  377. if (name.length === 2) {
  378. newStr = name.substr(0, 1) + '*';
  379. } else if (name.length > 2) {
  380. let char = '';
  381. for (let i = 0, len = name.length - 1; i < len; i++) {
  382. char += '*';
  383. }
  384. newStr = name.substr(0, 1) + char;
  385. } else {
  386. newStr = name;
  387. }
  388. return newStr;
  389. }
  390. const shippingAddress = (addres) => {
  391. let title;
  392. if (addres.length < 16) {
  393. title = addres + ' \n'
  394. } else {
  395. title = addres
  396. }
  397. return title
  398. }
  399. let printerJobs = new PrinterJobs();
  400. let codeValue = this.waybillNo
  401. const ENV = require('../../.env.js')
  402. let logistics = ENV.APP_LINK_URL + '/WaybillInquiry?waybillNo=' + codeValue
  403. let code128 = getCode128(codeValue);
  404. if (this.printerValue == 'zicox') {
  405. let strCmd = blesdk.CreatCPCLPage(384, 820 * this.waybillList.quantity, 1, 0);
  406. for (var i = 0; i < this.waybillList.quantity; i++) {
  407. let numa = i + 1
  408. let name = showFirstName(this.waybillList.senderAddressName)
  409. let phone = this.waybillList.senderAddressPhone.substr(0, 3) + "****" + this
  410. .waybillList
  411. .senderAddressPhone.substr(7)
  412. let name1 = showFirstName(this.waybillList.consigneeAddressName)
  413. let phone1 = this.waybillList.consigneeAddressPhone.substr(0, 3) + "****" + this
  414. .waybillList
  415. .consigneeAddressPhone.substr(7)
  416. strCmd += blesdk.addCPCLLocation(0);
  417. strCmd += blesdk.addCPCLSETMAG(0, 0);
  418. strCmd += blesdk.addCPCLText(0, 0 + 820 * i, '24', '0', 0, `#${this.userInfo.dept.name}`);
  419. strCmd += blesdk.addCPCLText(0, 30 + 820 * i, '24', '0', 0, numa + '/' + this.waybillList
  420. .quantity);
  421. strCmd += blesdk.addCPCLLocation(2);
  422. strCmd += blesdk.addCPCLBarCode(0, 50 + 820 * i, '128', 80, 0, 1, 1, '202405131452870423');
  423. strCmd += blesdk.addCPCLText(0, 130 + 820 * i, '7', '2', 0, '202405131452870423');
  424. strCmd += blesdk.addCPCLLocation(0);
  425. strCmd += blesdk.addCPCLSETMAG(2, 2);
  426. strCmd += blesdk.addCPCLText(0, 160 + 820 * i, '24', '0', 0, '收:');
  427. strCmd += blesdk.addCPCLSETMAG(0, 0);
  428. strCmd += blesdk.addCPCLText(90, 180 + 820 * i, '24', '0', 0, `${name}`);
  429. strCmd += blesdk.addCPCLText(150, 180 + 820 * i, '24', '0', 0, `${phone}`);
  430. strCmd += blesdk.addCPCLTextil(0, 210 + 820 * i, '24', '0', 0, this.waybillList
  431. .senderAddressDetails);
  432. strCmd += blesdk.addCPCLSETMAG(2, 2);
  433. strCmd += blesdk.addCPCLText(0, 270 + 820 * i, '24', '0', 0, '寄:');
  434. strCmd += blesdk.addCPCLSETMAG(0, 0);
  435. strCmd += blesdk.addCPCLText(90, 290 + 820 * i, '24', '0', 0, `${name1}`);
  436. strCmd += blesdk.addCPCLText(150, 290 + 820 * i, '24', '0', 0, `${phone1}`);
  437. strCmd += blesdk.addCPCLTextil(0, 320 + 820 * i, '24', '0', 0, this.waybillList
  438. .consigneeAddressDetails);
  439. // strCmd += blesdk.addCPCLLine(0, 380, 384, 380, 1);
  440. strCmd += blesdk.addCPCLText(0, 390 + 820 * i, '3', '0', 0, '下单时间:' + this.waybillList
  441. .orderTime);
  442. strCmd += blesdk.addCPCLText(0, 420 + 820 * i, '3', '0', 0, '备注:货物类型:' + this.waybillList
  443. .cargoType);
  444. strCmd += blesdk.addCPCLText(60, 450 + 820 * i, '3', '0', 0, '温度需求:' + this.waybillList
  445. .temperatureInterval);
  446. strCmd += blesdk.addCPCLText(60, 480 + 820 * i, '3', '0', 0, '配送要求:' + this.waybillList
  447. .deliveryCondition);
  448. strCmd += blesdk.addCPCLLocation(2);
  449. strCmd += blesdk.addCPCLQRCode(0, 510 + 820 * i, 'M', 3, 5, `${logistics}`);
  450. strCmd += blesdk.addCPCLText(0, 700 + 820 * i, '24', '0', 0, '扫码查询物流温湿度信息');
  451. }
  452. strCmd += blesdk.addCPCLPrint();
  453. uni.hideLoading()
  454. let buffer = gbk.strToGBKByte(strCmd)
  455. // this.printbuffs(buffer);
  456. let opt = {
  457. deviceId: this.deviceId,
  458. serviceId: this.serviceId,
  459. characteristicId: this.characteristicId,
  460. value: buffer,
  461. onceLength: 20
  462. }
  463. blesdk.sendDataToDevice(opt);
  464. } else {
  465. let numArr = []
  466. for (var i = 0; i < this.waybillList.quantity; i++) {
  467. let numa = i + 1
  468. numArr.push(numa)
  469. }
  470. numArr.forEach((numitem, indexnum) => {
  471. printerJobs
  472. .setSize(1, 1)
  473. .setAlign('LT')
  474. .print('#' + this.userInfo.dept.name)
  475. .print(numitem + '/' + this.waybillList.quantity)
  476. .setAlign('CT')
  477. .printBarcode(code128)
  478. .setSize(1, 1)
  479. .setAlign('LT')
  480. // .text(' ')
  481. // .text(codeValue + ' \n')
  482. // .print(printerUtil.fillLine())
  483. .setAlign('LT')
  484. .setSize(1, 2)
  485. .setSize(2, 1)
  486. .setBold()
  487. .text('收:')
  488. .setSize(1, 1)
  489. .setBold(false)
  490. .text(' ' + showFirstName(this.waybillList.senderAddressName))
  491. .text(' ' + this.waybillList.senderAddressPhone.substr(0, 3) + "****" + this
  492. .waybillList
  493. .senderAddressPhone.substr(7) + ' \n')
  494. .print(shippingAddress(this.waybillList.senderAddressDetails))
  495. .setSize(1, 2)
  496. .setSize(2, 1)
  497. .setBold()
  498. .text('寄:')
  499. .setSize(1, 1)
  500. .setBold(false)
  501. .text(' ' + showFirstName(this.waybillList.consigneeAddressName))
  502. .text(' ' + this.waybillList.consigneeAddressPhone.substr(0, 3) + "****" + this
  503. .waybillList
  504. .consigneeAddressPhone.substr(7) + ' \n')
  505. .print(shippingAddress(this.waybillList.consigneeAddressDetails))
  506. .print(printerUtil.fillLine())
  507. .print('下单时间:' + this.waybillList.orderTime)
  508. // .print(printerUtil.fillLine())
  509. .text('备注:')
  510. .text('货物类型:' + this.waybillList.cargoType + ' \n')
  511. .print(' 温度需求:' + this.waybillList.temperatureInterval)
  512. .print(' 配送要求:' + this.waybillList.deliveryCondition)
  513. .setAlign('CT')
  514. .printQrcode(logistics)
  515. .print('扫码查询物流温湿度信息 \n')
  516. .println()
  517. })
  518. let buffer = printerJobs.buffer();
  519. // this.printbuffs(buffer);
  520. let opt = {
  521. deviceId: this.deviceId,
  522. serviceId: this.serviceId,
  523. characteristicId: this.characteristicId,
  524. value: buffer,
  525. onceLength: 20
  526. }
  527. blesdk.sendDataToDevice(opt);
  528. }
  529. } else {
  530. var flag = true;
  531. for (let i = 0, len = this.humitureData.length; i < len; i++) {
  532. if (!this.humitureData[i].belowStandard) {
  533. flag = false;
  534. uni.$u.toast('数据不合格,无法打印!')
  535. return false;
  536. }
  537. }
  538. // 选择项全部合格
  539. if (flag) {
  540. // if (this.printerValue == 'zicox') {
  541. // let strHum = blesdk.CreatCPCLPage(384, 300, 1, 0);
  542. // strHum += blesdk.addCPCLText(0, 0, '24', '0', 0, `#${this.userInfo.dept.name}`);
  543. // strHum += blesdk.addCPCLText(0, 0, '24', '0', 0, `运单号:${this.waybillList.waybillNo}`);
  544. // strHum += blesdk.addCPCLText(0, 0, '24', '0', 0, `货物类型:${this.waybillList.cargoType}`);
  545. // strHum += blesdk.addCPCLText(0, 0, '24', '0', 0, `温度需求:${this.waybillList.temperatureInterval}`);
  546. // strHum += blesdk.addCPCLText(0, 0, '24', '0', 0, `配送要求:${this.waybillList.deliveryCondition}`);
  547. // strHum += blesdk.addCPCLText(0, 0, '24', '0', 0, `寄件人:${this.waybillList.senderAddressName}`);
  548. // strHum += blesdk.addCPCLText(0, 0, '24', '0', 0, `收件人:${this.waybillList.consigneeAddressName}`);
  549. // } else {
  550. // }
  551. let printerJobs = new PrinterJobs();
  552. printerJobs
  553. .setSize(1, 1)
  554. .setAlign('lt')
  555. .print('#' + this.userInfo.dept.name)
  556. .print('运单号:' + this.waybillList.waybillNo)
  557. .print('货物类型:' + this.waybillList.cargoType)
  558. .print('温度需求:' + this.waybillList.temperatureInterval)
  559. .print('配送要求:' + this.waybillList.deliveryCondition)
  560. .print('寄件人:' + this.waybillList.senderAddressName)
  561. .print('收件人:' + this.waybillList.consigneeAddressName)
  562. .print(printerUtil.fillLine())
  563. this.humitureData.forEach((item, index) => {
  564. // console.log(item,123)
  565. const exists = this.checkboxValue.some(Tid => Tid === item.id);
  566. if (item.isChecked) {
  567. // printerJobs
  568. // .print('设备号:' + item.sn)
  569. // .print('标识名:' + item.title)
  570. // .print('开始时间:' + item.startTime)
  571. // .print('结束时间:' + item.endTime)
  572. // .print(printerUtil.fillLine())
  573. item.arr.forEach((item1, index1) => {
  574. if (item1.arrNum < 2) {
  575. printerJobs
  576. .print('日期:' + item1.time + '单位℃ ')
  577. .text('时间 ')
  578. .text('|')
  579. .text(' ')
  580. .text('T1 ')
  581. .text(' ')
  582. .text('|')
  583. .text(' ')
  584. .text('T2 ')
  585. .text(' ')
  586. .text('|')
  587. .text(' ')
  588. .text('T3 ')
  589. .text(' ')
  590. .text('|')
  591. .text(' ')
  592. .text('T4 \n')
  593. item1.arr.forEach((item2, index2) => {
  594. printerJobs
  595. .text(`${item2[0].time}`)
  596. .text('|')
  597. .text(' ')
  598. .text(
  599. `${item2[0] == '---' ? '----' : character(item2[0].T_t) }`
  600. )
  601. .text(' ')
  602. .text('|')
  603. .text(' ')
  604. .text(
  605. `${item2[1] == '---' ? '----' : character(item2[1].T_t) }`
  606. )
  607. .text(' ')
  608. .text('|')
  609. .text(' ')
  610. .text(
  611. `${item2[2] == '---' ? '----' : character(item2[2].T_t) }`
  612. )
  613. .text(' ')
  614. .text('|')
  615. .text(' ')
  616. .text(
  617. `${item2[3] == '---' ? '----' : character(item2[3].T_t) }`
  618. )
  619. function character(value) {
  620. var arr = value.toFixed(1)
  621. if (arr.length == 3) {
  622. var arr1 = arr + ' '
  623. return arr1
  624. } else {
  625. return arr
  626. }
  627. }
  628. })
  629. } else {
  630. printerJobs
  631. .print('日期:' + item1.time + '单位℃ ')
  632. .text('时间')
  633. .text('|')
  634. .text('温度(℃)')
  635. .text(' ')
  636. .text('时间')
  637. .text('|')
  638. .text('温度(℃) \n')
  639. item1.arr.forEach((item2, index2) => {
  640. printerJobs
  641. .text(`${item2[0].time}`)
  642. .text('|')
  643. .text(
  644. `${item2[0] == '---' ? '----' : character(item2[0].T_t) }`
  645. )
  646. .text('|')
  647. .text(
  648. `${item2[1] == '---' ? '----' : character(item2[1].T_t) }`
  649. )
  650. .text(' ')
  651. if (isEven(index2 + 1)) {
  652. printerJobs.text(' \n')
  653. }
  654. function isEven(num) {
  655. return num % 2 === 0;
  656. }
  657. function character(value) {
  658. var arr = value.toFixed(1)
  659. if (arr.length == 3) {
  660. var arr1 = arr + ' '
  661. return arr1
  662. } else {
  663. return arr
  664. }
  665. }
  666. })
  667. function isLengthOdd(array) {
  668. return array.length % 2 === 1;
  669. }
  670. if (isLengthOdd(item1.arr)) {
  671. printerJobs.text(' \n')
  672. }
  673. }
  674. })
  675. // printerJobs.println()
  676. }
  677. })
  678. printerJobs.println()
  679. let buffer = printerJobs.buffer();
  680. // this.printbuffs(buffer);
  681. let opt = {
  682. deviceId: this.deviceId,
  683. serviceId: this.serviceId,
  684. characteristicId: this.characteristicId,
  685. value: buffer,
  686. onceLength: 20
  687. }
  688. blesdk.sendDataToDevice(opt);
  689. }
  690. }
  691. },
  692. async printbuffs(buffer) {
  693. uni.hideLoading()
  694. // 1.并行调用多次会存在写失败的可能性
  695. // 2.建议每次写入不超过20字节
  696. // 分包处理,延时调用
  697. const maxChunk = 20;
  698. const delay = 20;
  699. for (let i = 0, j = 0, length = buffer.byteLength; i < length; i += maxChunk, j++) {
  700. let subPackage = buffer.slice(i, i + maxChunk <= length ? (i + maxChunk) : length);
  701. setTimeout(await this.printbuff, j * delay, subPackage);
  702. }
  703. },
  704. printbuff(buffer) {
  705. let deviceId = this.deviceId;
  706. let serviceId = this.serviceId;
  707. let characteristicId = this.characteristicId;
  708. // console.log(deviceId, serviceId, characteristicId, 333)
  709. return new Promise((resolve, reject) => {
  710. uni.writeBLECharacteristicValue({
  711. deviceId,
  712. serviceId,
  713. characteristicId,
  714. value: buffer,
  715. success(res) {
  716. //console.log('message发送成功', JSON.stringify(res));
  717. resolve(res);
  718. },
  719. fail(err) {
  720. console.log('message发送失败', JSON.stringify(err));
  721. reject(err);
  722. }
  723. });
  724. });
  725. },
  726. // 获取设备信息探头
  727. getHumiture(waybillNo) {
  728. this.checkboxValue = []
  729. this.$api.get('/api/waybill-task', {
  730. waybillNo: waybillNo,
  731. }).then(res => {
  732. if (res.code == 200) {
  733. const arrlsist = res.data.list
  734. let arrList = []
  735. arrlsist.forEach((item, index) => {
  736. let dataList = {}
  737. dataList.id = item.id
  738. dataList.sn = item.sn
  739. dataList.deviceSensorList = item.deviceSensorList
  740. dataList.startTime = item.startTime
  741. dataList.endTime = item.endTime
  742. if (item.car.id) {
  743. dataList.title = item.car.carNo
  744. } else if (item.warehouse.id) {
  745. dataList.title = item.warehouse.name
  746. } else if (item.coolerBox.id) {
  747. dataList.title = item.coolerBox.name
  748. }
  749. arrList.push(dataList)
  750. })
  751. this.timeQuantumList = arrList
  752. this.timeQuantumList.forEach((item1, index1) => {
  753. item1.datetimeRange = []
  754. item1.datetimeRange.push(item1.startTime)
  755. item1.datetimeRange.push(item1.endTime)
  756. item1.isChecked = true
  757. this.checkboxValue.push(item1.id)
  758. })
  759. this.humitureInfo(arrList)
  760. }
  761. })
  762. },
  763. // 选择打印
  764. selectChange(value) {
  765. this.timeQuantumList.forEach((item, index) => {
  766. if (item.isChecked) {
  767. this.checkboxValue = []
  768. this.checkboxValue.push(item.id)
  769. }
  770. })
  771. // console.log(this.humitureData,'------')
  772. this.$forceUpdate()
  773. },
  774. selectChangeil(value) {
  775. this.timeQuantumList.forEach((item, index) => {
  776. if (value.id == item.id) {
  777. if (value.isChecked) {
  778. item.isChecked = false
  779. } else {
  780. item.isChecked = true
  781. }
  782. }
  783. })
  784. },
  785. // 获取温湿度信息
  786. humitureInfo(value) {
  787. let arrData = value
  788. let arrData1 = printList()
  789. arrData.forEach((item, index) => {
  790. let arr = []
  791. item.deviceSensorList.forEach((ote, te) => {
  792. arr.push(ote.T_id)
  793. })
  794. let params = {
  795. t_ids: arr,
  796. taskId: item.id,
  797. waybillNo: this.waybillNo,
  798. page: 1,
  799. pageSize: 9999,
  800. startTime: item.startTime,
  801. endTime: item.endTime,
  802. }
  803. item.arr = []
  804. this.getWaybillTask(params).then(res => {
  805. if (!res) {
  806. item.belowStandard = false
  807. } else {
  808. item.belowStandard = true
  809. const arrL = JSON.parse(JSON.stringify(res))
  810. const timeList = JSON.parse(JSON.stringify(res))
  811. const arrLil = res
  812. for (let i = 0; i < arrLil.length; i++) {
  813. for (let j = i + 1; j < arrLil.length; j++) {
  814. if (arrLil[i].T_time == arrLil[j].T_time) {
  815. arrLil.splice(j, 1);
  816. j--;
  817. }
  818. }
  819. }
  820. var resultArr = arrLil
  821. let list1 = []
  822. resultArr.forEach(k => {
  823. let arr1 = {
  824. T_sn: k.T_sn,
  825. time: k.T_time,
  826. arr: [],
  827. }
  828. list1.push(arr1)
  829. })
  830. this.maxData = list1
  831. for (let i = 0; i < timeList.length; i++) {
  832. for (let j = i + 1; j < timeList.length; j++) {
  833. if (timeList[i].time == timeList[j].time) {
  834. timeList.splice(j, 1);
  835. j--;
  836. }
  837. }
  838. }
  839. this.maxData.forEach((item3, index3) => {
  840. timeList.forEach((item2, index2) => {
  841. const result1 = arrL.find(fruit => fruit.T_id === 1 &&
  842. fruit.time === item2.time && fruit.T_time ===
  843. item3
  844. .time)
  845. const result2 = arrL.find(fruit => fruit.T_id === 2 &&
  846. fruit.time === item2.time && fruit.T_time ===
  847. item3
  848. .time)
  849. const result3 = arrL.find(fruit => fruit.T_id === 3 &&
  850. fruit.time === item2.time && fruit.T_time ===
  851. item3
  852. .time)
  853. const result4 = arrL.find(fruit => fruit.T_id === 4 &&
  854. fruit.time === item2.time && fruit.T_time ===
  855. item3
  856. .time)
  857. const flag = areAllUndefined(result1, result2, result3,
  858. result4)
  859. if (!flag) {
  860. function countFalseObjects(objects) {
  861. let count = 0;
  862. for (let i = 0; i < objects.length; i++) {
  863. if (objects[i] === undefined) {
  864. count++;
  865. }
  866. }
  867. return count;
  868. }
  869. const arrNum = countFalseObjects([result1, result2,
  870. result3, result4
  871. ])
  872. let list2 = []
  873. if (arrNum < 2) {
  874. list2.push(result1 == undefined ? '---' :
  875. result1)
  876. list2.push(result2 == undefined ? '---' :
  877. result2)
  878. list2.push(result3 == undefined ? '---' :
  879. result3)
  880. list2.push(result4 == undefined ? '---' :
  881. result4)
  882. } else {
  883. list2.push(result1 == undefined ? '---' :
  884. result1)
  885. list2.push(result2 == undefined ? '---' :
  886. result2)
  887. }
  888. // let list2 = [
  889. // result1 == undefined ? '---' : result1,
  890. // result2 == undefined ? '---' : result2,
  891. // result3 == undefined ? '---' : result3,
  892. // result4 == undefined ? '---' : result4,
  893. // ]
  894. item3.arrNum = arrNum
  895. item3.arr.push(list2)
  896. }
  897. function areAllUndefined(...args) {
  898. return args.every(arg => arg === undefined);
  899. }
  900. })
  901. })
  902. item.arr = this.maxData
  903. }
  904. })
  905. })
  906. this.humitureData = arrData
  907. // console.log(this.humitureData, 26)
  908. },
  909. getWaybillTask(params) {
  910. return new Promise((resolve, reject) => {
  911. this.$api.post('/api/waybill-task/print-data', params).then(res => {
  912. if (res.code == 200) {
  913. let arr1 = res.data.list
  914. if (arr1) {
  915. let arr2 = []
  916. arr1.forEach(item1 => {
  917. const dateString = item1.T_time;
  918. const parts = dateString.split(" ")[0].split("-");
  919. const extractedDate = parts[0] + "-" + parts[1] + "-" + parts[
  920. 2];
  921. const parts1 = dateString.split(" ")[1].split(":");
  922. const extractedTime = parts1[0] + ":" + parts1[1];
  923. let arr3 = {
  924. T_sn: item1.T_sn,
  925. T_id: item1.T_id,
  926. T_time: extractedDate,
  927. T_t: item1.T_t,
  928. T_rh: item1.T_rh,
  929. time: extractedTime
  930. }
  931. arr2.push(arr3)
  932. })
  933. resolve(arr2)
  934. }
  935. this.disqualification = true
  936. } else if (res.code == 5000) {
  937. // this.disqualification = false
  938. // let arr2 = []
  939. // resolve(arr2)
  940. resolve(false)
  941. }
  942. })
  943. });
  944. },
  945. changeDatetime(value, data) {
  946. this.timeQuantumList.forEach((item, index) => {
  947. if (data.id == item.id) {
  948. item.datetimeRange = value
  949. item.startTime = value[0]
  950. item.endTime = value[1]
  951. }
  952. })
  953. this.humitureData = []
  954. this.humitureInfo(this.timeQuantumList)
  955. }
  956. }
  957. }
  958. </script>
  959. <style lang="scss">
  960. page {
  961. background-color: #fff;
  962. }
  963. .title_bluetooth {
  964. display: flex;
  965. justify-content: center;
  966. align-items: center;
  967. font-size: 40rpx;
  968. margin: 20rpx;
  969. font-weight: 600;
  970. }
  971. .nearby_title {
  972. display: flex;
  973. justify-content: center;
  974. align-items: center;
  975. font-size: 30rpx;
  976. margin: 20rpx;
  977. font-weight: 600;
  978. }
  979. .card_stamp {
  980. display: flex;
  981. flex-direction: column;
  982. padding: 30rpx 20rpx;
  983. }
  984. .search_card {
  985. display: flex;
  986. justify-content: center;
  987. align-items: center;
  988. }
  989. .card_bluetooth {
  990. margin-top: 20rpx;
  991. }
  992. .equipment_title {
  993. font-size: 28rpx;
  994. font-weight: 600;
  995. }
  996. .card_equipment {
  997. margin-top: 20rpx;
  998. min-height: 90rpx;
  999. box-shadow: 0 4rpx 24rpx 0 rgba(0, 0, 0, 0.1);
  1000. padding: 10rpx 20rpx;
  1001. border-radius: 10rpx;
  1002. }
  1003. .waybill_num {
  1004. margin-top: 20rpx;
  1005. font-size: 30rpx;
  1006. font-weight: 600;
  1007. }
  1008. .waybill_numil {
  1009. margin-top: 10rpx;
  1010. font-size: 28rpx;
  1011. color: #767a82;
  1012. }
  1013. .time_title {
  1014. margin-top: 5rpx;
  1015. font-size: 28rpx;
  1016. }
  1017. .card_waybill {
  1018. display: flex;
  1019. flex-direction: column;
  1020. box-shadow: 1rpx 2rpx 14rpx rgba(0, 0, 0, .12);
  1021. padding: 20rpx;
  1022. border-radius: 10rpx;
  1023. margin-top: 20rpx;
  1024. }
  1025. .dateTime_card ::v-deep .icon-calendar {
  1026. display: none;
  1027. }
  1028. </style>