ソースを参照

學生帳號完成批次修改與個人修改 #251

osbert 4 年 前
コミット
01f5754c4a

+ 14 - 8
TEAMModelOS/ClientApp/src/api/stuAccount.js

@@ -24,7 +24,20 @@ export default {
             "schoolId": schoolId.toLowerCase(),
             "schoolId": schoolId.toLowerCase(),
             "students": []
             "students": []
         }
         }
-        format.students.push(data)
+        format.students.push(...data)
+        return post('/api/Student/student-manage', format)
+    },
+    /**
+     * 刪除學生
+     * @param {any} data
+     */
+    deleteStudent: function(data) {
+        let format = {
+            "grant_type": "delete",
+            "schoolId": schoolId.toLowerCase(),
+            "students": []
+        }
+        format.students.push(...data)
         return post('/api/Student/student-manage', format)
         return post('/api/Student/student-manage', format)
     },
     },
     updateStudent: function(data) {
     updateStudent: function(data) {
@@ -33,13 +46,6 @@ export default {
     updateAllStudent: function(data) {
     updateAllStudent: function(data) {
         return post('/api/Student/upsertAll', data)
         return post('/api/Student/upsertAll', data)
     },
     },
-    /**
-     * ����ɾ��ѧ��
-     * @param {any} data
-     */
-    deleteStudent: function(data) {
-        return post('/api/Student/delete', data)
-    },
     /**
     /**
      * ����ɾ��ѧ��
      * ����ɾ��ѧ��
      * @param {any} data
      * @param {any} data

+ 13 - 5
TEAMModelOS/ClientApp/src/store/module/schoolBaseInfo.js

@@ -29,10 +29,15 @@ export default {
             state.students.push(...data)
             state.students.push(...data)
         },
         },
         uptStudents(state, data) {
         uptStudents(state, data) {
-            data.forEach(function(uptItem){
-                state.students.forEach(function(orgItem){
-
-                })
+            data.forEach(function(item){
+                let objIndex = state.students.findIndex((obj => obj.id == item.id));
+                state.students[objIndex] = item
+            })
+        },
+        delStudents(state, data) {
+            data.forEach(function(item){
+                let objIndex = state.students.findIndex((obj => obj.id == item.id));
+                state.students.splice(objIndex, 1);
             })
             })
         }
         }
     },
     },
@@ -155,6 +160,9 @@ export default {
         },
         },
         uptStudentsToState(context, data) {            
         uptStudentsToState(context, data) {            
             context.commit('uptStudents', data)
             context.commit('uptStudents', data)
-        }
+        },
+        delStudentsToState(context, data) {            
+            context.commit('delStudents', data)
+        },
     }
     }
 }
 }

+ 69 - 71
TEAMModelOS/ClientApp/src/view/student-account/AddStudent.vue

@@ -142,10 +142,10 @@
                     <span style="color:white;">{{ gradeName }}</span>
                     <span style="color:white;">{{ gradeName }}</span>
                 </FormItem>
                 </FormItem>
             </div>
             </div>
-            <div style="display:flex;justify-content: space-between;">
+            <div style="display:flex;justify-content: space-between;" v-if="editStudentInfo.length == 1">
                 <!-- 學年度 -->
                 <!-- 學年度 -->
                 <FormItem :label="$t('stuAccount.academicYear')" prop="year" style="width:45%">
                 <FormItem :label="$t('stuAccount.academicYear')" prop="year" style="width:45%">
-                    <InputNumber v-model="editStudentInfo[0].year" :editable="false"></InputNumber>
+                    <Input v-model="editStudentInfo[0].year" disabled></Input>
                 </FormItem>
                 </FormItem>
             </div>
             </div>
         </Form>
         </Form>
@@ -296,44 +296,7 @@
                     } else {
                     } else {
                         this.gradeName = res.name
                         this.gradeName = res.name
                     }
                     }
-                })
-                if (this.bizType == 1) {
-                    
-                    
-                } else {
-
-                }
-            },
-            getCurrentClassroom(index) {
-                //bizType:1 新增
-                if (this.bizType == 1) {
-                    // this.studentInfo.classroomName = this.classroomList[index].classroomName
-                    // this.studentInfo.periodCode = this.classroomList[index].periodCode;
-                    // this.studentInfo.gradeCode = this.classroomList[index].gradeCode;
-                    // this.studentInfo.classId = this.classroomList[index].classId;
-                    // let currentInfo = this.$JSONPath.query(this.$store.state.schoolBaseInfo.schoolBaseInfo, "$..period[?(@.periodCode=='" + this.classroomList[index].periodCode + "')]")
-
-                    // if (currentInfo.length > 0) {
-                    //     this.studentInfo.periodName = currentInfo[0].periodName
-                    //     this.studentInfo.gradeName = this.$JSONPath.query(currentInfo, "$..grades[?(@.gradeCode=='" + this.classroomList[index].gradeCode + "')]")[0].gradeName
-                    // }
-
-                } else {
-                    // let currentInfo = this.$JSONPath.query(this.$store.state.schoolBaseInfo.schoolBaseInfo, "$..period[?(@.periodCode=='" + this.classroomList[index].periodCode + "')]")
-                    // let periodName = '数据错误'
-                    // let gradeName = '数据错误'
-                    // if (currentInfo.length > 0) {
-                    //     periodName = currentInfo[0].periodName
-                    //     gradeName = this.$JSONPath.query(currentInfo, "$..grades[?(@.gradeCode=='" + this.classroomList[index].gradeCode + "')]")[0].gradeName
-                    // }
-                    // for (let i = 0; i < this.editStudentInfo.length; i++) {
-                    //     this.editStudentInfo[i].periodCode = this.classroomList[index].periodCode
-                    //     this.editStudentInfo[i].gradeCode = this.classroomList[index].gradeCode
-                    //     this.editStudentInfo[i].classId = this.classroomList[index].classId
-                    //     this.$set(this.editStudentInfo[i],'periodName',periodName)
-                    //     this.$set(this.editStudentInfo[i],'gradeName',gradeName)
-                    // }
-                }
+                })   
             },
             },
             getClassroom() {
             getClassroom() {
                 this.classroomList = this.$store.state.schoolBaseInfo.classroomList
                 this.classroomList = this.$store.state.schoolBaseInfo.classroomList
@@ -355,35 +318,58 @@
                     this.same = false
                     this.same = false
                     if (this.bizType == 2) {
                     if (this.bizType == 2) {
                         this.isLoading = true
                         this.isLoading = true
-                        let editInfo = this.editStudentInfo.map(function(item){
-                            let itemTemp = item
-                            if(itemTemp.pw == '******') {
-                                delete itemTemp.pw
-                            }
-                            return itemTemp
-                        })
+                        var editInfo = this.editStudentInfo
 
 
-                        this.$api.stuAccount.saveAllStudent(this.schoolCode, this.editStudentInfo).then(
-                            (res) => {
-                                if (res.error == null) {
-                                    this.show = false
-                                    this.$emit('saveStudentInfo', {
-                                        action: 2, // 批量修改数据
-                                        studentInfo: this.editStudentInfo
-                                    })
-                                    this.$refs.updateForm.resetFields()
-                                    // this.initData();
-                                    this.uploadLoading = false
-                                } else {
-                                    this.$Message.error('API error!')
-                                }
-                                this.isLoading = false
-                            },
-                            (err) => {
-                                this.$Message.error('API error!')
+                        let stringify = JSON.stringify(this.editStudentInfo)
+                        let parse = JSON.parse(stringify)
+                        let apiData = []
+                        if(parse.length == 1){
+                            parse.forEach(function(item){
+                                item.year = item.year ? item.year.toString() : ''
+                                item.no = item.no ? item.no.toString() : ''
+                            })                            
+
+                            if(this.isRepeat(parse[0])){
+                                this.$Message.error('請檢查 帳號資訊 或 座號重複 了。')
                                 this.isLoading = false
                                 this.isLoading = false
+                            } else {
+                                apiData = parse
                             }
                             }
-                        )
+                        } else {
+                            let classId = parse[0].classId
+                            let temp = parse.map(function(item){
+                                return {
+                                    no : "",
+                                    id: item.id,
+                                    classId: classId,
+                                    name: item.name,
+                                    year: item.year ? item.year.toString() : ''
+                                }
+                            }) 
+                            apiData = temp
+                        }
+                        if(apiData.length > 0){
+                            this.$api.stuAccount.saveAllStudent(this.schoolCode, apiData).then(
+                                (res) => {
+                                    if (res.error == null) {
+                                        this.show = false
+                                        this.$emit('saveStudentInfo', {
+                                            action: 2, // 批量修改数据
+                                            studentInfos: res.students
+                                        })
+                                        this.$refs.updateForm.resetFields()
+                                        this.uploadLoading = false
+                                    } else {
+                                        this.$Message.error('API error!')
+                                    }
+                                    this.isLoading = false
+                                },
+                                (err) => {
+                                    this.$Message.error('API error!')
+                                    this.isLoading = false
+                                }
+                            )
+                        }
                     } else {
                     } else {
                         this.isLoading = true
                         this.isLoading = true
 
 
@@ -398,14 +384,10 @@
                             // "className":this.studentInfo.classroomName ? this.studentInfo.classroomName : ''
                             // "className":this.studentInfo.classroomName ? this.studentInfo.classroomName : ''
                         }
                         }
 
 
-                        let isRepeat= this.students.some(function(item){                            
-                            return (item.id === apiData.id || (apiData.classId !='' && apiData.classId === item.classId && apiData.no === item.no))
-                        })
-                        if(isRepeat){
+                        if(this.isRepeat(apiData)){
                             this.$Message.error('請檢查 帳號資訊 或 座號重複 了。')
                             this.$Message.error('請檢查 帳號資訊 或 座號重複 了。')
                             this.isLoading = false
                             this.isLoading = false
                         } else {
                         } else {
-
                             this.$api.stuAccount.saveStudent(this.schoolCode, apiData).then(
                             this.$api.stuAccount.saveStudent(this.schoolCode, apiData).then(
                                 (res) => {
                                 (res) => {
                                     if (res.error == null) {
                                     if (res.error == null) {
@@ -433,6 +415,22 @@
                 this.$router.push({
                 this.$router.push({
                     path: '/school/classroom'
                     path: '/school/classroom'
                 })
                 })
+            },
+            isRepeat(data){
+                if(this.bizType == 1){
+                    return this.students.some(function(item){
+                        return (item.id === data.id || (data.classId !='' && data.classId === item.classId && data.no === item.no))
+                    })
+                } else if(this.bizType == 2){
+                    let temp = this.students.filter(function(item){
+                        return (data.classId !='' && data.classId === item.classId && data.no === item.no)
+                    })
+                    if(temp.length > 0){
+                        return !(temp[0].id == data.id)
+                    } else {
+                        return false
+                    }
+                }                
             }
             }
         },
         },
         created() {
         created() {

+ 14 - 22
TEAMModelOS/ClientApp/src/view/student-account/Index.vue

@@ -161,14 +161,6 @@
                     return '--'
                     return '--'
                 }
                 }
             },
             },
-            getGradeList(index) {
-console.log(index, 'getGradeList')
-                // this.gradeList = this.schoolData.period[index].grade
-                // this.classroomShowList = this.classroomList.filter((item) => { return item.period == this.schoolData.period[index].code })
-                // if (this.classroomShowList.length == 0) {
-                //     this.$refs.classroom.clearSingleSelect()
-                // }
-            },
             getClassroomList(index) {
             getClassroomList(index) {
                 this.classroomShowList = this.classroomList.filter((item) => { return item.grade == this.gradeList[index].code })
                 this.classroomShowList = this.classroomList.filter((item) => { return item.grade == this.gradeList[index].code })
                 if (this.classroomShowList.length == 0) {
                 if (this.classroomShowList.length == 0) {
@@ -210,11 +202,13 @@ console.log(index, 'getGradeList')
                 let newStudents = data.studentInfos.map(function(item){
                 let newStudents = data.studentInfos.map(function(item){
                     let temp = item
                     let temp = item
                     temp.pw = '******'
                     temp.pw = '******'
+                    temp.year = parseInt(temp.year)
                     return temp
                     return temp
                 })
                 })
                 let storePath = (data.action == 1 ? 'schoolBaseInfo/setStudentsToState' : 'schoolBaseInfo/uptStudentsToState')
                 let storePath = (data.action == 1 ? 'schoolBaseInfo/setStudentsToState' : 'schoolBaseInfo/uptStudentsToState')
                 this.$store.dispatch(storePath, newStudents)
                 this.$store.dispatch(storePath, newStudents)
                 this.addStudentStatus = false
                 this.addStudentStatus = false
+                this.filterData()
             },
             },
             closeImportStudent(data) {
             closeImportStudent(data) {
                 this.findStudentInfo()
                 this.findStudentInfo()
@@ -240,16 +234,19 @@ console.log(index, 'getGradeList')
                 if (index != undefined) {
                 if (index != undefined) {
                     this.editStudentInfo = []
                     this.editStudentInfo = []
                     index.year = parseInt(index.year)
                     index.year = parseInt(index.year)
-                    this.editStudentInfo.push(index)
-                    
-                    // this.tableShowData[index]._checked = true
-                    // this.$forceUpdate()
+                    // 避免被深拷貝
+                    let obj = JSON.parse(JSON.stringify(index))
+                    this.editStudentInfo.push(obj)
+
                     this.addStudentStatus = true
                     this.addStudentStatus = true
                 } else {
                 } else {
-                    console.log(this.selections, 'selections')
                     if (this.selections.length > 0) {
                     if (this.selections.length > 0) {
                         this.editStudentInfo.length = 0
                         this.editStudentInfo.length = 0
                         this.editStudentInfo = [...this.selections]
                         this.editStudentInfo = [...this.selections]
+
+                        // 多筆設定拿掉classId
+                        this.editStudentInfo[0].classId = ''
+
                         this.addStudentStatus = true
                         this.addStudentStatus = true
                     }
                     }
                     else {
                     else {
@@ -270,18 +267,13 @@ console.log(index, 'getGradeList')
                         content: '<p>' + this.$t('stuAccount.tips2Content1') + " <strong style='color:red;'>" + this.tableShowData[index].name + '</strong></p>',
                         content: '<p>' + this.$t('stuAccount.tips2Content1') + " <strong style='color:red;'>" + this.tableShowData[index].name + '</strong></p>',
                         onOk: () => {
                         onOk: () => {
                             this.tableLoading = true
                             this.tableLoading = true
+
                             this.$api.stuAccount.deleteStudent(this.tableShowData[index]).then(
                             this.$api.stuAccount.deleteStudent(this.tableShowData[index]).then(
                                 (res) => {
                                 (res) => {
+                                    console.log(res)
                                     if (res.error == null) {
                                     if (res.error == null) {
-                                        //分页查询后,直接重新访问API
-                                        let findCountParams = {
-                                            "collectionName": "Student",
-                                            "queryDict": {
-                                                'code': this.$store.state.user.schoolCode
-                                            }
-                                        }
-                                        this.getResultCount(findCountParams)
-                                        this.findStudentInfo()
+                                        // this.$store.dispatch('schoolBaseInfo/delStudentsToState', newStudents)
+                                        // this.filterData()
                                     }
                                     }
                                     this.tableLoading = false
                                     this.tableLoading = false
                                 },
                                 },