From: marina Date: Tue, 4 Feb 2025 14:29:44 +0000 (+0300) Subject: ERP-302 Редактирование букета X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=1338173734e81788db65074dbe77d71a289e6da8;p=erp24_rep%2Fyii-erp24%2F.git ERP-302 Редактирование букета --- diff --git a/erp24/controllers/BouquetController.php b/erp24/controllers/BouquetController.php index c65ec2b9..ca60f81e 100644 --- a/erp24/controllers/BouquetController.php +++ b/erp24/controllers/BouquetController.php @@ -94,30 +94,34 @@ class BouquetController extends Controller 'availableItems' => $availableItems, ]); } - public function actionGetList() { \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; - $request = Yii::$app->request; + $request = Yii::$app->request->post(); $conditions = array_filter([ - 'tip' => $request->post('tip'), - 'color' => $request->post('color'), - 'species' => $request->post('species'), - 'category' => $request->post('category'), - 'size' => $request->post('size'), + 'type-num' => $request['type-num'] ?? null, + 'color' => $request['color'] ?? null, + 'species' => $request['species'] ?? null, + 'category' => $request['category'] ?? null, + 'size' => $request['size'] ?? null, ]); - $filters = array_map(fn($field, $value) => Products1cNomenclature::find()->select('id')->where([$field => $value]), array_keys($conditions), $conditions); + $subqueries = []; + foreach ($conditions as $field => $value) { + $subqueries[] = Products1cNomenclature::find()->select('id')->where([$field => $value]); + } $query = Products1c::find()->where([ 'tip' => Products1c::TYPE_PRODUCTS, 'view' => Products1c::IS_VISIBLE, ]); - if (!empty($filters)) { - $query->andWhere(['in', 'id', array_values($filters)]); + if (!empty($subqueries)) { + foreach ($subqueries as $subquery) { + $query->andWhere(['in', 'id', $subquery]); + } } return ArrayHelper::map($query->asArray()->all(), 'id', 'name'); diff --git a/erp24/views/bouquet/update.php b/erp24/views/bouquet/update.php index bdbe9095..c0f485df 100644 --- a/erp24/views/bouquet/update.php +++ b/erp24/views/bouquet/update.php @@ -29,24 +29,22 @@ $this->registerJsFile('/js/bouquet/bouquet.js', ['position' => \yii\web\View::PO 'fw-bold fs-5 text-center']) ?>
- select('category')->distinct()->column(), ['class' => 'form-select', 'prompt' => 'Выберите категорию']) ?> + select('category')->distinct()->column(), ['class' => 'form-select', 'prompt' => 'Выберите категорию', 'id' => 'category']) ?>
- select('species')->distinct()->column(), ['class' => 'form-select', 'prompt' => 'Выберите вид']) ?> + select('species')->distinct()->column(), ['class' => 'form-select', 'prompt' => 'Выберите вид', 'id' => 'species']) ?>
- select('type_num')->distinct()->column(), ['class' => 'form-select', 'prompt' => 'Выберите тип']) ?> + select('type_num')->distinct()->column(), ['class' => 'form-select', 'prompt' => 'Выберите тип', 'id' => 'type_num']) ?>
- select('size')->distinct()->column(), ['class' => 'form-select', 'prompt' => 'Выберите размер']) ?> + select('size')->distinct()->column(), ['class' => 'form-select', 'prompt' => 'Выберите размер', 'id' => 'size']) ?>
- select('color')->distinct()->column(), ['class' => 'form-select', 'prompt' => 'Выберите цвет']) ?> + select('color')->distinct()->column(), ['class' => 'form-select', 'prompt' => 'Выберите цвет', 'id' => 'color']) ?>
- 'btn btn-primary w-100 mb-3', 'id' => 'apply-button']) ?> -
'dual-list-form']); ?> @@ -59,6 +57,7 @@ $this->registerJsFile('/js/bouquet/bouquet.js', ['position' => \yii\web\View::PO 'ajaxUrl' => '/bouquet/get-list', 'showQuantity' => true, 'triggerButton' => 'apply-button', + 'filterFields' => ['size', 'color', 'species', 'category', 'type-num'] ]) ?>
diff --git a/erp24/widgets/DualList.php b/erp24/widgets/DualList.php index 63bca55c..28f614b0 100644 --- a/erp24/widgets/DualList.php +++ b/erp24/widgets/DualList.php @@ -12,6 +12,7 @@ class DualList extends Widget public $name; public $availableItems = []; public $selectedItems = []; + public $filterFields = []; public $ajaxUrl; public $showQuantity = false; @@ -190,27 +191,55 @@ CSS; { $id = $this->getId(); $ajaxUrl = is_string($this->ajaxUrl) ? Url::to($this->ajaxUrl) : ''; + $filterSelectors = json_encode(array_map(fn($field) => "#$field", $this->filterFields)); $js = << { + let el = $(selector); // Объявляем переменную el через let + let name = el.attr('name'); + + if (!name) return; + + let value; + if (el.is('select')) { + value = el.find('option:selected').text(); + if (value.toLowerCase().includes('выберите')) { + value = null; + } + } else { + value = el.val(); + } + + if (value) { + filters[name] = value; + } +}); + +$.ajax({ + url: '{$ajaxUrl}', + type: 'POST', + data: filters, + dataType: 'json', + success: function(data) { if (data && typeof data === 'object') { let select = $('#{$id}-available'); - select.empty(); // Очищаем только доступные элементы - // Преобразуем объект в массив - Object.keys(data).forEach(function(id) { - let text = data[id]; - select.append(new Option(text, id)); // Добавляем новые элементы + select.empty(); + Object.entries(data).forEach(([id, text]) => { + select.append(new Option(text, id)); }); - updateCounts(); // Обновляем количество доступных и выбранных элементов + updateCounts(); } else { - console.error('Полученные данные не являются объектом или не существуют'); + console.error('Ошибка загрузки данных'); } - }).fail(function(jqXHR, textStatus, errorThrown) { - console.error('Ошибка при загрузке данных:', textStatus, errorThrown); - }); -} + }, + error: function(jqXHR, textStatus, errorThrown) { + console.error('Ошибка запроса:', textStatus, errorThrown); + } +}); +} function filterItems(filterInputId, listSelector, isOption = true) { const filterValue = $(filterInputId).val().toLowerCase(); @@ -244,7 +273,6 @@ $('#{$id}-selected-count').text('Выбрано: ' + selectedCount); } $(document).ready(function() { -// Обработчик клика по кнопке для загрузки новых данных $('#{$this->triggerButton}').click(function() { loadAvailableItems(); });