From c19bb5ac1b4013aa700c0a658f20375be9703ea3 Mon Sep 17 00:00:00 2001
From: 龚焕茏 <2842157468@qq.com>
Date: 星期一, 08 七月 2024 18:45:47 +0800
Subject: [PATCH] feat:选择学生增加全选按钮

---
 src/views/exam/personalRandomTemplate/edit.vue |   60 ++++++++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 48 insertions(+), 12 deletions(-)

diff --git a/src/views/exam/personalRandomTemplate/edit.vue b/src/views/exam/personalRandomTemplate/edit.vue
index 763f87d..a2e4527 100644
--- a/src/views/exam/personalRandomTemplate/edit.vue
+++ b/src/views/exam/personalRandomTemplate/edit.vue
@@ -8,15 +8,21 @@
             :key="item.id"></el-option>
         </el-select>
       </el-form-item>
+      <el-form-item label="閮ㄩ棬锛�" prop="deptId" required>
+        <!-- <el-select v-model="form.deptId" collapse-tags @change="getSubject" placeholder="閮ㄩ棬">
+          <el-option v-for="item in depts" :key="item.id" :value="item.id" :label="item.name"></el-option>
+        </el-select> -->
+        <el-cascader
+          clearable
+          v-model="form.deptId"
+          :options="depts"
+          :props="{ emitPath: false, value: 'id', label: 'name',  checkStrictly: true }"
+          ></el-cascader>
+      </el-form-item>
       <el-form-item label="璇剧洰锛�" prop="subjectId" required>
-        <el-select ref="subjectIdRef" v-model="form.subjectId" placeholder="璇剧洰" multiple collapse-tags
+        <el-select ref="subjectIdRef" v-model="form.subjectId" :disabled="! form.deptId" placeholder="璇剧洰" multiple collapse-tags
           @visible-change="subjectIdEvent">
           <el-option v-for="item in subjectFilter" :key="item.id" :value="item.id" :label="item.name + ' '"></el-option>
-        </el-select>
-      </el-form-item>
-      <el-form-item label="閮ㄩ棬锛�" prop="deptId" required>
-        <el-select v-model="form.deptId" collapse-tags placeholder="閮ㄩ棬">
-          <el-option v-for="item in depts" :key="item.id" :value="item.id" :label="item.name"></el-option>
         </el-select>
       </el-form-item>
       <el-form-item label="璇曞嵎绫诲瀷锛�" prop="paperType" required>
@@ -147,14 +153,21 @@
           </el-select>
         </el-form-item>
         <el-form-item label="閮ㄩ棬锛�">
-          <el-select v-model="student.deptIds" clearable multiple>
+          <!-- <el-select v-model="student.deptIds" clearable multiple>
             <el-option v-for="item in depts" :key="item.id" :value="item.id" :label="item.name"></el-option>
-          </el-select>
+          </el-select> -->
+          <el-cascader
+          clearable
+          v-model="student.deptIds"
+          :options="depts"
+          :props="{ multiple: true, emitPath: false, value: 'id', label: 'name',  checkStrictly: true }"
+          ></el-cascader>
         </el-form-item>
         <el-form-item>
           <el-button type="primary" @click="selectStudent">鏌ヨ</el-button>
         </el-form-item>
       </el-form>
+      <el-button type="primary" @click="selectAllBoolean ? selectAll() : unselectAll()">{{ selectAllBoolean ? '鍏ㄩ��' : '鍙栨秷鍏ㄩ��' }}</el-button>
       <el-table ref="multipleTable" v-loading="student.listLoading" :data="tableData" border fit highlight-current-row
         style="width: 100%" @selection-change="handleSelection" row-key="id">
         <el-table-column type="selection" :reserve-selection="true"></el-table-column>
@@ -176,6 +189,7 @@
 import Pagination from '@/components/Pagination';
 import QuestionShow from '../question/components/Show';
 import examPaperApi from '@/api/examPaper';
+import subjectApi from '@/api/subject';
 import userApi from '@/api/user';
 import questionApi from '@/api/question';
 import departmentApi from '@/api/department';
@@ -185,6 +199,7 @@
 
   data() {
     return {
+      selectAllBoolean: true,
       tags: [],
       studentDialog: false,
       student: {
@@ -270,7 +285,7 @@
           questionType: null,
           subjectId: 1,
           pageIndex: 1,
-          pageSize: 5
+          pageSize: 500000000
         },
         listLoading: true,
         tableData: [],
@@ -284,7 +299,7 @@
       console.log(res);
       this.subjectFilter = res.response;
     });
-    departmentApi.getDeptAdmins().then(res => {
+    departmentApi.list().then(res => {
       this.depts = res.response;
     });
   },
@@ -326,13 +341,34 @@
         };
       });
     });
-
-    // this.subjectIdEvent(false)
   },
   methods: {
+    getSubject(deptId) {
+      // 鑾峰彇瀵瑰簲閮ㄩ棬鐨勮鐩�
+      subjectApi.selectByDeptId(deptId).then(res => {
+        this.form.subjectId = null
+        this.subjectFilter = res.response
+      })
+    },
     handleSelection(val) {
       this.student.multipleSelection = val;
     },
+    selectAll () {
+      this.selectAllBoolean = false;
+      let param = { ...this.student };
+      param.pageSize = 999999;
+      examPaperApi.selectStudent(param).then(res => {
+        this.handleSelection(res.response.list);
+        res.response.list.forEach(item => {
+          this.$refs.multipleTable.toggleRowSelection(item, true);
+        })
+        this.getStudent();
+      });
+    },
+    unselectAll () {
+      this.selectAllBoolean = true;
+      this.$refs.multipleTable.clearSelection();
+    },
     confirmStudentSelect() {
       this.form.userIds = this.student.multipleSelection.map((item) => item.id);
       this.form.examineeList = this.student.multipleSelection.map((item) => {

--
Gitblit v1.8.0