47 lines
1.1 KiB
JavaScript
Executable File
47 lines
1.1 KiB
JavaScript
Executable File
const Component = require(`vn-print/core/component`);
|
|
const reportBody = new Component('report-body');
|
|
const qrcode = require('qrcode');
|
|
|
|
module.exports = {
|
|
name: 'previa-label',
|
|
async serverPrefetch() {
|
|
this.previa = await this.fetchPrevia(this.id);
|
|
this.sector = await this.fetchSector(this.id);
|
|
this.previa = this.previa[0];
|
|
this.barcode = await this.getBarcodeBase64(this.id);
|
|
|
|
if (!this.previa)
|
|
throw new Error('Something went wrong');
|
|
|
|
if (!this.sector)
|
|
throw new Error('Something went wrong');
|
|
},
|
|
|
|
computed: {
|
|
|
|
},
|
|
methods: {
|
|
fetchPrevia(id) {
|
|
return this.findOneFromDef('previa', [id]);
|
|
},
|
|
getBarcodeBase64(id) {
|
|
const data = String(id);
|
|
|
|
return qrcode.toDataURL(data, {margin: 0});
|
|
},
|
|
fetchSector(id) {
|
|
return this.findOneFromDef('sector', [id]);
|
|
}
|
|
},
|
|
components: {
|
|
'report-body': reportBody.build()
|
|
},
|
|
props: {
|
|
id: {
|
|
type: Number,
|
|
required: true,
|
|
description: 'The saleGroupFk id'
|
|
},
|
|
}
|
|
};
|