From: Vladimir Fomichev Date: Tue, 17 Jun 2025 07:37:56 +0000 (+0300) Subject: простановка тултипов X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=f3c6a4085b7359787fec23b5b25097589ae073cf;p=erp24_rep%2Fyii-erp24%2F.git простановка тултипов --- diff --git a/erp24/controllers/AutoPlannogrammaController.php b/erp24/controllers/AutoPlannogrammaController.php index 3c52596c..46dff5e6 100644 --- a/erp24/controllers/AutoPlannogrammaController.php +++ b/erp24/controllers/AutoPlannogrammaController.php @@ -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' => 'Нет параметров']; } diff --git a/erp24/web/js/autoplannogramma/autoplannogramma.js b/erp24/web/js/autoplannogramma/autoplannogramma.js index f8df9689..481b2851 100644 --- a/erp24/web/js/autoplannogramma/autoplannogramma.js +++ b/erp24/web/js/autoplannogramma/autoplannogramma.js @@ -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 = '
Прогноз:
'; + for (const [type, groups] of Object.entries(productData)) { + tooltip += `
${type}
    `; + for (const [group, value] of Object.entries(groups)) { + tooltip += `
  • ${group}: ${value}
  • `; + } + tooltip += `
`; + } + tooltip += '
'; + + return tooltip; +} + + + +