quantum.vue 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060
  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. var readId;
  298. var writeId;
  299. // console.log(res, serviceId, '获取特征值成功')
  300. // that.pairedDeviceList = []
  301. // that.pairedDeviceList.push(item)
  302. var arrList = JSON.parse(JSON.stringify(res))
  303. for (var i = 0; i < arrList.characteristics
  304. .length; i++) {
  305. let write = false;
  306. let notify = false;
  307. let indicate = false;
  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. /* 获取蓝牙特征值uuid */
  332. let uuid = arrList.characteristics[i].uuid
  333. that.matchingUnit.characteristicId = uuid
  334. that.matchingUnit.serviceId = serviceId
  335. // console.log(that.matchingUnit, 'matchingUnit')
  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('CT')
  480. .text(codeValue + ' \n')
  481. .setAlign('LT')
  482. .setSize(1, 2)
  483. .setSize(2, 1)
  484. .setBold()
  485. .text('收:')
  486. .setSize(1, 1)
  487. .setBold(false)
  488. .text(' ' + showFirstName(this.waybillList.senderAddressName))
  489. .text(' ' + this.waybillList.senderAddressPhone.substr(0, 3) + "****" + this
  490. .waybillList
  491. .senderAddressPhone.substr(7) + ' \n')
  492. .print(shippingAddress(this.waybillList.senderAddressDetails))
  493. .setSize(1, 2)
  494. .setSize(2, 1)
  495. .setBold()
  496. .text('寄:')
  497. .setSize(1, 1)
  498. .setBold(false)
  499. .text(' ' + showFirstName(this.waybillList.consigneeAddressName))
  500. .text(' ' + this.waybillList.consigneeAddressPhone.substr(0, 3) + "****" + this
  501. .waybillList
  502. .consigneeAddressPhone.substr(7) + ' \n')
  503. .print(shippingAddress(this.waybillList.consigneeAddressDetails))
  504. .print(printerUtil.fillLine())
  505. .print('下单时间:' + this.waybillList.orderTime)
  506. .text('备注:')
  507. .text('货物类型:' + this.waybillList.cargoType + ' \n')
  508. .print(' 温度需求:' + this.waybillList.temperatureInterval)
  509. .print(' 配送要求:' + this.waybillList.deliveryCondition)
  510. .setAlign('CT')
  511. .printQrcode(logistics)
  512. .print('扫码查询物流温湿度信息 \n')
  513. .println()
  514. })
  515. let buffer = printerJobs.buffer();
  516. // this.printbuffs(buffer);
  517. let opt = {
  518. deviceId: this.deviceId,
  519. serviceId: this.serviceId,
  520. characteristicId: this.characteristicId,
  521. value: buffer,
  522. onceLength: 20
  523. }
  524. blesdk.sendDataToDevice(opt);
  525. }
  526. } else {
  527. var flag = true;
  528. for (let i = 0, len = this.humitureData.length; i < len; i++) {
  529. if (!this.humitureData[i].belowStandard) {
  530. flag = false;
  531. uni.$u.toast('数据不合格,无法打印!')
  532. return false;
  533. }
  534. }
  535. // 选择项全部合格
  536. if (flag) {
  537. // if (this.printerValue == 'zicox') {
  538. // let strHum = blesdk.CreatCPCLPage(384, 300, 1, 0);
  539. // strHum += blesdk.addCPCLText(0, 0, '24', '0', 0, `#${this.userInfo.dept.name}`);
  540. // strHum += blesdk.addCPCLText(0, 0, '24', '0', 0, `运单号:${this.waybillList.waybillNo}`);
  541. // strHum += blesdk.addCPCLText(0, 0, '24', '0', 0, `货物类型:${this.waybillList.cargoType}`);
  542. // strHum += blesdk.addCPCLText(0, 0, '24', '0', 0, `温度需求:${this.waybillList.temperatureInterval}`);
  543. // strHum += blesdk.addCPCLText(0, 0, '24', '0', 0, `配送要求:${this.waybillList.deliveryCondition}`);
  544. // strHum += blesdk.addCPCLText(0, 0, '24', '0', 0, `寄件人:${this.waybillList.senderAddressName}`);
  545. // strHum += blesdk.addCPCLText(0, 0, '24', '0', 0, `收件人:${this.waybillList.consigneeAddressName}`);
  546. // } else {
  547. // }
  548. let printerJobs = new PrinterJobs();
  549. printerJobs
  550. .setSize(1, 1)
  551. .setAlign('lt')
  552. .print('#' + this.userInfo.dept.name)
  553. .print('运单号:' + this.waybillList.waybillNo)
  554. .print('货物类型:' + this.waybillList.cargoType)
  555. .print('温度需求:' + this.waybillList.temperatureInterval)
  556. .print('配送要求:' + this.waybillList.deliveryCondition)
  557. .print('寄件人:' + this.waybillList.senderAddressName)
  558. .print('收件人:' + this.waybillList.consigneeAddressName)
  559. .print(printerUtil.fillLine())
  560. this.humitureData.forEach((item, index) => {
  561. // console.log(item,123)
  562. const exists = this.checkboxValue.some(Tid => Tid === item.id);
  563. if (item.isChecked) {
  564. // printerJobs
  565. // .print('设备号:' + item.sn)
  566. // .print('标识名:' + item.title)
  567. // .print('开始时间:' + item.startTime)
  568. // .print('结束时间:' + item.endTime)
  569. // .print(printerUtil.fillLine())
  570. item.arr.forEach((item1, index1) => {
  571. if (item1.arrNum < 2) {
  572. printerJobs
  573. .print('日期:' + item1.time + '单位℃ ')
  574. .text('时间 ')
  575. .text('|')
  576. .text(' ')
  577. .text('T1 ')
  578. .text(' ')
  579. .text('|')
  580. .text(' ')
  581. .text('T2 ')
  582. .text(' ')
  583. .text('|')
  584. .text(' ')
  585. .text('T3 ')
  586. .text(' ')
  587. .text('|')
  588. .text(' ')
  589. .text('T4 \n')
  590. item1.arr.forEach((item2, index2) => {
  591. printerJobs
  592. .text(`${item2[0].time}`)
  593. .text('|')
  594. .text(' ')
  595. .text(
  596. `${item2[0] == '---' ? '----' : character(item2[0].T_t) }`
  597. )
  598. .text(' ')
  599. .text('|')
  600. .text(' ')
  601. .text(
  602. `${item2[1] == '---' ? '----' : character(item2[1].T_t) }`
  603. )
  604. .text(' ')
  605. .text('|')
  606. .text(' ')
  607. .text(
  608. `${item2[2] == '---' ? '----' : character(item2[2].T_t) }`
  609. )
  610. .text(' ')
  611. .text('|')
  612. .text(' ')
  613. .text(
  614. `${item2[3] == '---' ? '----' : character(item2[3].T_t) }`
  615. )
  616. function character(value) {
  617. var arr = value.toFixed(1)
  618. if (arr.length == 3) {
  619. var arr1 = arr + ' '
  620. return arr1
  621. } else {
  622. return arr
  623. }
  624. }
  625. })
  626. } else {
  627. printerJobs
  628. .print('日期:' + item1.time + '单位℃ ')
  629. .text('时间')
  630. .text('|')
  631. .text('温度(℃)')
  632. .text(' ')
  633. .text('时间')
  634. .text('|')
  635. .text('温度(℃) \n')
  636. item1.arr.forEach((item2, index2) => {
  637. printerJobs
  638. .text(`${item2[0].time}`)
  639. .text('|')
  640. .text(
  641. `${item2[0] == '---' ? '----' : character(item2[0].T_t) }`
  642. )
  643. .text('|')
  644. .text(
  645. `${item2[1] == '---' ? '----' : character(item2[1].T_t) }`
  646. )
  647. .text(' ')
  648. // if (isEven(index2 + 1)) {
  649. // printerJobs.text(' \n')
  650. // }
  651. function isEven(num) {
  652. return num % 2 === 0;
  653. }
  654. function character(value) {
  655. var arr = value.toFixed(1)
  656. if (arr.length == 3) {
  657. var arr1 = arr + ' '
  658. return arr1
  659. } else {
  660. return arr
  661. }
  662. }
  663. })
  664. function isLengthOdd(array) {
  665. return array.length % 2 === 1;
  666. }
  667. if (isLengthOdd(item1.arr)) {
  668. printerJobs.text(' \n')
  669. }
  670. }
  671. })
  672. // printerJobs.println()
  673. }
  674. })
  675. printerJobs.println()
  676. let buffer = printerJobs.buffer();
  677. // this.printbuffs(buffer);
  678. let opt = {
  679. deviceId: this.deviceId,
  680. serviceId: this.serviceId,
  681. characteristicId: this.characteristicId,
  682. value: buffer,
  683. onceLength: 20
  684. }
  685. blesdk.sendDataToDevice(opt);
  686. }
  687. }
  688. },
  689. async printbuffs(buffer) {
  690. uni.hideLoading()
  691. uni.showLoading({
  692. title: '打印中,请稍等',
  693. mask: true,
  694. });
  695. // 1.并行调用多次会存在写失败的可能性
  696. // 2.建议每次写入不超过20字节
  697. // 分包处理,延时调用
  698. const maxChunk = 20;
  699. const delay = 20;
  700. for (let i = 0, j = 0, length = buffer.byteLength; i < length; i += maxChunk, j++) {
  701. let subPackage = buffer.slice(i, i + maxChunk <= length ? (i + maxChunk) : length);
  702. setTimeout(await this.printbuff, j * delay, subPackage);
  703. }
  704. uni.showToast({
  705. title: '打印完成',
  706. icon: 'none',
  707. duration: 2000
  708. })
  709. },
  710. printbuff(buffer) {
  711. let deviceId = this.deviceId;
  712. let serviceId = this.serviceId;
  713. let characteristicId = this.characteristicId;
  714. // console.log(deviceId, serviceId, characteristicId, 333)
  715. return new Promise((resolve, reject) => {
  716. uni.writeBLECharacteristicValue({
  717. deviceId,
  718. serviceId,
  719. characteristicId,
  720. value: buffer,
  721. success(res) {
  722. //console.log('message发送成功', JSON.stringify(res));
  723. resolve(res);
  724. },
  725. fail(err) {
  726. console.log('message发送失败', JSON.stringify(err));
  727. reject(err);
  728. }
  729. });
  730. });
  731. },
  732. // 获取设备信息探头
  733. getHumiture(waybillNo) {
  734. this.checkboxValue = []
  735. this.$api.get('/api/waybill-task', {
  736. waybillNo: waybillNo,
  737. }).then(res => {
  738. if (res.code == 200) {
  739. const arrlsist = res.data.list
  740. let arrList = []
  741. arrlsist.forEach((item, index) => {
  742. let dataList = {}
  743. dataList.id = item.id
  744. dataList.sn = item.sn
  745. dataList.deviceSensorList = item.deviceSensorList
  746. dataList.startTime = item.startTime
  747. dataList.endTime = item.endTime
  748. if (item.car.id) {
  749. dataList.title = item.car.carNo
  750. } else if (item.warehouse.id) {
  751. dataList.title = item.warehouse.name
  752. } else if (item.coolerBox.id) {
  753. dataList.title = item.coolerBox.name
  754. }
  755. arrList.push(dataList)
  756. })
  757. this.timeQuantumList = arrList
  758. this.timeQuantumList.forEach((item1, index1) => {
  759. item1.datetimeRange = []
  760. item1.datetimeRange.push(item1.startTime)
  761. item1.datetimeRange.push(item1.endTime)
  762. item1.isChecked = true
  763. this.checkboxValue.push(item1.id)
  764. })
  765. this.humitureInfo(arrList)
  766. }
  767. })
  768. },
  769. // 选择打印
  770. selectChange(value) {
  771. this.timeQuantumList.forEach((item, index) => {
  772. if (item.isChecked) {
  773. this.checkboxValue = []
  774. this.checkboxValue.push(item.id)
  775. }
  776. })
  777. // console.log(this.humitureData,'------')
  778. this.$forceUpdate()
  779. },
  780. selectChangeil(value) {
  781. this.timeQuantumList.forEach((item, index) => {
  782. if (value.id == item.id) {
  783. if (value.isChecked) {
  784. item.isChecked = false
  785. } else {
  786. item.isChecked = true
  787. }
  788. }
  789. })
  790. },
  791. // 获取温湿度信息
  792. humitureInfo(value) {
  793. let arrData = value
  794. let arrData1 = printList()
  795. arrData.forEach((item, index) => {
  796. let arr = []
  797. item.deviceSensorList.forEach((ote, te) => {
  798. arr.push(ote.T_id)
  799. })
  800. let params = {
  801. t_ids: arr,
  802. taskId: item.id,
  803. waybillNo: this.waybillNo,
  804. page: 1,
  805. pageSize: 9999,
  806. startTime: item.startTime,
  807. endTime: item.endTime,
  808. }
  809. item.arr = []
  810. this.getWaybillTask(params).then(res => {
  811. if (!res) {
  812. item.belowStandard = false
  813. } else {
  814. item.belowStandard = true
  815. const arrL = JSON.parse(JSON.stringify(res))
  816. const timeList = JSON.parse(JSON.stringify(res))
  817. const arrLil = res
  818. for (let i = 0; i < arrLil.length; i++) {
  819. for (let j = i + 1; j < arrLil.length; j++) {
  820. if (arrLil[i].T_time == arrLil[j].T_time) {
  821. arrLil.splice(j, 1);
  822. j--;
  823. }
  824. }
  825. }
  826. var resultArr = arrLil
  827. let list1 = []
  828. resultArr.forEach(k => {
  829. let arr1 = {
  830. T_sn: k.T_sn,
  831. time: k.T_time,
  832. arr: [],
  833. }
  834. list1.push(arr1)
  835. })
  836. this.maxData = list1
  837. for (let i = 0; i < timeList.length; i++) {
  838. for (let j = i + 1; j < timeList.length; j++) {
  839. if (timeList[i].time == timeList[j].time) {
  840. timeList.splice(j, 1);
  841. j--;
  842. }
  843. }
  844. }
  845. this.maxData.forEach((item3, index3) => {
  846. timeList.forEach((item2, index2) => {
  847. const result1 = arrL.find(fruit => fruit.T_id === 1 &&
  848. fruit.time === item2.time && fruit.T_time ===
  849. item3
  850. .time)
  851. const result2 = arrL.find(fruit => fruit.T_id === 2 &&
  852. fruit.time === item2.time && fruit.T_time ===
  853. item3
  854. .time)
  855. const result3 = arrL.find(fruit => fruit.T_id === 3 &&
  856. fruit.time === item2.time && fruit.T_time ===
  857. item3
  858. .time)
  859. const result4 = arrL.find(fruit => fruit.T_id === 4 &&
  860. fruit.time === item2.time && fruit.T_time ===
  861. item3
  862. .time)
  863. const flag = areAllUndefined(result1, result2, result3,
  864. result4)
  865. if (!flag) {
  866. function countFalseObjects(objects) {
  867. let count = 0;
  868. for (let i = 0; i < objects.length; i++) {
  869. if (objects[i] === undefined) {
  870. count++;
  871. }
  872. }
  873. return count;
  874. }
  875. const arrNum = countFalseObjects([result1, result2,
  876. result3, result4
  877. ])
  878. let list2 = []
  879. if (arrNum < 2) {
  880. list2.push(result1 == undefined ? '---' :
  881. result1)
  882. list2.push(result2 == undefined ? '---' :
  883. result2)
  884. list2.push(result3 == undefined ? '---' :
  885. result3)
  886. list2.push(result4 == undefined ? '---' :
  887. result4)
  888. } else {
  889. list2.push(result1 == undefined ? '---' :
  890. result1)
  891. list2.push(result2 == undefined ? '---' :
  892. result2)
  893. }
  894. // let list2 = [
  895. // result1 == undefined ? '---' : result1,
  896. // result2 == undefined ? '---' : result2,
  897. // result3 == undefined ? '---' : result3,
  898. // result4 == undefined ? '---' : result4,
  899. // ]
  900. item3.arrNum = arrNum
  901. item3.arr.push(list2)
  902. }
  903. function areAllUndefined(...args) {
  904. return args.every(arg => arg === undefined);
  905. }
  906. })
  907. })
  908. item.arr = this.maxData
  909. }
  910. })
  911. })
  912. this.humitureData = arrData
  913. // console.log(this.humitureData, 26)
  914. },
  915. getWaybillTask(params) {
  916. return new Promise((resolve, reject) => {
  917. setTimeout(() => {
  918. this.$api.post('/api/waybill-task/print-data', params).then(res => {
  919. if (res.code == 200) {
  920. let arr1 = res.data.list
  921. if (arr1) {
  922. let arr2 = []
  923. arr1.forEach(item1 => {
  924. const dateString = item1.T_time;
  925. const parts = dateString.split(" ")[0].split("-");
  926. const extractedDate = parts[0] + "-" + parts[1] +
  927. "-" + parts[
  928. 2];
  929. const parts1 = dateString.split(" ")[1].split(":");
  930. const extractedTime = parts1[0] + ":" + parts1[1];
  931. let arr3 = {
  932. T_sn: item1.T_sn,
  933. T_id: item1.T_id,
  934. T_time: extractedDate,
  935. T_t: item1.T_t,
  936. T_rh: item1.T_rh,
  937. time: extractedTime
  938. }
  939. arr2.push(arr3)
  940. })
  941. resolve(arr2)
  942. }
  943. this.disqualification = true
  944. } else if (res.code == 5000) {
  945. // this.disqualification = false
  946. // let arr2 = []
  947. // resolve(arr2)
  948. resolve(false)
  949. }
  950. })
  951. }, 300)
  952. });
  953. },
  954. changeDatetime(value, data) {
  955. this.timeQuantumList.forEach((item, index) => {
  956. if (data.id == item.id) {
  957. item.datetimeRange = value
  958. item.startTime = value[0]
  959. item.endTime = value[1]
  960. }
  961. })
  962. this.humitureData = []
  963. this.humitureInfo(this.timeQuantumList)
  964. }
  965. }
  966. }
  967. </script>
  968. <style lang="scss">
  969. page {
  970. background-color: #fff;
  971. }
  972. .title_bluetooth {
  973. display: flex;
  974. justify-content: center;
  975. align-items: center;
  976. font-size: 40rpx;
  977. margin: 20rpx;
  978. font-weight: 600;
  979. }
  980. .nearby_title {
  981. display: flex;
  982. justify-content: center;
  983. align-items: center;
  984. font-size: 30rpx;
  985. margin: 20rpx;
  986. font-weight: 600;
  987. }
  988. .card_stamp {
  989. display: flex;
  990. flex-direction: column;
  991. padding: 30rpx 20rpx;
  992. }
  993. .search_card {
  994. display: flex;
  995. justify-content: center;
  996. align-items: center;
  997. }
  998. .card_bluetooth {
  999. margin-top: 20rpx;
  1000. }
  1001. .equipment_title {
  1002. font-size: 28rpx;
  1003. font-weight: 600;
  1004. }
  1005. .card_equipment {
  1006. margin-top: 20rpx;
  1007. min-height: 90rpx;
  1008. box-shadow: 0 4rpx 24rpx 0 rgba(0, 0, 0, 0.1);
  1009. padding: 10rpx 20rpx;
  1010. border-radius: 10rpx;
  1011. }
  1012. .waybill_num {
  1013. margin-top: 20rpx;
  1014. font-size: 30rpx;
  1015. font-weight: 600;
  1016. }
  1017. .waybill_numil {
  1018. margin-top: 10rpx;
  1019. font-size: 28rpx;
  1020. color: #767a82;
  1021. }
  1022. .time_title {
  1023. margin-top: 5rpx;
  1024. font-size: 28rpx;
  1025. }
  1026. .card_waybill {
  1027. display: flex;
  1028. flex-direction: column;
  1029. box-shadow: 1rpx 2rpx 14rpx rgba(0, 0, 0, .12);
  1030. padding: 20rpx;
  1031. border-radius: 10rpx;
  1032. margin-top: 20rpx;
  1033. }
  1034. .dateTime_card ::v-deep .icon-calendar {
  1035. display: none;
  1036. }
  1037. </style>