123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641 |
- <template>
- <view class="content">
- <view class="body">
- <!-- <view>
- <textarea class="result" v-model="returnResult"></textarea>
- </view>
- <textarea class="input" @input="inputEvent" /> -->
- <!-- <button type="primary" @tap="sendData">发送(票据可使用)</button> -->
- <view style='margin-top:4%;display: flex;flex-direction: column;'>
- <button type='primary' class="btn" @tap='receiptTest' :loading='isReceiptSend'
- :disabled='isReceiptSend'>打印质检单小票</button>
- <button type='primary' class="btn" @tap='clearBlue'>重新连接蓝牙</button>
- <button type='primary' class="btn" @tap='goToList'>返回列表页</button>
- <!-- <button type='primary' @tap='labelTest' :loading='isLabelSend' :disabled='isLabelSend'>标签测试</button> -->
- </view>
- <view style='margin-top:4%;display: flex;flex-direction: row;'>
- <!-- hidden='true' -->
- <canvas canvas-id='edit_area_canvas'
- :style="{width:canvasWidth+'px',height:canvasHeight+'px'}"></canvas>
- </view>
- <!-- <picker style='margin:20px' mode='selector' :range='buffSize' :value='buffIndex' @change='buffBindChange'>
- 当前每次发送字节数为(点击可更换):{{buffSize[buffIndex]}}
- </picker>
-
- <picker style='margin:20px' mode='selector' :range='printNum' :value='printNumIndex' @change='printNumBindChange'>
- 当前打印份数(点击可更换):{{printNum[printNumIndex]}}
- </picker> -->
- </view>
- </view>
- </template>
- <script>
- var tsc = require("../../util/ble/tsc.js");
- var esc = require("../../util/ble/esc.js");
- var encode = require("../../util/ble/encoding.js");
- import {
- mapState
- } from 'vuex';
- export default {
- data() {
- return {
- sendContent: "",
- looptime: 0,
- currentTime: 1,
- lastData: 0,
- oneTimeData: 0,
- returnResult: "",
- canvasWidth: 180,
- canvasHeight: 180,
- imageSrc: '../../static/img/abc_ic_star_black_16dp.png',
- buffSize: [],
- buffIndex: 0,
- printNum: [],
- printNumIndex: 0,
- printerNum: 1,
- currentPrint: 1,
- isReceiptSend: false,
- isLabelSend: false,
- gridList: {}
- };
- },
- computed: mapState(['sysinfo', 'Bluetooth']),
- onLoad() {
- uni.showLoading({
- title: '加载中',
- mask: true
- })
- this.$api.doRequest('get', '/qualityInspectionManagement/api/getQualityInspection', {
- id: uni.getStorageSync('quality_print_id')
- }).then(res => {
- uni.hideLoading()
- if (res.data.data) {
- let data = res.data.data
- this.gridList.qualityNo = data.qualityNo
- }
- })
- let that = this;
- let {
- BLEInformation
- } = that.Bluetooth;
- uni.notifyBLECharacteristicValueChange({
- deviceId: BLEInformation.deviceId,
- serviceId: BLEInformation.notifyServiceId,
- characteristicId: BLEInformation.notifyCharaterId,
- state: true,
- success(res) {
- uni.onBLECharacteristicValueChange(function(r) {
- console.log(`characteristic ${r.characteristicId} has changed, now is ${r}`)
- })
- },
- fail: function(e) {
- console.log(e)
- },
- complete: function(e) {
- console.log(e)
- }
- })
- },
- onReady() {
- let list = []
- let numList = []
- let j = 0
- for (let i = 20; i < 200; i += 10) {
- list[j] = i;
- j++
- }
- for (let i = 1; i < 10; i++) {
- numList[i - 1] = i
- }
- this.buffSize = list;
- this.oneTimeData = list[0];
- this.printNum = numList;
- this.printerNum = numList[0];
- },
- onShow() {
- this.gridList = uni.getStorageSync("quality_print")
- this.utils.nullToString(this.gridList)
- if (!this.gridList.compId) {
- this.gridList.compId = uni.getStorageSync('pcUserInfo').compId
- }
- console.log(this.gridList)
- let that = this;
- let width;
- let height;
- uni.getImageInfo({
- src: that.imageSrc,
- success(res) {
- console.log(res.width)
- console.log(res.height)
- width = res.width
- height = res.height
- that.canvasWidth = res.width;
- that.canvasHeight = res.height;
- }
- })
- const ctx = uni.createCanvasContext("edit_area_canvas", this);
- // if (app.globalData.platform == "android") {
- // ctx.translate(width, height)
- // ctx.rotate(180 * Math.PI / 180)
- // }
- ctx.drawImage(this.imageSrc, 0, 0, width, height);
- ctx.draw();
- },
- onUnload() {
- let that = this;
- let {
- BLEInformation
- } = that.Bluetooth;
- // uni.closeBLEConnection({
- // deviceId: BLEInformation.deviceId,
- // success: function(res) {
- // console.log("关闭蓝牙成功")
- // },
- // })
- },
- methods: {
- clearBlue() {
- let tmp = this.Bluetooth;
- uni.closeBLEConnection({
- deviceId: tmp.BLEInformation.deviceId
- })
- tmp.BLEInformation.deviceId = ''
- this.$store.commit('BLEInformationSet', tmp);
- // uni.showToast({
- // title: '请重新打印质检小票',
- // icon: 'none'
- // })
- uni.navigateBack({
- delta: 1
- })
- },
- goToList() {
- uni.navigateTo({
- url: '/pages/erpbusiness/quality_testing?managementType=1'
- })
- },
- //获取输入内容
- inputEvent(e) {
- this.sendContent = e.detail.value;
- },
- //输入框点击发送
- sendData() {
- let data = this.sendContent + "\n"
- this.looptime = 0;
- var content = new encode.TextEncoder(
- 'gb18030', {
- NONSTANDARD_allowLegacyEncoding: true
- }).encode(data);
- this.prepareSend(content);
- },
- //打印票据数据
- receiptTest() {
- console.log(this.gridList,this.gridList.weighingManagement)
- var that = this;
- var canvasWidth = that.canvasWidth
- var canvasHeight = that.canvasHeight
- var command = esc.jpPrinter.createNew()
- command.init()
- //编号
- // command.rowSpace(10);
- if (that.gridList.qualityNo) {
- command.bold(3); //加粗
- command.setFontSize(36); //字体大小
- command.setSelectJustification(1) //居中
- command.rowSpace(100);
- command.setText(that.gridList.qualityNo.substring(that.gridList.qualityNo.length - 3));
- } else {
- uni.showToast('编号错误!')
- command.bold(3); //加粗
- command.setFontSize(36); //字体大小
- command.setSelectJustification(1) //居中
- command.rowSpace(100);
- command.setText("编号错误"+that.gridList.qualityNo);
- }
- command.setPrint();
- // 标题
- command.bold(1); //加粗
- command.setFontSize(16); //字体大小
- command.setSelectJustification(1) //居中
- // command.rowSpace(10);
- command.setText("粮食质检单");
- command.setPrint();
- command.rowSpace(60);
- command.bold(0); //取消加粗
- command.setFontSize(0); //正常字体
- // 二维码
- command.rowSpace(60);
- command.setSelectSizeOfModuleForQRCode(5);
- command.setSelectErrorCorrectionLevelForQRCode(7)
- command.setStoreQRCodeData(that.gridList.compId + '&' + that.gridList.qualityNo + '&' + that.gridList
- .warehouseId);
- command.setPrintQRCode();
- //客户姓名
- command.setSelectJustification(0); //居左
- command.setLeftMargin(30)
- command.setText("客户姓名:" + that.gridList.customerName?that.gridList.customerName:'');
- command.setPrint();
- //客户身份证
- command.setSelectJustification(0); //居左
- command.setLeftMargin(30)
- command.setText("客户身份证:" + (that.gridList.weighingManagement&&that.gridList.weighingManagement.customerNumberCard?that.gridList.weighingManagement.customerNumberCard:''));
- command.setPrint();
- //客户电话
- command.setSelectJustification(0); //居左
- command.setLeftMargin(30)
- command.setText("客户电话:" + (that.gridList.weighingManagement&&that.gridList.weighingManagement.customerPhone?that.gridList.weighingManagement.customerPhone:''));
- command.setPrint();
- //车牌号
- command.setSelectJustification(0); //居左
- command.setLeftMargin(30)
- command.setText("车牌号:" + that.gridList.carNumber);
- command.setPrint();
- if (that.gridList.boxNo) {
- //箱号
- command.setSelectJustification(0); //居左
- command.setLeftMargin(30)
- command.setText("箱号-1:" + that.gridList.boxNo);
- command.setPrint();
- }
- if (that.gridList.boxNoOther) {
- //箱号
- command.setSelectJustification(0); //居左
- command.setLeftMargin(30)
- command.setText("箱号-2:" + that.gridList.boxNoOther);
- command.setPrint();
- }
- if (that.gridList.titleNo) {
- //封号
- command.setSelectJustification(0); //居左
- command.setLeftMargin(30)
- command.setText("封号-1:" + that.gridList.titleNo);
- command.setPrint();
- }
- if (that.gridList.titleNoOther) {
- //封号
- command.setSelectJustification(0); //居左
- command.setLeftMargin(30)
- command.setText("封号-2:" + that.gridList.titleNoOther);
- command.setPrint();
- }
- //仓位号
- command.setSelectJustification(0); //居左
- command.setLeftMargin(30)
- command.setText("仓位号:" + that.gridList.binNumber);
- command.setPrint();
- //收货单位
- command.setSelectJustification(0); //居左
- command.setLeftMargin(30)
- command.setText("收货仓库:" + (that.gridList.warehouseName?that.gridList.warehouseName:that.gridList.weighingManagement.warehouseName));
- command.setPrint();
- //联系人
- // command.setSelectJustification(0); //居左
- // command.setLeftMargin(30)
- // command.setText("联系人:" + that.gridList.person);
- // command.setPrint();
- //联系电话
- // command.setSelectJustification(0); //居左
- // command.setLeftMargin(30)
- // command.setText("联系电话:" + that.gridList.personPhone);
- // command.setPrint();
- //货名
- command.setSelectJustification(0); //居左
- command.setLeftMargin(30)
- command.setText("货名:" + that.gridList.goodsName);
- command.setPrint();
- //类型
- command.setSelectJustification(0); //居左
- command.setLeftMargin(30)
- command.setText("类型:" + that.gridList.type);
- command.setPrint();
- //容量
- command.setSelectJustification(0); //居左
- command.setLeftMargin(30)
- command.setText("容量(克/升):" + that.gridList.bulkDensity);
- command.setPrint();
- //不完善粒
- command.setSelectJustification(0); //居左
- command.setLeftMargin(30)
- command.setText("不完善粒(%):" + that.gridList.imperfectGrain);
- command.setPrint();
- //等级
- command.setSelectJustification(0); //居左
- command.setLeftMargin(30)
- command.setText("等级:" + that.gridList.grade);
- command.setPrint();
- //水分
- command.setSelectJustification(0); //居左
- command.setLeftMargin(30)
- command.setText("水分(%):" + that.gridList.waterContent);
- command.setPrint();
- //热损伤
- command.setSelectJustification(0); //居左
- command.setLeftMargin(30)
- command.setText("热损伤(%):" + that.gridList.jiaorenli);
- command.setPrint();
- //单价
- command.setSelectJustification(0); //居左
- command.setLeftMargin(30)
- if (that.gridList.type == '潮粮') {
- command.setText("单价(元/公斤):" + that.gridList.tidalGrainPrice);
- } else {
- command.setText("单价(元/公斤):" + that.gridList.dryGrainPrice);
- }
- command.setPrint();
- //杂质
- command.setSelectJustification(0); //居左
- command.setLeftMargin(30)
- command.setText("杂质(%):" + that.gridList.impurity);
- command.setPrint();
- //霉变粒
- command.setSelectJustification(0); //居左
- command.setLeftMargin(30)
- command.setText("霉变粒(%):" + that.gridList.mildewGrain);
- command.setPrint();
- //购粮性质
- // command.setSelectJustification(0); //居左
- // command.setLeftMargin(30)
- // command.setText("购粮性质:" + that.gridList.natureOfGrainPurchase);
- // command.setPrint();
- //仓位号
- command.setSelectJustification(0); //居左
- command.setLeftMargin(30)
- command.setText("仓位号:" + that.gridList.binNumber);
- command.setPrint();
- //囤位号
- command.setSelectJustification(0); //居左
- command.setLeftMargin(30)
- command.setText("囤位号:" + that.gridList.storageTagNo);
- command.setPrint();
- //质检员
- command.setSelectJustification(0); //居左
- command.setLeftMargin(30)
- command.setText("质检员:" + that.gridList.qualityInspector);
- command.setPrint();
- //客户签名
- // command.rowSpace(100);
- // command.setSelectJustification(0); //居左
- // command.setLeftMargin(30)
- // command.setText("客户签名:");
- // command.setPrint();
- // command.rowSpace(100);
- //收货单位签名或盖章
- command.setSelectJustification(0); //居左
- command.setLeftMargin(30)
- command.setText("收货单位签名或盖章:");
- command.setPrintAndFeed(150);
- command.setPrintAndFeedRow(10);
- that.isReceiptSend = true;
- that.prepareSend(command.getData());
- },
- //准备发送,根据每次发送字节数来处理分包数量
- prepareSend(buff) {
- console.log(buff);
- // let that = this
- // let time = that.oneTimeData
- // let looptime = parseInt(buff.length / time);
- // let lastData = parseInt(buff.length % time);
- // console.log(looptime + "---" + lastData)
- // this.looptime = looptime + 1;
- // this.lastData = lastData;
- // this.currentTime = 1;
- // that.Send(buff)
- var that = this;
- var time = that.oneTimeData;
- var looptime = parseInt(buff.length / time);
- var lastData = parseInt(buff.length % time); //console.log(looptime + "---" + lastData)
- this.looptime = looptime + 1
- this.lastData = lastData
- this.currentTime = 1
- that.Send(buff);
- },
- //查询打印机状态
- queryStatus() {
- let command = esc.jpPrinter.Query();
- command.getRealtimeStatusTransmission(1);
- },
- //分包发送
- Send(buff) {
- let that = this
- let {
- currentTime,
- looptime: loopTime,
- lastData,
- oneTimeData: onTimeData,
- printerNum: printNum,
- currentPrint
- } = that;
- let buf;
- let dataView;
- if (currentTime < loopTime) {
- buf = new ArrayBuffer(onTimeData)
- dataView = new DataView(buf)
- for (var i = 0; i < onTimeData; ++i) {
- dataView.setUint8(i, buff[(currentTime - 1) * onTimeData + i])
- }
- } else {
- buf = new ArrayBuffer(lastData)
- dataView = new DataView(buf)
- for (var i = 0; i < lastData; ++i) {
- dataView.setUint8(i, buff[(currentTime - 1) * onTimeData + i])
- }
- }
- // console.log("第" + currentTime + "次发送数据大小为:" + buf.byteLength)
- let {
- BLEInformation
- } = that.Bluetooth;
- setTimeout(()=>{
- uni.writeBLECharacteristicValue({
- deviceId: BLEInformation.deviceId,
- serviceId: BLEInformation.writeServiceId,
- characteristicId: BLEInformation.writeCharaterId,
- value: buf,
- success: function(res) {
- if (currentTime <= loopTime) {
- // wx.showLoading({
- // title: '传输中...',
- // })
- } else {
- uni.showToast({
- title: '已打印第' + currentPrint + '张成功'
- });
- } //console.log(res)
- },
- fail: function(e) {
- uni.showToast({
- title: '打印第' + currentPrint + '张失败',
- icon: 'none'
- });
- console.log(e)
- },
- complete: function() {
- currentTime++;
-
- if (currentTime <= loopTime) {
- that.currentTime = currentTime
-
- that.Send(buff);
- } else {
- if (currentPrint == printNum) {
- that.looptime = 0
- that.lastData = 0
- that.currentTime = 1
- that.isReceiptSend = false
- that.currentPrint = 1
- } else {
- currentPrint++;
- that.currentPrint = currentPrint
- that.currentTime = 1
-
- that.Send(buff);
- }
- }
- }
- })
- },100);
- // plus.bluetooth.writeBLECharacteristicValue({
- // deviceId: BLEInformation.deviceId,
- // serviceId: BLEInformation.writeServiceId,
- // characteristicId: BLEInformation.writeCharaterId,
- // value: buf,
- // success: function(res) {
- // console.log(res)
- // },
- // fail: function(e) {
- // console.log(e)
- // },
- // complete: function() {
- // currentTime++
- // if (currentTime <= loopTime) {
- // that.currentTime = currentTime;
- // that.Send(buff)
- // } else {
- // uni.showToast({
- // title: '已打印第' + currentPrint + '张',
- // })
- // if (currentPrint == printNum) {
- // that.looptime = 0;
- // that.lastData = 0;
- // that.currentTime = 1;
- // that.isReceiptSend = false;
- // that.isLabelSend = false;
- // that.currentPrint = 1;
- // } else {
- // currentPrint++;
- // that.currentPrint = currentPrint;
- // that.currentTime = 1;
- // that.Send(buff)
- // }
- // }
- // }
- // })
- },
- buffBindChange: function(res) { //更改打印字节数
- let index = res.detail.value
- let time = this.buffSize[index]
- this.buffIndex = index;
- this.oneTimeData = time;
- },
- printNumBindChange: function(res) { //更改打印份数
- let index = res.detail.value
- let num = this.printNum[index]
- this.printNumIndex = index;
- this.printerNum = num;
- },
- }
- }
- </script>
- <style lang="less">
- .input {
- text-align: top;
- width: 90%;
- height: 150px;
- margin-left: 4%;
- margin-right: 4%;
- margin-top: 10px;
- margin-bottom: 12px;
- border: 1px solid slategray;
- }
- .receiver_info_scroll_view {
- width: 90%;
- height: 200px;
- margin-left: 4%;
- margin-right: 4%;
- margin-top: 10px;
- margin-bottom: 25px;
- border: 1px solid black;
- }
- .result {
- width: 90%;
- height: 150px;
- border: 1px solid black;
- margin-left: 4%;
- margin-bottom: 4%;
- margin-top: 5%;
- }
- button {
- width: 90%;
- margin-left: 5%;
- margin-right: 5%;
- }
- .switch {
- float: right;
- margin-right: 20px;
- margin-bottom: 16px;
- }
- text {
- color: #fff;
- display: block;
- }
- input {
- color: gainsboro;
- float: left;
- }
- .v_net_ssid {
- width: 100%;
- background: #fff;
- }
- .v_net_passw {
- width: 100%;
- background: antiquewhite;
- }
- .swiper {
- width: 100%;
- height: 100%;
- }
- .btn {
- margin-top: 50rpx;
- background: #22C572;
- }
- uni-button[loading][type=primary] {
- color: hsla(0, 0%, 100%, .6);
- background-color: #22C572;
- }
- </style>
|