From: marina Date: Tue, 28 Jan 2025 14:42:58 +0000 (+0300) Subject: ERP-282 Нужно сделать интерфейс настройки магазина X-Git-Tag: 1.7~34^2 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=e708cc3408320738f3d01d3a34d72f0945a60360;p=erp24_rep%2Fyii-erp24%2F.git ERP-282 Нужно сделать интерфейс настройки магазина --- 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',