diff --git a/src/api/emis/emisWaybill.js b/src/api/emis/emisWaybill.js index ed07ac07..12f90fa3 100644 --- a/src/api/emis/emisWaybill.js +++ b/src/api/emis/emisWaybill.js @@ -9,14 +9,14 @@ export function listEmisWaybill(query) { }) } -// 查询运单列表详细 -export function getInfoByBillCode(billCode) { - return request({ - url: '/emis/emisWaybill/getInfoByBillCode', - method: 'get', - params: {billCode: billCode} - }) -} +// 查询运单详细 +// export function getInfoByBillCode(billCode) { +// return request({ +// url: '/emis/emisWaybill/getInfoByBillCode', +// method: 'get', +// params: {billCode: billCode} +// }) +// } export function getWaybillDetail(billCode) { return request({ diff --git a/src/utils/TanexPrinterSdk.js b/src/utils/TanexPrinterSdk.js index 9f3d4386..a26a1948 100644 --- a/src/utils/TanexPrinterSdk.js +++ b/src/utils/TanexPrinterSdk.js @@ -64,6 +64,12 @@ class TanexPrinterSdk { // 默认打印机 defaultPrinter = null; + defaultTplCode = null; + + isSendSetToken=false; + isSendGetTpl=false; + isSendGetPrinter=false; + // 标识:是否连接成功 , 记录重试的次数,重新连接尝试的次数 connected = false; printerIsRead = false; @@ -130,29 +136,13 @@ class TanexPrinterSdk { return this.defaultPrinter; } - // 获取pdf链接 - getPdfUrl(ydSn,tplName,printerName){ - return this.HTTP_GET_PDF + '?ydSn=' + ydSn+"&tplName="+tplName+"&printerName="+printerName; - } - - // 下载PDF文件 - // downPdfFile(ydSn,tplName,printerName){ - // let link = document.createElement('a'); - // link.style.display = 'none'; - // link.href = this.HTTP_GET_PDF + '?ydSn=' + ydSn+"&tplName="+tplName+"&printerName="+printerName; - // // window.open(link.href, '_blank'); - // document.body.appendChild(link); - // link.click(); - // } - - // 批量获取PDF文件 - batchGetPDF(tplName,printerName,orderList,callback){ - if(tplName&&printerName&&orderList&&orderList.length>0){ + batchGetPDF(tplCode,printerName,orderList,callback){ + if(tplCode&&printerName&&orderList&&orderList.length>0){ this.setOnBatchGetPDF(callback); // 超时计算 - this.sendBatchGetPDFCMD(tplName,printerName,orderList); + this.sendBatchGetPDFCMD(tplCode,printerName,orderList); this.recievePdfFileTimer = setTimeout(function(){ if(this.onBatchGetPDFCallback){ if(this.onBatchGetPDFCallback.length>0){ @@ -170,19 +160,30 @@ class TanexPrinterSdk { } } - // 批量打印 - batchPrint(tplName,printerName,orderList){ - if(tplName&&printerName&&orderList&&orderList.length>0){ - this.sendBatchPrintCMD(tplName,printerName,orderList); + batchPrint(tplCode,printerName,orderList){ + if(tplCode&&printerName&&orderList&&orderList.length>0){ + this.sendBatchPrintCMD(tplCode,printerName,orderList); } } + refreshPrintTpl(){ + this.sendRefreshPrintTplListCMD(); + } + + getRequestId() { + let requestId = 'req' + new Date().getTime().toString(36) + Math.random().toString(36).substring(2, 9); + return requestId; + } //--内部方法-------------------------------------------------------------- sendSetTokenCMD(){ + // if(this.isSendSetToken){ + // return; + // } // {"CMD":"setToken","status":"1","Data":"token"} var printCmd={}; + printCmd['RequestId']=this.getRequestId(); printCmd['CMD']="setToken"; printCmd['Status']="1"; printCmd['Data']=getToken(); @@ -190,14 +191,15 @@ class TanexPrinterSdk { this.send(JSON.stringify(printCmd),null); } - sendBatchPrintCMD(tplName,printerName,orderList){ + sendBatchPrintCMD(tplCode,printerName,orderList){ // {"CMD":"batchPrint","status":"1","Data":["DT20210901001","DT20210901002"]} var printCmd={}; + printCmd['RequestId']=this.getRequestId(); printCmd['CMD']="batchPrint"; printCmd['Status']="1"; if(orderList!=null && orderList.length>0){ let printData={ - "tplName":tplName, + "tplCode":tplCode, "printerName":printerName, "orderList":orderList.toString() } @@ -207,14 +209,15 @@ class TanexPrinterSdk { } } - sendBatchGetPDFCMD(tplName,printerName,orderList){ + sendBatchGetPDFCMD(tplCode,printerName,orderList){ // {"CMD":"batchGetPDF","status":"1","Data":["DT20210901001","DT20210901002"]} var printCmd={}; + printCmd['RequestId']=this.getRequestId(); printCmd['CMD']="batchGetPDF"; printCmd['Status']="1"; if(orderList!=null && orderList.length>0){ let printData={ - "tplName":tplName, + "tplCode":tplCode, "printerName":printerName, "orderList":orderList.toString() } @@ -230,7 +233,13 @@ class TanexPrinterSdk { sendGetPrinterListCMD(){ // {"CMD":"getPrinterList","status":"1","Data":""} + + // if(this.isSendGetPrinter){ + // return; + // } + var printCmd={}; + printCmd['RequestId']=this.getRequestId(); printCmd['CMD']="getPrinterList"; printCmd['Status']="1"; printCmd['Data']=""; @@ -239,8 +248,12 @@ class TanexPrinterSdk { } sendGetPrintTplListCMD(){ + // if(this.isSendGetTpl){ + // return; + // } // {"CMD":"getPrintTplList","status":"1","Data":""} var printCmd={}; + printCmd['RequestId']=this.getRequestId(); printCmd['CMD']="getPrintTplList"; printCmd['Status']="1"; printCmd['Data']=""; @@ -248,12 +261,23 @@ class TanexPrinterSdk { this.send(JSON.stringify(printCmd),null); } + sendRefreshPrintTplListCMD(){ + // {"CMD":"getPrintTplList","status":"1","Data":"reInit"} + var printCmd={}; + printCmd['RequestId']=this.getRequestId(); + printCmd['CMD']="getPrintTplList"; + printCmd['Status']="1"; + printCmd['Data']="reInit"; + // console.log(JSON.stringify(printCmd)); + this.send(JSON.stringify(printCmd),null); + } + // 连接服务器的方法 connect() { // 连接服务器 if (!window.WebSocket) { - // console.log('您的浏览器不支持WebSocket'); + console.log('您的浏览器不支持WebSocket'); return null; } @@ -300,6 +324,10 @@ class TanexPrinterSdk { this.connected = false; this.connectRetryCount++; + if(this.connectRetryCount>120){ + this.connectRetryCount=0; + } + if(this.onCloseCallback.length>0){ this.onCloseCallback.forEach(callback=>{ if(callback!=null){ @@ -307,10 +335,11 @@ class TanexPrinterSdk { } }) } + // * this.connectRetryCount setTimeout(() => { this.connect() - }, 500 * this.connectRetryCount) + }, 1000 ) }; this.ws.onmessage = e => { @@ -374,6 +403,10 @@ class TanexPrinterSdk { innerGetPrinterList(msg){ // console.log("innerGetPrinterList") + + + this.isSendGetPrinter=true; + if(msg){ this.printerList=[]; // console.log(msg); @@ -391,22 +424,21 @@ class TanexPrinterSdk { innerGetPrintTplList(msg){ // console.log("innerGetPrintTplList") + + this.isSendGetTpl=false; + if(msg){ this.printTplList=[]; msg.Data.tplList.forEach(item=>{ - let optionItem={ - label:item, - value:item - } - this.printTplList.push(optionItem); - this.selTplName=this.printTplList[0].value; + this.printTplList.push(item); + this.defaultTplCode=this.printTplList[0].tplCode; }) + } } innerBatchGetPDF(msg){ // console.log("innerBatchGetPDF") - // console.log(msg) // 有出错,停止接收数据 if(msg.Status!='2'){ clearTimeout(this.recievePdfFileTimer); @@ -462,9 +494,6 @@ class TanexPrinterSdk { } - - - jsonToObj(json){ return JSON.parse(json) } @@ -487,6 +516,7 @@ class TanexPrinterSdk { // 发送数据的方法 send(data) { + console.log("send:"+data) if (this.getWSReadyState() === this.WS_OPEN ) { this.sendRetryCount = 0 this.ws.send(data) @@ -512,7 +542,7 @@ class TanexPrinterSdk { // this.ws.ping(); this.ws.send(0x9); } - }, 10000); + }, 1000); } } diff --git a/src/views/emis/EmisBaseTools/TanexPrinterPanel.vue b/src/views/emis/EmisBaseTools/TanexPrinterPanel.vue index 39435cf6..20a4fa07 100644 --- a/src/views/emis/EmisBaseTools/TanexPrinterPanel.vue +++ b/src/views/emis/EmisBaseTools/TanexPrinterPanel.vue @@ -11,15 +11,28 @@