From ea903448e8b6c79b94039717053957d40f6727ee Mon Sep 17 00:00:00 2001 From: marina Date: Tue, 17 Jun 2025 11:08:55 +0300 Subject: [PATCH] =?utf8?q?ERP-360=20=D0=A1=D0=B1=D0=BE=D1=80=D0=BA=D0=B0?= =?utf8?q?=20=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8=D1=86=D1=8B=20=D0=B0?= =?utf8?q?=D0=B2=D1=82=D0=BE=D0=BF=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../js/autoplannogramma/autoplannogramma.js | 166 +++++++----------- 1 file changed, 59 insertions(+), 107 deletions(-) diff --git a/erp24/web/js/autoplannogramma/autoplannogramma.js b/erp24/web/js/autoplannogramma/autoplannogramma.js index ee2c80fa..0fd2b4e7 100644 --- a/erp24/web/js/autoplannogramma/autoplannogramma.js +++ b/erp24/web/js/autoplannogramma/autoplannogramma.js @@ -42,120 +42,72 @@ document.addEventListener("DOMContentLoaded", () => { }); }); -$('.subcategory .list-group-item').on('click', function (e) { - e.preventDefault(); - window.getSelection()?.removeAllRanges(); - this.blur(); - - if (!$('#week').val() || !$('#year').val()) { - alert('Необходимо выбрать год и неделю для отображения планограммы'); - return; - } - - const $link = $(this); - const category = $link.data('category'); - const subcategory = $link.data('subcategory'); - const $row = $link.closest('tr'); - const filters = getFilterData(); - filters['month'] = getMonthByWeek(filters['week'], filters['year'], true); - filters.category = category; - filters.subcategory = subcategory; - - $('.loader-overlay').removeClass('d-none'); - - $.get('/auto-plannogramma/get-products', filters, response => { - $row.nextAll('tr.inserted-row').remove(); - - if (!response || response.length === 0) { - alert('Нет планограммы для выбранного периода'); +response.forEach(item => { + const tr = $(''); + + const subcategoryTd = $(` + + + ${item.name} + + + `); + tr.append(subcategoryTd); + + const valuesMap = Object.fromEntries(item.values.map(val => [ + val.store_id, + { + quantity: val.quantity, + id: val.id, + title: val.title || {} } + ])); - // Функция генерации текста для title - function generateTitleString(titleObj) { - if (!titleObj || typeof titleObj !== 'object') return ''; - let parts = []; + $('table thead th').each(function (index) { + const $th = $(this); + const storeId = $th.data('store-id'); - for (const [type, groups] of Object.entries(titleObj)) { - if (typeof groups !== 'object') continue; - let groupParts = []; - for (const [group, value] of Object.entries(groups)) { - groupParts.push(`${group}: ${value}`); - } - parts.push(`${type} — ${groupParts.join(', ')}`); - } + if (storeId === undefined) return; - return parts.join(' | '); - } + const isVisible = $(`table tbody tr:first td:eq(${index})`).is(':visible'); + if (!isVisible) return; - response.forEach(item => { - const tr = $(''); - - const subcategoryTd = $(` - - - ${item.name} - - - `); - tr.append(subcategoryTd); - - const valuesMap = Object.fromEntries(item.values.map(val => [ - val.store_id, - { - quantity: val.quantity, - id: val.id, - title: val.title || {} - } - ])); - - $('table thead th').each(function (index) { - const $th = $(this); - const storeId = $th.data('store-id'); - - if (storeId === undefined) return; - - const isVisible = $(`table tbody tr:first td:eq(${index})`).is(':visible'); - if (!isVisible) return; - - const tooltipTitle = generateTitleString(val.title); - const encodedTooltip = $('
').text(tooltipTitle).html(); // безопасно экранируем - - const td = $(` - -
- - -
- - `); - - tr.append(td); - }); + const val = valuesMap[storeId]; + if (!val) { + tr.append(``); + return; + } - $row.after(tr); - }); + const tooltipTitle = generateTitleString(val.title); + const encodedTooltip = $('
').text(tooltipTitle).html(); + + const td = $(` + +
+ + +
+ + `); + + tr.append(td); + }); - // Инициализация Bootstrap tooltips - $('[data-bs-toggle="tooltip"]').tooltip(); - }) - .fail(xhr => alert('Ошибка: ' + xhr.responseText)) - .always(() => { - $('.loader-overlay').addClass('d-none'); - }); + $row.after(tr); }); $('.category .list-group-item').on('click', function () { -- 2.39.5