From 7d5c0f1ab80bddfe0d38f4bbd837f35c697753f7 Mon Sep 17 00:00:00 2001 From: Vladimir Fomichev Date: Fri, 25 Jul 2025 11:15:21 +0300 Subject: [PATCH] =?utf8?q?=D0=A1=D0=B2=D1=8F=D0=B7=D1=8B=D0=B2=D0=B0=D0=BD?= =?utf8?q?=D0=B8=D0=B5=20=D1=84=D0=B8=D0=BB=D1=8C=D1=82=D1=80=D0=BE=D0=B2?= =?utf8?q?=20=D0=B0=D0=B4=D1=80=D0=B5=D1=81=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../AutoPlannogrammaController.php | 38 +++++++++++++ .../js/autoplannogramma/autoplannogramma.js | 53 +++++++++++++++++++ 2 files changed, 91 insertions(+) diff --git a/erp24/controllers/AutoPlannogrammaController.php b/erp24/controllers/AutoPlannogrammaController.php index 7dcf9bca..a5e2df8e 100644 --- a/erp24/controllers/AutoPlannogrammaController.php +++ b/erp24/controllers/AutoPlannogrammaController.php @@ -18,6 +18,7 @@ use yii_app\records\PricesDynamic; use yii_app\records\Products1c; use yii_app\records\Products1cNomenclature; use yii_app\records\CityStoreParams; +use yii_app\records\StoreCityList; use yii_app\records\StoreDynamic; use yii_app\records\SalesWriteOffsPlan; use yii_app\services\AutoPlannogrammaService; @@ -1851,4 +1852,41 @@ class AutoPlannogrammaController extends BaseController ]); } + + // Получить города по региону + public function actionCityList($region_id) + { + Yii::$app->response->format = Response::FORMAT_JSON; + $cities = StoreCityList::find() + ->where(['type' => StoreCityList::TYPE_CITY, 'parent_id' => $region_id]) + ->orderBy('name') + ->all(); + + return ArrayHelper::map($cities, 'id', 'name'); + } + +// Получить районы по городу + public function actionDistrictList($city_id) + { + Yii::$app->response->format = Response::FORMAT_JSON; + $districts = StoreCityList::find() + ->where(['type' => StoreCityList::TYPE_DISTRICT, 'parent_id' => $city_id]) + ->orderBy('name') + ->all(); + + return ArrayHelper::map($districts, 'id', 'name'); + } + + public function actionRegionByCity($city_id) + { + Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; + + $city = StoreCityList::findOne(['id' => $city_id, 'type' => StoreCityList::TYPE_CITY]); + if (!$city || !$city->parent_id) { + return ['id' => null, 'name' => null]; + } + + $region = StoreCityList::findOne(['id' => $city->parent_id, 'type' => StoreCityList::TYPE_REGION]); + return $region ? ['id' => $region->id, 'name' => $region->name] : ['id' => null, 'name' => null]; + } } diff --git a/erp24/web/js/autoplannogramma/autoplannogramma.js b/erp24/web/js/autoplannogramma/autoplannogramma.js index 1c5ce1f2..3b52f3e6 100644 --- a/erp24/web/js/autoplannogramma/autoplannogramma.js +++ b/erp24/web/js/autoplannogramma/autoplannogramma.js @@ -5,6 +5,59 @@ document.addEventListener("DOMContentLoaded", () => { row.style.display = "none"; } }); + let skipRegionChange = false; + + $('#region').on('change', function () { + if (skipRegionChange) return; + + var regionId = $(this).val(); + var citySelect = $('#city'); + var districtSelect = $('#district'); + + citySelect.val(null).trigger('change'); + citySelect.empty().append(''); + + districtSelect.val(null).trigger('change'); + districtSelect.empty().append(''); + + if (regionId) { + $.get('/auto-plannogramma/city-list?region_id=' + regionId, function (data) { + $.each(data, function (id, name) { + citySelect.append(''); + }); + }); + } + }); + + $('#city').on('change', function () { + var cityId = $(this).val(); + var regionSelect = $('#region'); + var districtSelect = $('#district'); + + districtSelect.val(null).trigger('change'); + districtSelect.empty().append(''); + + if (cityId) { + skipRegionChange = true; + + $.get('/auto-plannogramma/region-by-city?city_id=' + cityId, function (data) { + if (data && data.id) { + if (regionSelect.find("option[value='" + data.id + "']").length === 0) { + regionSelect.append(''); + } + regionSelect.val(data.id).trigger('change'); + } + skipRegionChange = false; + }); + + $.get('/auto-plannogramma/district-list?city_id=' + cityId, function (data) { + $.each(data, function (id, name) { + districtSelect.append(''); + }); + }); + } + }); + document.querySelectorAll(".category").forEach(category => { category.addEventListener("click", function () { -- 2.39.5