salix/print/templates/reports/item-label-qr/item-label-qr.js

44 lines
1.2 KiB
JavaScript
Executable File

const UserError = require('vn-loopback/util/user-error');
const moment = require('moment');
const qrcode = require('qrcode');
module.exports = {
name: 'item-label-qr',
async serverPrefetch() {
this.items = await this.rawSqlFromDef('item', [this.copies || 1, this.id]);
if (!this.items.length) throw new UserError(`Empty data source`);
this.qr = await this.getQr(this.items[0].buyFk);
this.vnDate = Date.vnNew();
this.date = moment(this.vnDate).format('YY/DD');
this.totalPages = this.items.length;
},
methods: {
getQr(data) {
data = {
company: 'vnl',
user: this.userId,
created: this.vnDate,
table: 'buy',
id: data
};
return qrcode.toDataURL(JSON.stringify(data), {
margin: 0,
errorCorrectionLevel: 'H'
});
}
},
props: {
id: {
type: Number,
required: true,
description: 'The item id'
},
copies: {
type: Number
},
userId: {
type: Number
}
}
};