emis-frontend/src/views/emis/EmisBaseTools/TanexPrinterPanel.vue

518 lines
16 KiB
Vue
Raw Normal View History

2024-05-24 05:35:58 +00:00
<template>
<div>
<!-- 打印机状态 -->
<!-- style="padding:5px 0px;text-align: right;position: fixed;top: 150px;right: 10px; z-index: 9999;" -->
<div >
<div style="display: inline-flex;">
<div v-if="printerStatus==0" style="display: inline-flex;">
<el-tag type="danger" >{{ printerStatusMessage }}</el-tag>
</div>
<div v-if="printerStatus==1" style="display: inline-flex;">
2024-05-30 12:39:28 +00:00
<div v-if="isShowPinters==1" style="font-size: 12px; line-height: 28px;font-weight: 600;">模板:</div>
<div v-if="isShowTpl==1" style="width: 150px;">
2024-05-29 08:18:45 +00:00
<el-select v-model="selTplCode" size="mini" placeholder="选择打印模板" clearable filterable>
2024-05-30 12:39:28 +00:00
<template slot="prefix">
<span style="padding: 5px;line-height: 28px;font-size: 16px;color: rgb(111 111 111);cursor: pointer;" @click="refreshPrintTpl()">
<i class="el-icon-refresh"></i>
</span>
</template>
<el-option
v-for="item in printTplList"
:key="item.tplCode"
:label="item.tplName"
:value="item.tplCode"
/>
2024-05-24 05:35:58 +00:00
</el-select>
</div>
2024-05-30 12:39:28 +00:00
<div v-if="selTplCode=='TAN-GC-130' && isShowSubBillRange" class="subBillRange" style="display: inline-flex;font-size: 12px; line-height: 28px; font-weight: 600;">
<span >子单范围:
2024-05-29 08:18:45 +00:00
<el-input size="mini" style="width:40px" v-model="subBillStart" type="text" maxlength="4" ></el-input>
-
<el-input size="mini" style="width:40px" v-model="subBillEnd" type="text" maxlength="4" ></el-input>
</span>
</div>
2024-05-30 12:39:28 +00:00
<div v-if="isShowPinters==1" style="font-size: 12px;line-height: 28px;font-weight: 600;">打印机:</div>
<div v-if="isShowPinters==1" style="width: 150px;">
<el-select v-model="selPrinterName" size="mini" placeholder="打印机" clearable filterable>
<el-option
v-for="item in printerList"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
</div>
</div>
<div v-if="printerStatus==1" style="display: inline-flex;">
2024-05-31 00:36:52 +00:00
<!-- <span style="color: green;font-weight: 600;font-size:13px;">【Printer Online】</span> -->
<span style="color: #b12e29;font-size:23px;" class="icon iconfont icon-printer" title="Printer Online"></span>
2024-05-24 05:35:58 +00:00
</div>
<div v-if="printerStatus==0" style="display: inline-flex;">
2024-05-31 10:12:59 +00:00
<a :href="printerDownUrl" style="color: blue;font-weight: 600;font-size:13px;text-decoration: underline">下载打印组件</a>
2024-05-24 05:35:58 +00:00
</div>
</div>
</div>
2024-05-31 10:12:59 +00:00
<el-dialog class="printPreDialog" title="预览" :visible.sync="openPdfView" width="95%" height="100%" :close-on-click-modal="false" v-dialogDrag append-to-body>
<div style="height:100%;width:100%;overflow: auto;">
<PdfViewer ref="pdfViewer" :pdfList="pdfList" @onPrint="onPdfViewPrint" ></PdfViewer>
2024-05-29 08:49:13 +00:00
</div>
2024-05-24 05:35:58 +00:00
</el-dialog>
</div>
</template>
<script>
import emitter from 'element-ui/src/mixins/emitter';
2024-05-31 10:12:59 +00:00
import PdfViewer from '@/components/PdfViewer/viewer.vue';
2024-05-24 05:35:58 +00:00
import PdfUtils from '@/utils/pdfUtils'
export default {
name: "TanexPrinterPanel",
components: {
PdfViewer,
},
mixins: [emitter],
props: {
value: {
2024-05-30 12:39:28 +00:00
type: [Number],
2024-05-24 05:35:58 +00:00
required: false
},
placeholder:{
type: [String],
required: false
2024-05-30 12:39:28 +00:00
},
isShowPinters:{
type: [Boolean],
required: false,
default: false
},
isShowTpl:{
type: [Boolean],
required: false,
default: false
},
isShowSubBillRange:{
type: [Boolean],
required: false,
default: false
2024-05-24 05:35:58 +00:00
}
},
data() {
return {
svalue: this.value,
2024-05-29 08:18:45 +00:00
subBillStart:1,
subBillEnd:1,
2024-05-24 05:35:58 +00:00
openPdfView:false,
2024-05-31 10:12:59 +00:00
pdfList:[],
2024-05-24 05:35:58 +00:00
tanexPrinter:null,
printerDownUrl:null,
printerStatus:0,
printerStatusMessage:'打印组件未连接',
orderList:[],
printerList:[],
printTplList:[],
2024-05-29 08:18:45 +00:00
selTplCode:null,
2024-05-24 05:35:58 +00:00
selPrinterName:null,
currentSelection:[],
};
},
watch: {
value(newVal) {
this.svalue = newVal;
if(this.svalue!=null) {
}
},
},
created() {
this.initTanexPrinterSdk();
},
beforeDestroy(){
2024-05-30 12:39:28 +00:00
// this.tanexPrinter.close();
2024-05-24 05:35:58 +00:00
},
methods: {
initTanexPrinterSdk(){
this.tanexPrinter = this.$tanexPrinter;
this.getConfigKey("sys.printer.downurl").then(response => {
this.printerDownUrl = response.msg;
});
this.tanexPrinter.init();
this.tanexPrinter.setOnOpen(this.onPrinterOpen);
this.tanexPrinter.setOnClose(this.onPrinterClose);
this.tanexPrinter.setOnError(this.onPrinterError);
this.tanexPrinter.setOnGetPrinter(this.onGetPrinter);
this.tanexPrinter.setOnGetPrintTpl(this.onGetPrintTpl);
},
onPrinterOpen(evt){
// console.log("onPrinterOpen")
this.printerStatus = 1;
2024-05-30 12:39:28 +00:00
this.$emit("input",this.printerStatus);
2024-05-24 05:35:58 +00:00
this.printerStatusMessage="打印组件已连接,可以打印.";
},
onPrinterClose(evt){
// console.log("onPrinterClose")
this.printerStatus = 0;
2024-05-30 12:39:28 +00:00
this.$emit("input",this.printerStatus);
2024-05-24 05:35:58 +00:00
this.printerStatusMessage="打印组件已断开!";
},
onPrinterError(evt){
// console.log("onPrinterError")
this.printerStatus = 0;
2024-05-30 12:39:28 +00:00
this.$emit("input",this.printerStatus);
2024-05-24 05:35:58 +00:00
this.printerStatusMessage="打印组件已断开!";
},
onGetPrinter(msg){
// console.log("onGetPrinter")
this.printerList=this.tanexPrinter.getPrinterTplList();
this.selPrinterName=this.tanexPrinter.getDefaultPrinter();
},
onGetPrintTpl(msg){
// console.log("onGetPrintTpl")
2024-05-29 08:18:45 +00:00
this.printTplList=[];
2024-05-24 05:35:58 +00:00
this.printTplList=this.tanexPrinter.getPrintTplList();
2024-05-29 08:18:45 +00:00
// console.log(this.printTplList)
this.selTplCode=this.printTplList[0].tplCode;
},
2024-05-30 12:39:28 +00:00
getDefaultPrinter(){
return this.tanexPrinter.getDefaultPrinter();
},
2024-05-29 08:18:45 +00:00
refreshPrintTpl(){
this.printTplList=[];
this.selTplCode=null;
this.tanexPrinter.refreshPrintTpl()
},
lpadZero(val,len) {
return (new Array(len + 1).join('0') + val).slice(-len);
2024-05-24 05:35:58 +00:00
},
2024-05-30 12:39:28 +00:00
/*
高级批量打印
[
{
"tplCode":tplCode,
"printerName":printerName,
"orderList":orderList.toString()
}
]
*/
batchPrintAdv(printDataList){
2024-05-31 10:12:59 +00:00
if(this.printerStatus !=1){
this.$modal.msgError("打印机未连接");
return;
}
2024-05-30 12:39:28 +00:00
this.tanexPrinter.batchPrintAdv(printDataList);
},
batchPrint(orderList,tplCode){
2024-05-31 10:12:59 +00:00
if(this.printerStatus !=1){
this.$modal.msgError("打印机未连接");
return;
}
2024-05-24 05:35:58 +00:00
let that = this;
2024-05-29 08:18:45 +00:00
let newOrderList=[];
2024-05-24 05:35:58 +00:00
if(orderList){
this.orderList=[...orderList]
}
2024-05-30 12:39:28 +00:00
if(tplCode){
this.selTplCode=tplCode
2024-05-29 08:18:45 +00:00
}
2024-05-30 12:39:28 +00:00
newOrderList=[...orderList];
2024-05-29 08:18:45 +00:00
2024-05-30 12:39:28 +00:00
that.tanexPrinter.batchPrint(that.selTplCode,that.selPrinterName,newOrderList)
},
2024-05-31 10:12:59 +00:00
2024-05-30 12:39:28 +00:00
printPreviewAdv(printDataList,billCount){
2024-05-31 10:12:59 +00:00
if(this.printerStatus !=1){
this.$modal.msgError("打印机未连接");
return;
}
2024-05-30 12:39:28 +00:00
let that = this;
const loadingInstance = this.$loading({
text: '正在生成预览...'
})
2024-05-31 10:12:59 +00:00
that.pdfList=[];
this.tanexPrinter.batchGetPDFAdv(printDataList,billCount,async function(code,msg,data){
console.log(msg);
console.log(code);
if(code == 500){
that.$modal.msgError("打印出错:"+msg);
}
else if(code == 200){
console.log("=====11111==>");
console.log(data);
loadingInstance.close();
2024-05-30 12:39:28 +00:00
let pdfUtils=new PdfUtils({});
2024-05-31 10:12:59 +00:00
let blobUrl= await pdfUtils.getBlobUrl(date.file);
let pdfInfo={
"billCode":date.ydSn,
"pdfUrl":blobUrl
}
that.pdfList.push(pdfInfo);
that.openPdfView = true;
// const pdfDataList=[...pdfList];
// for(let i=0;i<pdfDataList.length;i++){
// let url= await pdfUtils.getBlobUrl(item);
// // that.pdfUrl=url;
// let pdfInfo={
// "billCode":"1"+new Date().getTime(),
// "pdfUrl":url
// }
// console.log(pdfInfo);
// that.pdfList.push(pdfInfo);
// }
// pdfUtils.mergePdf3(pdfDataList, (new Date()).getTime()+".pdf",false )
// .then(url=>{
// loadingInstance.close();
// that.pdfUrl=url;
// that.openPdfView = true;
// })
// .catch(error => {
// // console.log(error)
// that.$modal.msgError("打印出错:"+erroMsg);
// });
2024-05-30 12:39:28 +00:00
}
2024-05-31 10:12:59 +00:00
else if(code == 800){
// 全部获取完成
console.log("===全部获取完成====>");
}
2024-05-30 12:39:28 +00:00
});
2024-05-24 05:35:58 +00:00
},
2024-05-30 12:39:28 +00:00
printPreview(orderList,tplCode,subStart,subEnd){
2024-05-31 10:12:59 +00:00
if(this.printerStatus !=1){
this.$modal.msgError("打印机未连接");
return;
}
2024-05-29 08:18:45 +00:00
let that = this;
let newOrderList=[];
2024-05-24 05:35:58 +00:00
if(orderList){
this.orderList=[...orderList]
}
2024-05-30 12:39:28 +00:00
if(tplCode){
this.selTplCode=tplCode
}
if(subStart){
this.subBillStart=subStart;
2024-05-29 08:18:45 +00:00
}
2024-05-30 12:39:28 +00:00
if(subEnd){
this.subBillEnd=subEnd;
}
newOrderList=[...orderList];
2024-05-24 05:35:58 +00:00
const loadingInstance = this.$loading({
text: '正在生成预览...'
})
2024-05-29 08:18:45 +00:00
2024-05-31 10:12:59 +00:00
this.pdfList=[];
// this.$refs.pdfViewer.clearList();
this.tanexPrinter.batchGetPDF(this.selTplCode,this.selPrinterName,newOrderList,async function(code,msg,pdfData){
if(code == 500){
that.$modal.msgError("打印出错:"+msg);
}
else if(code == 200){
loadingInstance.close();
2024-05-24 05:35:58 +00:00
let pdfUtils=new PdfUtils({});
2024-05-31 10:12:59 +00:00
let blobUrl= await pdfUtils.getBlobUrl(pdfData.file);
let pdfInfo={
"billCode":pdfData.ydSn,
"pdfUrl":blobUrl
}
that.pdfList.push(pdfInfo);
// this.$refs.pdfViewer.addPdfUrl(pdfData.ydSn,blobUrl);
that.openPdfView = true;
// const pdfDataList=[...pdfList];
// for(let i=0;i<pdfDataList.length;i++){
// let url= await pdfUtils.getBlobUrl(item);
// // that.pdfUrl=url;
// let pdfInfo={
// "billCode":"1"+new Date().getTime(),
// "pdfUrl":url
// }
// console.log(pdfInfo);
// that.pdfList.push(pdfInfo);
// }
// pdfUtils.mergePdf3(pdfDataList, (new Date()).getTime()+".pdf",false )
// .then(url=>{
// loadingInstance.close();
// that.pdfUrl=url;
// that.openPdfView = true;
// })
// .catch(error => {
// // console.log(error)
// that.$modal.msgError("打印出错:"+erroMsg);
// });
}
else if(code == 800){
// 全部获取完成
console.log("===全部获取完成====>");
2024-05-24 05:35:58 +00:00
}
});
},
downPDF(orderList){
2024-05-31 10:12:59 +00:00
if(this.printerStatus !=1){
this.$modal.msgError("打印机未连接");
return;
}
2024-05-29 08:18:45 +00:00
let that = this;
let newOrderList=[];
2024-05-24 05:35:58 +00:00
if(orderList){
this.orderList=[...orderList]
}
2024-05-29 08:18:45 +00:00
// 打印子单
if(this.selTplCode=="TAN-GC-130"){
for(let i=0;i<this.orderList.length;i++){
let billCode=this.orderList[i];
// 循环子单范围
for(let i=this.subBillStart;i<=this.subBillEnd;i++){
let subBillCode = billCode+""+this.lpadZero(i,4);
newOrderList.push(subBillCode);
}
}
}else{
newOrderList=[...orderList];
}
2024-05-31 00:36:52 +00:00
let fileName = newOrderList.join("");
2024-05-24 05:35:58 +00:00
const loadingInstance = this.$loading({
text: '正在下载...'
})
2024-05-31 10:12:59 +00:00
this.tanexPrinter.batchGetPDF(this.selTplCode,this.selPrinterName,newOrderList,function(code,msg,pdfData){
2024-05-24 05:35:58 +00:00
loadingInstance.close();
2024-05-31 10:12:59 +00:00
if(code == 500){
that.$modal.msgError("下载出错:"+msg);
}
else if(code == 200){
console.log("=====3333==>");
console.log(pdfData);
loadingInstance.close();
2024-05-24 05:35:58 +00:00
let pdfUtils=new PdfUtils({});
2024-05-31 10:12:59 +00:00
let pdfDataList=[];
pdfDataList.push(pdfData.file)
pdfUtils.mergePdf3(pdfDataList, pdfData.ydSn+".pdf",true )
// let blobUrl= await pdfUtils.getBlobUrl(pdfData.file);
// let pdfInfo={
// "billCode":pdfData.ydSn,
// "pdfUrl":blobUrl
// }
// that.pdfList.push(pdfInfo);
// that.openPdfView = true;
// const pdfDataList=[...pdfList];
// for(let i=0;i<pdfDataList.length;i++){
// let url= await pdfUtils.getBlobUrl(item);
// // that.pdfUrl=url;
// let pdfInfo={
// "billCode":"1"+new Date().getTime(),
// "pdfUrl":url
// }
// console.log(pdfInfo);
// that.pdfList.push(pdfInfo);
// }
// pdfUtils.mergePdf3(pdfDataList, (new Date()).getTime()+".pdf",false )
// .then(url=>{
// loadingInstance.close();
// that.pdfUrl=url;
// that.openPdfView = true;
// })
// .catch(error => {
// // console.log(error)
// that.$modal.msgError("打印出错:"+erroMsg);
// });
2024-05-31 00:36:52 +00:00
2024-05-24 05:35:58 +00:00
}
2024-05-31 10:12:59 +00:00
else if(code == 800){
// 全部获取完成
console.log("===全部获取完成====>");
}
// if(success){
// const pdfDataList=[...pdfList];
// let pdfUtils=new PdfUtils({});
// // for()
// // pdfUtils.mergePdf3(pdfDataList, (new Date()).getTime()+".pdf",true )
// pdfUtils.mergePdf3(pdfDataList, fileName+".pdf",true )
// }else{
// that.$modal.msgError("下载出错:"+erroMsg);
// }
2024-05-29 08:18:45 +00:00
});
2024-05-24 05:35:58 +00:00
},
2024-05-30 12:39:28 +00:00
// 响应PDF预览
onPdfViewPrint(){
this.$emit("onPrint");
}
2024-05-24 05:35:58 +00:00
}
};
</script>
<style lang="scss">
.printPreDialog .el-dialog__body {
margin: 0px!important;
}
2024-05-29 08:18:45 +00:00
.subBillRange .el-input__inner {
padding:0px;
text-align: center;
}
2024-05-24 05:35:58 +00:00
</style>