赵启卫 2 лет назад
Родитель
Сommit
bb39ae148c

+ 41 - 10
application/admin/controller/study/Plan.php

xqd xqd
@@ -196,23 +196,24 @@ class Plan extends AuthController
         if ($id) {
             $plan = PlanSteps::get($id);
             if (!$plan) return JsonService::fail('学习计划不存在!');
-            if ($op == 'getlist') {
-                //获取当前步骤的课程信息
-                $where = ['stepsid' => $id, ];
-                $list = PlanSteps::where($where)->select();
-                $count = count($list);
-                $return = [
-                    'data' => $list,
-                    'count' => $count,
-                ];
-                return JsonService::successlayui($return);
+            //获取当前步骤的课程信息
+            $where = ['stepsid' => $id, ];
+            $join = [
+                ['special s', 's.id = it.cid and s.is_del = 0 and s.status = 1']
+            ];
+            $coulist = [];
+            $list = PlanItems::alias('it')->field('s.*')->join($join)->where($where)->select();
+            foreach($list as $v){
+                $coulist[$v['id']] = $v;
             }
         } else {
             $plan = [];
+            $coulist = [];
         }
         $this->assign('id', $id);
         $this->assign('pid', $pid);
         $this->assign('plan', json_encode($plan));
+        $this->assign('coulist', json_encode($coulist));
         return $this->fetch();
     }
 
@@ -222,14 +223,44 @@ class Plan extends AuthController
             ['pid', 0],
             ['introduction', ''],
             ['sort', 0],
+            ['courseids', []],
         ]);
         $data['is_del'] = 0;
+        
+        
         if ($id) {
             PlanSteps::edit($data, $id);
+            PlanItems::where(['stepsid' => $id])->delete();
+            if ($data['courseids']){
+                $items = [];
+                foreach ($data['courseids'] as $one) {
+                    $items[] = [
+                        'stepsid' => $id,
+                        'pid' => $data['pid'],
+                        'cid' => $one,
+                        'add_time' => time(),
+                        'type' => 0,
+                    ];
+                }
+                PlanItems::setAll($items);
+            }
             return JsonService::successful('修改成功');
         } else {
             $data['add_time'] = time();
             $res = PlanSteps::set($data);
+            if ($data['courseids']){
+                $items = [];
+                foreach ($data['courseids'] as $one) {
+                    $items[] = [
+                        'stepsid' => $res->id,
+                        'pid' => $data['pid'],
+                        'cid' => $one,
+                        'add_time' => time(),
+                        'type' => 0,
+                    ];
+                }
+                PlanItems::setAll($items);
+            }
             if ($res)
                 return JsonService::successful('添加成功');
             else

+ 0 - 1
application/admin/view/study/plan/addcouse.php

xqd
@@ -13,7 +13,6 @@
                 </ul> -->
                 <div class="layui-tab-content">
                     <div class="layui-tab-item layui-show">
-                        
                         <table id="couList" lay-filter="couList"></table>
                         <script type="text/html" id="couid">
                             <input class="couids" type="checkbox" data-type="couids" lay-filter="filter" value="{{d.id}}" />

+ 12 - 14
application/admin/view/study/plan/createsteps.php

xqd xqd xqd xqd xqd
@@ -87,10 +87,10 @@
 {/block}
 {block name='script'}
 <script>
-    var id={$id}, pid={$pid}, plan=<?=isset($plan) ? $plan : []?>;
+    var id={$id}, pid={$pid}, plan=<?php echo isset($plan) ? $plan : []?>;
     var $ = layui.jquery;
     var layer = layui.layer;
-    var coursechecked = {};
+    var coursechecked = <?php echo isset($coulist) ? $coulist : '{}'?>;
     //加载列表
     require(['vue','helper','zh-cn','request','plupload','aliyun-oss','OssUpload'],function(Vue,$h) {
         new Vue({
@@ -140,6 +140,7 @@
                                 that.formData.courseids.push(i);
                             }
                             //console.log(that.courselist);
+                            layer.close(index)
                             //return false;
                         },
                         btn2: function (index, layero) {
@@ -151,18 +152,6 @@
                             //location.reload();
                         }
                     });
-                    // layList.tableList({o:'couList', done:function(){
-                        
-                    // }},
-                    //     "{:Url('admin/special._special_type/list', ['special_type'=>3])}",
-                    //     function (){
-                    //         return [
-                    //             {field: 'id', title: '排序', align: 'center'},
-                    //             {field: 'title', title: '课程名称',align: 'left'},
-
-                    //         ];
-                    //     }
-                    // );
                     
                 },
                 delitem:function (id){
@@ -188,6 +177,7 @@
                     that.$nextTick(function () {
                         if (!that.formData.stepname) return layList.msg('请输入学习步骤名称');
                         if (!that.formData.introduction) return layList.msg('请输入学习步骤介绍');
+                        if (that.formData.courseids.length == 0) return layList.msg('没有选择如任何课程,至少选择一个课程');
                         layList.loadFFF();
                         layList.basePost(layList.U({a: 'savesteps', q: {id: id}}), that.formData, function (res) {
                             layList.loadClear();
@@ -234,6 +224,14 @@
                     layList.form.render();
                     
                 });
+
+                if (coursechecked) {
+                    for(i in coursechecked) {
+                        that.courselist.push(coursechecked[i]);
+                        that.formData.courseids.push(i);
+                    }
+                }
+                
             }
         })
     });