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>
<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>
<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>
<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>
</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">
</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">
</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">
<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([
--- /dev/null
+$(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();
+ });
+});