From e708cc3408320738f3d01d3a34d72f0945a60360 Mon Sep 17 00:00:00 2001 From: marina Date: Tue, 28 Jan 2025 17:42:58 +0300 Subject: [PATCH] =?utf8?q?ERP-282=20=D0=9D=D1=83=D0=B6=D0=BD=D0=BE=20?= =?utf8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D1=82=D1=8C=20=D0=B8=D0=BD=D1=82?= =?utf8?q?=D0=B5=D1=80=D1=84=D0=B5=D0=B9=D1=81=20=D0=BD=D0=B0=D1=81=D1=82?= =?utf8?q?=D1=80=D0=BE=D0=B9=D0=BA=D0=B8=20=D0=BC=D0=B0=D0=B3=D0=B0=D0=B7?= =?utf8?q?=D0=B8=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/composer.json | 3 +- .../controllers/CityStoreParamsController.php | 33 +++++++++++++++- erp24/views/city-store-params/index.php | 39 +++++++++++-------- 3 files changed, 57 insertions(+), 18 deletions(-) diff --git a/erp24/composer.json b/erp24/composer.json index 965f092c..ec2445cc 100644 --- a/erp24/composer.json +++ b/erp24/composer.json @@ -37,7 +37,8 @@ "ext-xmlreader": "*", "enqueue/amqp-lib": "^0.10.19", "vlucas/phpdotenv": "^5.6", - "softark/yii2-dual-listbox": "^1.0" + "softark/yii2-dual-listbox": "^1.0", + "kartik-v/yii2-widget-depdrop": "dev-master" }, "require-dev": { "yiisoft/yii2-debug": "~2.1.0", diff --git a/erp24/controllers/CityStoreParamsController.php b/erp24/controllers/CityStoreParamsController.php index 65ae2405..9566e32a 100644 --- a/erp24/controllers/CityStoreParamsController.php +++ b/erp24/controllers/CityStoreParamsController.php @@ -197,7 +197,7 @@ class CityStoreParamsController extends Controller return [ 'success' => true, - 'data' => ArrayHelper::map($stores, 'id', function($store) { + 'data' => ArrayHelper::map($stores, 'id', function ($store) { return $store->id . ' ' . $store->name; }), ]; @@ -263,4 +263,35 @@ class CityStoreParamsController extends Controller ] ]; } + + public function actionGetAddressData() + { + $params = Yii::$app->request->post()['depdrop_all_params'] ?? []; + + if (isset($params['region'])) { + $cities = StoreCityList::findAll(['parent_id' => $params['region'], 'type' => StoreCityList::TYPE_CITY]); + if (!empty($cities)) { + $cityList = array_map(fn($city) => ['id' => $city->id, 'name' => $city->name], $cities); + + return json_encode([ + 'output' => $cityList, + 'selected' => $params['address_city'] ?? '' + ]); + } + } + + if (isset($params['city'])) { + $districts = StoreCityList::findAll(['parent_id' => $params['city'], 'type' => StoreCityList::TYPE_DISTRICT]); + if (!empty($districts)) { + $districtList = array_map(fn($district) => ['id' => $district->id, 'name' => $district->name], $districts); + + return json_encode([ + 'output' => $districtList, + 'selected' => $params['address_district'] ?? '' + ]); + } + } + + return json_encode(['output' => [], 'selected' => '']); + } } diff --git a/erp24/views/city-store-params/index.php b/erp24/views/city-store-params/index.php index a65101a8..463d8b90 100644 --- a/erp24/views/city-store-params/index.php +++ b/erp24/views/city-store-params/index.php @@ -9,6 +9,7 @@ use yii_app\records\AdminGroup; use yii_app\records\CityStore; use yii_app\records\StoreCityList; use yii_app\records\StoreType; +use kartik\depdrop\DepDrop; /* @var $this yii\web\View */ /* @var $dataProvider yii\data\ActiveDataProvider */ @@ -45,9 +46,9 @@ $this->registerJsFile('/js/city-store-params/city-store-params.js', ['position' 'class' => 'd-block mt-2 text-decoration-none', 'target' => '_blank' ]); ?> - +
registerJsFile('/js/city-store-params/city-store-params.js', ['position'
- 'CityStoreParams[address_region]', 'value' => null, - 'data' => [], + 'data' => ArrayHelper::map(StoreCityList::findAll(['type' => StoreCityList::TYPE_REGION]), 'id', 'name'), 'options' => [ 'placeholder' => 'Регион', 'class' => 'form-select', @@ -227,35 +228,41 @@ $this->registerJsFile('/js/city-store-params/city-store-params.js', ['position' ], ]); ?>
+
- 'CityStoreParams[address_city]', - 'value' => null, - 'data' => [], 'options' => [ + 'id' => 'city', 'placeholder' => 'Город', 'class' => 'form-select', - 'id' => 'city', ], 'pluginOptions' => [ - 'allowClear' => true, + 'depends' => ['region'], + 'placeholder' => 'Город', + 'url' => Url::to(['/city-store-params/get-address-data']), + 'params' => ['region'], + 'initialize' => true, ], ]); ?>
+
- 'CityStoreParams[address_district]', - 'value' => null, - 'data' => [], 'options' => [ + 'id' => 'district', 'placeholder' => 'Район', 'class' => 'form-select', - 'id' => 'district', ], 'pluginOptions' => [ - 'allowClear' => true, + 'depends' => ['city'], + 'placeholder' => 'Район', + 'url' => Url::to(['/city-store-params/get-address-data']), + 'params' => ['city'], + 'initialize' => false, ], ]); ?>
@@ -265,7 +272,7 @@ $this->registerJsFile('/js/city-store-params/city-store-params.js', ['position'
- 'CityStoreParams[territorial_manager]', 'value' => null, 'data' => [], @@ -285,10 +292,10 @@ $this->registerJsFile('/js/city-store-params/city-store-params.js', ['position'
- 'CityStoreParams[bush_chef_florist]', 'value' => null, - 'data' => [], + 'data' => [], 'options' => [ 'placeholder' => 'Кустовой шеф-флорист', 'class' => 'form-select', -- 2.39.5