$('.subcategory .list-group-item').on('click', function (e) {
e.preventDefault();
-
window.getSelection()?.removeAllRanges();
$(this).blur();
const $row = $link.closest('tr');
const $nextRow = $row.next();
- const subcategoryLabel = $link.closest('td.subcategory-cell').find('span.subcategory-label').text();
- if (subcategoryLabel.includes('нет данных')) {
+ const label = $link.closest('td').find('span.subcategory-label').text();
+ if (label.includes('нет данных')) {
alert('Нет планограммы для выбранного периода');
return;
}
-
+
if ($nextRow.hasClass('inserted-row')) {
- if ($nextRow.hasClass('d-none')) {
- $('tr.inserted-row').each(function () {
- const $insertedRow = $(this);
- const $span = $insertedRow.find('.list-group-item[data-category][data-subcategory]').first();
- const rowCategory = $span.data('category');
- const rowSubcategory = $span.data('subcategory');
+ const $span = $nextRow.find('.list-group-item[data-category][data-subcategory]').first();
+ const rowCategory = $span.data('category');
+ const rowSubcategory = $span.data('subcategory');
- if (rowCategory === category && rowSubcategory === subcategory) {
- $insertedRow.removeClass('d-none');
- }
- });
- } else {
+ if (rowCategory === category && rowSubcategory === subcategory) {
+ const isHidden = $nextRow.hasClass('d-none');
$('tr.inserted-row').each(function () {
- const $insertedRow = $(this);
- const $span = $insertedRow.find('.list-group-item[data-category][data-subcategory]').first();
- const rowCategory = $span.data('category');
- const rowSubcategory = $span.data('subcategory');
+ const $r = $(this);
+ const $s = $r.find('.list-group-item[data-category][data-subcategory]').first();
+ const rc = $s.data('category');
+ const rs = $s.data('subcategory');
- if (rowCategory === category && rowSubcategory === subcategory) {
- $insertedRow.addClass('d-none');
+ if (rc === category && rs === subcategory) {
+ $r.toggleClass('d-none', !isHidden);
}
});
+ return;
}
- return;
}
+ $('tr.inserted-row').each(function () {
+ const $span = $(this).find('.list-group-item[data-category][data-subcategory]').first();
+ const rowCategory = $span.data('category');
+
+ if (rowCategory !== category) {
+ $(this).addClass('d-none');
+ }
+ });
+
const filters = getFilterData();
filters.month = getMonthByWeek(week, year, true);
filters.category = category;
success: function (response) {
$row.nextAll('tr.inserted-row').remove();
+ if (!Array.isArray(response) || response.length === 0) {
+ alert('Нет планограммы для выбранного периода');
+ return;
+ }
+
const fragment = document.createDocumentFragment();
response.forEach(item => {
const tr = $('<tr>').addClass('inserted-row');
-
const subcategoryTd = $(`
- <td class="subcategory d-flex justify-content-end">
- <span class="list-group-item list-group-item-action subcategory-link w-90"
- data-category="${category}"
- data-subcategory="${subcategory}">
- ${item.name || ''}
- </span>
- </td>
- `);
+ <td class="subcategory d-flex justify-content-end">
+ <span class="list-group-item list-group-item-action subcategory-link w-90"
+ data-category="${category}"
+ data-subcategory="${subcategory}">
+ ${item.name || ''}
+ </span>
+ </td>
+ `);
tr.append(subcategoryTd);
const valuesMap = new Map(item.values?.map(val => [
$('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');
const encodedTooltip = $('<div>').text(tooltipTitle).html();
const td = $(`
- <td data-store-id="${storeId}">
- <div class="d-flex align-items-center">
- <input type="number"
- class="btn btn-primary input w-100"
- value="${val.quantity}"
- data-id="${val.id}"
- data-guid="${item.product_id || ''}"
- data-store_id="${storeId}"
- title="${encodedTooltip}"
- data-bs-toggle="tooltip"
- data-bs-placement="top"
- data-original-value="${val.quantity}">
- <button class="reject-btn border-0 bg-transparent cursor-pointer">
- <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
- <path d="M20 11v5a1 1 0 0 1-2 0v-4H7.414l1.293 1.293a1 1 0 0 1-1.414 1.414l-3-3a1 1 0 0 1 0-1.416l3-3a1 1 0 1 1 1.414 1.416L7.414 10H19a1 1 0 0 1 1 1z"
- fill="grey" stroke="none"/>
- </svg>
- </button>
- </div>
- </td>
- `);
-
+ <td data-store-id="${storeId}">
+ <div class="d-flex align-items-center">
+ <input type="number"
+ class="btn btn-primary input w-100"
+ value="${val.quantity}"
+ data-id="${val.id}"
+ data-guid="${item.product_id || ''}"
+ data-store_id="${storeId}"
+ title="${encodedTooltip}"
+ data-bs-toggle="tooltip"
+ data-bs-placement="top"
+ data-original-value="${val.quantity}">
+ <button class="reject-btn border-0 bg-transparent cursor-pointer">
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
+ <path d="M20 11v5a1 1 0 0 1-2 0v-4H7.414l1.293 1.293a1 1 0 0 1-1.414 1.414l-3-3a1 1 0 0 1 0-1.416l3-3a1 1 0 1 1 1.414 1.416L7.414 10H19a1 1 0 0 1 1 1z"
+ fill="grey" stroke="none"/>
+ </svg>
+ </button>
+ </div>
+ </td>
+ `);
tr.append(td);
});
});
$row.after(fragment);
-
- $('[data-bs-toggle="tooltip"]').tooltip({
- customClass: 'custom-tooltip'
- });
+ $('[data-bs-toggle="tooltip"]').tooltip({customClass: 'custom-tooltip'});
},
error: function (xhr) {
alert('Ошибка: ' + (xhr.responseText || 'Неизвестная ошибка сервера'));
$('.loader-overlay').removeClass('d-none');
+ $('tr.subcategory-row').each(function () {
+ const $span = $(this).find('.list-group-item[data-category][data-subcategory]').first();
+ const rowCategory = $span.data('category');
+
+ if (rowCategory === category) {
+ $(this).removeClass('d-none');
+ } else {
+ $(this).addClass('d-none');
+ }
+ });
+
$.get('/auto-plannogramma/get-subcategories', {category, year, week}, function (subcategories) {
const subMap = {};
subcategories.forEach(sub => {
subMap[sub.name] = sub.hasdata;
});
- $(`span.list-group-item[data-category="${category}"]`).each(function () {
+ $(`.subcategory-cell span.list-group-item[data-category="${category}"]`).each(function () {
const $span = $(this);
const subName = $span.data('subcategory');