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">
|
|
|
|
<div class="modal-dialog" role="document">
|
|
|
|
<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">
|
|
|
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
|
|
|
<p class="modal-title">
|
|
|
|
<template v-if="rows.length == 1">
|
|
|
|
{{ i18n.t('repository_row.modal_print_label.head_title', {repository_row: rows[0].attributes.name}) }}
|
|
|
|
<span class="id-label">
|
|
|
|
{{ i18n.t('repository_row.modal_print_label.id_label', {repository_row_id: rows[0].attributes.code}) }}
|
|
|
|
</span>
|
|
|
|
</template>
|
|
|
|
<template v-else>
|
|
|
|
{{ i18n.t('repository_row.modal_print_label.head_title_multiple', {repository_rows: rows.length}) }}
|
|
|
|
</template>
|
|
|
|
</p>
|
|
|
|
</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">
|
2022-09-29 20:45:10 +08:00
|
|
|
<button type="button" class="btn btn-default" 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">
|
|
|
|
<button type="button" class="close modal-absolute-close-button" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
|
|
|
<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">
|
|
|
|
<a :href="urls.fluicsInfo" target="blank" class="btn btn-primary" >
|
|
|
|
{{ i18n.t('repository_row.modal_print_label.no_printers.visit_blog') }}
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import DropdownSelector from 'vue/shared/dropdown_selector.vue'
|
2022-09-27 21:46:48 +08:00
|
|
|
import LabelPreview from 'vue/label_template/components/label_preview.vue'
|
2022-09-22 17:07:08 +08:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'PrintModalContainer',
|
|
|
|
props: {
|
|
|
|
showModal: Boolean,
|
|
|
|
row_ids: Array,
|
2022-09-27 21:57:23 +08:00
|
|
|
urls: Object,
|
|
|
|
zebraEnabled: Boolean
|
2022-09-22 17:07:08 +08:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
rows: [],
|
|
|
|
printers: [],
|
|
|
|
templates: [],
|
|
|
|
selectedPrinter: null,
|
|
|
|
selectedTemplate: null,
|
|
|
|
copies: 1,
|
2022-09-27 21:46:48 +08:00
|
|
|
zebraPrinters: null,
|
|
|
|
labelTemplateError: null,
|
|
|
|
labelTemplateCode: null
|
2022-09-22 17:07:08 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
components: {
|
2022-09-27 21:46:48 +08:00
|
|
|
DropdownSelector,
|
|
|
|
LabelPreview
|
2022-09-22 17:07:08 +08:00
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
$.get(this.urls.labelTemplates, (result) => {
|
|
|
|
this.templates = result.data
|
2022-09-29 20:47:59 +08:00
|
|
|
this.selectDefaultLabelTemplate();
|
2022-09-22 17:07:08 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
$.get(this.urls.printers, (result) => {
|
|
|
|
this.printers = result.data
|
|
|
|
})
|
|
|
|
|
|
|
|
$(this.$refs.modal).on('hidden.bs.modal', () => {
|
|
|
|
this.$emit('close');
|
|
|
|
});
|
|
|
|
|
2022-09-27 21:57:23 +08:00
|
|
|
if (this.zebraEnabled) {
|
|
|
|
this.initZebraPrinter();
|
|
|
|
}
|
2022-09-22 17:07:08 +08:00
|
|
|
},
|
|
|
|
computed: {
|
2022-10-25 21:54:05 +08:00
|
|
|
availableTemplates() {
|
2022-09-22 17:07:08 +08:00
|
|
|
let templates = this.templates;
|
|
|
|
if (this.selectedPrinter && this.selectedPrinter.attributes.type_of === 'zebra') {
|
|
|
|
templates = templates.filter(i => i.attributes.type === 'ZebraLabelTemplate')
|
|
|
|
}
|
|
|
|
|
|
|
|
return templates.map(i => {
|
2022-09-28 17:32:14 +08:00
|
|
|
return {
|
|
|
|
value: i.id,
|
|
|
|
label: i.attributes.name,
|
|
|
|
params: {
|
|
|
|
icon: i.attributes.icon_url,
|
|
|
|
description: i.attributes.description || ''
|
|
|
|
}
|
|
|
|
}
|
2022-09-22 17:07:08 +08:00
|
|
|
})
|
|
|
|
},
|
2022-10-25 21:54:05 +08:00
|
|
|
availablePrinters() {
|
2022-09-22 17:07:08 +08:00
|
|
|
return this.printers.map(i => {
|
2022-09-28 19:25:55 +08:00
|
|
|
return {
|
|
|
|
value: i.id,
|
2022-10-12 22:56:58 +08:00
|
|
|
label: i.attributes.display_name
|
2022-09-28 19:25:55 +08:00
|
|
|
}
|
2022-09-22 17:07:08 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
showModal() {
|
|
|
|
if (this.showModal) {
|
|
|
|
$(this.$refs.modal).modal('show');
|
2022-10-11 16:58:37 +08:00
|
|
|
this.validateTemplate();
|
2022-09-22 17:07:08 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
row_ids() {
|
|
|
|
$.get(this.urls.rows, {rows: this.row_ids}, (result) => {
|
|
|
|
this.rows = result.data
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2022-09-29 20:47:59 +08:00
|
|
|
selectDefaultLabelTemplate() {
|
|
|
|
if (this.selectedPrinter && this.templates) {
|
2022-09-28 19:25:55 +08:00
|
|
|
let template = this.templates.find(i => i.attributes.default
|
2022-09-29 20:47:59 +08:00
|
|
|
&& 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
|
|
|
selectPrinter(value) {
|
2022-09-29 20:47:59 +08:00
|
|
|
this.selectedPrinter = this.printers.find(i => i.id === value)
|
|
|
|
this.selectDefaultLabelTemplate();
|
2022-09-22 17:07:08 +08:00
|
|
|
},
|
|
|
|
selectTemplate(value) {
|
2022-09-27 21:46:48 +08:00
|
|
|
this.selectedTemplate = this.templates.find(i => i.id === value);
|
|
|
|
this.validateTemplate();
|
|
|
|
},
|
|
|
|
validateTemplate() {
|
|
|
|
if (!this.selectedTemplate || this.row_ids.length == 0) return;
|
|
|
|
|
|
|
|
$.post(this.urls.printValidation, {label_template_id: this.selectedTemplate.id, rows: this.row_ids}, (result) => {
|
|
|
|
this.labelTemplateError = null;
|
|
|
|
this.labelTemplateCode = result.label_code;
|
|
|
|
}).error((result) => {
|
|
|
|
this.labelTemplateError = result.responseJSON.error;
|
|
|
|
this.labelTemplateCode = result.responseJSON.label_code;
|
|
|
|
})
|
2022-09-22 17:07:08 +08:00
|
|
|
},
|
|
|
|
submitPrint() {
|
2022-10-10 19:33:35 +08:00
|
|
|
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,
|
|
|
|
rows: this.row_ids
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$.post(this.urls.print, {
|
|
|
|
rows: this.row_ids,
|
|
|
|
label_printer_id: this.selectedPrinter.id,
|
2022-09-22 17:07:08 +08:00
|
|
|
label_template_id: this.selectedTemplate.id,
|
2022-10-10 19:33:35 +08:00
|
|
|
copies: this.copies
|
|
|
|
}, (data) => {
|
|
|
|
$(this.$refs.modal).modal('hide');
|
|
|
|
this.$emit('close');
|
|
|
|
PrintProgressModal.init(data);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
});
|
2022-09-22 17:07:08 +08:00
|
|
|
},
|
|
|
|
initZebraPrinter() {
|
|
|
|
this.zebraPrinters = zebraPrint.init($('#LabelPrinterSelector'), {
|
|
|
|
clearSelectorOnFirstDevice: false,
|
2022-09-27 15:58:22 +08:00
|
|
|
appendDevice: (device) => {
|
2022-09-22 17:07:08 +08:00
|
|
|
this.printers.push({
|
|
|
|
id: `zebra${this.printers.length}`,
|
|
|
|
attributes: {
|
2022-10-06 20:52:15 +08:00
|
|
|
name: device.name,
|
2022-10-04 15:57:47 +08:00
|
|
|
display_name: device.name,
|
2022-10-12 22:56:58 +08:00
|
|
|
type_of: 'zebra'
|
2022-09-22 17:07:08 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2022-10-12 22:56:58 +08:00
|
|
|
}, false);
|
2022-09-28 17:32:14 +08:00
|
|
|
},
|
|
|
|
templateOption(option) {
|
|
|
|
return `
|
|
|
|
<div class="label-template-option" data-toggle="tooltip" data-placement="right" title="${option.params.description}">
|
|
|
|
<img src="${option.params.icon}"></img>
|
|
|
|
${option.label}
|
|
|
|
</div>
|
|
|
|
`
|
|
|
|
},
|
|
|
|
initTooltip() {
|
|
|
|
$('[data-toggle="tooltip"]').tooltip();
|
2022-09-22 17:07:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|