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 - previa'); if (!this.sector) throw new Error('Something went wrong - sector'); }, 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' }, } };