quantum.vue 32 KB

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