]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
ERP-302 Редактирование букета
authormarina <m.zozirova@gmail.com>
Mon, 10 Feb 2025 07:08:44 +0000 (10:08 +0300)
committermarina <m.zozirova@gmail.com>
Mon, 10 Feb 2025 07:08:44 +0000 (10:08 +0300)
erp24/composer.json
erp24/controllers/BouquetController.php
erp24/views/bouquet/view.php
erp24/widgets/FileUploadWidget.php [new file with mode: 0644]

index ec2445cc15904742c448d2f728edca1e42877719..cd7040feb3a46fb6ee5d9fdb6e82dd91da7300ff 100644 (file)
@@ -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",
index 20f95ca335a3e3de87bcdc578957ae9f405e2047..a0b6d35e91dbed0b0d4d67c716c794c49fe2b038 100644 (file)
@@ -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;
index ae401014796463885ed2fd63fb51a0f6a7d7b81a..a98ac8491b20ebf2afc6582136cecedcd5db2b30 100644 (file)
@@ -1,9 +1,13 @@
 <?php
 
+use app\widgets\FileUploadWidget;
+use app\widgets\MediaUploader;
+use dosamigos\fileupload\FileUploadUI;
 use kartik\file\FileInput;
 use yii\helpers\ArrayHelper;
 use yii\helpers\Html;
 use yii\helpers\Url;
+use yii\widgets\ActiveForm;
 use yii\widgets\DetailView;
 use yii_app\records\MatrixType;
 
@@ -17,69 +21,138 @@ $this->title = 'Три гладиолуса';
 $this->params['breadcrumbs'][] = ['label' => 'Букеты', 'url' => ['index']];
 $this->params['breadcrumbs'][] = $this->title;
 ?>
-<div class="bouquet-view p-4">
-    <?= Html::label('Состав букета', null, ['class' => 'h4']) ?>
-    <h1 class="ms-5"><?= Html::encode($this->title) ?></h1>
+<div class="bouquet-view border-bottom-4 p-4">
+    <div class="row d-flex border-bottom justify-content-between align-items-center py-4">
+        <div class="col-md-8 d-flex align-items-center">
+            <h3 class="ms-3 mb-0"><?= Html::encode("Состав букета: ") ?></h3>
+            <h2 class="ms-2 mb-0"><strong><?= Html::encode($this->title) ?></strong></h2>
+        </div>
 
-    <div class="row">
-        <div class="col-md-4">
-            Тут типа расчеты
+        <div class="col-md-4 d-flex align-items-center">
+            <div class="me-3 text-end">
+                <?= Html::label('Тип матрицы', null, ['class' => 'h5 mb-0']) ?>
+                <br>
+                <a href="<?= Url::to('/matrix-type') ?>" class="text-decoration-none" target="_blank">Редактировать</a>
+            </div>
+            <div style="min-width: 200px;">
+                <?= Html::dropDownList('matrix_type_id', null, ArrayHelper::map(MatrixType::find()->all(), 'id', 'name'), ['class' => 'form-control', 'prompt' => 'Тип матрицы']) ?>
+            </div>
         </div>
-        <div class="col-md-8">
-            <div class="row">
-                <div class="col-md-4">
-                    <?= Html::label('Фото', null, ['class' => 'h4']) ?>
-                    <?= FileInput::widget([
-                        'name' => 'attachment_4',
-                        'disabled' => true
-                    ]); ?>
-                </div>
-                <div class="col-md-7">
-                    <div class="row border-bottom">
-                        <div class="col-md-5">
-                            <?= Html::label('Тип матрицы', null, ['class' => 'h4']) ?>
-                            <br>
-                            <a href="<?= Url::to('/matrix-type') ?>" class="text-decoration-none" target="_blank">Редактировать</a>
-                        </div>
-                        <div class="col-md-7 pt-2 mb-2">
-                            <?= Html::dropDownList('matrix_type_id', null, ArrayHelper::map(MatrixType::find()->all(), 'id', 'name'), ['class' => 'form-control', 'prompt' => 'Тип матрицы']) ?>
-                        </div>
-                    </div>
-                    <div class="row">
-                        <?= Html::label('Прогноз продаж (мес.)', null, ['class' => 'h5 text-center pt-5']) ?>
-                    </div>
-                    <div class="row pt-2">
-                        <div class="col-md-4">
-                            <?= Html::label('Маркетплейсы', null, ['class' => 'h5 pt-2']) ?>
-                        </div>
-                        <div class="col-md-8">
-                            <?= Html::input('number', 'marketplace', null, ['class' => 'form-control']) ?>
-                        </div>
-                    </div>
-                    <div class="row pt-2">
-                        <div class="col-md-4">
-                            <?= Html::label('Интернет магазин', null, ['class' => 'h5 pt-2']) ?>
-                        </div>
-                        <div class="col-md-8">
-                            <?= Html::input('number', 'online_stores', null, ['class' => 'form-control']) ?>
-                        </div>
-                    </div>
-                    <div class="row">
-                        <?= Html::label('Оффлайн магазины', null, ['class' => 'h5 text-center pt-5']) ?>
-                    </div>
-                    <div class="row">
-                        <?php foreach (\yii_app\records\StoreType::find()->all() as $number => $store) { ?>
-                            <div class="col-md-3 pt-1 d-flex align-items-center">
-                                <span class="offline-stores me-3"><?= Html::encode($store->name) ?></span>
-                            </div>
-                            <div class="col-md-9 pt-1 d-flex align-items-center">
-                                <?= Html::input('number', "offline-store-$store->id", null, ['class' => 'form-control']) ?>
-                            </div>
-                        <?php } ?>
-                    </div>
+    </div>
+    <div class="row">
+        <div class="col-md-5">
+            <div class="row mb-2">
+                <div class="col-md-4 text-center font-weight-bold">Название</div>
+                <div class="col-md-2 text-center font-weight-bold">Кол-во</div>
+                <div class="col-md-1 text-center font-weight-bold">% списания</div>
+                <div class="col-md-2 text-center font-weight-bold">мрж-ть</div>
+                <div class="col-md-1 text-center font-weight-bold">% в сборке</div>
+                <div class="col-md-2 text-center font-weight-bold">ср.шт. в сборке</div>
+            </div>
+
+            <div class="list-container p-3 bg-white border rounded shadow-sm">
+                <div class="row">
+                    <div class="col-md-4 text-center">Гладиолусы краш</div>
+                    <div class="col-md-2 text-center">3.0</div>
+                    <div class="col-md-1 text-center">10%</div>
+                    <div class="col-md-2 text-center">30%</div>
+                    <div class="col-md-1 text-center">10%</div>
+                    <div class="col-md-2 text-center">3.2%</div>
                 </div>
             </div>
         </div>
+        <div class="site-index">
+            <h1>Загрузите файлы</h1>
+
+            <?php
+            // Использование виджета
+            echo FileUploadWidget::widget([
+                'containerId' => 'file-upload-widget',  // Можно указать свой id
+                'inputId' => 'file-upload',  // Можно указать свой id для input
+            ]);
+            ?>
+        </div>
+
+
+
+        <div class="col-md-3">
+            инпут поля
+        </div>
+        <!--        <div class="col-md-8">-->
+        <!--            <div class="row">-->
+        <!--                <div class="col-md-4">-->
+        <!--                    <div class="row">-->
+        <!--                    --><?php //= Html::label('Фото', null, ['class' => 'h4']) ?>
+        <!--                    --><?php //= FileInput::widget([
+        //                        'name' => 'attachment_4',
+        //                        'disabled' => true
+        //                    ]); ?>
+        <!--                    </div>-->
+        <!--                    <div class="row">-->
+        <!--                        --><?php //= Html::label('Видео', null, ['class' => 'h4']) ?>
+        <!--                        --><?php //= FileInput::widget([
+        //                            'name' => 'attachment_4',
+        //                            'disabled' => true
+        //                        ]); ?>
+        <!--                    </div>-->
+        <!--                </div>-->
+        <!--<!--                <div class="col-md-7">-->-->
+        <!--<!--                    <div class="row border-bottom">-->-->
+        <!--<!--                        <div class="col-md-5">-->-->
+        <!--<!--                            -->--><?php ////= Html::label('Тип матрицы', null, ['class' => 'h4']) ?>
+        <!--<!--                            <br>-->-->
+        <!--<!--                            <a href="-->-->
+        <?php ////= Url::to('/matrix-type') ?><!--<!--" class="text-decoration-none" target="_blank">Редактировать</a>-->
+        -->
+        <!--<!--                        </div>-->-->
+        <!--<!--                        <div class="col-md-7 pt-2 mb-2">-->-->
+        <!--<!--                            -->
+        --><?php ////= Html::dropDownList('matrix_type_id', null, ArrayHelper::map(MatrixType::find()->all(), 'id', 'name'), ['class' => 'form-control', 'prompt' => 'Тип матрицы']) ?>
+        <!--<!--                        </div>-->-->
+        <!--<!--                    </div>-->-->
+        <!--<!--                    <div class="row">-->-->
+        <!--<!--                        -->
+        --><?php ////= Html::label('Прогноз продаж (мес.)', null, ['class' => 'h5 text-center pt-5']) ?>
+        <!--<!--                    </div>-->-->
+        <!--<!--                    <div class="row pt-2">-->-->
+        <!--<!--                        <div class="col-md-4">-->-->
+        <!--<!--                            -->--><?php ////= Html::label('Маркетплейсы', null, ['class' => 'h5 pt-2']) ?>
+        <!--<!--                        </div>-->-->
+        <!--<!--                        <div class="col-md-8">-->-->
+        <!--<!--                            -->
+        --><?php ////= Html::input('number', 'marketplace', null, ['class' => 'form-control']) ?>
+        <!--<!--                        </div>-->-->
+        <!--<!--                    </div>-->-->
+        <!--<!--                    <div class="row pt-2">-->-->
+        <!--<!--                        <div class="col-md-4">-->-->
+        <!--<!--                            -->
+        --><?php ////= Html::label('Интернет магазин', null, ['class' => 'h5 pt-2']) ?>
+        <!--<!--                        </div>-->-->
+        <!--<!--                        <div class="col-md-8">-->-->
+        <!--<!--                            -->
+        --><?php ////= Html::input('number', 'online_stores', null, ['class' => 'form-control']) ?>
+        <!--<!--                        </div>-->-->
+        <!--<!--                    </div>-->-->
+        <!--<!--                    <div class="row">-->-->
+        <!--<!--                        -->
+        --><?php ////= Html::label('Оффлайн магазины', null, ['class' => 'h5 text-center pt-5']) ?>
+        <!--<!--                    </div>-->-->
+        <!--<!--                    <div class="row">-->-->
+        <!--<!--                        -->
+        --><?php ////foreach (\yii_app\records\StoreType::find()->all() as $number => $store) { ?>
+        <!--<!--                            <div class="col-md-3 pt-1 d-flex align-items-center">-->-->
+        <!--<!--                                <span class="offline-stores me-3">-->-->
+        <?php ////= Html::encode($store->name) ?><!--<!--</span>--> -->
+        <!--<!--                            </div>-->-->
+        <!--<!--                            <div class="col-md-9 pt-1 d-flex align-items-center">-->-->
+        <!--<!--                                -->
+        --><?php ////= Html::input('number', "offline-store-$store->id", null, ['class' => 'form-control']) ?>
+        <!--<!--                            </div>-->-->
+        <!--<!--                        -->--><?php ////} ?>
+        <!--<!--                    </div>-->-->
+        <!--<!--                </div>-->-->
+        <!--            </div>-->
+        <!--        </div>-->
     </div>
 </div>
 
diff --git a/erp24/widgets/FileUploadWidget.php b/erp24/widgets/FileUploadWidget.php
new file mode 100644 (file)
index 0000000..b4e60fd
--- /dev/null
@@ -0,0 +1,129 @@
+<?php
+
+namespace app\widgets;
+
+use yii\base\Widget;
+use yii\helpers\Html;
+
+class FileUploadWidget extends Widget
+{
+    public $containerId = 'file-upload-widget';  // Идентификатор контейнера
+    public $inputId = 'file-upload';  // Идентификатор input для файлов
+    public $maxFiles = 10;  // Максимальное количество файлов (по желанию)
+
+    public function init()
+    {
+        parent::init();
+    }
+
+    public function run()
+    {
+        $this->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 = <<<CSS
+        .file-container {
+            display: flex;
+            flex-wrap: wrap;
+            gap: 10px;
+        }
+
+        .upload-label {
+            position: relative;
+            width: 100px;
+            height: 100px;
+            background-color: #f0f0f0;
+            border: 2px dashed #ccc;
+            display: flex;
+            justify-content: center;
+            align-items: center;
+            cursor: pointer;
+        }
+
+        .upload-label input[type="file"] {
+            display: none;
+        }
+
+        .plus-icon {
+            font-size: 2rem;
+            color: #555;
+        }
+
+        .uploaded-image {
+            width: 100px;
+            height: 100px;
+            object-fit: cover;
+            border: 2px solid #ccc;
+        }
+
+        .uploaded-container {
+            position: relative;
+        }
+
+        .remove-btn {
+            position: absolute;
+            top: 5px;
+            right: 5px;
+            background-color: red;
+            color: white;
+            border: none;
+            border-radius: 50%;
+            width: 20px;
+            height: 20px;
+            font-size: 14px;
+            cursor: pointer;
+        }
+        CSS;
+
+        $js = <<<JS
+        (function(\$) {
+            \$(document).on('change', '#$this->inputId', function(event) {
+                const files = event.target.files;
+                
+                for (const file of files) {
+                    const reader = new FileReader();
+                    reader.onload = function(e) {
+                        const fileContainer = \$(<div class="uploaded-container"></div>);
+                        
+                        const img = \$(<img src="\${e.target.result}" class="uploaded-image">);
+                        const removeButton = \$(<button class="remove-btn">X</button>);
+                        
+                        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);
+    }
+}