This commit is contained in:
linfso 2024-05-19 12:07:15 +08:00
parent d04aa860c1
commit 56054d3ba4
5 changed files with 210 additions and 126 deletions

View File

@ -8,8 +8,8 @@ VUE_APP_VERSION = '20240516'
# 开发环境 # 开发环境
#VUE_APP_BASE_API = '/dev-api' #VUE_APP_BASE_API = '/dev-api'
VUE_APP_PDOMAIN = 'tanex56' VUE_APP_PDOMAIN = 'tanex56'
# VUE_APP_BASE_API = 'http://api.emis.tanex56.com/api/bizsvr' VUE_APP_BASE_API = 'http://api.emis.tanex56.com/api/bizsvr'
VUE_APP_BASE_API = 'http://47.102.220.189:58089/api/bizsvr' # VUE_APP_BASE_API = 'http://47.102.220.189:58089/api/bizsvr'
# VUE_APP_BASE_API = 'http://47.96.189.20:58089/api/bizsvr' # VUE_APP_BASE_API = 'http://47.96.189.20:58089/api/bizsvr'

View File

@ -1,9 +1,10 @@
'use strict' 'use strict'
import { download } from '@/utils/request'
/* /*
TanexPrinterSdk TanexPrinterSdk
getPrinterList: 获取打印机列表 getPrinterList: 获取打印机列表
getPrinterTplList: 获取打印模版列表 getPrintTplList: 获取打印模版列表
batchPrint:发送打印 batchPrint:发送打印
getPrinterVer:获取打印组件版本信息 getPrinterVer:获取打印组件版本信息
@ -14,13 +15,17 @@
*/ */
import { getToken } from '@/utils/auth' import { getToken } from '@/utils/auth'
import { forEach } from 'lodash';
class TanexPrinterSdk { class TanexPrinterSdk {
VERSION="1.0.0" VERSION="1.0.0"
MAX_SENT_RETRY_COUNT = 9; MAX_SENT_RETRY_COUNT = 9;
// WS_URL = "ws://127.0.0.1:17080"; // WS_URL = "ws://127.0.0.1:17080";
WS_URL = "ws://192.168.88.100:17080"; // WS_URL = "ws://192.168.88.100:17080";
WS_URL = "ws://192.168.88.100:17080/ws";
HTTP_GET_PDF = "http://192.168.88.100:17080/api/downPdfFile";
AUTH_TOKEN=null; AUTH_TOKEN=null;
WS_INIT = 0; WS_INIT = 0;
@ -31,10 +36,13 @@ class TanexPrinterSdk {
// 和服务端连接的socket对象 // 和服务端连接的socket对象
ws = null; ws = null;
// WS 回调函数 // WS 回调函数
onOpen =null; onOpenCallback =[];
onClose = null; onCloseCallback=[];
onError =null; onErrorCallback =[];
onMessage = null; // onMessageCallback =[];
onGetPrinterCallback =[];
onGetPrintTplCallback =[];
// 自定义 回调函数 // 自定义 回调函数
callbacks ={} callbacks ={}
@ -63,22 +71,62 @@ class TanexPrinterSdk {
} }
return this.instance return this.instance
} }
// 外部方法----------------------------------------------------------------
initSdk(callbacks){ init(onOpen,onClose,onError,onGetPrinter,onGetPrintTpl,OnGetPrintTpl){
// 初始化参数建立连接
this.token=getToken(); this.token=getToken();
this.callbacks=callbacks;
this.onOpen=callbacks['onOpen'];
this.onClose=callbacks['onClose'];
this.onError=callbacks['onError'];
this.callbacks['onGetPrinterList']=this.onGetPrinterList;
this.connect(); this.connect();
this.start(); this.start();
} }
sendToken(){ setOnOpen(callback){
this.onOpenCallback.push(callback);
}
setOnClose(callback){
this.onCloseCallback.push(callback);
}
setOnError(callback){
this.onErrorCallback.push(callback);
}
setOnGetPrinter(callback){
this.onGetPrinterCallback.push(callback);
}
setOnGetPrintTpl(callback){
this.onGetPrintTplCallback.push(callback);
}
// 获取打印机列表
getPrinterTplList(){
return this.printerList;
}
// 获取打印模版列表
getPrintTplList(){
return this.printTplList;
}
// 获取默认打印机
getDefaultPrinter(){
return this.defaultPrinter;
}
// 下载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();
}
//--内部方法--------------------------------------------------------------
sendSetTokenCMD(){
// {"CMD":"setToken","status":"1","Data":"token"} // {"CMD":"setToken","status":"1","Data":"token"}
var printCmd={}; var printCmd={};
printCmd['CMD']="setToken"; printCmd['CMD']="setToken";
@ -88,7 +136,7 @@ class TanexPrinterSdk {
this.send(JSON.stringify(printCmd),null); this.send(JSON.stringify(printCmd),null);
} }
batchPrint(tplName,printerName,orderList){ sendBatchPrintCMD(tplName,printerName,orderList){
// {"CMD":"batchPrint","status":"1","Data":["DT20210901001","DT20210901002"]} // {"CMD":"batchPrint","status":"1","Data":["DT20210901001","DT20210901002"]}
var printCmd={}; var printCmd={};
printCmd['CMD']="batchPrint"; printCmd['CMD']="batchPrint";
@ -105,24 +153,24 @@ class TanexPrinterSdk {
} }
} }
getPrinterList(callback){ sendGetPrinterListCMD(){
// {"CMD":"getPrinterList","status":"1","Data":""} // {"CMD":"getPrinterList","status":"1","Data":""}
var printCmd={}; var printCmd={};
printCmd['CMD']="getPrinterList"; printCmd['CMD']="getPrinterList";
printCmd['Status']="1"; printCmd['Status']="1";
printCmd['Data']=""; printCmd['Data']="";
console.log(JSON.stringify(printCmd)); console.log(JSON.stringify(printCmd));
this.send(JSON.stringify(printCmd),callback); this.send(JSON.stringify(printCmd),null);
} }
getPrinterTplList(callback){ sendGetPrintTplListCMD(){
// {"CMD":"getPrinterTplList","status":"1","Data":""} // {"CMD":"getPrintTplList","status":"1","Data":""}
var printCmd={}; var printCmd={};
printCmd['CMD']="getPrinterTplList"; printCmd['CMD']="getPrintTplList";
printCmd['Status']="1"; printCmd['Status']="1";
printCmd['Data']=""; printCmd['Data']="";
console.log(JSON.stringify(printCmd)); console.log(JSON.stringify(printCmd));
this.send(JSON.stringify(printCmd),callback); this.send(JSON.stringify(printCmd),null);
} }
@ -140,8 +188,10 @@ class TanexPrinterSdk {
this.ws.onerror = () => { this.ws.onerror = () => {
console.log("ws onerror!"); console.log("ws onerror!");
if(this.onError!=null){ if(this.onErrorCallback.length>0){
this.onError(); this.onErrorCallback.forEach(callback=>{
callback();
})
} }
} }
this.ws.onopen = () => { this.ws.onopen = () => {
@ -150,23 +200,31 @@ class TanexPrinterSdk {
this.connected = true this.connected = true
this.connectRetryCount = 0 this.connectRetryCount = 0
if(this.onOpen != null){ if(this.onOpenCallback.length>0){
this.onOpen() this.onOpenCallback.forEach(callback=>{
callback();
})
} }
this.sendToken(); this.sendSetTokenCMD();
this.getPrinterList(); this.sendGetPrinterListCMD();
this.getPrinterTplList(); this.sendGetPrintTplListCMD();
}; };
this.ws.onpong = () => {
console.log("ws onpong!");
}
this.ws.onclose = () => { this.ws.onclose = () => {
console.log("ws onclose!"); console.log("ws onclose!");
this.connected = false; this.connected = false;
this.connectRetryCount++; this.connectRetryCount++;
if(this.onClose != null){ if(this.onCloseCallback.length>0){
this.onClose() this.onCloseCallback.forEach(callback=>{
callback();
})
} }
setTimeout(() => { setTimeout(() => {
@ -175,18 +233,43 @@ class TanexPrinterSdk {
}; };
this.ws.onmessage = e => { this.ws.onmessage = e => {
// console.log('ws onmessage:' + e.data) console.log('ws onmessage:' + e.data)
if (e.data.charAt(0) === "{") { if (e.data.charAt(0) === "{") {
var msg = this.jsonToObj(e.data); var msg = this.jsonToObj(e.data);
if(msg["CMD"]=='printerIsRead'){ if(msg["CMD"]=='printerIsRead'){
printerIsRead=true; printerIsRead=true;
}else{
if (this.callbacks[msg["CMD"]]) {
this.callbacks[msg["CMD"]](msg);
} }
else{
if(msg["CMD"]=='getPrinterList'){
this.innerGetPrinterList(msg)
if(this.onGetPrinterCallback.length>0){
this.onGetPrinterCallback.forEach(callback=>{
callback();
})
}
}
if(msg["CMD"]=='getPrintTplList'){
this.innerGetPrintTplList(msg)
if(this.onGetPrintTplCallback.length>0){
this.onGetPrintTplCallback.forEach(callback=>{
callback();
})
}
}
// 通知其他客户端
// if (this.callbacks[msg["CMD"]]) {
// this.callbacks[msg["CMD"]](msg);
// }
} }
} else { } else {
console("数据格式非法:" + e.data); console.log("数据格式非法:" + e.data);
} }
}; };
@ -202,21 +285,39 @@ class TanexPrinterSdk {
return this.ws; return this.ws;
} }
onGetPrinterList(msg){ innerGetPrinterList(msg){
console.log("onGetPrinterList") console.log("innerGetPrinterList")
if(msg){ if(msg){
this.printerList=[]; this.printerList=[];
console.log(msg);
msg.Data.printerList.forEach(item=>{ msg.Data.printerList.forEach(item=>{
let optionItem={ let optionItem={
label:item, label:item,
value:item value:item
} }
this.printerList.push(optionItem); this.printerList.push(optionItem);
this.selPrinterName=msg.Data.defaultPrinter; this.defaultPrinter=msg.Data.defaultPrinter;
}) })
} }
} }
innerGetPrintTplList(msg){
console.log("innerGetPrintTplList")
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;
})
}
}
jsonToObj(json){ jsonToObj(json){
return JSON.parse(json) return JSON.parse(json)
} }
@ -260,9 +361,11 @@ class TanexPrinterSdk {
// 开启心跳检测 // 开启心跳检测
start() { start() {
this.heartbeatInterval = setInterval(() => { this.heartbeatInterval = setInterval(() => {
this.data = {type: "ping"}; if (this.getWSReadyState() === this.WS_OPEN ) {
this.send(JSON.stringify(this.data)); // this.ws.ping();
}, 5000); this.ws.send(0x9);
}
}, 10000);
} }
} }

View File

@ -10,6 +10,7 @@
v-model="svalue" v-model="svalue"
:placeholder="placeholder" :placeholder="placeholder"
style="width:100%" style="width:100%"
@focus="onFocus"
@change="onChange"> @change="onChange">
<!-- allow-create --> <!-- allow-create -->
<div style="padding: 0px 8px 0 20px;width:100%;line-height:34px;display:inline-flex; border-bottom: 1px solid #e7e7e7;"> <div style="padding: 0px 8px 0 20px;width:100%;line-height:34px;display:inline-flex; border-bottom: 1px solid #e7e7e7;">
@ -17,10 +18,10 @@
<span style="font-size: 13px;font-weight: 600;">货物大类</span> <span style="font-size: 13px;font-weight: 600;">货物大类</span>
</div> </div>
<div style="width:50%;text-align:right"> <div style="width:50%;text-align:right">
<el-button type="primary" size="mini" style="padding:2px 10px" @click="hideMe">确定</el-button> <el-button type="primary" size="mini" style="padding:2px 10px" @click="confirmOk">确定</el-button>
</div> </div>
</div> </div>
<el-option v-for="item in optionItems" :key="item.id" :label="item.goodsName" :value="item.id"> <el-option v-for="item in optionItems" :key="item.goodsName" :label="item.goodsName" :value="item.goodsName">
</el-option> </el-option>
</el-select> </el-select>
<!-- <el-checkbox-group v-model="svalue"> <!-- <el-checkbox-group v-model="svalue">
@ -64,56 +65,53 @@
}, },
created() { created() {
if(this.value) { // if(this.value) {
this.svalue = this.value.split(','); // this.svalue = this.value.split(',');
} // }
this.queryData(); // this.queryData();
}, },
methods: { methods: {
hideMe(){ confirmOk(){
this.$refs.selectRef.blur();
}, let selIdStr="";
onChange(val) {
let selData = [];
let selCodeStr = "";
let selNameStr=""; let selNameStr="";
let selData = [];
this.svalue.forEach(item=>{ this.svalue.forEach(item=>{
let itemData=this.itemMap[item]; let itemData=this.itemMap[item];
if(itemData!=null){ if(itemData!=null){
selData.push(itemData) selData.push(itemData)
selCodeStr=selCodeStr+itemData.id+","; selIdStr=selIdStr+itemData.goodsName+",";
selNameStr=selNameStr+itemData.goodsName+","; selNameStr=selNameStr+itemData.goodsName+",";
}else{
// if( this.$refs.selectRef.createdLabel!=null ){
const itemData = {
goodsCode:'-1',
goodsName:item,
}
selData.push(itemData)
selCodeStr=selCodeStr+itemData.goodsName+",";
selNameStr=selNameStr+itemData.goodsName+",";
// }
} }
}); });
selCodeStr = selCodeStr.substring(0,selCodeStr.length-1); selIdStr = selIdStr.substring(0,selIdStr.length-1);
this.$emit('input', selCodeStr) this.$emit('input', selIdStr)
this.$emit('onChange', selData,selNameStr) this.$emit('onChange', selData,selNameStr)
this.$refs.selectRef.createdLabel = null
this.$refs.selectRef.blur();
},
onFocus(){
this.queryData();
},
onChange(val) {
}, },
queryData(queryVal) { queryData(queryVal) {
this.queryParams.pageNum=1; this.queryParams.pageNum=1;
this.queryParams.goodsName=queryVal; this.queryParams.goodsName=queryVal;
listSimpleEmisGoods(this.queryParams).then(response => { listSimpleEmisGoods(this.queryParams).then(response => {
this.optionItems= response.rows this.optionItems=response.rows
console.log(this.optionItems);
this.optionItems.forEach(item => { this.optionItems.forEach(item => {
if(!(id in this.itemMap)){ if(!(item.goodsName in this.itemMap)){
this.itemMap[item.id]=item; this.itemMap[item.goodsName]=item;
} }
}); });
}); });
}, },
} }
}; };
</script> </script>

View File

@ -282,7 +282,7 @@
</el-collapse-item> </el-collapse-item>
<el-collapse-item title="" name="3"> <el-collapse-item title="" name="3">
<template slot="title"> <template slot="title">
<div class="form-group-title"><span class="title">{{ $t('重量收费信息') }}</span> <div class="form-group-title"><span class="title">{{ $t('货物收费信息') }}</span>
</div> </div>
</template> </template>
<el-row :gutter="0" style="display: flex;flex-wrap: wrap;"> <el-row :gutter="0" style="display: flex;flex-wrap: wrap;">
@ -304,7 +304,14 @@
<el-form-item label="总件数" prop="parcelQty" label-width="70px"> <el-form-item label="总件数" prop="parcelQty" label-width="70px">
<el-input v-model="form.parcelQty" style="text-align: right;" placeholder="" /> <el-input v-model="form.parcelQty" style="text-align: right;" placeholder="" />
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="12">
<el-form-item label="实际重量" prop="billWeight" label-width="70px">
<el-input v-model="form.billWeight" @blur="reCalcSettlementWeight" style="text-align: right;min-width: 80px" placeholder="请输入实际重量" >
<span slot="suffix">(kg)</span>
</el-input>
</el-form-item>
</el-col>
<el-col :span="24"> <el-col :span="24">
<el-form-item label="" prop="goodsType" label-width="0px"> <el-form-item label="" prop="goodsType" label-width="0px">
<!-- <GoodsSimplePicker v-model="form.goodsType" @onChange="onGoodsChange" placeholder="选择货物信息"></GoodsSimplePicker> --> <!-- <GoodsSimplePicker v-model="form.goodsType" @onChange="onGoodsChange" placeholder="选择货物信息"></GoodsSimplePicker> -->
@ -374,13 +381,7 @@
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="12">
<el-form-item label="实际重量" prop="billWeight" label-width="70px">
<el-input v-model="form.billWeight" @blur="reCalcSettlementWeight" style="text-align: right;min-width: 80px" placeholder="请输入实际重量" >
<span slot="suffix">(kg)</span>
</el-input>
</el-form-item>
</el-col>
<el-col :span="12"> <el-col :span="12">
<el-form-item label="总体积" prop="totalVolume" label-width="70px" > <el-form-item label="总体积" prop="totalVolume" label-width="70px" >
<div style=""> <div style="">

View File

@ -130,13 +130,12 @@
</el-form-item> </el-form-item>
</SearchForm> </SearchForm>
<!-- 打印机状态 -->
<div style="padding:5px 0px;text-align: right;position: absolute; <div style="padding:5px 0px;text-align: right;position: fixed;top: 150px;right: 10px; z-index: 9999;">
top: 150px;
right: 10px;">
<el-tag type="danger" v-if="printerStatus==0">{{ printerStatusMessage }}</el-tag> <el-tag type="danger" v-if="printerStatus==0">{{ printerStatusMessage }}</el-tag>
<el-tag type="success" v-if="printerStatus==1">{{ printerStatusMessage }}</el-tag> <el-tag type="success" v-if="printerStatus==1">{{ printerStatusMessage }}</el-tag>
</div> </div>
<XdTable v-loading="loading" <XdTable v-loading="loading"
border stripe border stripe
size="small" size="small"
@ -674,17 +673,14 @@ export default {
initTanexPrinterSdk(){ initTanexPrinterSdk(){
this.tanexPrinter = this.$tanexPrinter; this.tanexPrinter = this.$tanexPrinter;
console.log( this.tanexPrinter); console.log( this.tanexPrinter);
// openCallback, closeCallback,errorCallback,messageCallback
//tanexPrinterIns
let callbacks={ this.tanexPrinter.init();
onOpen: this.onPrinterOpen,
onClose: this.onPrinterClose, this.tanexPrinter.setOnOpen(this.onPrinterOpen);
onError: this.onPrinterError, this.tanexPrinter.setOnClose(this.onPrinterClose);
getPrinterList:this.onGetPrinterList, this.tanexPrinter.setOnError(this.onPrinterError);
getPrinterTplList:this.onGetPrinterTplList this.tanexPrinter.setOnGetPrinter(this.onGetPrinter);
} this.tanexPrinter.setOnGetPrintTpl(this.onGetPrintTpl);
this.tanexPrinter.initSdk(callbacks);
}, },
onPrinterOpen(evt){ onPrinterOpen(evt){
console.log("onPrinterOpen") console.log("onPrinterOpen")
@ -703,33 +699,15 @@ export default {
this.printerStatusMessage="打印组件已断开!"; this.printerStatusMessage="打印组件已断开!";
}, },
onGetPrinterList(msg){ onGetPrinter(msg){
console.log("onGetPrinterList") console.log("onGetPrinter")
if(msg){ this.printerList=this.tanexPrinter.getPrinterTplList();
this.printerList=[]; this.selPrinterName=this.tanexPrinter.getDefaultPrinter();
msg.Data.printerList.forEach(item=>{
let optionItem={
label:item,
value:item
}
this.printerList.push(optionItem);
this.selPrinterName=msg.Data.defaultPrinter;
})
}
}, },
onGetPrinterTplList(msg){ onGetPrintTpl(msg){
console.log("onGetPrinterTplList") console.log("onGetPrintTpl")
if(msg){ this.printTplList=this.tanexPrinter.getPrintTplList();
this.printTplList=[]; this.selTplName=this.printTplList[0].value;
msg.Data.tplList.forEach(item=>{
let optionItem={
label:item,
value:item
}
this.printTplList.push(optionItem);
this.selTplName=this.printTplList[0].value;
})
}
}, },
handleBatchPrint(){ handleBatchPrint(){
@ -753,7 +731,11 @@ export default {
}, },
handleDownPDF(){ handleDownPDF(){
let orderList=[];
this.currentSelection.forEach(item=>{
orderList.push(item.billCode);
this.tanexPrinter.downPdfFile(item.billCode,this.selTplName,this.selPrinterName)
});
}, },
/** 查询运单列表列表 */ /** 查询运单列表列表 */