Printreading.vue 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841
  1. <template>
  2. <view class="bluetooths">
  3. <view class="bluetooths_btn">
  4. <text class="bluetooths_txt1">搜索打印机/停止搜索</text>
  5. <u-switch v-model="checked" size='40' @change='change'></u-switch>
  6. </view>
  7. <view class="text-red">已连接设备</view>
  8. <view>
  9. <view v-if="connected===''">
  10. <view style="padding:30rpx 0;color: #cccc;">暂未连接任何设备</view>
  11. </view>
  12. <view v-else style="display: flex;align-items: center;justify-content: space-between;padding:30rpx 0;">
  13. <view style="display: flex;align-items: center;">
  14. <image src="../../static/img/dyj.svg" mode="widthFix" style="width: 60rpx;height: 60rpx;"></image>
  15. <view style="margin-left: 30rpx;color: #040203;font-size: 35rpx;">
  16. {{connected==''?'打印机未命名':connected}}
  17. </view>
  18. </view>
  19. <view>
  20. <view style="text-decoration: underline;">{{close}}</view>
  21. </view>
  22. </view>
  23. </view>
  24. <view class="text-red">可连接设备</view>
  25. <view v-if="devices.length==0">
  26. <view style="padding:30rpx 0;color: #cccc;">暂无可连接设备</view>
  27. </view>
  28. <view v-else>
  29. <view v-for="(item, index) in devices" :key="index">
  30. <view v-if="item.name!=''" style="display: flex;align-items: center;justify-content: space-between;padding:30rpx 0;" @click="onConn(item)">
  31. <view style="display: flex;align-items: center;">
  32. <image src="../../static/img/dyj.svg" mode="widthFix" style="width: 60rpx;height: 60rpx;">
  33. </image>
  34. <view style="margin-left: 30rpx;color: #040203;font-size: 35rpx;">
  35. {{item.name==''?'打印机未命名':item.name}}
  36. </view>
  37. </view>
  38. <view>
  39. <u-icon name="info-circle" color="#7c7a7b" size="30"></u-icon>
  40. </view>
  41. </view>
  42. </view>
  43. </view>
  44. <u-button type="primary" :disabled="disabled" style="margin-top: 100upx;" @click="senBleLabel2()">票据打印</u-button>
  45. </view>
  46. </template>
  47. <script>
  48. import tsc from '../../../pages_warehouse/static/libs/tsc.js'
  49. import esc from '../../../pages_warehouse/static/libs/esc.js'
  50. export default {
  51. data() {
  52. return {
  53. Admin_rh:this.$store.state.Admin_rh,//控制登录用户显示湿度 0隐藏 1显示
  54. bool:true,//链接成功可打印 true未连接
  55. onConns:true,//打印机是否链接 true未链接
  56. devices: [],
  57. disabled:false,//防止多次触发
  58. disBoll:null,
  59. currDev: null,
  60. connId: '',
  61. checked: false,
  62. connected: '', //已连接蓝牙
  63. tableDomId: '',
  64. tableImgPath: '',
  65. dangTime:null,//打印时间
  66. songhuo: this.$store.state.FirmList.songhuo, //送货公司
  67. shouhuo: this.$store.state.FirmList.shouhuo, //收货公司
  68. PrinList: this.$store.state.PrinList, //打印T_sn与主机名
  69. wdList:[] ,//数据包
  70. Admin_name:this.$store.state.Admin_name ,//公司名称
  71. maxData:[
  72. {T_name:'T1传感器',Maxwen: '',Minwen: '',pingjue: 0,},
  73. {T_name:'T2传感器',Maxwen: '',Minwen: '',pingjue: 0,},
  74. {T_name:'T3传感器',Maxwen: '',Minwen: '',pingjue: 0,},
  75. {T_name:'T4传感器',Maxwen: '',Minwen: '',pingjue: 0,}
  76. ]
  77. }
  78. },
  79. watch:{
  80. bool(newName, oldName) {
  81. console.log('是否变化',newName, oldName)
  82. if(newName){
  83. this.senBleLabel2()
  84. }
  85. },
  86. },
  87. created() {
  88. this.wdList = this.$store.state.PrinData.wdList
  89. console.log('created================1',this.$store.state.PrinData.wdList)
  90. // console.log('created================2',this.$store.state.PrinData.wdList.reverse())
  91. console.log('created================3',this.wdList)
  92. },
  93. mounted() {
  94. console.log('1================1',this.wdList)
  95. var staTime = this.wdList[this.wdList.length-1].T_time
  96. var endTime = this.wdList[0].T_time
  97. this.ewApi()
  98. console.log('2================1',this.wdList)
  99. },
  100. onUnload() {
  101. this.closeBluetoothAdapter()
  102. },
  103. methods: {
  104. ewApi() {
  105. console.log('wdList数据',this.wdList)
  106. var arr = this.wdList
  107. var _this = this;
  108. var Arr1 = []//T1数据
  109. var Arr2 = []//T2数据
  110. var Arr3 = []//T3数据
  111. var Arr4 = []//T4数据
  112. arr.forEach(function(item,index){
  113. Arr1.push(item.T1)
  114. Arr2.push(item.T2)
  115. Arr3.push(item.T3)
  116. Arr4.push(item.T4)
  117. })
  118. console.log('检查t1-t4',Arr1,Arr2,Arr3,Arr4)
  119. if(Arr1[0]!=null){
  120. var it1 = ''
  121. var iArr1 = []
  122. var sum = 0 //求和
  123. Arr1.forEach(function(item,index){
  124. var T_it = item.T_t
  125. it1 = item.T_t
  126. iArr1.push(it1)
  127. sum = Number(sum) + Number(T_it)//求和
  128. })
  129. this.maxData[0].Maxwen = Math.max(...iArr1)
  130. this.maxData[0].Minwen = Math.min(...iArr1)
  131. console.log('====================================888')
  132. this.maxData[0].pingjue = parseFloat(sum/arr.length).toFixed(1)//求平均值
  133. console.log('====================================999')
  134. console.log('iArr1',iArr1,this.maxData)
  135. }
  136. if(Arr2[0]!=null){
  137. console.log('进入iArr2')
  138. var it1 = ''
  139. var iArr1 = []
  140. var sum = 0 //求和
  141. Arr2.forEach(function(item,index){
  142. console.log('循环====',item,index)
  143. var T_it = item.T_t
  144. it1 = item.T_t
  145. iArr1.push(it1)
  146. sum = Number(sum) + Number(T_it)//求和
  147. })
  148. console.log('=================进入iArr288888888888')
  149. this.maxData[1].Maxwen = Math.max(...iArr1)
  150. this.maxData[1].Minwen = Math.min(...iArr1)
  151. console.log('=================进入iArr2')
  152. this.maxData[1].pingjue = parseFloat(sum/arr.length).toFixed(1)//求平均值
  153. console.log('iArr2',iArr1,this.maxData)
  154. }
  155. if(Arr3[0]!=null){
  156. var it1 = ''
  157. var iArr1 = []
  158. var sum = 0 //求和
  159. Arr3.forEach(function(item,index){
  160. var T_it = item.T_t
  161. it1 = item.T_t
  162. iArr1.push(it1)
  163. sum = Number(sum) + Number(T_it)//求和
  164. })
  165. this.maxData[2].Maxwen = Math.max(...iArr1)
  166. this.maxData[2].Minwen = Math.min(...iArr1)
  167. this.maxData[2].pingjue = parseFloat(sum/arr.length).toFixed(1)//求平均值
  168. console.log('iArr1',iArr1,this.maxData)
  169. }
  170. if(Arr4[0]!=null){
  171. var it1 = ''
  172. var iArr1 = []
  173. var sum = 0 //求和
  174. Arr4.forEach(function(item,index){
  175. var T_it = item.T_t
  176. it1 = item.T_t
  177. iArr1.push(it1)
  178. sum = Number(sum) + Number(T_it)//求和
  179. })
  180. this.maxData[3].Maxwen = Math.max(...iArr1)
  181. this.maxData[3].Minwen = Math.min(...iArr1)
  182. this.maxData[3].pingjue = parseFloat(sum/arr.length).toFixed(1)//求平均值
  183. console.log('iArr1',iArr1,this.maxData)
  184. }
  185. console.log('检查最大值',this.maxData)
  186. },
  187. getCurrentTime() { //获取当前时间
  188. var _this = this;
  189. let yy = new Date().getFullYear();
  190. let mm = new Date().getMonth() + 1;
  191. let dd = new Date().getDate();
  192. let hh = new Date().getHours();
  193. let mf = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes() : new Date().getMinutes();
  194. let ss = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds() : new Date().getSeconds();
  195. if (hh < 10) {
  196. hh = '0' + hh
  197. }
  198. if (mm < 10) {
  199. mm = '0' + mm
  200. }
  201. if (dd < 10) {
  202. dd = '0' + dd
  203. }
  204. _this.dangTime = yy + '-' + mm + '-' + dd + ' ' + hh + ':' + mf + ':' + ss;
  205. },
  206. change(status) {
  207. console.log('sss', status)
  208. if (status) { //搜索打印机
  209. this.searchBle()
  210. } else { //停止搜索
  211. this.closeBluetoothAdapter()
  212. this.stopFindBule()
  213. }
  214. },
  215. //关闭蓝牙模块
  216. closeBluetoothAdapter() {
  217. uni.closeBluetoothAdapter({
  218. success(res) {
  219. uni.showToast({
  220. title:'关闭蓝牙模块',
  221. icon:'none'
  222. })
  223. }
  224. })
  225. },
  226. destroyed: function() {
  227. if (this.connId != '') {
  228. uni.closeBLEConnection({
  229. deviceId: this.connId,
  230. success(res) {
  231. console.log(res)
  232. }
  233. })
  234. }
  235. },
  236. searchBle() {
  237. var that = this
  238. console.log("initBule")
  239. uni.openBluetoothAdapter({success(res) {
  240. console.log("打开 蓝牙模块",res)
  241. that.onDevice()
  242. uni.getBluetoothAdapterState({
  243. success: function(res) {
  244. console.log(res)
  245. if (res.available) {
  246. if (res.discovering) {
  247. that.stopFindBule()
  248. }
  249. //搜索蓝牙
  250. //开始搜寻附近的蓝牙外围设备
  251. console.log("开始搜寻附近的蓝牙外围设备")
  252. uni.startBluetoothDevicesDiscovery({
  253. success(res) {
  254. console.log(res)
  255. }
  256. })
  257. } else {
  258. console.log('本机蓝牙不可用')
  259. }
  260. },
  261. })
  262. },
  263. fail:err=>{ //未打开
  264. uni.showToast({icon:'none',title: '查看手机蓝牙是否打开'});
  265. that.checked = false
  266. }
  267. })
  268. },
  269. onDevice() {//寻找到蓝牙设备
  270. var that = this
  271. //监听寻找到新设备的事件
  272. uni.onBluetoothDeviceFound(function(devices) {
  273. console.log(JSON.stringify(devices))
  274. var re = JSON.parse(JSON.stringify(devices))
  275. console.log(re.devices[0].name + " " + re.devices[0].deviceId)
  276. let name = re.devices[0].name
  277. if (name != "未知设备") {
  278. let deviceId = re.devices[0].deviceId
  279. that.devices.push({
  280. name: name,
  281. deviceId: deviceId,
  282. services: []
  283. })
  284. }
  285. })
  286. },
  287. stopFindBule() {//停止搜寻附近的蓝牙外围设备
  288. var that = this
  289. uni.stopBluetoothDevicesDiscovery({
  290. success(res) {
  291. console.log(res)
  292. that.checked = false
  293. }
  294. })
  295. },
  296. onConn(item) {//点击连接相应蓝牙设备
  297. var that = this
  298. let deviceId = item.deviceId
  299. uni.showLoading({
  300. title:'连接中...'
  301. })
  302. uni.createBLEConnection({
  303. deviceId: deviceId,
  304. complete(res) {
  305. if (res.errMsg == "createBLEConnection:ok") {
  306. that.connected = item.name
  307. uni.hideLoading()
  308. uni.showToast({
  309. title: "蓝牙连接成功",
  310. icon: 'none',
  311. })
  312. that.onConns = false
  313. that.connId = deviceId;
  314. that.currDev = item
  315. setTimeout(function() {
  316. that.getBLEServices(deviceId)
  317. }, 2000)
  318. } else {
  319. console.log(res)
  320. }
  321. //连接成功 关闭搜索
  322. that.stopFindBule()
  323. },
  324. })
  325. },
  326. getBLEServices(_deviceId) {//获取蓝牙设备所有服务(service)
  327. var that = this;
  328. let deviceId = _deviceId
  329. uni.getBLEDeviceServices({
  330. // 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
  331. deviceId: deviceId,
  332. complete(res) {
  333. console.log(res)
  334. let serviceId = ""
  335. for (var s = 0; s < res.services.length; s++) {
  336. console.log(res.services[s].uuid)
  337. let serviceId = res.services[s].uuid
  338. uni.getBLEDeviceCharacteristics({
  339. // 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
  340. deviceId: deviceId,
  341. // 这里的 serviceId 需要在 getBLEDeviceServices 接口中获取
  342. serviceId: serviceId,
  343. success(res) {
  344. var re = JSON.parse(JSON.stringify(res))
  345. console.log('re',re)
  346. for (var c = 0; c < re.characteristics.length; c++) {
  347. if (re.characteristics[c].properties.write == true) {
  348. let uuid = re.characteristics[c].uuid
  349. console.log(' deviceId = [' + deviceId + '] serviceId = [' + serviceId + '] characteristics=[' + uuid)
  350. for (var index in that.devices) {
  351. if (that.devices[index].deviceId == deviceId) {
  352. that.devices[index].services.push({
  353. serviceId: serviceId,
  354. characteristicId: uuid
  355. })
  356. break
  357. }
  358. }
  359. that.bool = false
  360. console.log(JSON.stringify(that.devices))
  361. }
  362. }
  363. }
  364. })
  365. }
  366. },
  367. fail(res) {
  368. console.log(res)
  369. },
  370. })
  371. },
  372. senBlData(deviceId, serviceId, characteristicId, uint8Array) {
  373. var that = this
  374. var uint8Buf = Array.from(uint8Array);
  375. function split_array(datas, size) {
  376. uni.showLoading({
  377. title:'打印中..',
  378. })
  379. var result = {};
  380. var j = 0
  381. if (datas.length < size) {
  382. size = datas.length
  383. }
  384. for (var i = 0; i < datas.length; i += size) {
  385. result[j] = datas.slice(i, i + size)
  386. j++
  387. }
  388. // result[j] = datas
  389. console.log('打印result',result,j)
  390. that.disBoll = j
  391. return result
  392. }
  393. var sendloop = split_array(uint8Buf, 20);
  394. function realWriteData(sendloop, i) {
  395. console.log('发送数据2',sendloop, i)
  396. if(that.disBoll===i){
  397. that.disabled = false
  398. uni.hideLoading()
  399. console.log('此处设置为false',that.disabled)
  400. }
  401. var data = sendloop[i]
  402. if (typeof(data) == "undefined") {
  403. return
  404. }
  405. var buffer = new ArrayBuffer(data.length)
  406. var dataView = new DataView(buffer)
  407. for (var j = 0; j < data.length; j++) {
  408. dataView.setUint8(j, data[j]);
  409. }
  410. uni.writeBLECharacteristicValue({
  411. deviceId,
  412. serviceId,
  413. characteristicId,
  414. value: buffer,
  415. success(res) {
  416. realWriteData(sendloop, i + 1);
  417. // if(uni.getSystemInfoSync().platform == 'ios'){
  418. // console.log('ios系统')
  419. // setTimeout(() =>{
  420. // },50)
  421. // }else if(uni.getSystemInfoSync().platform == 'android'){
  422. // console.log('android系统')
  423. // realWriteData(sendloop, i + 1);
  424. // }
  425. },
  426. fail(e) {
  427. uni.showToast({
  428. title:"发送数据失败",
  429. icon:'error',
  430. duration:'5000'
  431. })
  432. console.log(e)
  433. }
  434. })
  435. }
  436. var i = 0;
  437. realWriteData(sendloop, i);
  438. // if(uni.getSystemInfoSync().platform == 'ios'){
  439. // console.log('ios系统')
  440. // setTimeout(() =>{
  441. // },50)
  442. // }else if(uni.getSystemInfoSync().platform == 'android'){
  443. // console.log('android系统')
  444. // var i = 0;
  445. // realWriteData(sendloop, i);
  446. // }
  447. },
  448. senBleLabel2() {
  449. console.log('=======================================')
  450. console.log(this.wdList)
  451. //票据模式
  452. if(this.onConns){
  453. uni.showToast({
  454. title:'打印机未连接哦',
  455. icon:'none'
  456. })
  457. }else if(this.bool){
  458. uni.showToast({
  459. title:'正在读取数据...',
  460. icon:'none'
  461. })
  462. }else{
  463. uni.hideLoading()
  464. this.disabled = true
  465. console.log('此处设置为true',this.disabled)
  466. var Arr1 = []//T1数据
  467. var Arr2 = []//T2数据
  468. var Arr3 = []//T3数据
  469. var Arr4 = []//T4数据
  470. this.wdList.forEach(function(item,index){
  471. Arr1.push(item.T1)
  472. Arr2.push(item.T2)
  473. Arr3.push(item.T3)
  474. Arr4.push(item.T4)
  475. })
  476. if(Arr2[0]==null && Arr3[0]==null && Arr4[0]==null){
  477. console.log('等于一个探头')
  478. var wenyu = this.PrinList.T_Tlower+'~'+this.PrinList.T_Tupper//温度阈值
  479. var shiyu = this.PrinList.T_RHlower+'~'+this.PrinList.T_RHupper//湿度阈值
  480. this.getCurrentTime()
  481. let deviceId = this.currDev.deviceId;
  482. let serviceId = this.currDev.services[0].serviceId;
  483. let characteristicId = this.currDev.services[0].characteristicId;
  484. var tm1 = this.wdList[0].T_time
  485. var tm2 = this.wdList[this.wdList.length-1].T_time
  486. var staTime = tm1.slice(0,tm1.length-3)
  487. var endTime = tm2.slice(0,tm2.length-3)
  488. var command = esc.jpPrinter.createNew()
  489. command.init()
  490. command.setText("#冷链记录单");
  491. command.setPrint();
  492. command.setText(`${this.Admin_name}`);
  493. command.setPrint();
  494. command.setText(`送货单位:${this.songhuo===null?'':this.songhuo}`);
  495. command.setPrint();
  496. command.setText(`收货单位:${this.shouhuo===null?'':this.shouhuo}`);
  497. command.setPrint();
  498. // command.setText(`打印时间:${this.dangTime}\n`);
  499. command.setText(`-------------------------------`);
  500. command.setPrint();
  501. command.setText(`设备号:${this.PrinList.T_sn}`);
  502. command.setPrint();
  503. command.setText(`标识名:${this.PrinList.T_devName}`);
  504. command.setPrint();
  505. command.setText(`温度阈值:${wenyu}°C`);
  506. command.setPrint();
  507. if(this.Admin_rh===1){
  508. command.setText(`湿度阈值:${shiyu}Rh`);
  509. command.setPrint();
  510. }
  511. command.setText(`-------------------------------`);
  512. command.setText("探头");
  513. command.setAbsolutePrintPosition(50);
  514. command.setText("|");//20
  515. command.setAbsolutePrintPosition(70);
  516. command.setText("最大值");//80
  517. command.setAbsolutePrintPosition(150);
  518. command.setText("|");//----80
  519. command.setAbsolutePrintPosition(170);
  520. command.setText("最小值");//80
  521. command.setAbsolutePrintPosition(250);
  522. command.setText("|");//20
  523. command.setAbsolutePrintPosition(270);
  524. command.setText("平均值");
  525. command.setPrint()
  526. command.setText("T1");
  527. command.setAbsolutePrintPosition(50);
  528. command.setText("|");//20
  529. command.setAbsolutePrintPosition(70);
  530. command.setText(`${this.maxData[0].Maxwen==''?'----':parseFloat(this.maxData[0].Maxwen).toFixed(1)}`);//80
  531. command.setAbsolutePrintPosition(150);
  532. command.setText("|");//----80
  533. command.setAbsolutePrintPosition(170);
  534. command.setText(`${this.maxData[0].Minwen==''?'----':parseFloat(this.maxData[0].Minwen).toFixed(1)}`);//80
  535. command.setAbsolutePrintPosition(250);
  536. command.setText("|");//20
  537. command.setAbsolutePrintPosition(270);
  538. command.setText(`${this.maxData[0].pingjue==''?'----':this.maxData[0].pingjue}`);
  539. command.setPrint()
  540. command.setText(`-------------------------------`);
  541. command.setPrint()
  542. let times = ''
  543. let dataTM = [] //筛选出日期
  544. let _this = this
  545. let array = this.wdList
  546. console.log('检查数据包array',array)
  547. for(var i=0;i<array.length;i++){
  548. if (times.substr(0, 10) != array[i].T_time.substr(0, 10)) {
  549. times = array[i].T_time.substr(0, 10);
  550. if (array[i].T_time.substr(0, 10) != _this.times) {
  551. dataTM.push(times)
  552. }
  553. }
  554. }
  555. const set = new Set(dataTM); //[1,1,1,2,2,3,4]
  556. dataTM = [...set] //去除重复的数据
  557. console.log('检查数据包dataTM',dataTM)
  558. for(var i=0;i<dataTM.length;i++){
  559. command.setPrint()
  560. command.setText(`日期:${dataTM[i]} (单位:°C)`)
  561. command.setPrint()
  562. if(Arr2[0]==null && Arr3[0]==null && Arr4[0]==null){
  563. command.setText("时间");
  564. command.setAbsolutePrintPosition(75);
  565. command.setText("|");//20
  566. command.setAbsolutePrintPosition(100);
  567. command.setText("T1");//80
  568. command.setAbsolutePrintPosition(160);
  569. command.setText("||");//----80
  570. command.setAbsolutePrintPosition(200);
  571. command.setText("时间");//80
  572. command.setAbsolutePrintPosition(275);
  573. command.setText("|");//20
  574. command.setAbsolutePrintPosition(300);
  575. command.setText("T1");
  576. command.setPrint()
  577. }else{
  578. command.setText("时间");
  579. command.setAbsolutePrintPosition(75);
  580. command.setText("|");//20
  581. command.setAbsolutePrintPosition(100);
  582. command.setText("T1");//80
  583. command.setAbsolutePrintPosition(160);
  584. command.setText("|");//----80
  585. command.setAbsolutePrintPosition(200);
  586. command.setText("T2");//80
  587. command.setAbsolutePrintPosition(275);
  588. command.setText("|");//20
  589. command.setAbsolutePrintPosition(300);
  590. command.setText("T3");
  591. command.setAbsolutePrintPosition(360);
  592. command.setText("T4");
  593. command.setPrint()
  594. }
  595. // var xc_l = Math.ceil(array.length / 2);
  596. var xc_l_j = 0
  597. // console.log("xc_l:",xc_l)
  598. for(var j=0;j<array.length;j++){
  599. console.log('dayin',array[j].T1.times1)
  600. if (dataTM[i] != array[j].T_time.substr(0,10)) {
  601. continue;
  602. }
  603. if(xc_l_j == 0 ){
  604. command.setText(`${array[j].T1.times1}`);
  605. command.setAbsolutePrintPosition(75);
  606. command.setText("|");
  607. command.setAbsolutePrintPosition(100);
  608. command.setText(`${array[j].T1==null?'----':parseFloat(array[j].T1.T_t).toFixed(1)}`);
  609. command.setAbsolutePrintPosition(160);
  610. command.setText("||");
  611. xc_l_j =1
  612. }else{
  613. command.setAbsolutePrintPosition(200);
  614. command.setText(`${array[j].T1.times1}`);
  615. command.setAbsolutePrintPosition(275);
  616. command.setText("|");
  617. command.setAbsolutePrintPosition(300);
  618. command.setText(`${array[j].T1==null?'----':parseFloat(array[j].T1.T_t).toFixed(1)}`);
  619. command.setPrint()
  620. xc_l_j =0
  621. }
  622. }
  623. // 强行换行
  624. if(xc_l_j == 1){
  625. command.setPrint()
  626. xc_l_j =0
  627. }
  628. }
  629. command.setText(`-------------------------------`);
  630. command.setPrint()
  631. command.setText(`开始时间:${staTime}`);
  632. command.setPrint()
  633. command.setText(`结束时间:${endTime}`);
  634. command.setPrint()
  635. command.setText(`-------------------------------`);
  636. command.setPrint()
  637. command.setText(`配送人:`);
  638. command.setPrint()
  639. command.setPrint()
  640. command.setText(`接收人:`);
  641. command.setPrint()
  642. command.setPrint()
  643. command.setPrint()
  644. command.setPrintAndFeedRow(1)
  645. this.senBlData(deviceId, serviceId, characteristicId, command.getData())
  646. }else{
  647. console.log('大于一个探头')
  648. var wenyu = this.PrinList.T_Tlower+'~'+this.PrinList.T_Tupper//温度阈值
  649. var shiyu = this.PrinList.T_RHlower+'~'+this.PrinList.T_RHupper//湿度阈值
  650. var staTime = this.wdList[0].T_time
  651. var endTime = this.wdList[this.wdList.length-1].T_time
  652. this.getCurrentTime()
  653. let deviceId = this.currDev.deviceId;
  654. let serviceId = this.currDev.services[0].serviceId;
  655. let characteristicId = this.currDev.services[0].characteristicId;
  656. var command = esc.jpPrinter.createNew()
  657. command.init()
  658. command.setText(`#冷链记录单`);
  659. command.setPrint();
  660. command.setText(`${this.Admin_name}`);
  661. command.setPrint();
  662. command.setText(`送货单位:${this.songhuo===null?'':this.songhuo}`);
  663. command.setPrint();
  664. command.setText(`收货单位:${this.shouhuo===null?'':this.shouhuo}`);
  665. command.setPrint();
  666. // command.setText(`打印时间:${this.dangTime}\n`);
  667. command.setText(`-------------------------------`);
  668. command.setPrint();
  669. command.setText(`设备号:${this.PrinList.T_sn}`);
  670. command.setPrint();
  671. command.setText(`标识名:${this.PrinList.T_devName}`);
  672. command.setPrint();
  673. command.setText(`温度阈值:${wenyu}°C`);
  674. command.setPrint();
  675. if(this.Admin_rh==1){
  676. command.setText(`湿度阈值:${shiyu}Rh`);
  677. command.setPrint();
  678. }
  679. command.setText(`-------------------------------`);
  680. command.setPrint();
  681. command.setText("探头");
  682. command.setAbsolutePrintPosition(50);
  683. command.setText("|");//20
  684. command.setAbsolutePrintPosition(70);
  685. command.setText("最大值");//80
  686. command.setAbsolutePrintPosition(150);
  687. command.setText("|");//----80
  688. command.setAbsolutePrintPosition(170);
  689. command.setText("最小值");//80
  690. command.setAbsolutePrintPosition(250);
  691. command.setText("|");//20
  692. command.setAbsolutePrintPosition(270);
  693. command.setText("平均值");
  694. command.setPrint()
  695. for(var i= 0 ;i<this.maxData.length;i++){
  696. console.log('开始打印',this.maxData[i])
  697. command.setText("T"+(i+1));
  698. command.setAbsolutePrintPosition(50);
  699. command.setText("|");//20
  700. command.setAbsolutePrintPosition(70);
  701. command.setText(`${this.maxData[i].Maxwen==''?'---':parseFloat(this.maxData[i].Maxwen).toFixed(1)}`);//80
  702. command.setAbsolutePrintPosition(150);
  703. command.setText("|");//----80
  704. command.setAbsolutePrintPosition(170);
  705. command.setText(`${this.maxData[i].Minwen==''?'---':parseFloat(this.maxData[i].Minwen).toFixed(1)}`);//80
  706. command.setAbsolutePrintPosition(250);
  707. command.setText("|");//20
  708. command.setAbsolutePrintPosition(270);
  709. command.setText(`${this.maxData[i].pingjue==''?'---':this.maxData[i].pingjue}`);
  710. command.setPrint()
  711. }
  712. command.setText(`-------------------------------`);
  713. let times = ''
  714. let dataTM = [] //筛选出日期
  715. let _this = this
  716. let array = this.wdList//数据包this.wdList 已经在data函数反转.reverse() 最早一条在最前面 最新一条在最后面
  717. for(var i=0;i<array.length;i++){
  718. if (times.substr(0, 10) != array[i].T_time.substr(0, 10)) {
  719. times = array[i].T_time.substr(0, 10);
  720. if (array[i].T_time.substr(0, 10) != _this.times) {
  721. dataTM.push(times)
  722. }
  723. }
  724. }
  725. const set = new Set(dataTM); //[1,1,1,2,2,3,4]
  726. dataTM = [...set] //去除重复的数据
  727. for(var i=0;i<dataTM.length;i++){
  728. command.setPrint()
  729. command.setText(`日期:${dataTM[i]} (单位:°C)\n`)
  730. command.setText("时间");
  731. command.setAbsolutePrintPosition(70);
  732. command.setText("|");//20
  733. command.setAbsolutePrintPosition(90);
  734. command.setText("T1");//80
  735. command.setAbsolutePrintPosition(140);
  736. command.setText("|");//----80
  737. command.setAbsolutePrintPosition(160);
  738. command.setText("T2");//80
  739. command.setAbsolutePrintPosition(210);
  740. command.setText("|");//20
  741. command.setAbsolutePrintPosition(230);
  742. command.setText("T3");
  743. command.setAbsolutePrintPosition(280);
  744. command.setText("|");//20
  745. command.setAbsolutePrintPosition(300);
  746. command.setText("T4");
  747. command.setPrint()
  748. for(var j=0;j<array.length;j++){
  749. if (dataTM[i] == array[j].T_time.substr(0,10)) { //根据你遍历的年月日和数据里面的日期进行对比,满足就是那个日期的数据,打印对应的数据应该就可以了
  750. command.setText(`${array[j].T1.times1}`);
  751. command.setAbsolutePrintPosition(70);
  752. command.setText("|");//20
  753. command.setAbsolutePrintPosition(90);
  754. command.setText(`${array[j].T1==null?'---':parseFloat(array[j].T1.T_t).toFixed(1)}`);//80
  755. command.setAbsolutePrintPosition(140);
  756. command.setText("|");//----80
  757. command.setAbsolutePrintPosition(160);
  758. command.setText(`${array[j].T2==null?'---':parseFloat(array[j].T2.T_t).toFixed(1)}`);//80
  759. command.setAbsolutePrintPosition(210);
  760. command.setText("|");//20
  761. command.setAbsolutePrintPosition(230);
  762. command.setText(`${array[j].T3==null?'---':parseFloat(array[j].T3.T_t).toFixed(1)}`);
  763. command.setAbsolutePrintPosition(280);
  764. command.setText("|");//20
  765. command.setAbsolutePrintPosition(300);
  766. command.setText(`${array[j].T4==null?'---':parseFloat(array[j].T4.T_t).toFixed(1)}`);
  767. command.setPrint()
  768. }
  769. }
  770. }
  771. command.setText(`-------------------------------\n`);
  772. command.setText(`开始时间:${staTime}\n`);
  773. command.setText(`结束时间:${endTime}\n`);
  774. command.setText(`-------------------------------\n`);
  775. command.setText(`配送人:\n`);
  776. command.setText(`\n`);
  777. command.setText(`接收人:\n`);
  778. command.setText(`\n`);
  779. command.setText(`\n`);
  780. command.setPrintAndFeedRow(1)
  781. this.senBlData(deviceId, serviceId, characteristicId, command.getData())
  782. }
  783. }
  784. },
  785. }
  786. }
  787. </script>
  788. <style lang="scss">
  789. .bluetooths {
  790. padding: 10px 20px;
  791. .bluetooths_btn {
  792. display: flex;
  793. align-items: center;
  794. justify-content: space-between;
  795. padding: 15px 0;
  796. background: #fff;
  797. border-bottom: 1px solid #F1F1F1;
  798. .bluetooths_txt1 {
  799. font-size: 30rpx;
  800. font-weight: bold;
  801. color: #007AFF;
  802. }
  803. }
  804. .blueBTn {
  805. font-size: 25rpx;
  806. flex: 1;
  807. }
  808. }
  809. .text-red {
  810. margin-top: 20px;
  811. color: #7c7a7b;
  812. font-size: 30rpx;
  813. }
  814. </style>