]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
правка отображения и скрытия подкатегорий и категорий
authormarina <m.zozirova@gmail.com>
Mon, 23 Jun 2025 15:20:49 +0000 (18:20 +0300)
committermarina <m.zozirova@gmail.com>
Mon, 23 Jun 2025 15:20:49 +0000 (18:20 +0300)
erp24/views/auto-plannogramma/index.php
erp24/web/js/autoplannogramma/autoplannogramma.js

index a2460b40e56ac7a9821a70b74a37a3bb3e9c842c..9ee91af0c7f654a0e334ea6715693ff3227c3a55 100644 (file)
@@ -219,7 +219,7 @@ $this->registerJsFile('/js/autoplannogramma/autoplannogramma.js', ['position' =>
                 </tr>
 
                 <?php foreach ($subcategories as $subcategory): ?>
-                    <tr>
+                    <tr class="subcategory-row">
                         <td class="subcategory subcategory-cell">
                             <span class="list-group-item list-group-item-action subcategory-label"
                                   data-category="<?= Html::encode($category) ?>"
index e4caabafd708f209f98483ea223d268fb8e6630f..e337b58d11f19f8bd79241df591c8fea976a5055 100644 (file)
@@ -49,7 +49,6 @@ $(document).ready(function () {
 
 $('.subcategory .list-group-item').on('click', function (e) {
     e.preventDefault();
-
     window.getSelection()?.removeAllRanges();
     $(this).blur();
 
@@ -66,39 +65,42 @@ $('.subcategory .list-group-item').on('click', function (e) {
     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;
@@ -113,20 +115,24 @@ $('.subcategory .list-group-item').on('click', function (e) {
         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 => [
@@ -141,7 +147,6 @@ $('.subcategory .list-group-item').on('click', function (e) {
                 $('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');
@@ -152,28 +157,27 @@ $('.subcategory .list-group-item').on('click', function (e) {
                     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);
                 });
 
@@ -181,10 +185,7 @@ $('.subcategory .list-group-item').on('click', function (e) {
             });
 
             $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 || 'Неизвестная ошибка сервера'));
@@ -203,13 +204,24 @@ $('.category .list-group-item').on('click', function () {
 
     $('.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');