jjsendCommand.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. <template>
  2. <view class="content">
  3. <view class="body">
  4. <!-- <view>
  5. <textarea class="result" v-model="returnResult"></textarea>
  6. </view>
  7. <textarea class="input" @input="inputEvent" /> -->
  8. <!-- <button type="primary" @tap="sendData">发送(票据可使用)</button> -->
  9. <view style='margin-top:4%;display: flex;flex-direction: column;'>
  10. <button class="btn" type='primary' @tap='receiptTest' :loading='isReceiptSend'
  11. :disabled='isReceiptSend'>打印检斤单小票</button>
  12. <button type='primary' class="btn" @tap='goToList'>返回列表页</button>
  13. <!-- <button type='primary' @tap='labelTest' :loading='isLabelSend' :disabled='isLabelSend'>标签测试</button> -->
  14. </view>
  15. <view style='margin-top:4%;display: flex;flex-direction: row;'>
  16. <!-- hidden='true' -->
  17. <canvas canvas-id='edit_area_canvas'
  18. :style="{width:canvasWidth+'px',height:canvasHeight+'px'}"></canvas>
  19. </view>
  20. <!-- <picker style='margin:20px' mode='selector' :range='buffSize' :value='buffIndex' @change='buffBindChange'>
  21. 当前每次发送字节数为(点击可更换):{{buffSize[buffIndex]}}
  22. </picker>
  23. <picker style='margin:20px' mode='selector' :range='printNum' :value='printNumIndex' @change='printNumBindChange'>
  24. 当前打印份数(点击可更换):{{printNum[printNumIndex]}}
  25. </picker> -->
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. var tsc = require("../../util/ble/tsc.js");
  31. var esc = require("../../util/ble/esc.js");
  32. var encode = require("../../util/ble/encoding.js");
  33. import {
  34. mapState
  35. } from 'vuex';
  36. export default {
  37. data() {
  38. return {
  39. sendContent: "",
  40. looptime: 0,
  41. currentTime: 1,
  42. lastData: 0,
  43. oneTimeData: 0,
  44. returnResult: "",
  45. canvasWidth: 180,
  46. canvasHeight: 180,
  47. imageSrc: '../../static/img/abc_ic_star_black_16dp.png',
  48. buffSize: [],
  49. buffIndex: 0,
  50. printNum: [],
  51. printNumIndex: 0,
  52. printerNum: 1,
  53. currentPrint: 1,
  54. isReceiptSend: false,
  55. isLabelSend: false,
  56. gridList: {}
  57. };
  58. },
  59. computed: mapState(['sysinfo', 'Bluetooth']),
  60. onLoad() {
  61. let that = this;
  62. let {
  63. BLEInformation
  64. } = that.Bluetooth;
  65. uni.notifyBLECharacteristicValueChange({
  66. deviceId: BLEInformation.deviceId,
  67. serviceId: BLEInformation.notifyServiceId,
  68. characteristicId: BLEInformation.notifyCharaterId,
  69. state: true,
  70. success(res) {
  71. uni.onBLECharacteristicValueChange(function(r) {
  72. console.log(`characteristic ${r.characteristicId} has changed, now is ${r}`)
  73. })
  74. },
  75. fail: function(e) {
  76. console.log(e)
  77. },
  78. complete: function(e) {
  79. console.log(e)
  80. }
  81. })
  82. },
  83. onReady() {
  84. let list = []
  85. let numList = []
  86. let j = 0
  87. for (let i = 20; i < 200; i += 10) {
  88. list[j] = i;
  89. j++
  90. }
  91. for (let i = 1; i < 10; i++) {
  92. numList[i - 1] = i
  93. }
  94. this.buffSize = list;
  95. this.oneTimeData = list[0];
  96. this.printNum = numList;
  97. this.printerNum = numList[0];
  98. },
  99. onShow() {
  100. this.gridList = uni.getStorageSync("acquisitionInspection_print")
  101. let that = this;
  102. let width;
  103. let height;
  104. uni.getImageInfo({
  105. src: that.imageSrc,
  106. success(res) {
  107. console.log(res.width)
  108. console.log(res.height)
  109. width = res.width
  110. height = res.height
  111. that.canvasWidth = res.width;
  112. that.canvasHeight = res.height;
  113. }
  114. })
  115. const ctx = uni.createCanvasContext("edit_area_canvas", this);
  116. // if (app.globalData.platform == "android") {
  117. // ctx.translate(width, height)
  118. // ctx.rotate(180 * Math.PI / 180)
  119. // }
  120. ctx.drawImage(this.imageSrc, 0, 0, width, height);
  121. ctx.draw();
  122. },
  123. onUnload() {
  124. let that = this;
  125. let {
  126. BLEInformation
  127. } = that.Bluetooth;
  128. // uni.closeBLEConnection({
  129. // deviceId: BLEInformation.deviceId,
  130. // success: function(res) {
  131. // console.log("关闭蓝牙成功")
  132. // },
  133. // })
  134. },
  135. methods: {
  136. goToList(){
  137. uni.navigateTo({
  138. url: '/pages/erpbusiness/acquisitionInspection/acquisitionInspection'
  139. })
  140. },
  141. //获取输入内容
  142. inputEvent(e) {
  143. this.sendContent = e.detail.value;
  144. },
  145. //输入框点击发送
  146. sendData() {
  147. let data = this.sendContent + "\n"
  148. this.looptime = 0;
  149. var content = new encode.TextEncoder(
  150. 'gb18030', {
  151. NONSTANDARD_allowLegacyEncoding: true
  152. }).encode(data);
  153. this.prepareSend(content);
  154. },
  155. //打印票据数据
  156. receiptTest() {
  157. var that = this;
  158. var canvasWidth = that.canvasWidth
  159. var canvasHeight = that.canvasHeight
  160. var command = esc.jpPrinter.createNew()
  161. command.init()
  162. //编号
  163. command.bold(3); //加粗
  164. command.setFontSize(36); //字体大小
  165. command.setSelectJustification(1) //居中
  166. command.rowSpace(10);
  167. // command.rowSpace(10);
  168. command.setText(that.gridList.number.substring(that.gridList.number.length - 3));
  169. command.setPrint();
  170. command.rowSpace(60);
  171. command.bold(0); //取消加粗
  172. command.setFontSize(0); //正常字体
  173. // 标题
  174. command.bold(1); //加粗
  175. command.setFontSize(16); //字体大小
  176. command.setSelectJustification(1) //居中
  177. // command.rowSpace(10);
  178. command.setText("粮食检斤单");
  179. command.setPrint();
  180. command.rowSpace(60);
  181. command.bold(0); //取消加粗
  182. command.setFontSize(0); //正常字体
  183. // 二维码
  184. command.rowSpace(60);
  185. command.setSelectSizeOfModuleForQRCode(5);
  186. command.setSelectErrorCorrectionLevelForQRCode(7)
  187. command.setStoreQRCodeData(that.gridList.compId + '&' + that.gridList.number + '&' + that.gridList
  188. .warehouseId);
  189. command.setPrintQRCode();
  190. //编号
  191. command.setSelectJustification(0); //居左
  192. command.setLeftMargin(30)
  193. command.setText("编号:" + that.gridList.number);
  194. command.setPrint();
  195. //客户姓名
  196. command.setSelectJustification(0); //居左
  197. command.setLeftMargin(30)
  198. command.setText("客户姓名:" + that.gridList.customer);
  199. command.setPrint();
  200. //客户身份证
  201. command.setSelectJustification(0); //居左
  202. command.setLeftMargin(30)
  203. command.setText("客户身份证:" + that.gridList.customerNumberCard);
  204. command.setPrint();
  205. //客户电话
  206. command.setSelectJustification(0); //居左
  207. command.setLeftMargin(30)
  208. command.setText("客户电话:" + that.gridList.customerPhone);
  209. command.setPrint();
  210. //车牌号
  211. command.setSelectJustification(0); //居左
  212. command.setLeftMargin(30)
  213. command.setText("车牌号:" + that.gridList.carNumber);
  214. command.setPrint();
  215. //仓位号
  216. command.setSelectJustification(0); //居左
  217. command.setLeftMargin(30)
  218. command.setText("仓位号:" + that.gridList.binNumber);
  219. command.setPrint();
  220. //收货单位
  221. command.setSelectJustification(0); //居左
  222. command.setLeftMargin(30)
  223. command.setText("收货单位:" + that.gridList.compName);
  224. command.setPrint();
  225. //联系人
  226. command.setSelectJustification(0); //居左
  227. command.setLeftMargin(30)
  228. command.setText("联系人:" + that.gridList.person);
  229. command.setPrint();
  230. //联系电话
  231. command.setSelectJustification(0); //居左
  232. command.setLeftMargin(30)
  233. command.setText("联系电话:" + that.gridList.personPhone);
  234. command.setPrint();
  235. //货名
  236. command.setSelectJustification(0); //居左
  237. command.setLeftMargin(30)
  238. command.setText("货名:" + that.gridList.goodsName);
  239. command.setPrint();
  240. //类型
  241. command.setSelectJustification(0); //居左
  242. command.setLeftMargin(30)
  243. command.setText("类型:" + that.gridList.type);
  244. command.setPrint();
  245. //皮重
  246. command.setSelectJustification(0); //居左
  247. command.setLeftMargin(30)
  248. if(!that.gridList.tare) that.gridList.tare = ''
  249. command.setText("皮重(公斤):" + that.gridList.tare);
  250. command.setPrint();
  251. //皮检时间
  252. command.setSelectJustification(0); //居左
  253. command.setLeftMargin(30)
  254. if(!that.gridList.tareDate) that.gridList.tareDate = ''
  255. command.setText("皮检时间:" + that.gridList.tareDate);
  256. command.setPrint();
  257. //毛重
  258. command.setSelectJustification(0); //居左
  259. command.setLeftMargin(30)
  260. command.setText("毛重(公斤):" + that.gridList.grossWeight);
  261. command.setPrint();
  262. //毛检时间
  263. command.setSelectJustification(0); //居左
  264. command.setLeftMargin(30)
  265. command.setText("毛检时间:" + that.gridList.grossDate);
  266. command.setPrint();
  267. //净重
  268. command.setSelectJustification(0); //居左
  269. command.setLeftMargin(30)
  270. if(!that.gridList.netWeight) that.gridList.netWeight = ''
  271. command.setText("净重(公斤):" + that.gridList.netWeight);
  272. command.setPrint();
  273. //收货单位签名或盖章
  274. command.setSelectJustification(0); //居左
  275. command.setLeftMargin(30)
  276. command.setText("收货单位签名或盖章:");
  277. command.setPrintAndFeed(120);
  278. command.setPrintAndFeedRow(10);
  279. that.isReceiptSend = true;
  280. that.prepareSend(command.getData());
  281. },
  282. //准备发送,根据每次发送字节数来处理分包数量
  283. prepareSend(buff) {
  284. console.log(buff);
  285. let that = this
  286. let time = that.oneTimeData
  287. let looptime = parseInt(buff.length / time);
  288. let lastData = parseInt(buff.length % time);
  289. console.log(looptime + "---" + lastData)
  290. this.looptime = looptime + 1;
  291. this.lastData = lastData;
  292. this.currentTime = 1;
  293. that.Send(buff)
  294. },
  295. //查询打印机状态
  296. queryStatus() {
  297. let command = esc.jpPrinter.Query();
  298. command.getRealtimeStatusTransmission(1);
  299. },
  300. //分包发送
  301. Send(buff) {
  302. let that = this
  303. let {
  304. currentTime,
  305. looptime: loopTime,
  306. lastData,
  307. oneTimeData: onTimeData,
  308. printerNum: printNum,
  309. currentPrint
  310. } = that;
  311. let buf;
  312. let dataView;
  313. if (currentTime < loopTime) {
  314. buf = new ArrayBuffer(onTimeData)
  315. dataView = new DataView(buf)
  316. for (var i = 0; i < onTimeData; ++i) {
  317. dataView.setUint8(i, buff[(currentTime - 1) * onTimeData + i])
  318. }
  319. } else {
  320. buf = new ArrayBuffer(lastData)
  321. dataView = new DataView(buf)
  322. for (var i = 0; i < lastData; ++i) {
  323. dataView.setUint8(i, buff[(currentTime - 1) * onTimeData + i])
  324. }
  325. }
  326. console.log("第" + currentTime + "次发送数据大小为:" + buf.byteLength)
  327. let {
  328. BLEInformation
  329. } = that.Bluetooth;
  330. plus.bluetooth.writeBLECharacteristicValue({
  331. deviceId: BLEInformation.deviceId,
  332. serviceId: BLEInformation.writeServiceId,
  333. characteristicId: BLEInformation.writeCharaterId,
  334. value: buf,
  335. success: function(res) {
  336. console.log(res)
  337. },
  338. fail: function(e) {
  339. console.log(e)
  340. },
  341. complete: function() {
  342. currentTime++
  343. if (currentTime <= loopTime) {
  344. that.currentTime = currentTime;
  345. that.Send(buff)
  346. } else {
  347. uni.showToast({
  348. title: '已打印第' + currentPrint + '张',
  349. })
  350. if (currentPrint == printNum) {
  351. that.looptime = 0;
  352. that.lastData = 0;
  353. that.currentTime = 1;
  354. that.isReceiptSend = false;
  355. that.isLabelSend = false;
  356. that.currentPrint = 1;
  357. } else {
  358. currentPrint++;
  359. that.currentPrint = currentPrint;
  360. that.currentTime = 1;
  361. that.Send(buff)
  362. }
  363. }
  364. }
  365. })
  366. },
  367. buffBindChange: function(res) { //更改打印字节数
  368. let index = res.detail.value
  369. let time = this.buffSize[index]
  370. this.buffIndex = index;
  371. this.oneTimeData = time;
  372. },
  373. printNumBindChange: function(res) { //更改打印份数
  374. let index = res.detail.value
  375. let num = this.printNum[index]
  376. this.printNumIndex = index;
  377. this.printerNum = num;
  378. },
  379. }
  380. }
  381. </script>
  382. <style lang="less">
  383. .input {
  384. text-align: top;
  385. width: 90%;
  386. height: 150px;
  387. margin-left: 4%;
  388. margin-right: 4%;
  389. margin-top: 10px;
  390. margin-bottom: 12px;
  391. border: 1px solid slategray;
  392. }
  393. .receiver_info_scroll_view {
  394. width: 90%;
  395. height: 200px;
  396. margin-left: 4%;
  397. margin-right: 4%;
  398. margin-top: 10px;
  399. margin-bottom: 25px;
  400. border: 1px solid black;
  401. }
  402. .result {
  403. width: 90%;
  404. height: 150px;
  405. border: 1px solid black;
  406. margin-left: 4%;
  407. margin-bottom: 4%;
  408. margin-top: 5%;
  409. }
  410. button {
  411. width: 90%;
  412. margin-left: 5%;
  413. margin-right: 5%;
  414. }
  415. .switch {
  416. float: right;
  417. margin-right: 20px;
  418. margin-bottom: 16px;
  419. }
  420. text {
  421. color: #fff;
  422. display: block;
  423. }
  424. input {
  425. color: gainsboro;
  426. float: left;
  427. }
  428. .v_net_ssid {
  429. width: 100%;
  430. background: #fff;
  431. }
  432. .v_net_passw {
  433. width: 100%;
  434. background: antiquewhite;
  435. }
  436. .swiper {
  437. width: 100%;
  438. height: 100%;
  439. }
  440. .btn {
  441. margin-top: 50rpx;
  442. background: #22C572;
  443. }
  444. </style>