exsendCommand.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  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 type='primary' class="btn" @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("exWarehousing_print")
  101. console.log(this.gridList)
  102. let that = this;
  103. let width;
  104. let height;
  105. uni.getImageInfo({
  106. src: that.imageSrc,
  107. success(res) {
  108. console.log(res.width)
  109. console.log(res.height)
  110. width = res.width
  111. height = res.height
  112. that.canvasWidth = res.width;
  113. that.canvasHeight = res.height;
  114. }
  115. })
  116. const ctx = uni.createCanvasContext("edit_area_canvas", this);
  117. // if (app.globalData.platform == "android") {
  118. // ctx.translate(width, height)
  119. // ctx.rotate(180 * Math.PI / 180)
  120. // }
  121. ctx.drawImage(this.imageSrc, 0, 0, width, height);
  122. ctx.draw();
  123. },
  124. onUnload() {
  125. let that = this;
  126. let {
  127. BLEInformation
  128. } = that.Bluetooth;
  129. // uni.closeBLEConnection({
  130. // deviceId: BLEInformation.deviceId,
  131. // success: function(res) {
  132. // console.log("关闭蓝牙成功")
  133. // },
  134. // })
  135. },
  136. methods: {
  137. goToList(){
  138. uni.navigateTo({
  139. url: '/pages/erp/index?companyId=1'
  140. })
  141. },
  142. //获取输入内容
  143. inputEvent(e) {
  144. this.sendContent = e.detail.value;
  145. },
  146. //输入框点击发送
  147. sendData() {
  148. let data = this.sendContent + "\n"
  149. this.looptime = 0;
  150. var content = new encode.TextEncoder(
  151. 'gb18030', {
  152. NONSTANDARD_allowLegacyEncoding: true
  153. }).encode(data);
  154. this.prepareSend(content);
  155. },
  156. //打印票据数据
  157. receiptTest() {
  158. var that = this;
  159. var canvasWidth = that.canvasWidth
  160. var canvasHeight = that.canvasHeight
  161. var command = esc.jpPrinter.createNew()
  162. command.init()
  163. // 标题
  164. command.bold(1); //加粗
  165. command.setFontSize(16); //字体大小
  166. command.setSelectJustification(1) //居中
  167. // command.rowSpace(10);
  168. command.setText("出库检斤单");
  169. command.setPrint();
  170. command.rowSpace(60);
  171. command.bold(0); //取消加粗
  172. command.setFontSize(0); //正常字体
  173. command.setSelectJustification(0); //居左
  174. command.setLeftMargin(30)
  175. command.setText("时间:" + that.gridList.updateDate);
  176. command.setPrint();
  177. command.setSelectJustification(0); //居左
  178. command.setLeftMargin(30)
  179. command.setText("送货单位:" + that.gridList.seller);
  180. command.setPrint();
  181. command.setSelectJustification(0); //居左
  182. command.setLeftMargin(30)
  183. command.setText("收货单位:" + that.gridList.buyer);
  184. command.setPrint();
  185. command.setSelectJustification(0); //居左
  186. command.setLeftMargin(30)
  187. command.setText("货名:" + that.gridList.goodsName);
  188. command.setPrint();
  189. command.setSelectJustification(0); //居左
  190. command.setLeftMargin(30)
  191. command.setText("质检员:" + that.gridList.backOffice);
  192. command.setPrint();
  193. command.setSelectJustification(0); //居左
  194. command.setLeftMargin(30)
  195. command.setText("毛重(吨)" + that.gridList.grossWeight);
  196. command.setPrint();
  197. command.setSelectJustification(0); //居左
  198. command.setLeftMargin(30)
  199. command.setText("皮重(吨)" + that.gridList.tare);
  200. command.setPrint();
  201. command.setSelectJustification(0); //居左
  202. command.setLeftMargin(30)
  203. command.setText("净重(吨)" + that.gridList.netWeight);
  204. command.setPrint();
  205. command.setSelectJustification(0); //居左
  206. command.setLeftMargin(30)
  207. command.setText("运输方式:" + that.gridList.outType);
  208. command.setPrint();
  209. if(that.gridList.outType=="集装箱船"||taht.gridList.outType=="汽运"){
  210. command.setSelectJustification(0); //居左
  211. command.setLeftMargin(30)
  212. command.setText("车牌号:" + that.gridList.carNo);
  213. command.setPrint();
  214. }else if(that.gridList.outType=="火运"){
  215. command.setSelectJustification(0); //居左
  216. command.setLeftMargin(30)
  217. command.setText("车号:" + that.gridList.carNo);
  218. command.setPrint();
  219. }else if(that.gridList.outType=="散船"){
  220. command.setSelectJustification(0); //居左
  221. command.setLeftMargin(30)
  222. command.setText("船名:" + that.gridList.shipName);
  223. command.setPrint();
  224. }
  225. if (that.gridList.outType=="集装箱船"||that.gridList.outType=="汽运") {
  226. //箱号
  227. command.setSelectJustification(0); //居左
  228. command.setLeftMargin(30)
  229. command.setText("箱号-1:" + that.gridList.boxNo);
  230. command.setPrint();
  231. //箱号
  232. command.setSelectJustification(0); //居左
  233. command.setLeftMargin(30)
  234. command.setText("箱号-2:" + that.gridList.boxNoOther);
  235. command.setPrint();
  236. }else if(that.gridList.outType=="火运"){
  237. command.setSelectJustification(0); //居左
  238. command.setLeftMargin(30)
  239. command.setText("车厢号-1:" + that.gridList.wingNumber);
  240. command.setPrint();
  241. command.setSelectJustification(0); //居左
  242. command.setLeftMargin(30)
  243. command.setText("车厢号-2:" + that.gridList.wingNumberOther);
  244. command.setPrint();
  245. }else if(that.gridList.outType=="散船"){
  246. command.setSelectJustification(0); //居左
  247. command.setLeftMargin(30)
  248. command.setText("船次:" + that.gridList.shipNumber);
  249. command.setPrint();
  250. }
  251. //客户签名
  252. // command.rowSpace(100);
  253. // command.setSelectJustification(0); //居左
  254. // command.setLeftMargin(30)
  255. // command.setText("客户签名:");
  256. // command.setPrint();
  257. // command.rowSpace(100);
  258. //收货单位签名或盖章
  259. command.setSelectJustification(0); //居左
  260. command.setLeftMargin(30)
  261. command.setText("收货单位签名或盖章:");
  262. command.setPrintAndFeed(150);
  263. command.setPrintAndFeedRow(8);
  264. that.isReceiptSend = true;
  265. that.prepareSend(command.getData());
  266. },
  267. //准备发送,根据每次发送字节数来处理分包数量
  268. prepareSend(buff) {
  269. console.log(buff);
  270. let that = this
  271. let time = that.oneTimeData
  272. let looptime = parseInt(buff.length / time);
  273. let lastData = parseInt(buff.length % time);
  274. console.log(looptime + "---" + lastData)
  275. this.looptime = looptime + 1;
  276. this.lastData = lastData;
  277. this.currentTime = 1;
  278. that.Send(buff)
  279. },
  280. //查询打印机状态
  281. queryStatus() {
  282. let command = esc.jpPrinter.Query();
  283. command.getRealtimeStatusTransmission(1);
  284. },
  285. //分包发送
  286. Send(buff) {
  287. let that = this
  288. let {
  289. currentTime,
  290. looptime: loopTime,
  291. lastData,
  292. oneTimeData: onTimeData,
  293. printerNum: printNum,
  294. currentPrint
  295. } = that;
  296. let buf;
  297. let dataView;
  298. if (currentTime < loopTime) {
  299. buf = new ArrayBuffer(onTimeData)
  300. dataView = new DataView(buf)
  301. for (var i = 0; i < onTimeData; ++i) {
  302. dataView.setUint8(i, buff[(currentTime - 1) * onTimeData + i])
  303. }
  304. } else {
  305. buf = new ArrayBuffer(lastData)
  306. dataView = new DataView(buf)
  307. for (var i = 0; i < lastData; ++i) {
  308. dataView.setUint8(i, buff[(currentTime - 1) * onTimeData + i])
  309. }
  310. }
  311. console.log("第" + currentTime + "次发送数据大小为:" + buf.byteLength)
  312. let {
  313. BLEInformation
  314. } = that.Bluetooth;
  315. plus.bluetooth.writeBLECharacteristicValue({
  316. deviceId: BLEInformation.deviceId,
  317. serviceId: BLEInformation.writeServiceId,
  318. characteristicId: BLEInformation.writeCharaterId,
  319. value: buf,
  320. success: function(res) {
  321. console.log(res)
  322. },
  323. fail: function(e) {
  324. console.log(e)
  325. },
  326. complete: function() {
  327. currentTime++
  328. if (currentTime <= loopTime) {
  329. that.currentTime = currentTime;
  330. that.Send(buff)
  331. } else {
  332. uni.showToast({
  333. title: '已打印第' + currentPrint + '张',
  334. })
  335. if (currentPrint == printNum) {
  336. that.looptime = 0;
  337. that.lastData = 0;
  338. that.currentTime = 1;
  339. that.isReceiptSend = false;
  340. that.isLabelSend = false;
  341. that.currentPrint = 1;
  342. } else {
  343. currentPrint++;
  344. that.currentPrint = currentPrint;
  345. that.currentTime = 1;
  346. that.Send(buff)
  347. }
  348. }
  349. }
  350. })
  351. },
  352. buffBindChange: function(res) { //更改打印字节数
  353. let index = res.detail.value
  354. let time = this.buffSize[index]
  355. this.buffIndex = index;
  356. this.oneTimeData = time;
  357. },
  358. printNumBindChange: function(res) { //更改打印份数
  359. let index = res.detail.value
  360. let num = this.printNum[index]
  361. this.printNumIndex = index;
  362. this.printerNum = num;
  363. },
  364. }
  365. }
  366. </script>
  367. <style lang="less">
  368. .input {
  369. text-align: top;
  370. width: 90%;
  371. height: 150px;
  372. margin-left: 4%;
  373. margin-right: 4%;
  374. margin-top: 10px;
  375. margin-bottom: 12px;
  376. border: 1px solid slategray;
  377. }
  378. .receiver_info_scroll_view {
  379. width: 90%;
  380. height: 200px;
  381. margin-left: 4%;
  382. margin-right: 4%;
  383. margin-top: 10px;
  384. margin-bottom: 25px;
  385. border: 1px solid black;
  386. }
  387. .result {
  388. width: 90%;
  389. height: 150px;
  390. border: 1px solid black;
  391. margin-left: 4%;
  392. margin-bottom: 4%;
  393. margin-top: 5%;
  394. }
  395. button {
  396. width: 90%;
  397. margin-left: 5%;
  398. margin-right: 5%;
  399. }
  400. .switch {
  401. float: right;
  402. margin-right: 20px;
  403. margin-bottom: 16px;
  404. }
  405. text {
  406. color: #fff;
  407. display: block;
  408. }
  409. input {
  410. color: gainsboro;
  411. float: left;
  412. }
  413. .v_net_ssid {
  414. width: 100%;
  415. background: #fff;
  416. }
  417. .v_net_passw {
  418. width: 100%;
  419. background: antiquewhite;
  420. }
  421. .swiper {
  422. width: 100%;
  423. height: 100%;
  424. }
  425. .btn{
  426. margin-top: 50rpx;
  427. background: #22C572;
  428. }
  429. uni-button[loading][type=primary] {
  430. color: hsla(0,0%,100%,.6);
  431. background-color: #22C572;
  432. }
  433. </style>