chengwl 5 år sedan
förälder
incheckning
21cc6d16ef
2 ändrade filer med 47 tillägg och 3 borttagningar
  1. 14 0
      controllers/SiteController.php
  2. 33 3
      views/site/index.php

+ 14 - 0
controllers/SiteController.php

@@ -121,7 +121,21 @@ class SiteController extends Controller
     public function actionDelete($id)
     {
         $this->findModel($id)->delete();
+      
 
+
+        return $this->redirect(['index']);
+    }
+
+    public function actionDeleteAll()
+    {
+        $request = Yii::$app->request;
+        $id = $request->post('id');   
+        if(is_array($id)){
+            $ids=implode(',',$id);
+        }
+        $model = new Orderreturn(); //你要批量删除的表
+        $model->deleteAll('id in (' . $ids . ')');
         return $this->redirect(['index']);
     }
     public function actionExport(){

+ 33 - 3
views/site/index.php

@@ -4,6 +4,8 @@ use yii\helpers\Html;
 use yii\grid\GridView;
 use yii\widgets\ActiveForm;
 use yii\bootstrap\Nav;
+use yii\grid\CheckboxColumn;
+use yii\helpers\Url;
 
 /* @var $this yii\web\View */
 /* @var $searchModel app\models\OrderreturnSearch */
@@ -51,9 +53,17 @@ $this->params['breadcrumbs'][] = $this->title;
 
     <?= GridView::widget([
         'dataProvider' => $dataProvider,
+        'showFooter' => true,
         // 'filterModel' => $searchModel,
+        'id' => 'grid',
         'columns' => [
-            ['class' => 'yii\grid\SerialColumn'],
+            [
+                'class'=>CheckboxColumn::className(),
+                'name'=>'id',
+                'headerOptions' => ['width'=>'30'],
+                'footer' => '<button href="#" class="btn btn-default btn-xs btn-delete" url="'. Url::toRoute('site/delete-all') .'">批量删除</button>',
+                'footerOptions' => ['colspan' => 5],
+            ],
 
             'id',
             'deliveryid',
@@ -66,10 +76,30 @@ $this->params['breadcrumbs'][] = $this->title;
             'receiptdate',
             'num',
             'mark',
-
-            ['class' => 'yii\grid\ActionColumn'],
+            ['class' => 'yii\grid\ActionColumn', 'header' => '管理操作', 'footerOptions' => ['class'=>'hide']],
+            // ['class' => 'yii\grid\ActionColumn'],
         ],
     ]); ?>
+    
 
 
 </div>
+<?php
+$script = <<< js
+    $(".btn-delete").on("click", function(){
+        var ids = $("#grid").yiiGridView("getSelectedRows");
+        var self = $(this);
+        if(ids.length == 0) return false;
+        $.ajax({
+           url:self.attr("url"),
+           type:"post",
+           data:{id:ids},
+           success:function(res){
+           
+           }
+        });
+    });
+js;
+
+$this->registerJs($script);
+?>