POS search improvements: clear button, 600ms debounce, empty screen on clear
This commit is contained in:
@@ -1013,25 +1013,51 @@ function getCsrfToken() {
|
|||||||
|
|
||||||
// Обработчик поиска с debounce
|
// Обработчик поиска с debounce
|
||||||
const searchInput = document.getElementById('searchInput');
|
const searchInput = document.getElementById('searchInput');
|
||||||
|
const clearSearchBtn = document.getElementById('clearSearchBtn');
|
||||||
|
|
||||||
searchInput.addEventListener('input', (e) => {
|
searchInput.addEventListener('input', (e) => {
|
||||||
const query = e.target.value.trim();
|
const query = e.target.value.trim();
|
||||||
|
|
||||||
|
// Показываем/скрываем кнопку очистки
|
||||||
|
if (e.target.value.length > 0) {
|
||||||
|
clearSearchBtn.style.display = 'block';
|
||||||
|
} else {
|
||||||
|
clearSearchBtn.style.display = 'none';
|
||||||
|
}
|
||||||
|
|
||||||
// Отменяем предыдущий таймер
|
// Отменяем предыдущий таймер
|
||||||
if (searchDebounceTimer) {
|
if (searchDebounceTimer) {
|
||||||
clearTimeout(searchDebounceTimer);
|
clearTimeout(searchDebounceTimer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Если поле пустое — очищаем экран
|
||||||
|
if (query === '') {
|
||||||
|
currentSearchQuery = '';
|
||||||
|
ITEMS = []; // Очистка
|
||||||
|
renderProducts(); // Пустой экран
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Для витрины — мгновенная клиентская фильтрация
|
// Для витрины — мгновенная клиентская фильтрация
|
||||||
if (isShowcaseView) {
|
if (isShowcaseView) {
|
||||||
renderProducts();
|
renderProducts();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Для обычных товаров/комплектов — серверный поиск с debounce 300мс
|
// Для обычных товаров/комплектов — серверный поиск с debounce 600мс
|
||||||
searchDebounceTimer = setTimeout(async () => {
|
searchDebounceTimer = setTimeout(async () => {
|
||||||
currentSearchQuery = query;
|
currentSearchQuery = query;
|
||||||
await loadItems(); // Перезагрузка с серверным поиском
|
await loadItems(); // Перезагрузка с серверным поиском
|
||||||
}, 300);
|
}, 600);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Обработчик кнопки очистки поиска
|
||||||
|
clearSearchBtn.addEventListener('click', () => {
|
||||||
|
searchInput.value = '';
|
||||||
|
clearSearchBtn.style.display = 'none';
|
||||||
|
currentSearchQuery = '';
|
||||||
|
ITEMS = [];
|
||||||
|
renderProducts(); // Пустой экран
|
||||||
});
|
});
|
||||||
|
|
||||||
// Инициализация
|
// Инициализация
|
||||||
|
|||||||
@@ -15,7 +15,12 @@
|
|||||||
<div class="col-md-8" style="display: flex; flex-direction: column; height: 100%;">
|
<div class="col-md-8" style="display: flex; flex-direction: column; height: 100%;">
|
||||||
<!-- Search Box -->
|
<!-- Search Box -->
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<input type="text" class="form-control" id="searchInput" placeholder="Поиск по товарам...">
|
<div class="input-group">
|
||||||
|
<input type="text" class="form-control" id="searchInput" placeholder="Поиск по товарам...">
|
||||||
|
<button class="btn btn-outline-secondary" type="button" id="clearSearchBtn" style="display: none;">
|
||||||
|
<i class="bi bi-x-lg"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Categories -->
|
<!-- Categories -->
|
||||||
|
|||||||
Reference in New Issue
Block a user