liu tao 1 год назад
Родитель
Сommit
ba6dce7709
2 измененных файлов с 44 добавлено и 1 удалено
  1. 14 0
      apps/api/admin/examquestion/views.py
  2. 30 1
      uis/admin/examquestion/index.html

+ 14 - 0
apps/api/admin/examquestion/views.py

@@ -52,6 +52,20 @@ class ExamQuestionViewSet(CustomModelViewSet):
             SysLog.objects.addnew(request.user, SysLog.INSERT, u"删除试题库试题,id=%d" % instance.id)
         return response_ok()
 
+    @action(methods=['post'], detail=False)
+    def batch_del(self, request):
+        ids = request.data
+        try:
+            if ids:
+                with transaction.atomic():
+                    ExamQuestion.objects.filter(id__in=ids).update(delete=True)
+        except CustomError as e:
+            return response_error(e.get_error_msg())
+        except Exception as e:
+            traceback.print_exc()
+            return response_error(str(e))
+        return response_ok()
+
     @action(methods=['get'], detail=False)
     def export(self, request):
         queryset = self.filter_queryset(self.queryset)

+ 30 - 1
uis/admin/examquestion/index.html

@@ -94,6 +94,9 @@
                             <button class="layui-btn layui-btn-sm" id="btn_download">
                                 <i class="layui-icon layui-icon-download-circle"></i>导出
                             </button>
+                            <button class="layui-btn layui-btn-sm" id="exam_question_del">
+                                <i class="layui-icon layui-icon-delete"></i>批量删除
+                            </button>
                         </div>
                         <form class="layui-form" lay-filter="query-form-element">
                             <div class="seach_items">
@@ -159,7 +162,8 @@
             elem: '#exam_question_datagrid'
             , url: '/admin/examquestion/'
             , cols: [[
-                {title: '编号', type: 'numbers'}
+                {type: 'checkbox', fixed: 'left'}
+                , {title: '编号', type: 'numbers'}
                 , {field: 'subject_text', title: '科目', width: 150}
                 , {field: 'chapter_text', title: '章节', width: 150}
                 , {field: 'type_text', title: '题型', width: 100}
@@ -253,6 +257,31 @@
             });
         });
 
+        $('#exam_question_del').on('click', function () {
+            layer.confirm('确定要删除选中试题吗?', function (index) {
+                layer.close(index);
+                var checkStatus = table.checkStatus('exam_question_datagrid');
+                var item = [];
+                for (var i = 0; i < checkStatus.data.length; i++) {
+                    item.push(checkStatus.data[i].id);
+                }
+                if (item.length <= 0) {
+                    return;
+                }
+
+                admin.req({
+                    url: '/admin/examquestion/batch_del/'
+                    , type: 'post'
+                    , data: JSON.stringify(item)
+                    , dataType: 'json'
+                    , contentType: 'application/json'
+                    , done: function (res) {
+                        table.reload('exam_question_datagrid', {});
+                    }
+                });
+            });
+        });
+
         upload.render({
             elem: '#btn_add_single'
             ,url: '/admin/examquestion/import_single/'