208 lines
7.9 KiB
Plaintext
208 lines
7.9 KiB
Plaintext
<el-row id="print">
|
|
<el-row>
|
|
<el-col :span="12">
|
|
<el-input v-model="qrcode"
|
|
placeholder="请扫描二维码"
|
|
@@change="scanCode" ref="QrCode">
|
|
</el-input>
|
|
</el-col>
|
|
<el-col :span="8">
|
|
<el-input v-model.number="num"
|
|
placeholder="请输入数量">
|
|
</el-input>
|
|
</el-col>
|
|
<el-col :span="4">
|
|
<el-button type="primary" @@click="genCode">生成</el-button>
|
|
</el-col>
|
|
</el-row>
|
|
<div style="margin: 20px 0;"></div>
|
|
@* 富文本 *@
|
|
@* <el-input type="textarea"
|
|
:autosize="{ minRows: 4}"
|
|
readonly
|
|
v-model="gendCode">
|
|
</el-input> *@
|
|
<el-divider></el-divider>
|
|
<el-table :data="invTable" max-height="400" stripe border
|
|
style="width: 100%">
|
|
<el-table-column fixed="left"
|
|
label="操作"
|
|
width="120"
|
|
align="center">
|
|
<template slot-scope="scope">
|
|
<el-button @@click.native.prevent="deleteRow(scope.$index, invTable)"
|
|
type="text"
|
|
size="small">
|
|
移除
|
|
</el-button>
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column label="唯一码" width="220" align="center" prop="UniqueCode"></el-table-column>
|
|
<el-table-column label="批次" width="220" align="center" prop="Batch"></el-table-column>
|
|
</el-table>
|
|
<el-button style="float: right" type="primary" @@click="print">打印</el-button>
|
|
</el-row>
|
|
|
|
<script>
|
|
var app = new Vue({
|
|
el: "#print",
|
|
data() {
|
|
return {
|
|
invTable:[],
|
|
printData:[],
|
|
gendCode: '',
|
|
qrcode: '',
|
|
num: 1,
|
|
clear: false,
|
|
template: {
|
|
"panels": [
|
|
{
|
|
"index": 0,
|
|
"height": 20,
|
|
"width": 30,
|
|
"paperHeader": 43.5,
|
|
"paperFooter": 56.69,
|
|
"printElements": [
|
|
{
|
|
"options": {
|
|
"left": 0,
|
|
"top": 2,
|
|
"height": 52,
|
|
"width": 81,
|
|
"title": "",
|
|
"field": "uniqueCode",
|
|
"testData": "",
|
|
"textType": "qrcode",
|
|
"barcodeMode": "CODE39"
|
|
},
|
|
"printElementType": {
|
|
"type": "text"
|
|
}
|
|
}
|
|
],
|
|
"paperNumberLeft": 55.5,
|
|
"paperNumberTop": 34.5,
|
|
"paperNumberDisabled": true
|
|
}
|
|
]
|
|
}
|
|
}
|
|
},
|
|
methods: {
|
|
// 删除已绑定行
|
|
deleteRow(index, rows) {
|
|
rows.splice(index, 1);
|
|
},
|
|
scanCode() {
|
|
var _this = this;
|
|
// 调用后台方法,判断是否在物料表内
|
|
$.ajax({
|
|
type: "post",
|
|
dataType: "json",
|
|
data: { code: _this.qrcode },
|
|
url: "/configs/Print/ScanCode",
|
|
success: function (json) {
|
|
// console.log(json);
|
|
if (json.Code != 200) {
|
|
_this.$message({
|
|
message: "扫描失败!" + json.Msg,
|
|
type: "warning",
|
|
duration: "10000",
|
|
});
|
|
}
|
|
if (_this.clear) {
|
|
_this.gendCode = "";
|
|
_this.invTable = [];
|
|
_this.printData = [];
|
|
}
|
|
},
|
|
error: function (json) {
|
|
_this.$message({
|
|
message: "扫描失败!",
|
|
type: "error",
|
|
duration: "10000",
|
|
});
|
|
},
|
|
});
|
|
},
|
|
genCode() {
|
|
var _this = this;
|
|
if (_this.qrcode == "") {
|
|
_this.$message({
|
|
message: "请扫描二维码后再操作!",
|
|
type: "warning",
|
|
duration: "500",
|
|
});
|
|
return;
|
|
}
|
|
if (_this.num == "") {
|
|
_this.$message({
|
|
message: "请输入数量后再操作!",
|
|
type: "warning",
|
|
duration: "500",
|
|
});
|
|
return;
|
|
}
|
|
// 调用后台方法,生成唯一码,(流水号)
|
|
$.ajax({
|
|
type: "post",
|
|
dataType: "json",
|
|
data: { code: _this.qrcode, num: _this.num },
|
|
url: "/configs/Print/GenCode",
|
|
success: function (json) {
|
|
if (json.Code != 200) {
|
|
_this.$message({
|
|
message: "生成失败!" + json.Msg,
|
|
type: "warning",
|
|
duration: "10000",
|
|
});
|
|
return;
|
|
}
|
|
else{
|
|
// console.log(json);
|
|
json.Data.forEach(function (item) {
|
|
// _this.gendCode += item.UniqueCode + '\n';
|
|
// _this.gendCode += item.Batch + '\n';
|
|
_this.invTable.push({
|
|
"UniqueCode": item.UniqueCode,
|
|
"Batch": item.Batch
|
|
});
|
|
_this.printData.push({ uniqueCode: item.UniqueCode });
|
|
_this.printData.push({ uniqueCode: item.Batch });
|
|
});
|
|
|
|
}
|
|
},
|
|
error: function (json) {
|
|
_this.$message({
|
|
message: "生成失败!",
|
|
type: "error",
|
|
duration: "10000",
|
|
});
|
|
},
|
|
});
|
|
_this.num = 1;
|
|
},
|
|
print() {
|
|
var _this = this;
|
|
_this.printData = [];
|
|
this.invTable.forEach(function (item) {
|
|
_this.printData.push({ uniqueCode: item.UniqueCode });
|
|
_this.printData.push({ uniqueCode: item.Batch });
|
|
});;
|
|
// _this.gendCode = "";
|
|
hiprint.init();
|
|
var hiprintTemplate = new hiprint.PrintTemplate({
|
|
template: this.template
|
|
})
|
|
hiprintTemplate.print(this.printData);
|
|
// _this.printData = [];
|
|
_this.clear = true;
|
|
//清空
|
|
_this.qrcode = '';
|
|
_this.num = 1;
|
|
}
|
|
}
|
|
});
|
|
</script>
|