shilipojs 3 年 前
コミット
554d02db9f

+ 2 - 2
src/api/webApi/elective/dispatch.js

@@ -47,11 +47,11 @@ export function classesResult(params) {
 }
 
 // 分派转移
-export function resultDispatch(params) {
+export function resultDispatch(data) {
   return request({
     url: '/front/elective/classes/result/dispatch',
     method: 'post',
-    params
+    data
   })
 }
 

+ 86 - 58
src/views/elective/dispatch/components/class-adjust.vue

@@ -6,38 +6,34 @@
     width="70%"
   >
     <el-form ref="form" :model="form" label-width="50px" label-position="right">
-      <el-row justify="center">
+      <el-row>
         <el-row>
-          <el-col class="flex-center-column"  :span="12">
+
+          <el-col class="flex-center-column" :span="12">
             <el-form-item>
-              <mx-select @change="getStudents('from',$event)" :span="12" :list="display" v-model="fromClassId" placeholder="请选择" item-label="className" item-value="classId"
+              <mx-select @change="getStudents('from',$event)" :span="12" :list="display" v-model="fromClassId"
+                         placeholder="请选择" item-label="className" item-value="classId"
               ></mx-select>
             </el-form-item>
-            <el-form-item >
+            <el-form-item>
               <class-table :list="studentsTableLeft" @confirm="studentSelected($event,'from')"></class-table>
             </el-form-item>
           </el-col>
           <el-col class="flex-center-column" :span="12">
-            <el-form-item >
-              <mx-select @change="getStudents('to',$event)"  :span="12" :list="display" v-model="toClassId"  placeholder="请选择" item-label="className" item-value="classId"
+            <el-form-item>
+              <mx-select @change="getStudents('to',$event)" :span="12" :list="display" v-model="toClassId"
+                         placeholder="请选择" item-label="className" item-value="classId"
               ></mx-select>
             </el-form-item>
-            <el-form-item >
-              <class-table :list="studentsTableRight" @confirm="studentSelected($event,'to')" ></class-table>
+            <el-form-item>
+              <class-table :list="studentsTableRight" @confirm="studentSelected($event,'to')"></class-table>
             </el-form-item>
           </el-col>
         </el-row>
-<!--        <el-col>-->
-<!--          <el-alert-->
-<!--            title="不可关闭的 alert"-->
-<!--            type="success"-->
-<!--            :closable="false">-->
-<!--          </el-alert>-->
-<!--        </el-col>-->
         <el-col :span="24" class="flex-center" v-if="fromClassId && toClassId" style="margin-top: 20px">
           <el-transfer
             v-model="tranRight"
-            :titles="[fromClassId ? getClassName(fromClassId) : '未选择', toClassId ? getClassName(toClassId) : '未选择']"
+            :titles="[fromClassId ? `${getClassName(fromClassId)}(添加)` : '未选择', toClassId ? `${getClassName(toClassId)}(添加)`: '未选择']"
             :data="parentFrame"
             @change="transferChange"
           >
@@ -53,7 +49,7 @@
 </template>
 
 <script>
-import { classesResult, getDispatchResult } from '@/api/webApi/elective/dispatch'
+import { classesResult, resultDispatch } from '@/api/webApi/elective/dispatch'
 import MxClassTreeTranslateMixin from '@/components/Cache/modules/mx-classTree-translate-mixin.js'
 import MxSelect from '@/components/mx-select/mx-select'
 import ClassTable from './class-table'
@@ -64,10 +60,10 @@ export default {
     MxSelect,
     ClassTable
   },
+  inject: ['refreshData'],
   mixins: [MxClassTreeTranslateMixin],
   data() {
     return {
-      studentListOne: [],
       form: {},
       studentsTableLeft: [],
       studentsTableRight: [],
@@ -75,7 +71,6 @@ export default {
       toClassId: '',
       group: '',
       settings: [],
-      classList: [],
       selectedLeft: [],
       selectedRight: [],
       show: false,
@@ -90,8 +85,7 @@ export default {
       return selected.map(item => {
         return {
           key: item.studentId,
-          label: item.studentName,
-          classId: item.classId
+          label: item.name,
         }
       })
     },
@@ -110,7 +104,7 @@ export default {
       // 获取左tran实际的数据
       // 母框去重右框
       return this.parentFrame.filter(item => {
-        if(this.tranRight.findIndex(r => r == item.key ) == -1) {
+        if (this.tranRight.findIndex(r => r == item.key) == -1) {
           return item
         }
       })
@@ -119,71 +113,104 @@ export default {
       // 获取左tran实际的数据
       // 母框去重右框
       return this.parentFrame.filter(item => {
-      if(this.tranRight.findIndex(r => r == item.key ) != -1 )return item
+        if (this.tranRight.findIndex(r => r == item.key) != -1) return item
+      })
+    },
+    saveResultDispatch(clazzId,students) {
+      // 分派转移
+      resultDispatch({
+        roundId: this.group.roundId,
+        students: students,
+        toClazzId: clazzId
+      }).then(res => {
+        console.log(res)
       })
     },
     confirm() {
-       // 左tran 是包含 右边的  (只是不显示右tran的数据)要先去重
-       // 左tran 去掉跟左table重复的数据就是 右tran 需要调换的
-       // 同理右tran 去掉跟右table重复的数据就是 左tran 需要调换的
-       // 1.去重
+      if( !this.fromClassId || !this.toClassId) {
+        this.$message.warning('请先选择需要调整的两个班级')
+        return
+      }
+      // 左tran 是包含 右边的  (只是不显示右tran的数据)要先去重
+      // 左tran 去掉跟左table重复的数据就是 右tran 需要调换的
+      // 同理右tran 去掉跟右table重复的数据就是 左tran 需要调换的
+      // 1.去重
       // 左tran实际勾选去除左边table
       const left = this.getTranLeft().filter(item => {
         return this.studentsTableLeft.findIndex(s => s.studentId == item.key) == -1
-      })
+      }).map(item => item.key)
       //  右tran实际勾选去除右边table
       const right = this.getTranRight().filter(item => {
         return this.studentsTableRight.findIndex(s => s.studentId == item.key) == -1
-      })
+      }).map(item => item.key)
       console.log(left) // 左边的学生放入左边表格
-      console.log(right)// 右边的学生放入右边边表格
-       // 2.分别调用调换接口
+      if( !left.length && !right.length) {
+        this.$message.warning('调整人数不可为0')
+        return
+      }
+      // 2.分别调用调换接口
+      if (left.length) this.saveResultDispatch(this.fromClassId,left)
+      console.log(left)// 左边的学生放入左边表格
+      console.log(right)// 右边的学生放入右边表格
+      if (right.length) this.saveResultDispatch(this.toClassId,right)
+      this.$nextTick(()=> {
+        this.show = false
+        // 注销数据
+        Object.assign(this.$data,this.$options.data());
+        this.refreshData()
+      })
+
+      // 2.分别调用调换接口
 
     },
-    studentSelected(list,type) {
+    studentSelected(list, type) {
       // 1 添加至母框
-      if(type== 'from'){
-        this.selectedLeft = list
-      }
-      if(type== 'to'){
-        this.selectedRight = list
-      }
+      if (type == 'from') this.selectedLeft = list
+      if (type == 'to') this.selectedRight = list
+
     },
-    getStudents(type,classId) {
+    getStudents(type, classId) {
       console.log(type)
       console.log(classId)
       classesResult({
-        group: this.group.groupId,
+        groupId: this.group.groupId,
         roundId: this.group.roundId,
         classId: classId
       }).then(res => {
-        console.log(res)
-      })
-      getDispatchResult().then(res => {
-        console.log(res)
-         if( type =='from') this.studentsTableLeft = res.data[0].students.map(item => {
-           item.classId = classId
-           item.className =  this.getClassName(classId)
-           return item
-         })
-         if( type =='to') this.studentsTableRight = res.data[1].students.map(item => {
-           item.classId = classId
-           item.className =  this.getClassName(classId)
-           return item
-         })
+        if( type == 'from') {
+          if(!res.hasOwnProperty('data')){
+            this.studentsTableLeft = []
+            return
+          }
+          this.studentsTableLeft = res.data.students.map(item => {
+            item.classId = classId
+            item.className = this.getClassName(classId)
+            return item
+          })
+        }else if( type == 'to') {
+          if(!res.hasOwnProperty('data')){
+            this.studentsTableRight = []
+            return
+          }
+          this.studentsTableRight = res.data.students.map(item => {
+            item.classId = classId
+            item.className = this.getClassName(classId)
+            return item
+          })
+        }
       })
     },
     // 判断是否有这个元素
     getDisable(itemId) {
-       return this.fromClassId == itemId || this.toClassId == itemId
+      return this.fromClassId == itemId || this.toClassId == itemId
     },
     transferChange(currentVal, direction, array) {
-      if(!this.fromClassId || !this.toClassId) {
+      if (!this.fromClassId || !this.toClassId) {
         this.$message.warning('需要选择两个班级')
         return
       }
     },
-    open(row ,settings) {
+    open(row, settings) {
       console.log(row)
       console.log(settings)
       this.group = row
@@ -200,7 +227,8 @@ export default {
   flex-direction: column;
   justify-content: center;
 }
-.flex-center{
+
+.flex-center {
   display: flex;
   flex-direction: row;
   justify-content: center;

+ 5 - 1
src/views/elective/dispatch/components/class-table.vue

@@ -15,7 +15,7 @@
       >
       </el-table-column>
       <el-table-column
-        prop="studentName"
+        prop="name"
         label="姓名"
       >
       </el-table-column>
@@ -23,10 +23,14 @@
         prop="sex"
         label="性别"
       >
+        <template slot-scope="scope">
+          {{scope.$index % 2 == 0 ? '男' : '女'}}
+        </template>
       </el-table-column>
       <el-table-column
         prop="rankInGroup"
         label="排名"
+        type="index"
       >
       </el-table-column>
     </el-table>

+ 12 - 11
src/views/elective/dispatch/components/dispatch-table.vue

@@ -116,17 +116,18 @@ export default {
       if (!this.listGroupsOptions.length) return []
       // if (!this.settings.length) return []
       if (!this.round.groupList) return []
-      const rows = this.round.groupList.map(rg => ({
-        groupId: rg.groupId,
-        roundId: this.round.roundId,
-        groupName: rg.name,
-        number: this.round.enrollGroupCount[rg.groupId] || 200, // 录取人数
-        classCount: rg.classCount || 2, // 班级数
-        expectedCount: this.settings.filter(item => item.groupId == rg.groupId).map(item => item.expectedCount).toString(),
-        groupClass: this.settings
-          .filter(item => item.groupId == rg.groupId)
-          .map(item => this.getClassName(item.classId)).toString()
-      }))
+      const rows = this.round.roundGroups.map(rg => ({
+
+          groupId: rg.groupId,
+          roundId: this.round.roundId,
+          groupName: this.translateGroup(rg.groupId),
+          number: this.round.enrollGroupCount[rg.groupId] || 200, // 录取人数
+          classCount: rg.classCount, // 班级数
+          expectedCount: this.settings.filter(item => item.groupId == rg.groupId).map(item => item.expectedCount).toString(),
+          groupClass: this.settings
+            .filter(item => item.groupId == rg.groupId)
+            .map(item => this.getClassName(item.classId)).toString()
+        }))
       console.log('displayRows computed:', rows)
       return rows
     }