]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Связывание фильтров адреса
authorVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Fri, 25 Jul 2025 08:15:21 +0000 (11:15 +0300)
committerVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Fri, 25 Jul 2025 08:15:21 +0000 (11:15 +0300)
erp24/controllers/AutoPlannogrammaController.php
erp24/web/js/autoplannogramma/autoplannogramma.js

index 7dcf9bcae9d4267c047f2683d93fcc798749ae99..a5e2df8ebd554936f773d0b55f85cbc4524400bb 100644 (file)
@@ -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];
+    }
 }
index 1c5ce1f2f7c3cfa6a0027ab3b30399bab54961b3..3b52f3e69a8aefbf6b222a58fd2cd178cd0d7950 100644 (file)
@@ -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('<option></option>');
+
+        districtSelect.val(null).trigger('change');
+        districtSelect.empty().append('<option></option>');
+
+        if (regionId) {
+            $.get('/auto-plannogramma/city-list?region_id=' + regionId, function (data) {
+                $.each(data, function (id, name) {
+                    citySelect.append('<option value="' + id + '">' + name + '</option>');
+                });
+            });
+        }
+    });
+
+    $('#city').on('change', function () {
+        var cityId = $(this).val();
+        var regionSelect = $('#region');
+        var districtSelect = $('#district');
+
+        districtSelect.val(null).trigger('change');
+        districtSelect.empty().append('<option></option>');
+
+        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('<option value="' + data.id + '">' + data.name + '</option>');
+                    }
+                    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('<option value="' + id + '">' + name + '</option>');
+                });
+            });
+        }
+    });
+
 
     document.querySelectorAll(".category").forEach(category => {
         category.addEventListener("click", function () {