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;
]);
}
+
+ // Получить города по региону
+ 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];
+ }
}
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 () {