]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
ERP-282 Нужно сделать интерфейс настройки магазина
authormarina <m.zozirova@gmail.com>
Wed, 22 Jan 2025 06:44:50 +0000 (09:44 +0300)
committermarina <m.zozirova@gmail.com>
Wed, 22 Jan 2025 06:44:50 +0000 (09:44 +0300)
erp24/controllers/CityStoreParamsController.php
erp24/records/CityStore.php
erp24/views/city-store-params/index.php
erp24/web/js/city-store-params/city-store-params.js [new file with mode: 0644]

index b8987a8e8a486732c8958ecada093e1d2005339e..cd2dcfc56e08dfe0ca119d33d7e9805624fadb1d 100644 (file)
@@ -3,10 +3,14 @@
 namespace app\controllers;
 
 use Yii;
+use yii\base\Action;
 use yii\data\ActiveDataProvider;
+use yii\helpers\ArrayHelper;
 use yii\web\Controller;
 use yii\web\NotFoundHttpException;
 use yii\filters\VerbFilter;
+use yii\web\Response;
+use yii_app\records\CityStore;
 use yii_app\records\CityStoreParams;
 
 /**
@@ -107,4 +111,50 @@ class CityStoreParamsController extends Controller
 
         throw new NotFoundHttpException('The requested page does not exist.');
     }
+
+    public function actionEdit()
+    {
+
+        Yii::$app->response->format = Response::FORMAT_JSON;
+
+        $data = Yii::$app->request->get();
+        $addressCity = $data['address_city'] ?? '';
+        $addressRegion = $data['address_region'] ?? '';
+        $addressDistrict = $data['address_district'] ?? '';
+        $territorialManager = $data['territorial_manager'] ?? '';
+        $storeType = $data['store_type'] ?? '';
+        $bushChefFlorist = $data['bush_chef_florist'] ?? '';
+
+        $stores = CityStore::find()
+            ->andWhere(['=', 'visible', CityStore::IS_VISIBLE])
+            ->all();
+
+        return ArrayHelper::map($stores, 'id', function ($store) {
+            return $store->id . ' ' . $store->name;
+        });
+    }
+
+    public function getData()
+    {
+        Yii::$app->response->format = Response::FORMAT_JSON;
+
+        $storeId = Yii::$app->request->get('selected_store');
+
+        $store = CityStore::findOne($storeId);
+
+        if (empty($stores)) {
+            return ['error' => 'Не найдено магазинов'];
+        }
+
+        $storeTypes = ArrayHelper::map($stores, 'id', 'store_type');
+        $cities = ArrayHelper::map($stores, 'id', 'city');
+        $territorialManagers = ArrayHelper::map($stores, 'id', 'territorial_manager');
+
+        return [
+            'store_types' => $storeTypes,
+            'cities' => $cities,
+            'territorial_managers' => $territorialManagers,
+        ];
+
+    }
 }
index 2f7648dcffd769e42916d89ec3e068e8bcc66f01..0e4b322b9736734c82dfb44c0c92eec79a0c32c2 100755 (executable)
@@ -64,6 +64,8 @@ use Yii;
 class CityStore extends ActiveRecord
 {
 
+    public const IS_VISIBLE = 1;
+
     /**
      * {@inheritdoc}
      */
index 0e24789d93a3486a1208ee56642bf05ac17d9063..435a8659108b77288b9c6aebdd74726d6a056713 100644 (file)
@@ -2,47 +2,70 @@
 
 use kartik\select2\Select2;
 use softark\duallistbox\DualListbox;
+use yii\helpers\ArrayHelper;
 use yii\helpers\Html;
-use yii\grid\GridView;
+use yii\helpers\Url;
+use yii_app\records\Admin;
+use yii_app\records\AdminGroup;
 use yii_app\records\City;
+use yii_app\records\StoreCityList;
 
 /* @var $this yii\web\View */
 /* @var $dataProvider yii\data\ActiveDataProvider */
 
 $this->title = 'City Store Params';
 $this->params['breadcrumbs'][] = $this->title;
+
+$this->registerJsFile('/js/city-store-params/city-store-params.js', ['position' => \yii\web\View::POS_END]);
 ?>
     <div class="container mt-4 border-bottom">
         <div class="row">
             <div class="col-md-2">
                 <div class="card p-3 bg-light shadow-sm">
-                    <?= Html::dropDownList('address_city', null, \yii\helpers\ArrayHelper::map(City::find()->all(), 'id_city', 'city_name_ru'), ['prompt' => 'Выберите город', 'class' => 'form-select']); ?>
+                    <?= Html::dropDownList('address_city', null,
+                        ArrayHelper::map(StoreCityList::findAll(['type' => StoreCityList::TYPE_CITY]), 'id', 'name'),
+                        ['prompt' => 'Выберите город', 'class' => 'form-select', 'id' => 'address_city']);
+                    ?>
                 </div>
             </div>
 
             <div class="col-md-2">
                 <div class="card p-3 bg-light shadow-sm">
-                    <?= Html::dropDownList('address_region', null, \yii\helpers\ArrayHelper::map(City::find()->where(['!=', 'region_name', ''])->all(), 'id_region', 'region_name'), ['prompt' => 'Выберите регион', 'class' => 'form-select']); ?>
-                    <?= Html::a('Редактировать', [\yii\helpers\Url::to('/store_type')], ['class' => 'd-block mt-2 text-decoration-none']); ?>
+                    <?= Html::dropDownList('address_region', null,
+                        ArrayHelper::map(StoreCityList::findAll(['type' => StoreCityList::TYPE_REGION]), 'id', 'name'),
+                        ['prompt' => 'Выберите регион', 'class' => 'form-select', 'id' => 'address_region']);
+                    ?>
+                    <?= Html::a('Редактировать', [
+                            Url::to('/store_type')], ['class' => 'd-block mt-2 text-decoration-none']);
+                    ?>
                 </div>
             </div>
 
             <div class="col-md-2 border-end border-2">
                 <div class="card p-3 bg-light shadow-sm">
-                    <?= Html::dropDownList('address_district', null, \yii\helpers\ArrayHelper::map(City::find()->where(['!=', 'region_name', ''])->all(), 'id_region', 'region_name'), ['prompt' => 'Выберите район', 'class' => 'form-select']); ?>
+                    <?= Html::dropDownList('address_district', null,
+                        ArrayHelper::map(StoreCityList::findAll(['type' => StoreCityList::TYPE_DISTRICT]), 'id', 'name'),
+                        ['prompt' => 'Выберите район', 'class' => 'form-select', 'id' => 'address_district']);
+                    ?>
                 </div>
             </div>
 
             <div class="col-md-2 border-end border-2">
                 <div class="card p-3 bg-light shadow-sm">
-                    <?= Html::dropDownList('store_type', null, \yii\helpers\ArrayHelper::map(City::find()->where(['!=', 'region_name', ''])->all(), 'id_region', 'region_name'), ['prompt' => 'Выберите тип магазина', 'class' => 'form-select']); ?>
+                    <?= Html::dropDownList('store_type', null,
+                        ArrayHelper::map(City::find()->where(['!=', 'region_name', ''])->all(), 'id_region', 'region_name'),
+                        ['prompt' => 'Выберите тип магазина', 'class' => 'form-select', 'id' => 'store_type']);
+                    ?>
                     <?= Html::a('Редактировать', [\yii\helpers\Url::to('/store_type')], ['class' => 'd-block mt-2 text-decoration-none']); ?>
                 </div>
             </div>
 
             <div class="col-md-2 border-end border-2">
                 <div class="card p-3 bg-light shadow-sm">
-                    <?= Html::dropDownList('territorial_manager', null, \yii\helpers\ArrayHelper::map(\yii_app\api3\modules\v1\models\Admin::findAll(['group_id' => \yii_app\records\AdminGroup::GROUP_BUSH_DIRECTOR]), 'id', 'name_full'), ['prompt' => 'Выберите территориального управляющего', 'class' => 'form-select']); ?>
+                    <?= Html::dropDownList('territorial_manager', null,
+                        ArrayHelper::map(Admin::findAll(['group_id' => AdminGroup::GROUP_BUSH_DIRECTOR]), 'id', 'name_full'),
+                        ['prompt' => 'Выберите территориального управляющего', 'class' => 'form-select', 'id' => 'territorial_manager']);
+                    ?>
                 </div>
             </div>
         </div>
@@ -56,7 +79,10 @@ $this->params['breadcrumbs'][] = $this->title;
 
             <div class="col-md-2 border-end border-2">
                 <div class="card p-3 bg-light shadow-sm">
-                    <?= Html::dropDownList('bush_chef_florist', null, \yii\helpers\ArrayHelper::map(\yii_app\records\Admin::findAll(['group_id' => \yii_app\records\AdminGroup::GROUP_BUSH_CHEF_FLORIST]), 'id', 'name_full'), ['prompt' => 'Выберите кустового шеф флориста', 'class' => 'form-select']); ?>
+                    <?= Html::dropDownList('bush_chef_florist', null,
+                        ArrayHelper::map(Admin::findAll(['group_id' => \yii_app\records\AdminGroup::GROUP_BUSH_CHEF_FLORIST]), 'id', 'name_full'),
+                        ['prompt' => 'Выберите кустового шеф флориста', 'class' => 'form-select', 'id' => 'bush_chef_florist']);
+                    ?>
                 </div>
             </div>
 
@@ -64,7 +90,7 @@ $this->params['breadcrumbs'][] = $this->title;
 
             <div class="col-md-2 d-flex justify-content-center align-items-center">
                 <div class="card p-45 bg-light shadow-sm w-100">
-                    <?= Html::button('Применить', ['class' => 'btn btn-primary w-100']); ?>
+                    <?= Html::button('Применить', ['class' => 'btn btn-primary w-100', 'id' => 'apply-button']); ?>
                 </div>
             </div>
         </div>
@@ -75,16 +101,11 @@ $this->params['breadcrumbs'][] = $this->title;
         <div class="row">
             <div class="col-md-3">
                 <div class="form-group">
-                    <?= Html::dropDownList('selectedValues[]', null, [
-                        '1' => 'Option 1',
-                        '2' => 'Option 2',
-                        '3' => 'Option 3',
-                        '4' => 'Option 4',
-                    ], [
+                    <?= Html::dropDownList('selectedValues[]', null, [], [
                         'multiple' => true,
-                        'size' => 10,  // Количество отображаемых строк
-                        'class' => 'form-control', // Стиль для кнопки
-                        'id' => 'selectedValues', // ID для элемента
+                        'size' => 16,
+                        'class' => 'form-control',
+                        'id' => 'selected_store',
                     ]) ?>
                 </div>
             </div>
@@ -106,15 +127,15 @@ $this->params['breadcrumbs'][] = $this->title;
                         </div>
                         <div class="col-md-3">
                             <?= Html::label('Регион'); ?>
-                            <?= Html::dropDownList('city', null, \yii\helpers\ArrayHelper::map(\yii_app\api3\modules\v1\models\Admin::findAll(['group_id' => \yii_app\records\AdminGroup::GROUP_BUSH_DIRECTOR]), 'id', 'name_full'), ['prompt' => 'Город', 'class' => 'form-select']); ?>
+                            <?= Html::dropDownList('city', null, [], ['prompt' => 'Город', 'class' => 'form-select']); ?>
                         </div>
                         <div class="col-md-3">
                             <?= Html::label('Город'); ?>
-                            <?= Html::dropDownList('city', null, \yii\helpers\ArrayHelper::map(\yii_app\api3\modules\v1\models\Admin::findAll(['group_id' => \yii_app\records\AdminGroup::GROUP_BUSH_DIRECTOR]), 'id', 'name_full'), ['prompt' => 'Город', 'class' => 'form-select']); ?>
+                            <?= Html::dropDownList('city', null, [], ['prompt' => 'Город', 'class' => 'form-select']); ?>
                         </div>
                         <div class="col-md-3">
                             <?= Html::label('Район'); ?>
-                            <?= Html::dropDownList('city', null, \yii\helpers\ArrayHelper::map(\yii_app\api3\modules\v1\models\Admin::findAll(['group_id' => \yii_app\records\AdminGroup::GROUP_BUSH_DIRECTOR]), 'id', 'name_full'), ['prompt' => 'Город', 'class' => 'form-select']); ?>
+                            <?= Html::dropDownList('city', null, [], ['prompt' => 'Город', 'class' => 'form-select']); ?>
                         </div>
                     </div>
                     <div class="row">
@@ -124,7 +145,7 @@ $this->params['breadcrumbs'][] = $this->title;
 
                         </div>
                         <div class="col-md-9">
-                            <?= Html::dropDownList('city', null, \yii\helpers\ArrayHelper::map(\yii_app\api3\modules\v1\models\Admin::findAll(['group_id' => \yii_app\records\AdminGroup::GROUP_BUSH_DIRECTOR]), 'id', 'name_full'), ['prompt' => 'Город', 'class' => 'form-select']); ?>
+                            <?= Html::dropDownList('city', null, [], ['prompt' => 'Город', 'class' => 'form-select']); ?>
                         </div>
                     </div>
                     <div class="row border-bottom">
@@ -134,7 +155,7 @@ $this->params['breadcrumbs'][] = $this->title;
 
                         </div>
                         <div class="col-md-9">
-                            <?= Html::dropDownList('city', null, \yii\helpers\ArrayHelper::map(\yii_app\api3\modules\v1\models\Admin::findAll(['group_id' => \yii_app\records\AdminGroup::GROUP_BUSH_DIRECTOR]), 'id', 'name_full'), ['prompt' => 'Город', 'class' => 'form-select']); ?>
+                            <?= Html::dropDownList('city', null, [], ['prompt' => 'Город', 'class' => 'form-select']); ?>
                         </div>
                     </div>
                     <div class="row">
@@ -142,22 +163,21 @@ $this->params['breadcrumbs'][] = $this->title;
                         <div class="col-md-4">
                             <!-- Лейбл для первого города -->
                             <?= Html::label('Город 1', null, ['class' => 'form-label']); ?>
-                            <?= Html::dropDownList('city1', null, \yii\helpers\ArrayHelper::map(\yii_app\api3\modules\v1\models\Admin::findAll(['group_id' => \yii_app\records\AdminGroup::GROUP_BUSH_DIRECTOR]), 'id', 'name_full'), ['prompt' => 'Город', 'class' => 'form-select']); ?>
+                            <?= Html::dropDownList('city1', null, [], ['prompt' => 'Город', 'class' => 'form-select']); ?>
 
                             <!-- Лейбл для второго города -->
                             <?= Html::label('Город 2', null, ['class' => 'form-label']); ?>
-                            <?= Html::dropDownList('city2', null, \yii\helpers\ArrayHelper::map(\yii_app\api3\modules\v1\models\Admin::findAll(['group_id' => \yii_app\records\AdminGroup::GROUP_BUSH_DIRECTOR]), 'id', 'name_full'), ['prompt' => 'Город', 'class' => 'form-select']); ?>
+                            <?= Html::dropDownList('city2', null, [], ['prompt' => 'Город', 'class' => 'form-select']); ?>
 
                             <!-- Лейбл для третьего города -->
                             <?= Html::label('Город 3', null, ['class' => 'form-label']); ?>
-                            <?= Html::dropDownList('city3', null, \yii\helpers\ArrayHelper::map(\yii_app\api3\modules\v1\models\Admin::findAll(['group_id' => \yii_app\records\AdminGroup::GROUP_BUSH_DIRECTOR]), 'id', 'name_full'), ['prompt' => 'Город', 'class' => 'form-select']); ?>
+                            <?= Html::dropDownList('city3', null, [], ['prompt' => 'Город', 'class' => 'form-select']); ?>
 
                             <!-- Лейбл для четвертого города -->
                             <?= Html::label('Город 4', null, ['class' => 'form-label']); ?>
-                            <?= Html::dropDownList('city4', null, \yii\helpers\ArrayHelper::map(\yii_app\api3\modules\v1\models\Admin::findAll(['group_id' => \yii_app\records\AdminGroup::GROUP_BUSH_DIRECTOR]), 'id', 'name_full'), ['prompt' => 'Город', 'class' => 'form-select']); ?>
+                            <?= Html::dropDownList('city4', null, [], ['prompt' => 'Город', 'class' => 'form-select']); ?>
                         </div>
 
-                        <!-- Многовыборный дропдаун -->
                         <div class="col-md-8">
                             <div class="container mt-5">
                                 <?= DualListbox::widget([
diff --git a/erp24/web/js/city-store-params/city-store-params.js b/erp24/web/js/city-store-params/city-store-params.js
new file mode 100644 (file)
index 0000000..76a6419
--- /dev/null
@@ -0,0 +1,89 @@
+$(document).ready(function () {
+    function sendData() {
+        var formData = {
+            address_city: $('#address_city').val(),
+            address_region: $('#address_region').val(),
+            address_district: $('#address_district').val(),
+            store_type: $('#store_type').val(),
+            territorial_manager: $('#territorial_manager').val(),
+            bush_chef_florist: $('#bush_chef_florist').val(),
+        };
+
+        $.ajax({
+            url: 'city-store-params/edit',
+            type: 'GET',
+            data: formData,
+            success: function (response) {
+                if (response && typeof response === 'object') {
+                    var options = '';
+                    $.each(response, function (key, value) {
+                        options += '<option value="' + key + '">' + value + '</option>';
+                    });
+                    $('#selectedValues').html(options);
+                }
+            },
+            error: function (xhr, status, error) {
+                console.error("Ошибка AJAX: " + error);
+            }
+        });
+    }
+
+    $('#address_city, #address_region, #address_district, #store_type, #territorial_manager, #bush_chef_florist').on('change', function () {
+        sendData();
+    });
+
+    $('#apply-button').on('click', function () {
+        sendData();
+    });
+
+    function sendData() {
+        var selectedValues = $('#selectedValues').val();
+
+        if (!selectedValues || selectedValues.length === 0) {
+            return;
+        }
+
+        $.ajax({
+            url: 'city-store-params/get-data',
+            type: 'GET',
+            data: { selectedValues: selectedValues },
+            success: function (response) {
+                if (response.error) {
+                    alert(response.error);
+                    return;
+                }
+
+                if (response.store_types) {
+                    var storeTypeOptions = '<option value="">Тип магазина</option>';
+                    $.each(response.store_types, function (key, value) {
+                        storeTypeOptions += '<option value="' + key + '">' + value + '</option>';
+                    });
+                    $('#store_type').html(storeTypeOptions);
+                }
+
+                if (response.cities) {
+                    var cityOptions = '<option value="">Город</option>';
+                    $.each(response.cities, function (key, value) {
+                        cityOptions += '<option value="' + key + '">' + value + '</option>';
+                    });
+                    $('#city').html(cityOptions);
+                }
+
+                if (response.territorial_managers) {
+                    var territorialManagerOptions = '<option value="">Территориально управляющий</option>';
+                    $.each(response.territorial_managers, function (key, value) {
+                        territorialManagerOptions += '<option value="' + key + '">' + value + '</option>';
+                    });
+                    $('#territorial_manager').html(territorialManagerOptions);
+                }
+            },
+            error: function (xhr, status, error) {
+                console.error("Ошибка AJAX: " + error);
+            }
+        });
+    }
+
+    $('#selected-store').on('change', function () {
+        sendData();
+    });
+});