69 lines
1.9 KiB
JavaScript
Executable File
69 lines
1.9 KiB
JavaScript
Executable File
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) {
|
|
return this.findOneFromDef('item', [id, warehouseId]);
|
|
},
|
|
fetchItemTags(itemId) {
|
|
return this.rawSqlFromDef('itemTags', [itemId]).then(rows => {
|
|
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
|
|
}
|
|
}
|
|
};
|