]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
простановка тултипов
authorVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Tue, 17 Jun 2025 07:37:56 +0000 (10:37 +0300)
committerVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Tue, 17 Jun 2025 07:37:56 +0000 (10:37 +0300)
erp24/controllers/AutoPlannogrammaController.php
erp24/web/js/autoplannogramma/autoplannogramma.js

index 3c52596c349d6a85d9b18d777a9865eeaa92fcd8..46dff5e6d239adfc5818f258831cbbd7df554fd4 100644 (file)
@@ -1750,10 +1750,15 @@ class AutoPlannogrammaController extends BaseController
         ]);
     }
 
-    public function actionWeeklyBouquetProductsForecast($storeId, $month, $year, $week)
+    public function actionWeeklyBouquetProductsForecast()
     {
         Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
+       $request = Yii::$app->request;
 
+           $storeId = $request->get('storeId', null);
+           $month = $request->get('month');
+           $year = $request->get('year');
+           $week = $request->get('week');
         if (!$month || !$year || $week === null) {
             return ['success' => false, 'message' => 'Нет параметров'];
         }
index f8df96891d6c88e55544e093da2f314f0447a13d..481b2851874ad829e76dfe66eeeaffdd49bdaa0e 100644 (file)
@@ -127,6 +127,26 @@ $('.subcategory .list-group-item').on('click', function (e) {
 
             $row.after(tr);
         });
+        document.body.addEventListener("mouseover", (e) => {
+            if (!e.target.matches("input[data-guid][data-store_id][data-bs-toggle='tooltip']")) return;
+            console.log('mouseover');
+            const input = e.target;
+            const guid = input.dataset.guid;
+            const storeId = input.dataset.store_id;
+            const week = document.getElementById("week")?.value;
+            console.log('mouseover', guid);
+            if (!guid || !storeId || !week) return;
+
+            const html = buildForecastTooltip(23, storeId, guid);
+            console.log(html);
+            if (html) {
+                input.setAttribute("title", ""); // обязательно
+                input.setAttribute("data-bs-original-title", html);
+                input.setAttribute("aria-label", html);
+
+                bootstrap.Tooltip.getOrCreateInstance(input, { html: true }).show();
+            }
+        });
     })
         .fail(xhr => alert('Ошибка: ' + xhr.responseText))
         .always(() => {
@@ -240,8 +260,8 @@ $(document).on('click', '.input', function () {
     const data = {
         storeId: storeId,
         year: year,
-        week: week,
-        month: month
+        week: 23,
+        month: 8
     };
 
     $.get('/auto-plannogramma/weekly-bouquet-products-forecast', data, (response) => {
@@ -251,6 +271,7 @@ $(document).on('click', '.input', function () {
         if ($el.tooltip) {
             $el.tooltip('dispose').tooltip();
         }
+
     });
 });
 
@@ -373,4 +394,56 @@ function getMonthNumberByWeek(week, year) {
         return startMonth;
     }
     return startMonth;
-}
\ No newline at end of file
+}
+
+
+// Глобальный кэш прогнозов
+const forecastCache = {};
+
+document.addEventListener("DOMContentLoaded", async () => {
+    const week = '23';
+    const month = 6;
+    const year = new Date().getFullYear();
+
+    if (!week) return;
+
+    try {
+        const response = await fetch(`/auto-plannogramma/weekly-bouquet-products-forecast?month=${month}&year=${year}&week=${week}`);
+        const json = await response.json();
+        if (json.success && json.data) {
+            Object.assign(forecastCache, json.data);
+        }
+        console.log(json);
+        console.log(forecastCache);
+    } catch (e) {
+        console.error("Ошибка загрузки прогнозов:", e);
+    }
+});
+
+function buildForecastTooltip(week, storeId, guid) {
+    console.log(week, storeId, guid);
+    const weekData = forecastCache[week];
+    if (!weekData) return null;
+
+    const storeData = weekData[storeId];
+    if (!storeData) return null;
+
+    const productData = storeData[guid];
+    if (!productData) return null;
+
+    let tooltip = '<div><strong>Прогноз:</strong><br>';
+    for (const [type, groups] of Object.entries(productData)) {
+        tooltip += `<div><em>${type}</em><ul>`;
+        for (const [group, value] of Object.entries(groups)) {
+            tooltip += `<li>${group}: ${value}</li>`;
+        }
+        tooltip += `</ul></div>`;
+    }
+    tooltip += '</div>';
+
+    return tooltip;
+}
+
+
+
+