feat(ui): improve product search and inventory interaction

- Добавить двойной клик по товару в поисковике для быстрого добавления
- Добавить автофокус и селект на поле ввода количества при добавлении товара в инвентарь
- Вынести логику поиска товара по ID в отдельный метод _findProductById для переиспользования
This commit is contained in:
2026-01-26 23:40:27 +03:00
parent 67ad0e50ee
commit 9a7c0728f0
2 changed files with 36 additions and 12 deletions

View File

@@ -402,6 +402,13 @@
const completeBtn = document.getElementById('complete-inventory-btn'); const completeBtn = document.getElementById('complete-inventory-btn');
if (completeBtn) completeBtn.disabled = false; if (completeBtn) completeBtn.disabled = false;
// Фокус на поле ввода количества в новой строке
const quantityInput = newRow.querySelector('.quantity-fact-input');
if (quantityInput) {
quantityInput.focus();
quantityInput.select();
}
this.showNotification('Товар добавлен', 'success'); this.showNotification('Товар добавлен', 'success');
} else { } else {
this.showNotification('Ошибка: ' + (data.error || 'Не удалось добавить товар'), 'error'); this.showNotification('Ошибка: ' + (data.error || 'Не удалось добавить товар'), 'error');

View File

@@ -207,6 +207,18 @@
self._toggleProduct(productId); self._toggleProduct(productId);
} }
}); });
// Двойной клик по товару - сразу добавляет в документ
this.elements.grid.addEventListener('dblclick', function(e) {
var productCard = e.target.closest('.product-picker-item');
if (productCard && self.options.onAddSelected) {
var productId = productCard.dataset.productId;
var product = self._findProductById(productId);
if (product) {
self.options.onAddSelected(product, self);
}
}
});
} }
// Добавить выбранный // Добавить выбранный
@@ -435,17 +447,7 @@
*/ */
ProductSearchPicker.prototype._toggleProduct = function(productId) { ProductSearchPicker.prototype._toggleProduct = function(productId) {
var self = this; var self = this;
var product = null; var product = this._findProductById(productId);
// Находим товар в списке
for (var i = 0; i < this.state.products.length; i++) {
var p = this.state.products[i];
if (String(p.id).replace('product_', '') === productId) {
product = p;
product.id = productId; // Сохраняем очищенный ID
break;
}
}
if (!product) return; if (!product) return;
@@ -473,6 +475,21 @@
this._updateSelectionUI(); this._updateSelectionUI();
}; };
/**
* Поиск товара по ID в загруженном списке
*/
ProductSearchPicker.prototype._findProductById = function(productId) {
for (var i = 0; i < this.state.products.length; i++) {
var p = this.state.products[i];
if (String(p.id).replace('product_', '') === productId) {
var product = Object.assign({}, p);
product.id = productId; // Сохраняем очищенный ID
return product;
}
}
return null;
};
/** /**
* Принудительно снять выделение со всех товаров * Принудительно снять выделение со всех товаров
*/ */