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

69 lines
1.9 KiB
JavaScript
Raw Normal View History

2019-10-31 11:43:04 +00:00
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: 'item-label',
async serverPrefetch() {
this.item = await this.fetchItem(this.itemId, this.warehouseId);
this.tags = await this.fetchItemTags(this.itemId);
this.barcode = await this.getBarcodeBase64(this.itemId);
if (!this.item)
throw new Error('Something went wrong');
},
computed: {
dated() {
const filters = this.$options.filters;
return filters.date(new Date(), '%W/%d');
},
labelPage() {
const labelNumber = this.labelNumber ? this.labelNumber : 1;
const totalLabels = this.totalLabels ? this.totalLabels : 1;
return `${labelNumber}/${totalLabels}`;
}
},
methods: {
fetchItem(id, warehouseId) {
2020-09-28 11:54:02 +00:00
return this.findOneFromDef('item', [id, warehouseId]);
2019-10-31 11:43:04 +00:00
},
fetchItemTags(itemId) {
2020-09-28 11:54:02 +00:00
return this.rawSqlFromDef('itemTags', [itemId]).then(rows => {
2019-10-31 11:43:04 +00:00
const tags = {};
rows.forEach(row => tags[row.code] = row.value);
return tags;
});
},
getBarcodeBase64(itemId) {
return qrcode.toDataURL(itemId, {margin: 0});
},
packing() {
const stems = this.item.stems ? this.item.stems : 1;
return `${this.item.packing}x${stems}`;
}
},
components: {
'report-header': reportHeader.build(),
'report-footer': reportFooter.build()
},
props: {
itemId: {
required: true
},
warehouseId: {
required: true
},
labelNumber: {
type: String
},
totalLabels: {
type: String
}
}
};