salix/print/templates/reports/collection-label/collection-label.js

41 lines
1.3 KiB
JavaScript

const Component = require(`${appPath}/core/component`);
const reportHeader = new Component('report-header');
const reportFooter = new Component('report-footer');
const qrcode = require('qrcode');
module.exports = {
name: 'collection-label',
async serverPrefetch() {
this.isCollection = await this.isCollection(this.param);
this.tags = await this.fetchCollectionTicket(this.isCollection, this.param, this.param);
this.barcode = await this.getBarcodeBase64(this.param);
if (!this.tags)
throw new Error('Something went wrong');
},
methods: {
isCollection(param) {
return this.findOneFromDef('isCollection', [param]);
},
fetchCollectionTicket(isCollection, param, param) {
return this.rawSqlFromDef('collectionTicket', [isCollection, param, param]).then(rows => {
const tags = {};
rows.forEach(row => tags[row.code] = row.value);
return tags;
});
},
getBarcodeBase64(param) {
return qrcode.toDataURL(param, {margin: 0});
}
},
components: {
'report-header': reportHeader.build(),
'report-footer': reportFooter.build()
},
props: {
param: {
required: true
}
}
};