Добавлена поддержка ProductKit в POS, улучшена прокрутка и фиксация элементов
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
// POS Terminal JavaScript
|
||||
|
||||
const CATEGORIES = JSON.parse(document.getElementById('categoriesData').textContent);
|
||||
const PRODUCTS = JSON.parse(document.getElementById('productsData').textContent);
|
||||
const ITEMS = JSON.parse(document.getElementById('itemsData').textContent); // Единый массив товаров и комплектов
|
||||
|
||||
// Отладка: проверить количество загруженных товаров
|
||||
// Отладка: проверить количество загруженных позиций
|
||||
console.log('Загружено категорий:', CATEGORIES.length);
|
||||
console.log('Загружено товаров:', PRODUCTS.length);
|
||||
console.log('Товары:', PRODUCTS);
|
||||
console.log('Загружено позиций (товары + комплекты):', ITEMS.length);
|
||||
const productsCount = ITEMS.filter(i => i.type === 'product').length;
|
||||
const kitsCount = ITEMS.filter(i => i.type === 'kit').length;
|
||||
console.log(` - Товаров: ${productsCount}, Комплектов: ${kitsCount}`);
|
||||
console.log('Позиции:', ITEMS);
|
||||
|
||||
let currentCategoryId = null;
|
||||
const cart = new Map(); // productId -> {id, name, price, qty}
|
||||
@@ -72,48 +75,48 @@ function renderProducts() {
|
||||
const searchTerm = document.getElementById('searchInput').value.toLowerCase();
|
||||
|
||||
let filtered = currentCategoryId
|
||||
? PRODUCTS.filter(p => (p.category_ids || []).includes(currentCategoryId))
|
||||
: PRODUCTS;
|
||||
? ITEMS.filter(item => (item.category_ids || []).includes(currentCategoryId))
|
||||
: ITEMS;
|
||||
|
||||
if (searchTerm) {
|
||||
filtered = filtered.filter(p => p.name.toLowerCase().includes(searchTerm));
|
||||
filtered = filtered.filter(item => item.name.toLowerCase().includes(searchTerm));
|
||||
}
|
||||
|
||||
filtered.forEach(p => {
|
||||
filtered.forEach(item => {
|
||||
const col = document.createElement('div');
|
||||
col.className = 'col-6 col-sm-4 col-md-3 col-lg-2';
|
||||
|
||||
const card = document.createElement('div');
|
||||
card.className = 'card product-card';
|
||||
card.onclick = () => addToCart(p);
|
||||
card.onclick = () => addToCart(item);
|
||||
|
||||
const body = document.createElement('div');
|
||||
body.className = 'card-body';
|
||||
|
||||
// Изображение товара
|
||||
// Изображение товара/комплекта
|
||||
const imageDiv = document.createElement('div');
|
||||
imageDiv.className = 'product-image';
|
||||
if (p.image) {
|
||||
if (item.image) {
|
||||
const img = document.createElement('img');
|
||||
img.src = p.image;
|
||||
img.alt = p.name;
|
||||
img.src = item.image;
|
||||
img.alt = item.name;
|
||||
imageDiv.appendChild(img);
|
||||
} else {
|
||||
imageDiv.innerHTML = '<i class="bi bi-image"></i>';
|
||||
}
|
||||
|
||||
// Информация о товаре
|
||||
// Информация о товаре/комплекте
|
||||
const info = document.createElement('div');
|
||||
info.className = 'product-info';
|
||||
|
||||
const name = document.createElement('div');
|
||||
name.className = 'product-name';
|
||||
name.textContent = p.name;
|
||||
name.textContent = item.name;
|
||||
|
||||
const stock = document.createElement('div');
|
||||
stock.className = 'product-stock';
|
||||
stock.textContent = p.in_stock ? 'В наличии' : 'Под заказ';
|
||||
if (!p.in_stock) {
|
||||
stock.textContent = item.in_stock ? 'В наличии' : 'Под заказ';
|
||||
if (!item.in_stock) {
|
||||
stock.style.color = '#dc3545';
|
||||
}
|
||||
|
||||
@@ -121,11 +124,11 @@ function renderProducts() {
|
||||
sku.className = 'product-sku';
|
||||
|
||||
const skuText = document.createElement('span');
|
||||
skuText.textContent = p.sku || 'н/д';
|
||||
skuText.textContent = item.sku || 'н/д';
|
||||
|
||||
const priceSpan = document.createElement('span');
|
||||
priceSpan.className = 'product-price';
|
||||
priceSpan.textContent = `${formatMoney(p.price)}`;
|
||||
priceSpan.textContent = `${formatMoney(item.price)}`;
|
||||
|
||||
sku.appendChild(skuText);
|
||||
sku.appendChild(priceSpan);
|
||||
@@ -142,11 +145,11 @@ function renderProducts() {
|
||||
});
|
||||
}
|
||||
|
||||
function addToCart(p) {
|
||||
if (!cart.has(p.id)) {
|
||||
cart.set(p.id, { id: p.id, name: p.name, price: Number(p.price), qty: 1 });
|
||||
function addToCart(item) {
|
||||
if (!cart.has(item.id)) {
|
||||
cart.set(item.id, { id: item.id, name: item.name, price: Number(item.price), qty: 1, type: item.type });
|
||||
} else {
|
||||
cart.get(p.id).qty += 1;
|
||||
cart.get(item.id).qty += 1;
|
||||
}
|
||||
renderCart();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user