76 lines
2.4 KiB
JavaScript
76 lines
2.4 KiB
JavaScript
const jsBarcode = require('jsbarcode');
|
|
const {DOMImplementation, XMLSerializer} = require('xmldom');
|
|
const vnReport = require('../../../core/mixins/vn-report.js');
|
|
|
|
module.exports = {
|
|
name: 'collection-label',
|
|
mixins: [vnReport],
|
|
props: {
|
|
id: {
|
|
type: Number,
|
|
required: true,
|
|
description: 'The ticket or collection id'
|
|
},
|
|
labelCount: {
|
|
type: Number,
|
|
required: false,
|
|
description: 'The number of labels'
|
|
}
|
|
},
|
|
async serverPrefetch() {
|
|
let ticketIds;
|
|
const res = await this.rawSqlFromDef('tickets', [this.id]);
|
|
|
|
if (res.length) {
|
|
ticketIds = [];
|
|
for (const row of res)
|
|
ticketIds.push(row.ticketFk);
|
|
} else
|
|
ticketIds = [this.id];
|
|
|
|
this.labelsData = await this.rawSqlFromDef('labelsData', [ticketIds]);
|
|
this.checkMainEntity(this.labelsData);
|
|
},
|
|
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);
|
|
},
|
|
getVertical(labelData) {
|
|
let value;
|
|
if (labelData.collectionFk) {
|
|
value = `${labelData.collectionFk} ~ `;
|
|
if (labelData.code == 'V')
|
|
value = value + `${labelData.wagon}-${labelData.level}`;
|
|
else
|
|
value = value + `${labelData.color.substring(0, 4)}`;
|
|
} else
|
|
value = '-'.repeat(19);
|
|
|
|
return value;
|
|
},
|
|
getAgencyDescripton(labelData) {
|
|
let value;
|
|
if (labelData.agencyDescription)
|
|
value = labelData.agencyDescription.toUpperCase().substring(0, 11);
|
|
else
|
|
value = '---';
|
|
|
|
if (labelData.routeFk)
|
|
value = `${value} [${labelData.routeFk.toString().substring(0, 3)}]`;
|
|
|
|
return value;
|
|
},
|
|
},
|
|
};
|