2023-05-11 17:21:50 +08:00
|
|
|
<template>
|
2023-11-09 19:40:06 +08:00
|
|
|
<div
|
|
|
|
class="flex items-center mr-3 flex-nowrap relative"
|
|
|
|
v-click-outside="closeSearchInputs"
|
2023-08-01 16:41:58 +08:00
|
|
|
>
|
2023-12-15 23:33:13 +08:00
|
|
|
<button :class="{hidden: searchOpened}" ref='searchInputBtn' class="btn btn-light btn-black icon-btn" data-e2e="e2e-BT-invInventoryRT-search" :title="i18n.t('repositories.show.search_button_tooltip')" @click="openSearch">
|
2023-06-08 14:33:37 +08:00
|
|
|
<i class="sn-icon sn-icon-search"></i>
|
2023-05-11 17:21:50 +08:00
|
|
|
</button>
|
2023-05-23 18:33:07 +08:00
|
|
|
<div v-if="searchOpened || barcodeSearchOpened" class="w-52 flex">
|
2023-07-11 03:09:29 +08:00
|
|
|
<div v-if="searchOpened" class="sci-input-container-v2 w-full right-icon">
|
2023-05-11 17:21:50 +08:00
|
|
|
<input
|
|
|
|
ref="searchInput"
|
|
|
|
class="sci-input-field"
|
|
|
|
type="text"
|
|
|
|
:placeholder="i18n.t('repositories.show.filter_inventory_items')"
|
|
|
|
@keyup="setValue"
|
|
|
|
/>
|
2023-07-11 03:09:29 +08:00
|
|
|
<i class="sn-icon sn-icon-search !mr-2.5"></i>
|
2023-05-11 17:21:50 +08:00
|
|
|
</div>
|
2023-07-11 03:09:29 +08:00
|
|
|
<div v-if="barcodeSearchOpened" class="sci-input-container-v2 w-full right-icon ml-2">
|
2023-05-11 17:21:50 +08:00
|
|
|
<input
|
|
|
|
ref="barcodeSearchInput"
|
|
|
|
class="sci-input-field"
|
|
|
|
type="text"
|
|
|
|
:placeholder="i18n.t('repositories.show.filter_inventory_items_with_ean')"
|
2023-08-01 16:41:58 +08:00
|
|
|
@keyup="setBarcodeValue"
|
2023-05-11 17:21:50 +08:00
|
|
|
/>
|
2023-07-11 03:09:29 +08:00
|
|
|
<i class='sn-icon sn-icon-barcode barcode-scanner !mr-2.5'></i>
|
2023-05-11 17:21:50 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-12-15 23:33:13 +08:00
|
|
|
<button :class="{hidden: barcodeSearchOpened}" ref='barcodeSearchInputBtn' class="btn btn-light btn-black icon-btn ml-2" data-e2e="e2e-BT-invInventoryRT-barcode" :title="i18n.t('repositories.show.ean_search_button_tooltip')" @click="openBarcodeSearch">
|
2023-06-08 14:33:37 +08:00
|
|
|
<i class='sn-icon sn-icon-barcode barcode-scanner'></i>
|
2023-05-11 17:21:50 +08:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2024-01-04 23:34:36 +08:00
|
|
|
import { vOnClickOutside } from '@vueuse/components';
|
2023-11-09 19:40:06 +08:00
|
|
|
|
2023-05-11 17:21:50 +08:00
|
|
|
export default {
|
|
|
|
name: 'RepositorySearchContainer',
|
2023-10-24 02:57:12 +08:00
|
|
|
directives: {
|
2023-11-16 23:25:34 +08:00
|
|
|
'click-outside': vOnClickOutside
|
2023-10-24 02:57:12 +08:00
|
|
|
},
|
2023-05-11 17:21:50 +08:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
barcodeSearchOpened: false,
|
|
|
|
barcodeValue: '',
|
|
|
|
searchOpened: false,
|
|
|
|
value: ''
|
2024-01-04 23:34:36 +08:00
|
|
|
};
|
2023-05-11 17:21:50 +08:00
|
|
|
},
|
2023-11-09 19:40:06 +08:00
|
|
|
directives: {
|
|
|
|
'click-outside': vOnClickOutside
|
|
|
|
},
|
2023-05-11 17:21:50 +08:00
|
|
|
watch: {
|
|
|
|
barcodeValue() {
|
|
|
|
this.updateRepositoySearch();
|
|
|
|
},
|
|
|
|
value() {
|
|
|
|
this.updateRepositoySearch();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
activeValue() {
|
|
|
|
return this.value.length > 0 ? this.value : this.barcodeValue;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
setValue(e) {
|
|
|
|
this.value = e.target.value;
|
|
|
|
},
|
|
|
|
setBarcodeValue(e) {
|
|
|
|
this.barcodeValue = e.target.value;
|
|
|
|
},
|
|
|
|
openBarcodeSearch() {
|
|
|
|
this.clearValues();
|
2023-08-01 16:41:58 +08:00
|
|
|
this.searchOpened = false;
|
2023-05-11 17:21:50 +08:00
|
|
|
this.barcodeSearchOpened = true;
|
|
|
|
this.$nextTick(() => {
|
|
|
|
this.$refs.barcodeSearchInput.focus();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
openSearch() {
|
|
|
|
this.clearValues();
|
2023-08-01 16:41:58 +08:00
|
|
|
this.barcodeSearchOpened = false;
|
2023-05-11 17:21:50 +08:00
|
|
|
this.searchOpened = true;
|
|
|
|
this.$nextTick(() => {
|
|
|
|
this.$refs.searchInput.focus();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
closeBarcodeSearch() {
|
|
|
|
if (this.barcodeValue.length == 0) {
|
2023-05-23 18:33:07 +08:00
|
|
|
setTimeout(() => {
|
|
|
|
this.barcodeSearchOpened = false;
|
|
|
|
}, 100);
|
2023-05-11 17:21:50 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
closeSearch() {
|
|
|
|
if (this.value.length == 0) {
|
2023-05-23 18:33:07 +08:00
|
|
|
setTimeout(() => {
|
|
|
|
this.searchOpened = false;
|
|
|
|
}, 100);
|
2023-05-11 17:21:50 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
updateRepositoySearch() {
|
|
|
|
$('.dataTables_filter input').val(this.activeValue).trigger('keyup');
|
|
|
|
},
|
|
|
|
clearValues() {
|
|
|
|
this.value = '';
|
|
|
|
this.barcodeValue = '';
|
|
|
|
if (this.$refs.searchInput) this.$refs.searchInput.value = '';
|
|
|
|
if (this.$refs.barcodeSearchInput) this.$refs.barcodeSearchInput.value = '';
|
2023-08-01 16:41:58 +08:00
|
|
|
},
|
|
|
|
closeSearchInputs() {
|
|
|
|
this.closeSearch();
|
|
|
|
this.closeBarcodeSearch();
|
2023-05-11 17:21:50 +08:00
|
|
|
}
|
|
|
|
}
|
2024-01-04 23:34:36 +08:00
|
|
|
};
|
2023-05-11 17:21:50 +08:00
|
|
|
</script>
|