From 77416bac725c0518910f32f05494bf2cfed9baaa Mon Sep 17 00:00:00 2001 From: marina Date: Mon, 10 Feb 2025 10:08:44 +0300 Subject: [PATCH] =?utf8?q?ERP-302=20=D0=A0=D0=B5=D0=B4=D0=B0=D0=BA=D1=82?= =?utf8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=B1=D1=83?= =?utf8?q?=D0=BA=D0=B5=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/composer.json | 3 +- erp24/controllers/BouquetController.php | 24 +++ erp24/views/bouquet/view.php | 189 ++++++++++++++++-------- erp24/widgets/FileUploadWidget.php | 129 ++++++++++++++++ 4 files changed, 286 insertions(+), 59 deletions(-) create mode 100644 erp24/widgets/FileUploadWidget.php diff --git a/erp24/composer.json b/erp24/composer.json index ec2445cc..cd7040fe 100644 --- a/erp24/composer.json +++ b/erp24/composer.json @@ -38,7 +38,8 @@ "enqueue/amqp-lib": "^0.10.19", "vlucas/phpdotenv": "^5.6", "softark/yii2-dual-listbox": "^1.0", - "kartik-v/yii2-widget-depdrop": "dev-master" + "kartik-v/yii2-widget-depdrop": "dev-master", + "2amigos/yii2-file-upload-widget": "~1.0" }, "require-dev": { "yiisoft/yii2-debug": "~2.1.0", diff --git a/erp24/controllers/BouquetController.php b/erp24/controllers/BouquetController.php index 20f95ca3..a0b6d35e 100644 --- a/erp24/controllers/BouquetController.php +++ b/erp24/controllers/BouquetController.php @@ -94,6 +94,30 @@ class BouquetController extends Controller 'availableItems' => $availableItems, ]); } + public function actionUploadPhoto() { + $model = new \yii\base\DynamicModel(['images']); + + if (Yii::$app->request->isPost) { + $files = UploadedFile::getInstances($model, 'images'); + $savedFiles = []; + + foreach ($files as $file) { + $filePath = 'uploads/' . $file->baseName . '.' . $file->extension; + if ($file->saveAs($filePath)) { + $savedFiles[] = $filePath; + } + } + + // Переадресуем обратно, передавая список загруженных файлов + return $this->render('upload', [ + 'initialPreview' => $savedFiles + ]); + } + + return $this->render('upload', [ + 'initialPreview' => [] + ]); + } public function actionGetList() { \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; diff --git a/erp24/views/bouquet/view.php b/erp24/views/bouquet/view.php index ae401014..a98ac849 100644 --- a/erp24/views/bouquet/view.php +++ b/erp24/views/bouquet/view.php @@ -1,9 +1,13 @@ title = 'Три гладиолуса'; $this->params['breadcrumbs'][] = ['label' => 'Букеты', 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; ?> -
- 'h4']) ?> -

title) ?>

+
+
+
+

+

title) ?>

+
-
-
- Тут типа расчеты +
+ +
+ all(), 'id', 'name'), ['class' => 'form-control', 'prompt' => 'Тип матрицы']) ?> +
-
-
-
- 'h4']) ?> - 'attachment_4', - 'disabled' => true - ]); ?> -
-
-
- -
- all(), 'id', 'name'), ['class' => 'form-control', 'prompt' => 'Тип матрицы']) ?> -
-
-
- 'h5 text-center pt-5']) ?> -
-
-
- 'h5 pt-2']) ?> -
-
- 'form-control']) ?> -
-
-
-
- 'h5 pt-2']) ?> -
-
- 'form-control']) ?> -
-
-
- 'h5 text-center pt-5']) ?> -
-
- all() as $number => $store) { ?> -
- name) ?> -
-
- id", null, ['class' => 'form-control']) ?> -
- -
+
+
+
+
+
Название
+
Кол-во
+
% списания
+
мрж-ть
+
% в сборке
+
ср.шт. в сборке
+
+ +
+
+
Гладиолусы краш
+
3.0
+
10%
+
30%
+
10%
+
3.2%
+
+

Загрузите файлы

+ + 'file-upload-widget', // Можно указать свой id + 'inputId' => 'file-upload', // Можно указать свой id для input + ]); + ?> +
+ + + +
+ инпут поля +
+ + + + + 'h4']) ?> + 'attachment_4', + // 'disabled' => true + // ]); ?> + + + 'h4']) ?> + 'attachment_4', + // 'disabled' => true + // ]); ?> + + + --> + --> + --> + --> 'h4']) ?> + --> + --> + + --> + --> + --> + + -->all(), 'id', 'name'), ['class' => 'form-control', 'prompt' => 'Тип матрицы']) ?> + --> + --> + --> + + --> 'h5 text-center pt-5']) ?> + --> + --> + --> + --> 'h5 pt-2']) ?> + --> + --> + + --> 'form-control']) ?> + --> + --> + --> + --> + + --> 'h5 pt-2']) ?> + --> + --> + + --> 'form-control']) ?> + --> + --> + --> + + --> 'h5 text-center pt-5']) ?> + --> + --> + + -->all() as $number => $store) { ?> + --> + --> + name) ?> --> + --> + --> + + -->id", null, ['class' => 'form-control']) ?> + --> + --> + --> + --> + +
diff --git a/erp24/widgets/FileUploadWidget.php b/erp24/widgets/FileUploadWidget.php new file mode 100644 index 00000000..b4e60fd4 --- /dev/null +++ b/erp24/widgets/FileUploadWidget.php @@ -0,0 +1,129 @@ +registerAssets(); + + return $this->renderContent(); + } + + // Рендеринг HTML-контента для виджета + protected function renderContent() + { + return Html::tag('div', + Html::tag('label', + Html::tag('input', '', ['type' => 'file', 'id' => $this->inputId, 'multiple' => true]) . + Html::tag('span', '+', ['class' => 'plus-icon']), + ['for' => $this->inputId, 'class' => 'upload-label'] + ), + ['id' => $this->containerId, 'class' => 'file-container'] + ); + } + + // Встраивание CSS и JS непосредственно в HTML + protected function registerAssets() + { + $view = $this->getView(); + + $css = <<inputId', function(event) { + const files = event.target.files; + + for (const file of files) { + const reader = new FileReader(); + reader.onload = function(e) { + const fileContainer = \$(
); + + const img = \$(); + const removeButton = \$(); + + removeButton.on('click', function() { + fileContainer.remove(); + }); + + fileContainer.append(img).append(removeButton); + \$('#$this->containerId').prepend(fileContainer); + }; + + reader.readAsDataURL(file); + } + }); + })(jQuery); + JS; + + // Вставляем CSS и JS в страницу + $view->registerCss($css); + $view->registerJs($js); + } +} -- 2.39.5