2022-09-22 17:07:08 +08:00
|
|
|
<template>
|
|
|
|
<div ref="modal" class="modal fade" id="modal-print-repository-row-label" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
|
2023-12-15 23:33:13 +08:00
|
|
|
<div class="modal-dialog" role="document" data-e2e="e2e-MD-printLabel">
|
2022-09-22 17:07:08 +08:00
|
|
|
<div class="modal-content">
|
2022-10-25 21:54:05 +08:00
|
|
|
<div v-if="availablePrinters.length > 0" class="printers-available">
|
2022-09-22 17:07:08 +08:00
|
|
|
<div class="modal-header">
|
2023-08-17 19:55:17 +08:00
|
|
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="sn-icon sn-icon-close"></i></button>
|
2023-12-21 18:55:12 +08:00
|
|
|
<div class="modal-title">
|
|
|
|
<div v-if="rows.length == 1" class="flex flex-row">
|
|
|
|
<div class="font-bold">{{ i18n.t('repository_row.modal_print_label.head_title', {repository_row: rows[0].attributes.name}) }}</div>
|
2022-09-22 17:07:08 +08:00
|
|
|
<span class="id-label">
|
|
|
|
{{ i18n.t('repository_row.modal_print_label.id_label', {repository_row_id: rows[0].attributes.code}) }}
|
|
|
|
</span>
|
2023-12-21 18:55:12 +08:00
|
|
|
</div>
|
|
|
|
<div v-else>
|
|
|
|
<div class="font-bold">{{ i18n.t('repository_row.modal_print_label.head_title_multiple', {repository_rows: rows.length}) }}</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-09-22 17:07:08 +08:00
|
|
|
</div>
|
|
|
|
<div class="modal-body">
|
|
|
|
<div class=printers-container>
|
|
|
|
<label>
|
|
|
|
{{ i18n.t('repository_row.modal_print_label.printer') }}
|
|
|
|
</label>
|
|
|
|
<DropdownSelector
|
|
|
|
:disableSearch="true"
|
2022-10-25 21:54:05 +08:00
|
|
|
:options="availablePrinters"
|
2022-09-22 17:07:08 +08:00
|
|
|
:selectorId="`LabelPrinterSelector`"
|
|
|
|
@dropdown:changed="selectPrinter"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class=labels-container>
|
|
|
|
<label>
|
|
|
|
{{ i18n.t('repository_row.modal_print_label.label') }}
|
|
|
|
</label>
|
|
|
|
|
|
|
|
<DropdownSelector
|
2022-09-29 20:47:59 +08:00
|
|
|
ref="labelTemplateDropdown"
|
2022-09-22 17:07:08 +08:00
|
|
|
:disableSearch="true"
|
2022-10-25 21:54:05 +08:00
|
|
|
:options="availableTemplates"
|
2022-09-22 17:07:08 +08:00
|
|
|
:selectorId="`LabelTemplateSelector`"
|
2022-09-28 17:32:14 +08:00
|
|
|
:optionLabel="templateOption"
|
|
|
|
:onOpen="initTooltip"
|
2022-09-22 17:07:08 +08:00
|
|
|
@dropdown:changed="selectTemplate"
|
|
|
|
/>
|
2022-09-27 21:46:48 +08:00
|
|
|
<div v-if="labelTemplateError" class="label-template-warning">
|
|
|
|
{{ labelTemplateError }}
|
|
|
|
</div>
|
2022-09-22 17:07:08 +08:00
|
|
|
</div>
|
|
|
|
<p class="sci-input-container">
|
|
|
|
<label>
|
|
|
|
{{ i18n.t('repository_row.modal_print_label.number_of_copies') }}
|
|
|
|
</label>
|
|
|
|
<input v-model="copies" type=number class="sci-input-field print-copies-input" min="1">
|
|
|
|
</p>
|
2022-09-27 21:46:48 +08:00
|
|
|
<div class="label-preview-title">
|
|
|
|
{{ i18n.t('repository_row.modal_print_label.label_preview') }}
|
|
|
|
</div>
|
|
|
|
<div class="label-preview-container">
|
2022-10-06 17:09:10 +08:00
|
|
|
<LabelPreview v-if="labelTemplateCode" :zpl='labelTemplateCode' :template="selectedTemplate" :previewUrl="urls.labelPreview" :viewOnly="true"/>
|
2022-09-27 21:46:48 +08:00
|
|
|
</div>
|
2022-09-22 17:07:08 +08:00
|
|
|
</div>
|
|
|
|
<div class="modal-footer">
|
2023-06-19 21:45:22 +08:00
|
|
|
<button type="button" class="btn btn-secondary" data-dismiss="modal"> {{ i18n.t('general.cancel') }}</button>
|
2022-10-12 22:56:58 +08:00
|
|
|
<button class="btn btn-primary" @click="submitPrint">
|
2022-10-01 01:48:13 +08:00
|
|
|
{{ i18n.t(`repository_row.modal_print_label.${labelTemplateError ? 'print_anyway' : 'print_label'}`) }}
|
2022-09-22 17:07:08 +08:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div v-else class="no-printers-available">
|
|
|
|
<div class="modal-body no-printers-container">
|
2023-12-15 23:33:13 +08:00
|
|
|
<button type="button" class="close modal-absolute-close-button" data-dismiss="modal" aria-label="Close"><i class="sn-icon sn-icon-close" data-e2e="e2e-BT-printLabelMD-close"></i></button>
|
2022-09-22 17:07:08 +08:00
|
|
|
<img src='/images/printers/no_available_printers.png'>
|
|
|
|
<p class="no-printer-title">
|
|
|
|
{{ i18n.t('repository_row.modal_print_label.no_printers.title') }}
|
|
|
|
</p>
|
|
|
|
<p class="no-printer-body">
|
|
|
|
{{ i18n.t('repository_row.modal_print_label.no_printers.description') }}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<div class="modal-footer">
|
2023-12-15 23:33:13 +08:00
|
|
|
<a :href="urls.fluicsInfo" target="blank" class="btn btn-primary" data-e2e="e2e-BT-printLabelMD-visitBlog" >
|
2022-09-22 17:07:08 +08:00
|
|
|
{{ i18n.t('repository_row.modal_print_label.no_printers.visit_blog') }}
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2024-01-31 18:10:11 +08:00
|
|
|
/* global HelperModule */
|
|
|
|
|
2024-01-04 23:34:36 +08:00
|
|
|
import DropdownSelector from '../shared/dropdown_selector.vue';
|
|
|
|
import LabelPreview from '../label_template/components/label_preview.vue';
|
2022-09-22 17:07:08 +08:00
|
|
|
|
2024-01-04 23:34:36 +08:00
|
|
|
export default {
|
|
|
|
name: 'PrintModalContainer',
|
|
|
|
props: {
|
|
|
|
showModal: Boolean,
|
|
|
|
row_ids: Array,
|
2024-01-09 16:37:50 +08:00
|
|
|
repository_id: Number,
|
2024-01-04 23:34:36 +08:00
|
|
|
urls: Object
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
rows: [],
|
|
|
|
printers: [],
|
|
|
|
templates: [],
|
|
|
|
selectedPrinter: null,
|
|
|
|
selectedTemplate: null,
|
|
|
|
copies: 1,
|
|
|
|
zebraPrinters: null,
|
|
|
|
labelTemplateError: null,
|
|
|
|
labelTemplateCode: null
|
|
|
|
};
|
|
|
|
},
|
|
|
|
components: {
|
|
|
|
DropdownSelector,
|
|
|
|
LabelPreview
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
$.get(this.urls.labelTemplates, (result) => {
|
|
|
|
this.templates = result.data;
|
|
|
|
this.selectDefaultLabelTemplate();
|
|
|
|
});
|
|
|
|
|
|
|
|
$.get(this.urls.printers, (result) => {
|
|
|
|
this.printers = result.data;
|
|
|
|
});
|
|
|
|
|
|
|
|
$(this.$refs.modal).on('hidden.bs.modal', () => {
|
|
|
|
this.copies = 1;
|
|
|
|
this.zebraPrinters = null;
|
|
|
|
this.$emit('close');
|
|
|
|
});
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
availableTemplates() {
|
|
|
|
let { templates } = this;
|
|
|
|
if (this.selectedPrinter && this.selectedPrinter.attributes.type_of === 'zebra') {
|
|
|
|
templates = templates.filter((i) => i.attributes.type === 'ZebraLabelTemplate');
|
|
|
|
}
|
|
|
|
|
|
|
|
return templates.map((i) => ({
|
|
|
|
value: i.id,
|
|
|
|
label: i.attributes.name,
|
|
|
|
params: {
|
|
|
|
icon: i.attributes.icon_url,
|
|
|
|
description: i.attributes.description || ''
|
|
|
|
}
|
|
|
|
})).sort((temp1, temp2) => (temp1.label?.toLowerCase() > temp2.label?.toLowerCase() ? 1 : -1));
|
2022-09-22 17:07:08 +08:00
|
|
|
},
|
2024-01-04 23:34:36 +08:00
|
|
|
availablePrinters() {
|
|
|
|
return this.printers.map((i) => ({
|
|
|
|
value: i.id,
|
|
|
|
label: i.attributes.display_name
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
showModal() {
|
|
|
|
if (this.showModal) {
|
|
|
|
this.initZebraPrinter();
|
|
|
|
$(this.$refs.modal).modal('show');
|
|
|
|
this.validateTemplate();
|
2022-09-22 17:07:08 +08:00
|
|
|
}
|
|
|
|
},
|
2024-01-04 23:34:36 +08:00
|
|
|
row_ids() {
|
2024-01-09 16:37:50 +08:00
|
|
|
$.get(this.urls.rows, { repository_id: this.repository_id, row_ids: this.row_ids }, (result) => {
|
2024-01-04 23:34:36 +08:00
|
|
|
this.rows = result.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
selectDefaultLabelTemplate() {
|
|
|
|
if (this.selectedPrinter && this.templates) {
|
|
|
|
const template = this.templates.find((i) => i.attributes.default
|
|
|
|
&& i.type.includes(this.selectedPrinter.attributes.type_of));
|
|
|
|
if (template) {
|
|
|
|
this.$nextTick(() => {
|
|
|
|
this.$refs.labelTemplateDropdown.selectValues(template.id);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2022-09-22 17:07:08 +08:00
|
|
|
},
|
2024-01-04 23:34:36 +08:00
|
|
|
selectPrinter(value) {
|
|
|
|
this.selectedPrinter = this.printers.find((i) => i.id === value);
|
|
|
|
this.selectDefaultLabelTemplate();
|
|
|
|
},
|
|
|
|
selectTemplate(value) {
|
|
|
|
this.selectedTemplate = this.templates.find((i) => i.id === value);
|
|
|
|
this.validateTemplate();
|
|
|
|
},
|
|
|
|
validateTemplate() {
|
|
|
|
if (!this.selectedTemplate || this.row_ids.length == 0) return;
|
2022-09-22 17:07:08 +08:00
|
|
|
|
2024-01-09 16:37:50 +08:00
|
|
|
$.post(this.urls.printValidation, {
|
|
|
|
repository_id: this.repository_id,
|
|
|
|
label_template_id: this.selectedTemplate.id,
|
|
|
|
row_ids: this.row_ids
|
|
|
|
}, (result) => {
|
2024-01-04 23:34:36 +08:00
|
|
|
this.labelTemplateError = null;
|
|
|
|
this.labelTemplateCode = result.label_code;
|
|
|
|
}).fail((result) => {
|
2024-01-31 18:10:11 +08:00
|
|
|
if (result.responseJSON) {
|
|
|
|
this.labelTemplateError = result.responseJSON.error;
|
|
|
|
this.labelTemplateCode = result.responseJSON.label_code;
|
|
|
|
} else {
|
|
|
|
this.labelTemplateError = null;
|
|
|
|
this.labelTemplateCode = null;
|
|
|
|
HelperModule.flashAlertMsg(this.i18n.t('repository_row.modal_print_label.general_error'), 'danger');
|
|
|
|
}
|
2022-09-22 17:07:08 +08:00
|
|
|
});
|
|
|
|
},
|
2024-01-04 23:34:36 +08:00
|
|
|
submitPrint() {
|
|
|
|
this.$nextTick(() => {
|
|
|
|
if (this.selectedPrinter.attributes.type_of === 'zebra') {
|
|
|
|
this.zebraPrinters.print(
|
|
|
|
this.urls.zebraProgress,
|
|
|
|
'.label-printing-progress-modal',
|
|
|
|
'#modal-print-repository-row-label',
|
|
|
|
{
|
|
|
|
printer_name: this.selectedPrinter.attributes.name,
|
|
|
|
number_of_copies: this.copies,
|
|
|
|
label_template_id: this.selectedTemplate.id,
|
2024-01-09 16:37:50 +08:00
|
|
|
row_ids: this.row_ids,
|
|
|
|
repository_id: this.repository_id
|
2022-09-28 17:32:14 +08:00
|
|
|
}
|
2024-01-04 23:34:36 +08:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$.post(this.urls.print, {
|
2024-01-09 16:37:50 +08:00
|
|
|
row_ids: this.row_ids,
|
|
|
|
repository_id: this.repository_id,
|
2024-01-04 23:34:36 +08:00
|
|
|
label_printer_id: this.selectedPrinter.id,
|
|
|
|
label_template_id: this.selectedTemplate.id,
|
|
|
|
copies: this.copies
|
|
|
|
}, (data) => {
|
|
|
|
$(this.$refs.modal).modal('hide');
|
|
|
|
this.$emit('close');
|
|
|
|
PrintProgressModal.init(data);
|
2024-01-31 18:10:11 +08:00
|
|
|
}).fail(() => {
|
|
|
|
HelperModule.flashAlertMsg(this.i18n.t('repository_row.modal_print_label.general_error'), 'danger');
|
2024-01-04 23:34:36 +08:00
|
|
|
});
|
2022-09-22 17:07:08 +08:00
|
|
|
}
|
2024-01-04 23:34:36 +08:00
|
|
|
});
|
2022-09-22 17:07:08 +08:00
|
|
|
},
|
2024-01-04 23:34:36 +08:00
|
|
|
initZebraPrinter() {
|
|
|
|
this.zebraPrinters = zebraPrint.init($('#LabelPrinterSelector'), {
|
|
|
|
clearSelectorOnFirstDevice: false,
|
|
|
|
appendDevice: (device) => {
|
|
|
|
this.printers.push({
|
|
|
|
id: `zebra${this.printers.length}`,
|
|
|
|
attributes: {
|
|
|
|
name: device.name,
|
|
|
|
display_name: device.name,
|
|
|
|
type_of: 'zebra'
|
|
|
|
}
|
|
|
|
});
|
2022-09-29 20:47:59 +08:00
|
|
|
}
|
2024-01-04 23:34:36 +08:00
|
|
|
}, false);
|
|
|
|
},
|
|
|
|
templateOption(option) {
|
|
|
|
return `
|
2022-09-28 17:32:14 +08:00
|
|
|
<div class="label-template-option" data-toggle="tooltip" data-placement="right" title="${option.params.description}">
|
2023-07-14 18:31:15 +08:00
|
|
|
<img src="${option.params.icon}" style=""></img>
|
2022-09-28 17:32:14 +08:00
|
|
|
${option.label}
|
|
|
|
</div>
|
2024-01-04 23:34:36 +08:00
|
|
|
`;
|
|
|
|
},
|
|
|
|
initTooltip() {
|
|
|
|
$('[data-toggle="tooltip"]').tooltip();
|
2022-09-22 17:07:08 +08:00
|
|
|
}
|
|
|
|
}
|
2024-01-04 23:34:36 +08:00
|
|
|
};
|
2022-09-22 17:07:08 +08:00
|
|
|
</script>
|