2023-08-02 05:35:40 +00:00
|
|
|
const config = require(`vn-print/core/config`);
|
|
|
|
const vnReport = require('../../../core/mixins/vn-report.js');
|
|
|
|
const md5 = require('md5');
|
|
|
|
const fs = require('fs-extra');
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
name: 'cmr',
|
|
|
|
mixins: [vnReport],
|
|
|
|
async serverPrefetch() {
|
|
|
|
this.data = await this.findOneFromDef('data', [this.id]);
|
|
|
|
if (this.data.ticketFk) {
|
|
|
|
this.merchandises = await this.rawSqlFromDef('merchandise', [this.data.ticketFk]);
|
2023-08-02 07:09:50 +00:00
|
|
|
this.signature = await this.findOneFromDef('signature', [this.data.ticketFk]);
|
|
|
|
} else
|
|
|
|
this.merchandises = null;
|
2023-08-02 05:35:40 +00:00
|
|
|
},
|
|
|
|
props: {
|
|
|
|
id: {
|
|
|
|
type: Number,
|
|
|
|
required: true,
|
|
|
|
description: 'The cmr id'
|
|
|
|
},
|
|
|
|
},
|
2023-08-02 07:09:50 +00:00
|
|
|
computed: {
|
|
|
|
signPath() {
|
|
|
|
if (!this.signature) return;
|
2023-08-02 05:35:40 +00:00
|
|
|
|
2023-08-02 07:09:50 +00:00
|
|
|
const signatureName = this.signature.signature
|
2023-08-02 05:35:40 +00:00
|
|
|
const hash = md5(signatureName.toString()).substring(0, 3);
|
|
|
|
const file = `${config.storage.root}/${hash}/${signatureName}.png`;
|
|
|
|
if (!fs.existsSync(file)) return null;
|
|
|
|
|
|
|
|
return `data:image/png;base64, ${Buffer.from(fs.readFileSync(file), 'utf8').toString('base64')}`;
|
2023-08-02 07:09:50 +00:00
|
|
|
},
|
|
|
|
async getStamp() {
|
|
|
|
const data = this.data.stamp.toString('base64');
|
|
|
|
return `data:image/png;base64, ${data}`;
|
2023-08-02 05:35:40 +00:00
|
|
|
}
|
2023-08-02 07:09:50 +00:00
|
|
|
},
|
2023-08-02 05:35:40 +00:00
|
|
|
};
|