Forráskód Böngészése

20250227 练习追加删除学员,上下级

贾小兵 2 hónapja
szülő
commit
e4d79689d5

+ 1 - 1
application/admin/controller/teacher/Collection.php

@@ -204,7 +204,7 @@ class Collection extends Backend
             //判断是否有已经开始考试的人员
             $isset_exam = $this->exam_model->where(['user_id'=>['in',$array_diff],'exam_collection_id'=>$ids,'exam_status'=>4])->find();
             if(!empty($isset_exam)){
-                $this->error('删除的人员已再考试中,请重新选择');
+                $this->error('删除的人员已进行考试,请重新选择');
             }
         }
         $result = false;

+ 102 - 155
application/admin/controller/teacher/Practice.php

@@ -19,7 +19,9 @@ use app\admin\model\teacher\ExamsScore;
 class Practice extends Backend
 {
 
-    protected $noNeedRight = ['score'];
+    protected $noNeedRight = ['score','adduser','edituser', 'viewuser'];
+
+
     /**
      * Collection模型对象
      * @var \app\admin\model\teacher\Collection
@@ -50,9 +52,10 @@ class Practice extends Backend
      * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
      * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
      */
-    public function add()
+    public function adduser($ids = null)
     {
         if (false === $this->request->isPost()) {
+            $this->assignConfig('user_ids',[]);
             return $this->view->fetch();
         }
         $params = $this->request->post('row/a');
@@ -60,7 +63,7 @@ class Practice extends Backend
             $this->error(__('Parameter %s can not be empty', ''));
         }
         if(empty($params['depart_ids'])){
-            $this->error('请选择区队名称');
+            $this->error('请选择学员名称');
         }
         if(!empty($params['question_setting_method'])){
             if($params['question_setting_method']==2 && empty($params['question_ids'])){
@@ -70,170 +73,50 @@ class Practice extends Backend
                 $this->error('出题方式为任务自选,请选择任务');
             }
         }
-
-        $params = $this->preExcludeFields($params);
-
-        if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
-            $params[$this->dataLimitField] = $this->auth->id;
-        }
-        $result = false;
-        Db::startTrans();
-        try {
-            $depart_ids = $params['depart_ids'];
-            if($params['question_setting_method']==3 && !empty($params['fault_name'])){
-                $params['question_name'] = $params['fault_name'];
-                unset($params['fault_name']);
-            }
-            $result = $this->model->allowField(true)->save($params);
-            foreach(explode(',',$depart_ids) as $item){
-                if(!empty($item)){
-                    $arr = [
-                        'exam_collection_id' => $this->model->exam_collection_id,
-                        'dept_id' => $item,
-                        'update_time' => date('Y-m-d H:i:s'),
-                    ];
-                    Db::name('real_exam_collection_dept')->insert($arr);
-                }
-            }
-
-            //匹配的学员自动加入  mx_real_exam 考试表  总分
-            $admin_list = Db::name('admin')->where('depart_id','in',$depart_ids)->select();
-            foreach ($admin_list as $it){
-                $arr1 = [
-                    'exam_collection_id' => $this->model->exam_collection_id,
-                    'exam_collection_name' => $params['exam_collection_name'],
-                    'exam_collection_type' => $params['exam_collection_type'],
-                    'sim_type' => $params['sim_type'],
-                    'user_username' => $it['username'],
-                    'user_nickname' => $it['nickname'],
-                    'user_id' => $it['id'],
-                    'user_depart_id' => $it['depart_id'],
-                    'create_time'=>date('Y-m-d H:i:s'),
-                    'update_time' => date('Y-m-d H:i:s'),
-                ];
-                $examid = Db::name('real_exam')->insertGetId($arr1);
-                //匹配的学员自动加入  mx_real_exam_fault 考试故障关联表
-                $fault_list = Fault::where(['sim_type' => $params['sim_type'], 'fault_state' => 0,'fault_type'=>3])->select();
-                if($params['question_setting_method']==1){ //系统随机
-                    if($params['sim_type']=='0002'){
-                        $fault_key1 = rand(0, 1);
-                        $fault_key2 = 4;
-                        $fault_key3 = rand(10,11);
-                    }else{
-                        $fault_key1 = rand(0, 1);
-                        $fault_key2 = rand(2, 3);
-                        $fault_key3 = rand(4, 5);
-                    }
-                    $fault_key = [$fault_key1,$fault_key2,$fault_key3];
-                }else if($params['question_setting_method']==2){//教师自选
-                    $question_ids = $params['question_ids'];
-                }else if($params['question_setting_method']==3){ //任务自选
-                    $task_ids = Db::name('task_fault')->where(['task_id'=>['in',$params['task_id']]])->column('fault_id');
-                }
-                foreach ($fault_list as $key=> $item1){
-                    $flag = 0;
-                    if(!empty($fault_key) && in_array($key,$fault_key)){
-                        $flag = 1;
-                    }
-                    if(!empty($question_ids) && in_array($item1['fault_id'],explode(',',$question_ids))){
-                        $flag = 1;
-                    }
-                    if(!empty($task_ids) && in_array($item1['fault_id'],$task_ids)){
-                        $flag = 1;
-                    }
-                    $add= [
-                        'exam_id'=>$examid,
-                        'fault_id'=>$item1['fault_id'],
-                        'ref_type'=>2,
-                        'flag'=>$flag,
-                        'ref_state'=>3,
-//                        'sim_fault_question_value'=>'0000000'.rand(1,2),
-                        'createtime'=>time(),
-                        'updatetime'=>time(),
-                        'create_time'=>date('Y-m-d H:i:s'),
-                        'update_time'=>date('Y-m-d H:i:s'),
-                    ];
-                    Db::name('real_exam_fault')->insert($add);
-                }
-                unset($item1);
-
-            }
-            Db::commit();
-        } catch (ValidateException|PDOException|Exception $e) {
-            Db::rollback();
-            $this->error($e->getMessage());
-        }
-        if ($result === false) {
-            $this->error(__('No rows were inserted'));
+        $depart_ids = $params['depart_ids'];
+        //先判断是否已经存在
+        $isset_exam = $this->exam_model->where(['user_id'=>['in',$depart_ids],'exam_collection_id'=>$ids])->find();
+        if(!empty($isset_exam)){
+            $this->error('添加的人员已存在该练习中,请重新选择');
         }
-        $this->success();
-    }
-
-    public function edit($ids = null)
-    {
         $row = $this->model->get($ids);
-        if (!$row) {
-            $this->error(__('No Results were found'));
-        }
-        if (false === $this->request->isPost()) {
-            $this->view->assign('row', $row);
-            $this->assignConfig('row_info', $row);
-            return $this->view->fetch();
-        }
-        $params = $this->request->post('row/a');
-        if (empty($params)) {
-            $this->error(__('Parameter %s can not be empty', ''));
-        }
-        if(!empty($params['question_setting_method'])){
-            if($params['question_setting_method']==2 && empty($params['question_ids'])){
-                $this->error('出题方式为考题自选,请选择考题');
-            }
-            if($params['question_setting_method']==3 && empty($params['task_id'])){
-                $this->error('出题方式为任务自选,请选择任务');
-            }
-        }
-        $params = $this->preExcludeFields($params);
         $result = false;
         Db::startTrans();
         try {
-            $depart_ids = $params['depart_ids'];
+            
             if($params['question_setting_method']==3 && !empty($params['fault_name'])){
                 $params['question_name'] = $params['fault_name'];
                 unset($params['fault_name']);
             }
-            $result = $row->allowField(true)->save($params);
+            // $result = $this->model->allowField(true)->save($params);
+            
+            $row->xueyuan_count = $row->xueyuan_count+$params['xueyuan_count'];
+            $row->save();
 
-            Db::name('real_exam_collection_dept')->where(['exam_collection_id'=>$row->exam_collection_id])->delete();
             foreach(explode(',',$depart_ids) as $item){
                 if(!empty($item)){
+                    $admin = Db::name('admin')->where('id',$item)->find();
                     $arr = [
-                        'exam_collection_id' => $row->exam_collection_id,
-                        'dept_id' => $item,
-                        'update_time' => date('Y-m-d H:i:s'),
-                    ];
-                    Db::name('real_exam_collection_dept')->insert($arr);
-                }
-            }
-
-            Db::name('real_exam')->where(['exam_collection_id'=>$row->exam_collection_id,'starttime'=>0])->delete();
-            //匹配的学员自动加入  mx_real_exam 考试表  总分
-            $admin_list = Db::name('admin')->where('depart_id','in',$depart_ids)->select();
-            foreach ($admin_list as $it){
-                $real_exam = Db::name('real_exam')->where(['exam_collection_id'=>$row->exam_collection_id,'user_id'=>$it['id']])->find();
-                if(empty($real_exam)){
-                    $arr1 = [
-                        'exam_collection_id' => $row->exam_collection_id,
-                        'exam_collection_name' => $params['exam_collection_name'],
+                        'exam_collection_id' => $ids,
+                        'exam_collection_name' => $row->exam_collection_name,
+                        'question_setting_method' => $params['question_setting_method'],
                         'exam_collection_type' => $row['exam_collection_type'],
                         'sim_type' => $params['sim_type'],
-                        'user_username' => $it['username'],
-                        'user_nickname' => $it['nickname'],
-                        'user_id' => $it['id'],
-                        'user_depart_id' => $it['depart_id'],
-                        'create_time'=>date('Y-m-d H:i:s'),
+                        'user_username' => $admin['username'],
+                        'user_nickname' => $admin['nickname'],
+                        'user_id' => $item,
+                        'seat_id'=>0,
+                        'task_id'=>$params['task_id'],
+                        'question_ids'=>$params['question_ids'],
+                        'question_name'=>$params['question_name'],
+                        'user_depart_id' => $admin['depart_id'],
+                        'createtime'=>time(),
+                        'updatetime'=>time(),
+                        'create_time' => date('Y-m-d H:i:s'),
                         'update_time' => date('Y-m-d H:i:s'),
                     ];
-                    $examid = Db::name('real_exam')->insertGetId($arr1);
+                    $examid = $this->exam_model->insertGetId($arr);
+
                     //匹配的学员自动加入  mx_real_exam_fault 考试故障关联表
                     $fault_list = Fault::where(['sim_type' => $params['sim_type'], 'fault_state' => 0,'fault_type'=>3])->select();
                     if($params['question_setting_method']==1){ //系统随机
@@ -252,8 +135,6 @@ class Practice extends Backend
                     }else if($params['question_setting_method']==3){ //任务自选
                         $task_ids = Db::name('task_fault')->where(['task_id'=>['in',$params['task_id']]])->column('fault_id');
                     }
-                    Db::name('real_exam_fault')->where(['exam_id'=>$examid])->delete();
-
                     foreach ($fault_list as $key=> $item1){
                         $flag = 0;
                         if(!empty($fault_key) && in_array($key,$fault_key)){
@@ -270,8 +151,7 @@ class Practice extends Backend
                             'fault_id'=>$item1['fault_id'],
                             'ref_type'=>2,
                             'flag'=>$flag,
-                            'ref_state'=>3,
-//                        'sim_fault_question_value'=>'0000000'.rand(1,2),
+                            'ref_state'=>0,
                             'createtime'=>time(),
                             'updatetime'=>time(),
                             'create_time'=>date('Y-m-d H:i:s'),
@@ -282,6 +162,73 @@ class Practice extends Backend
                     unset($item1);
                 }
             }
+            $result = true;
+
+            Db::commit();
+        } catch (ValidateException|PDOException|Exception $e) {
+            Db::rollback();
+            $this->error($e->getMessage());
+        }
+        if ($result === false) {
+            $this->error(__('No rows were inserted'));
+        }
+        $this->success();
+    }
+
+
+
+    public function edituser($ids = null)
+    {
+        $row = $this->model->get($ids);
+        if (!$row) {
+            $this->error(__('No Results were found'));
+        }
+       //获取当前考试的全部用户id
+        $user_ids = $this->exam_model->where(['exam_collection_id'=>$ids])->column('user_id');
+        if (false === $this->request->isPost()) {
+            $this->view->assign('row', $row);
+            $this->view->assign('user_ids',implode(',', $user_ids));
+            $this->assignConfig('user_ids', $user_ids);
+            return $this->view->fetch();
+        }
+        $params = $this->request->post('row/a');
+        if (empty($params)) {
+            $this->error(__('Parameter %s can not be empty', ''));
+        }
+        $params = $this->preExcludeFields($params);
+        $depart_id = $params['depart_id'];
+
+        //比较两者的不同,然后在删除
+        $array_diff = array_diff($user_ids,explode(',',$depart_id));
+
+        if(!empty($depart_id)){ 
+            //判断是否有已经开始考试的人员
+            $isset_exam = $this->exam_model->where(['user_id'=>['in',$array_diff],'exam_collection_id'=>$ids,'exam_status'=>4])->find();
+            if(!empty($isset_exam)){
+                $this->error('删除的人员已进行考试,请重新选择');
+            }
+        }
+        $result = false;
+        Db::startTrans();
+        try {
+            
+            if(!empty($depart_id)){ 
+                $depart_count = count($array_diff);
+                $params['xueyuan_count'] = $row->xueyuan_count-$depart_count??0;
+                $result = $row->allowField(true)->save($params);
+
+                foreach($array_diff as $item){
+                    if(!empty($item)){
+                        $exam =  $this->exam_model->where(['exam_collection_id'=>$ids,'user_id'=>$item])->find();
+                        //删除real_exam 的人员
+                        $this->exam_model->where(['exam_collection_id'=>$ids,'user_id'=>$item])->delete();
+                        //删除real_exam_fault 的故障内容
+                        Db::name('real_exam_fault')->where(['exam_id'=>$exam['exam_id']])->delete();
+                    }
+                }
+            }
+            $result = true;
+
             Db::commit();
         } catch (ValidateException|PDOException|Exception $e) {
             Db::rollback();
@@ -332,7 +279,7 @@ class Practice extends Backend
 
             }
             //删除考试关联区队表 mx_real_exam_collection_dept
-            Db::name('real_exam_collection_dept')->where('exam_collection_id',$ids)->delete();
+            // Db::name('real_exam_collection_dept')->where('exam_collection_id',$ids)->delete();
 
 
             Db::commit();

+ 4 - 86
application/admin/view/teacher/practice/add.html

@@ -4,113 +4,31 @@
         <input class="form-control" name="row[exam_collection_type]" type="hidden" value="1">
         <input class="form-control" name="row[create_user_id]" type="hidden" value="{$auth->id}">
         <input class="form-control" name="row[create_by]" type="hidden" value="{$auth->nickname}">
-        <input class="form-control depart_ids" name="row[depart_ids]" type="hidden" value="">
-        <input class="form-control question_ids" name="row[question_ids]" type="hidden" value="0">
-        <input class="form-control task_id" name="row[task_id]" type="hidden" value="0">
-        <input class="form-control depart_ids" name="row[depart_ids]" type="hidden" value="0">
 
-
-
-        <div class="form-group col-sm-6">
+        <div class="form-group col-sm-12">
             <label class="control-label col-xs-12 col-sm-3 addRedStar">{:__('Exam_collection_name')}:</label>
             <div class="col-xs-12 col-sm-7">
                 <input id="c-exam_collection_name" data-rule="required" class="form-control" name="row[exam_collection_name]" type="text">
             </div>
         </div>
-        <div class="form-group col-sm-6">
-            <label class="control-label col-xs-12 col-sm-3 addRedStar">{:__('Sim_type')}:</label>
-            <div class="col-xs-12 col-sm-7">
-                <select id="c-sim_type" data-rule="required" class="form-control" name="row[sim_type]">
-                    <option value="">请选择</option>
-                    {foreach name="sim_sim_type" item="vo"}
-                    <option value="{$key}" >{$vo}</option>
-                    {/foreach}
-                </select>
-            </div>
-        </div>
-<!--        <div class="form-group col-sm-6">-->
-<!--            <label class="control-label col-xs-12 col-sm-3 addRedStar">{:__('Start_time')}:</label>-->
-<!--            <div class="col-xs-12 col-sm-7">-->
-<!--                <input id="c-start_time" class="form-control datetimepicker" data-date-format="YYYY-MM-DD" data-use-current="true" name="row[start_time]" type="text" value="">-->
-<!--            </div>-->
-<!--        </div>-->
-<!--        <div class="form-group col-sm-6">-->
-<!--            <label class="control-label col-xs-12 col-sm-3 addRedStar">{:__('End_time')}:</label>-->
-<!--            <div class="col-xs-12 col-sm-7">-->
-<!--                <input id="c-end_time" class="form-control datetimepicker" data-date-format="YYYY-MM-DD" data-use-current="true" name="row[end_time]" type="text" value="">-->
-<!--            </div>-->
-<!--        </div>-->
 
-        <div class="form-group col-sm-6">
+        <div class="form-group col-sm-12">
             <label class="control-label col-xs-12 col-sm-3 addRedStar">{:__('Limit_duration')}:</label>
             <div class="col-xs-12 col-sm-7">
                 <div class="input-group input-groupp-sm">
-                    <input id="c-limit_duration" class="form-control"  type="number"  name="row[limit_duration]" type="number">
+                    <input id="c-limit_duration" class="form-control"  type="number"  name="row[limit_duration]" type="number" min="0">
                     <span class="input-group-addon">分钟</span>
                 </div>
             </div>
         </div>
 
-        <div class="form-group col-sm-6">
-            <label class="control-label col-xs-12 col-sm-3 addRedStar">{:__('Question_setting_method')}:</label>
-            <div class="col-xs-12 col-sm-7">
-                <select id="c-question_setting_method" data-rule="required" class="form-control" name="row[question_setting_method]">
-                    <option value="">请选择</option>
-                    {foreach name="sim_question_setting_method" item="vo"}
-                    <option value="{$key}" >{$vo}</option>
-                    {/foreach}
-                </select>
-            </div>
-            <div class="btn btn-info btn-sm" style="display: none">自选考题编辑</div>
-            <div class="btn btn-info btn-task" style="display: none">自选任务编辑</div>
-        </div>
-
-        <div class="form-group col-sm-6 tasks" style="display:none;left: 48%">
-            <label class="control-label col-xs-12 col-sm-3 addRedStar">{:__('故障题目')}:</label>
-            <div class="col-xs-12 col-sm-7">
-                <input id="c-task_name" readonly class="form-control" name="row[task_name]" type="hidden">
-                <input id="c-fault_name" readonly class="form-control" name="row[fault_name]" type="text">
-            </div>
-        </div>
-
-        <div class="form-group col-sm-6 questions" style="display:none;left: 48%">
-            <label class="control-label col-xs-12 col-sm-3 addRedStar">{:__('故障名称')}:</label>
-            <div class="col-xs-12 col-sm-7">
-                <input id="c-question_name" readonly  class="form-control" name="row[question_name]" type="text">
-            </div>
-        </div>
     </div>
-    <div class="panel panel-default panel-intro">
-        <div class="panel-body">
-            <div class="tableTitle success" style="font-size: 16px;margin: 10px 0">统计情况</div>
-            <div class="panel-success">
-                <div>本次练习区队数量:<span class="qudui_total">0</span><input type="hidden" name="row[qudui_count]" value="0" class="qudui_input" />‌</div>
-                <div>计划参加练习学员数量:<span class="xueyuan_total">0</span><input type="hidden" name="row[xueyuan_count]" value="0" class="xueyuan_input" /></div>
-                <!--                <div>每批次考试学员数量:<span>0</span></div>-->
-                <!--                <div>计划考试批次:<span>0</span> </div>-->
-            </div>
-            <div id="myTabContent" class="tab-content">
-                <div class="tab-pane fade active in" id="one">
-                    <div class="widget-body no-padding">
-                        <div id="toolbar" class="toolbar">
-                            {:build_toolbar('refresh')}
-                        </div>
-                        <table id="table1" class="table table-striped table-bordered table-hover table-nowrap"
-                               data-operate-edit="{:$auth->check('category/edit')}"
-                               data-operate-del="{:$auth->check('category/del')}" data-show-export="false" data-search="false"
-                               width="100%">
-                        </table>
-                    </div>
-                </div>
 
-            </div>
-        </div>
-    </div>
 
     <div class="form-group layer-footer">
         <label class="control-label col-xs-12 col-sm-2"></label>
         <div class="col-xs-12 col-sm-8">
-            <button type="submit" class="btn btn-primary btn-embossed disabled">{:__('OK')}</button>
+            <button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
         </div>
     </div>
 </form>

+ 6 - 85
application/admin/view/teacher/practice/edit.html

@@ -1,108 +1,29 @@
 <form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
     <div class="row">
-        <input class="form-control depart_ids" name="row[depart_ids]" type="hidden" value="{$row.depart_ids|htmlentities}">
-        <input class="form-control question_ids" name="row[question_ids]" type="hidden" value="{$row.question_ids|htmlentities}">
-        <input class="form-control task_id" name="row[task_id]" type="hidden" value="{$row.task_id|htmlentities}">
-        <div class="form-group col-sm-6">
+        <div class="form-group col-sm-12">
             <label class="control-label col-xs-12 col-sm-3 addRedStar">{:__('Exam_collection_name')}:</label>
             <div class="col-xs-12 col-sm-7">
-                <input id="c-exam_collection_name" data-rule="required" class="form-control" name="row[exam_collection_name]" value="{$row.exam_collection_name|htmlentities}" type="text">
+                <input id="c-exam_collection_name" {if $row.starttime>0} readonly {/if} data-rule="required" class="form-control" name="row[exam_collection_name]" value="{$row.exam_collection_name|htmlentities}" type="text">
             </div>
         </div>
-        <div class="form-group col-sm-6">
-            <label class="control-label col-xs-12 col-sm-3 addRedStar">{:__('Sim_type')}:</label>
-            <div class="col-xs-12 col-sm-7">
-                <select id="c-sim_type" data-rule="required" class="form-control" name="row[sim_type]">
-                    <option value="">请选择</option>
-                    {foreach name="sim_sim_type" item="vo"}
-                    <option value="{$key}" {if $row.sim_type eq $key} selected {/if}>{$vo}</option>
-                    {/foreach}
-                </select>
-            </div>
-        </div>
-<!--        <div class="form-group col-sm-6">-->
-<!--            <label class="control-label col-xs-12 col-sm-3 addRedStar">{:__('Start_time')}:</label>-->
-<!--            <div class="col-xs-12 col-sm-7">-->
-<!--                <input id="c-start_time" class="form-control datetimepicker" data-date-format="YYYY-MM-DD" data-use-current="true" name="row[start_time]" type="text" value="{$row.start_time|htmlentities}">-->
-<!--            </div>-->
-<!--        </div>-->
-<!--        <div class="form-group col-sm-6">-->
-<!--            <label class="control-label col-xs-12 col-sm-3 addRedStar">{:__('End_time')}:</label>-->
-<!--            <div class="col-xs-12 col-sm-7">-->
-<!--                <input id="c-end_time" class="form-control datetimepicker" data-date-format="YYYY-MM-DD" data-use-current="true" name="row[end_time]" type="text" value="{$row.end_time|htmlentities}">-->
-<!--            </div>-->
-<!--        </div>-->
 
-        <div class="form-group col-sm-6">
+
+        <div class="form-group col-sm-12">
             <label class="control-label col-xs-12 col-sm-3 addRedStar">{:__('Limit_duration')}:</label>
             <div class="col-xs-12 col-sm-7">
                 <div class="input-group input-groupp-sm">
-                    <input id="c-limit_duration" class="form-control"  type="number"  name="row[limit_duration]" type="number" value="{$row.limit_duration|htmlentities}">
+                    <input id="c-limit_duration" class="form-control" min="0" {if $row.starttime>0} readonly {/if} type="number" name="row[limit_duration]" type="number" value="{$row.limit_duration|htmlentities}">
                     <span class="input-group-addon">分钟</span>
                 </div>
             </div>
         </div>
 
-        <div class="form-group col-sm-6">
-            <label class="control-label col-xs-12 col-sm-3 addRedStar">{:__('Question_setting_method')}:</label>
-            <div class="col-xs-12 col-sm-7">
-                <select id="c-question_setting_method" data-rule="required" class="form-control" name="row[question_setting_method]">
-                    <option value="">请选择</option>
-                    {foreach name="sim_question_setting_method" item="vo"}
-                    <option value="{$key}" {if $row.question_setting_method eq $key} selected {/if}>{$vo}</option>
-                    {/foreach}
-                </select>
-            </div>
-            <div class="btn btn-info btn-sm" {if $row.question_setting_method neq 2}style="display: none"{/if} >自选考题编辑</div>
-            <div class="btn btn-info btn-task" {if $row.question_setting_method neq 3}style="display: none"{/if} >自选任务编辑</div>
-        </div>
-        <div class="form-group col-sm-6 questions" {if $row.question_setting_method neq 2}style="display: none" {else} style="left: 48%" {/if}>
-            <label class="control-label col-xs-12 col-sm-3 addRedStar">{:__('故障名称')}:</label>
-            <div class="col-xs-12 col-sm-7">
-                <input id="c-question_name" readonly  class="form-control" name="row[question_name]" type="text" value="{$row.question_name|htmlentities}">
-            </div>
-        </div>
-
-        <div class="form-group col-sm-6 tasks" {if $row.question_setting_method neq 3}style="display:none;" {else} style="left: 48%"  {/if}>
-            <label class="control-label col-xs-12 col-sm-3 addRedStar">{:__('故障题目')}:</label>
-            <div class="col-xs-12 col-sm-7">
-                <input id="c-task_name" readonly class="form-control" name="row[task_name]" type="hidden"  value="{$row.task_name|htmlentities}">
-                <input id="c-fault_name" readonly class="form-control" name="row[fault_name]" type="text"  value="{$row.question_name|htmlentities}">
-            </div>
-        </div>
-
-    </div>
-    <div class="panel panel-default panel-intro">
-        <div class="panel-body">
-            <div class="tableTitle success" style="font-size: 16px;margin: 10px 0">统计情况</div>
-            <div class="panel-success">
-                <div>本次练习区队数量:<span class="qudui_total">0</span><input type="hidden" name="row[qudui_count]" value="0" class="qudui_input" />‌</div>
-                <div>计划参加练习学员数量:<span class="xueyuan_total">0</span><input type="hidden" name="row[xueyuan_count]" value="0" class="xueyuan_input" /></div>
-                <!--                <div>每批次考试学员数量:<span>0</span></div>-->
-                <!--                <div>计划考试批次:<span>0</span> </div>-->
-            </div>
-            <div id="myTabContent" class="tab-content">
-                <div class="tab-pane fade active in" id="one">
-                    <div class="widget-body no-padding">
-                        <div id="toolbar" class="toolbar">
-                            {:build_toolbar('refresh')}
-                        </div>
-                        <table id="table1" class="table table-striped table-bordered table-hover table-nowrap"
-                               data-operate-edit="{:$auth->check('category/edit')}"
-                               data-operate-del="{:$auth->check('category/del')}" data-show-export="false" data-search="false"
-                               width="100%">
-                        </table>
-                    </div>
-                </div>
-
-            </div>
-        </div>
     </div>
 
     <div class="form-group layer-footer">
         <label class="control-label col-xs-12 col-sm-2"></label>
         <div class="col-xs-12 col-sm-8">
-            <button type="submit" class="btn btn-primary btn-embossed disabled">{:__('OK')}</button>
+            <button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
         </div>
     </div>
 </form>

+ 0 - 2
public/assets/js/backend/teacher/collection.js

@@ -202,8 +202,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
             Table.api.bindevent(table);
         },
 
-
-
         task: function () {
             // 初始化表格参数配置
             Table.api.init({

+ 114 - 108
public/assets/js/backend/teacher/practice.js

@@ -3,8 +3,8 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','editable'], function
     var Controller = {
 
         index: function () {
-            $('.btn-add').data('area',['85%','85%']);
-            $('.btn-edit').data('area',['85%','85%']);
+            // $('.btn-add').data('area',['85%','85%']);
+            // $('.btn-edit').data('area',['85%','85%']);
             // 初始化表格参数配置
             Table.api.init({
                 extend: {
@@ -34,8 +34,8 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','editable'], function
                         {checkbox: true},
                         {field: 'exam_collection_id', title: __('编号'),operate: false},
                         {field: 'exam_collection_name', title: __('Exam_collection_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
-                        {field: 'sim_type', title: __('Sim_type'),searchList:{"0001":"FZD04B型侦毒器","0002":"FZB006型毒剂报警器","0003":"防化兵用毒剂报警器"},formatter: Table.api.formatter.simtype},
-                        {field: 'question_setting_method', title: __('Question_setting_method'),searchList:{"1":"系统随机","2":"教师自选","3":"任务自选"},formatter: Table.api.formatter.simmethod},
+                        // {field: 'sim_type', title: __('Sim_type'),searchList:{"0001":"FZD04B型侦毒器","0002":"FZB006型毒剂报警器","0003":"防化兵用毒剂报警器"},formatter: Table.api.formatter.simtype},
+                        // {field: 'question_setting_method', title: __('Question_setting_method'),searchList:{"1":"系统随机","2":"教师自选","3":"任务自选"},formatter: Table.api.formatter.simmethod},
                         // {field: 'exam_collection_type', title: __('Exam_collection_type'),operate: false,formatter: function (value, row, index) {
                         //         return '练习';
                         //     }
@@ -50,17 +50,11 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','editable'], function
 
                         // {field: 'task_id', title: __('Task_id')},
                         {field: 'limit_duration', title: __('Limit_duration')},
-                        // {field: 'start_time', title: __('Start_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
-                        // {field: 'end_time', title: __('End_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
-                        // {field: 'create_user_id', title: __('Create_user_id')},
                         {field: 'create_by', title: __('Create_by'), operate: 'LIKE'},
-                        {field: 'qudui_count', title: __('区队数量'), operate: false},
+                        // {field: 'qudui_count', title: __('区队数量'), operate: false},
                         {field: 'xueyuan_count', title: __('应考人数'), operate: false},
                         {field: 'yikao_count', title: __('已考人数'), operate: false},
                         {field: 'createtime', title: __('Create_time'),  operate:'RANGE', addclass:'datetimerange', autocomplete:false,formatter: Table.api.formatter.datetime},
-                        // {field: 'update_by', title: __('Update_by'), operate: 'LIKE'},
-                        // {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
-                        // {field: 'remark', title: __('Remark'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                         {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                             // formatter: Table.api.formatter.operate
                             formatter: Table.api.formatter.buttons,
@@ -71,7 +65,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','editable'], function
                                     icon: 'fa fa-pencil',
                                     title: '编辑',
                                     classname: 'btn btn-success btn-xs btn-magic btn-dialog',
-                                    extend: 'data-area=\'["85%","85%"]\'',
+                                    // extend: 'data-area=\'["85%","85%"]\'',
                                     url: 'teacher/practice/edit',
                                 },
                                 {
@@ -90,6 +84,45 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','editable'], function
                                 },
                                 {
                                     name: 'dispatch',
+                                    text: '查看学员',
+                                    icon: 'fa fa-eye',
+                                    title: '查看学员',
+                                    visible: function (rr) {
+                                        if(rr.user_count > 0){
+                                            return true;
+                                        }
+                                        return false;
+                                    },
+                                    classname: 'btn btn-warning btn-xs btn-magic btn-dialog',
+                                    extend: 'data-area=\'["85%","85%"]\'',
+                                    url: 'teacher/collection/viewuser',
+                                },
+                                {
+                                    name: 'dispatch',
+                                    text: '添加学员',
+                                    icon: 'fa fa-plus',
+                                    title: '添加学员',
+                                    classname: 'btn btn-success btn-xs btn-magic btn-dialog',
+                                    extend: 'data-area=\'["85%","85%"]\'',
+                                    url: 'teacher/practice/adduser',
+                                },
+                                {
+                                    name: 'dispatch',
+                                    text: '删除学员',
+                                    icon: 'fa fa-pencil',
+                                    title: '删除学员',
+                                    visible: function (rr) {
+                                        if(rr.user_count > 0){
+                                            return true;
+                                        }
+                                        return false;
+                                    },
+                                    classname: 'btn btn-info btn-xs btn-magic btn-dialog',
+                                    extend: 'data-area=\'["75%","75%"]\'',
+                                    url: 'teacher/practice/edituser',
+                                },
+                                {
+                                    name: 'dispatch',
                                     text: '删除',
                                     icon: 'fa fa-trash',
                                     title: '删除',
@@ -369,16 +402,68 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','editable'], function
                 table2.bootstrapTable('refresh');
             }, 30000);
 
-
         },
         add: function () {
-            Controller.api.bindevent();
+            Controller.api.bindevent1();
         },
         edit: function () {
-            Controller.api.bindevent();
+            Controller.api.bindevent1();
+        },
+        adduser: function () {
+            Controller.api.bindevent2();
+        },
+        edituser: function () {
+            Controller.api.bindevent2();
         },
         api: {
-            bindevent: function () {
+            bindevent1: function () {
+                Form.api.bindevent($("form[role=form]"));
+            },
+            initSubTable: function (index, row, $detail,parent_table) {
+                var admin_id = row.id;
+                var cur_table = $detail.html('<table id="sub_'+ admin_id +'" style="background-color:#d7d1d147"></table>').find('table');
+                var sub_table = $(cur_table);
+                sub_table.bootstrapTable({
+                    // url: 'area/index',
+                    toolbar: false,
+                    showColumns: false,
+                    showToggle: false,
+                    showExport: false,
+                    search: false,
+                    pagination:false,
+                    commonSearch: false,
+                    sortOrder: 'ASC',
+                    checkboxHeader: false,
+                    columns: [
+                        {checkbox: true,
+                            formatter: function(value,rows,index){
+                                console.log('Config.user_ids');
+                                console.log(Config.user_ids);
+                                if(Config.user_ids.length==0){
+                                    return false;
+                                }else if(Config.user_ids.indexOf(rows.id)>-1){
+                                    return true;
+                                }else{
+                                    return {disabled : true}
+                                }
+                            }
+                        },
+                        // {field: 'id', title: 'ID'},
+                        {field: 'username', title: __('学号')},
+                        {field: 'nickname', title: __('姓名')},
+                    ],
+                    data: row.alluser
+                });
+                Table.api.bindevent(sub_table);
+                sub_table.on("check.bs.table uncheck.bs.table check-all.bs.table uncheck-all.bs.table post-body.bs.table", function (e) {
+                    var selectedIds = Table.api.selectedids(sub_table);
+                    console.log(selectedIds);
+                    $(".xueyuan_input").val(selectedIds.length);
+                    $(".xueyuan_total").html(selectedIds.length);
+                    $(".depart_ids").val(selectedIds.join());
+                })
+            },
+            bindevent2: function () {
                 var rel_Ids = [];
                 var qudui_total = 0;
                 var xueyuan_total = 0;
@@ -396,108 +481,34 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','editable'], function
                     fixedColumns: true,
                     fixedRightNumber: 1,
                     searchFormVisible:false,
-                    pagination:false,
+                    // pagination:false,
+                    detailView: true,//父子表
                     Search:false,
                     columns: [
                         [
-                            {checkbox: true,
-                                formatter: function(value,row,index){
-                                    // console.log(row.id+'####'+Config.row_info.depart_ids)
-                                    if(Config.row_info != undefined && Config.row_info.depart_ids.indexOf(row.id)>-1){
-                                        rel_Ids.push(row.id);
-                                        return true;
-                                    }
-                                    return false;
-                                }
-                            },
+                            {checkbox: true,},
                             {field: 'department_name', title: __('区队名称'), operate: false,width: '400px', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                             {field: 'department_admin_count', title: __('全部人员数量'),operate: false},
                         ]
                     ],
-                    onLoadSuccess: function(data) {
-                        $.each(data.rows, function(index, row) {
-                            if(Config.row_info != undefined && Config.row_info.depart_ids.indexOf(row.id)>-1){
-                                qudui_total = qudui_total+1;
-                                xueyuan_total = xueyuan_total+row.department_admin_count;
-                            }
-
-                        });
-                        $(".qudui_total").html(qudui_total);
-                        $(".xueyuan_total").html(xueyuan_total);
-                        $(".qudui_input").val(qudui_total);
-                        $(".xueyuan_input").val(xueyuan_total);
+                    onExpandRow: function (index, row, $detail) {
+                        Controller.api.initSubTable(index, row, $detail);
                     },
-                    // 点击每一个单选框时触发的操作
-                    onCheck:function(row){
-                        rel_Ids.push(row.id);
-                        qudui_total = qudui_total+1;
-                        xueyuan_total = xueyuan_total+row.department_admin_count;
+                    onCheck: function (row, $element) {
+                        $('.btn-disabled').addClass('disabled');
+                        var id = row.id;
+                        $("#sub_" + id).bootstrapTable("checkAll");
 
-                        $(".depart_ids").val(rel_Ids.join());
-                        $(".qudui_total").html(qudui_total);
-                        $(".xueyuan_total").html(xueyuan_total);
-                        $(".qudui_input").val(qudui_total);
-                        $(".xueyuan_input").val(xueyuan_total);
                     },
-                    // 取消每一个单选框时对应的操作;
-                    onUncheck:function(row){
-                        var index = rel_Ids.indexOf(row.id);
-                        if(index > -1) {
-                            rel_Ids.splice(index, 1);
-                        }
-                        qudui_total = qudui_total-1;
-                        xueyuan_total = xueyuan_total-row.department_admin_count;
-
-                        $(".depart_ids").val(rel_Ids.join());
-                        $(".qudui_total").html(qudui_total);
-                        $(".xueyuan_total").html(xueyuan_total);
-                        $(".qudui_input").val(qudui_total);
-                        $(".xueyuan_input").val(xueyuan_total);
-                    }
+                    onUncheck: function (row) {
+                        var id = row.id;
+                        $("#sub_" + id).bootstrapTable("uncheckAll");
+                    },
                 });
 
                 // 为表格绑定事件
                 Table.api.bindevent(table);
 
-                // table.on('click-row.bs.table', function (e, row, element) {
-                //     console.log(rel_Ids)
-                //     // console.log('row')
-                //     if(!$.inArray(row.id,rel_Ids)){
-                //         if(Config.row_info.starttime>0){
-                //             Layer.alert('考试正在进行中,只可增加区队不可取消区队');
-                //             return false;
-                //         }
-                //         arr = $.grep(rel_Ids, function(value) {
-                //             return value != row["id"];
-                //         });
-                //         rel_Ids = arr;
-                //         qudui_total = qudui_total-1;
-                //         xueyuan_total = xueyuan_total-row.department_admin_count;
-                //     }else if(rel_Ids.indexOf(row.id)>-1){
-                //         if(Config.row_info.starttime>0){
-                //             Layer.alert('考试正在进行中,只可增加区队不可取消区队');
-                //             return false;
-                //         }
-                //         var index = rel_Ids.indexOf(row.id);
-                //         if(index > -1) {
-                //             rel_Ids.splice(index, 1);
-                //         }
-                //         qudui_total = qudui_total-1;
-                //         xueyuan_total = xueyuan_total-row.department_admin_count;
-                //     }else{
-                //         qudui_total = qudui_total+1;
-                //         xueyuan_total = xueyuan_total+row.department_admin_count;
-                //         rel_Ids.push(row.id);
-                //     }
-                //     console.log(qudui_total);
-                //     console.log(xueyuan_total);
-                //     $(".depart_ids").val(rel_Ids.join());
-                //     $(".qudui_total").html(qudui_total);
-                //     $(".xueyuan_total").html(xueyuan_total);
-                //     $(".qudui_input").val(qudui_total);
-                //     $(".xueyuan_input").val(xueyuan_total);
-                // });
-
                 $(document).on('change', '#c-question_setting_method', function () {
                     if($(this).val()==1){
                         $(".btn-sm,.btn-task").css('display','none');
@@ -569,11 +580,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','editable'], function
                     });
                 });
 
-                // $("input[name='btSelectAll']").click(function () {
-                //     var ids = Table.api.selectedids(table);
-                //     console.log(ids);
-                //     $(".depart_ids").val(ids);
-                // });
                 $("button[name=commonSearch]").css('display','none');
                 $("input[name='btSelectAll']").css('display','none');
                 Form.api.bindevent($("form[role=form]"));