<template>
|
<div class="print-container">
|
<div class="margin-bottom-20">
|
<object id="LODOP" classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" width="800" height="600">
|
<param name="Caption" value="显示区" />
|
<param name="Border" value="0" />
|
<param name="Color" value="white" />
|
<embed id="LODOP_EM" type="application/x-print-lodop" width="800" height="600" pluginspage="/upload/install_lodop32.exe" />
|
</object>
|
</div>
|
<el-button type="primary" class="no-print" @click="print">打印</el-button>
|
<el-button type="primary" class="no-print" @click="setting">设置模板</el-button>
|
</div>
|
</template>
|
|
<script>
|
import VueBarcode from "@xkeshi/vue-barcode";
|
|
export default {
|
name: "PrintBarcode",
|
components: {
|
barcode: VueBarcode
|
},
|
data() {
|
return {
|
LODOP: null
|
};
|
},
|
mounted() {
|
this.init();
|
},
|
methods: {
|
// 初始化数据
|
async init() {
|
// 打印类别
|
const printType = localStorage.getItem("printType");
|
|
const columList = await this.getColumnList();
|
let code = await this.getLodopTemplate(printType);
|
if (!code) code = "{}";
|
|
// =====判断浏览器类型:===============
|
let LODOP = null;
|
var isIE = navigator.userAgent.indexOf("MSIE") >= 0 || navigator.userAgent.indexOf("Trident") >= 0;
|
var LODOP_OBJ = document.getElementById("LODOP");
|
var LODOP_EM = document.getElementById("LODOP_EM");
|
LODOP = isIE ? LODOP_OBJ : LODOP_EM;
|
this.LODOP = LODOP;
|
LODOP.SET_LICENSES("达令心潮(北京)商贸有限公司", "B95259F540E2C256132EC7CE6AB55737", "", "");
|
if (printType === "货位条码打印") {
|
const positionNames = localStorage.getItem("positionNames").split(",");
|
// 明细行数据循环
|
for (const positionName of positionNames) {
|
LODOP.NewPage();
|
|
let _code = code.replace("PRINT_INITA(0,", "SET_PRINT_PAGESIZE(");
|
const key = "{货位名称}";
|
const value = positionName;
|
_code = _code.replace(key, value);
|
// eslint-disable-next-line
|
eval(_code);
|
}
|
} else {
|
const tableData = localStorage.getItem("tableData");
|
if (!tableData) {
|
this.$message.error("没有可生成的数据");
|
return;
|
}
|
// 物料明细行数据循环
|
const _tableData = JSON.parse(tableData);
|
for (const item of _tableData) {
|
const productInfo = await this.getProductInfo(item.product_Id);
|
this.createBarcode(LODOP, item, code, columList, productInfo);
|
}
|
}
|
LODOP.SET_SHOW_MODE("PREVIEW_IN_BROWSE", true); // 预览界面内嵌到页面内
|
LODOP.PREVIEW();
|
},
|
// 获得字段
|
getColumnList() {
|
return new Promise((resolve, reject) => {
|
const url = "/api/sys/print/getColumnList";
|
var params = {};
|
this.common.ajax(
|
url,
|
params,
|
res => {
|
this.common.showMsg(res);
|
if (res.result) {
|
resolve(res.data);
|
} else {
|
reject();
|
}
|
},
|
true
|
);
|
});
|
},
|
// 获取模板
|
getLodopTemplate(sendBillName) {
|
return new Promise((resolve, reject) => {
|
const url = "/api/sys/print/getLodopTemplate";
|
var params = {
|
sendBillName: sendBillName
|
};
|
this.common.ajax(
|
url,
|
params,
|
res => {
|
this.common.showMsg(res);
|
if (res.result) {
|
resolve(res.data.designConent);
|
} else {
|
reject();
|
}
|
},
|
true
|
);
|
});
|
},
|
// 获取物料数据
|
getProductInfo(product_Id) {
|
return new Promise((resolve, reject) => {
|
const url = "/api/basicInfo/base/productInfo/getById";
|
var params = {
|
id: product_Id
|
};
|
this.common.ajax(
|
url,
|
params,
|
res => {
|
this.common.showMsg(res);
|
if (res.result) {
|
resolve(res.data);
|
} else {
|
reject();
|
}
|
},
|
true
|
);
|
});
|
},
|
// 创建物料条码
|
createBarcode(LODOP, item, code, columList, productInfo) {
|
// 条码数量循环
|
for (let i = 0; i < item.quantity; i++) {
|
LODOP.NewPage();
|
|
let _code = code.replace("PRINT_INITA(0,", "SET_PRINT_PAGESIZE(");
|
// eslint-disable-next-line
|
for (const colInfo of columList) {
|
const key = "{" + colInfo.columnComment + "}";
|
const columnName = this.common.caseStyle(colInfo.columnName);
|
const value = item[columnName] || (productInfo ? productInfo[columnName] : "");
|
_code = _code.replace(key, value);
|
}
|
// 自定义键值
|
let keyValues = localStorage.getItem("keyValues");
|
if (keyValues) {
|
keyValues = JSON.parse(keyValues);
|
keyValues.forEach(item => {
|
const key = "{" + item.key + "}";
|
const value = item.value;
|
_code = _code.replace(key, value);
|
});
|
}
|
// eslint-disable-next-line
|
eval(_code);
|
}
|
},
|
// 打印
|
print() {
|
this.LODOP.PRINT();
|
},
|
// 设计模板
|
setting() {
|
window.open("/#/inbound/purchase/print-barcode-setting");
|
}
|
}
|
};
|
</script>
|
|
<style lang="scss" scoped>
|
.print-container {
|
padding: 20px;
|
.print-page {
|
page-break-after: always;
|
margin-top: 20px;
|
}
|
}
|
|
@media print {
|
.canvas-container {
|
-moz-box-shadow: none;
|
-webkit-box-shadow: none;
|
box-shadow: none;
|
margin: 0px;
|
.canvas-content {
|
border: 0px dotted #000000;
|
}
|
}
|
.no-print {
|
display: none;
|
}
|
.page-next {
|
page-break-after: always;
|
}
|
}
|
</style>
|