2023-01-23 12:15:30 +00:00
|
|
|
const vnReport = require('../../../core/mixins/vn-report.js');
|
2019-10-31 11:43:04 +00:00
|
|
|
const qrcode = require('qrcode');
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
name: 'item-label',
|
2023-01-23 12:15:30 +00:00
|
|
|
mixins: [vnReport],
|
2019-10-31 11:43:04 +00:00
|
|
|
async serverPrefetch() {
|
2023-01-23 12:15:30 +00:00
|
|
|
this.item = await this.findOneFromDef('item', [this.id, this.warehouseId]);
|
|
|
|
this.checkMainEntity(this.item);
|
2022-09-26 11:33:27 +00:00
|
|
|
this.tags = await this.fetchItemTags(this.id);
|
|
|
|
this.barcode = await this.getBarcodeBase64(this.id);
|
2019-10-31 11:43:04 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
labelPage() {
|
|
|
|
const labelNumber = this.labelNumber ? this.labelNumber : 1;
|
|
|
|
const totalLabels = this.totalLabels ? this.totalLabels : 1;
|
|
|
|
|
|
|
|
return `${labelNumber}/${totalLabels}`;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2022-09-26 11:33:27 +00:00
|
|
|
fetchItemTags(id) {
|
|
|
|
return this.rawSqlFromDef('itemTags', [id]).then(rows => {
|
2019-10-31 11:43:04 +00:00
|
|
|
const tags = {};
|
|
|
|
rows.forEach(row => tags[row.code] = row.value);
|
|
|
|
|
|
|
|
return tags;
|
|
|
|
});
|
|
|
|
},
|
2022-09-26 11:33:27 +00:00
|
|
|
getBarcodeBase64(id) {
|
2022-10-03 11:35:49 +00:00
|
|
|
const data = String(id);
|
|
|
|
|
|
|
|
return qrcode.toDataURL(data, {margin: 0});
|
2019-10-31 11:43:04 +00:00
|
|
|
},
|
|
|
|
packing() {
|
|
|
|
const stems = this.item.stems ? this.item.stems : 1;
|
|
|
|
return `${this.item.packing}x${stems}`;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
props: {
|
2022-09-26 11:33:27 +00:00
|
|
|
id: {
|
2022-10-03 11:35:49 +00:00
|
|
|
type: Number,
|
2022-09-26 11:33:27 +00:00
|
|
|
required: true,
|
|
|
|
description: 'The item id'
|
2019-10-31 11:43:04 +00:00
|
|
|
},
|
|
|
|
warehouseId: {
|
2022-10-03 11:35:49 +00:00
|
|
|
type: Number,
|
2019-10-31 11:43:04 +00:00
|
|
|
required: true
|
|
|
|
},
|
|
|
|
labelNumber: {
|
2022-10-03 11:35:49 +00:00
|
|
|
type: Number
|
2019-10-31 11:43:04 +00:00
|
|
|
},
|
|
|
|
totalLabels: {
|
2022-10-03 11:35:49 +00:00
|
|
|
type: Number
|
2019-10-31 11:43:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|