37 lines
1.2 KiB
JavaScript
37 lines
1.2 KiB
JavaScript
|
const vnReport = require('../../../core/mixins/vn-report.js');
|
||
|
const {DOMImplementation, XMLSerializer} = require('xmldom');
|
||
|
const jsBarcode = require('jsbarcode');
|
||
|
|
||
|
module.exports = {
|
||
|
name: 'entry-label',
|
||
|
mixins: [vnReport],
|
||
|
async serverPrefetch() {
|
||
|
this.buys = await this.rawSqlFromDef('entry', [this.id]);
|
||
|
const maxLabelNum = Math.max(...this.buys.map(buy => buy.labelNum));
|
||
|
this.maxLabelNum = maxLabelNum;
|
||
|
},
|
||
|
methods: {
|
||
|
getBarcode(id) {
|
||
|
const xmlSerializer = new XMLSerializer();
|
||
|
const document = new DOMImplementation().createDocument('http://www.w3.org/1999/xhtml', 'html', null);
|
||
|
const svgNode = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
||
|
|
||
|
jsBarcode(svgNode, id, {
|
||
|
xmlDocument: document,
|
||
|
format: 'code128',
|
||
|
displayValue: false,
|
||
|
width: 3.8,
|
||
|
height: 115,
|
||
|
});
|
||
|
return xmlSerializer.serializeToString(svgNode);
|
||
|
}
|
||
|
},
|
||
|
props: {
|
||
|
id: {
|
||
|
type: Number,
|
||
|
required: true,
|
||
|
description: 'The entry id'
|
||
|
}
|
||
|
}
|
||
|
};
|