school-detail.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <template>
  2. <div class="app-container">
  3. <el-card>
  4. <template #header>学校信息</template>
  5. <el-form label-position="right" label-width="80px">
  6. <el-form-item label="学校">
  7. {{ school && school.schoolName }}
  8. </el-form-item>
  9. <el-form-item v-if="!allowClassSelect&&isSenior&&isFrontStudent" class="form-item-readonly">
  10. 未到重选班级时间<span class="f-red">*</span>
  11. </el-form-item>
  12. </el-form>
  13. <class-tree-form ref="studentForms" :data-source="classTree" :model-value="model"
  14. :disabled="!allowClassSelect"></class-tree-form>
  15. <div class="fx-row fx-cen-cen mt20">
  16. <el-button v-if="isFrontTeacher" type="primary" round style="width: 150px" @click="handleExchange">申请换班
  17. </el-button>
  18. <el-button v-if="allowClassSelect" type="primary" round style="width: 150px" @click="handleSelectClass">保存班级
  19. </el-button>
  20. </div>
  21. </el-card>
  22. <el-card v-if="isFrontTeacher" class="mt20">
  23. <template #header>授课班级变更申请列表</template>
  24. <headteacher-form-list ref="formList" :options="formListOptions"></headteacher-form-list>
  25. </el-card>
  26. <el-dialog v-if="applyDialogVisible" :visible.sync="applyDialogVisible" title="申请更换授课班级" type="center"
  27. width="600px">
  28. <class-tree-form ref="form" :modelValue="model" :rules="rules" :dataSource="classTree">
  29. </class-tree-form>
  30. <div class="fx-row fx-end-cen mt20">
  31. <el-button @click="handleClose">取消</el-button>
  32. <el-button type="primary" @click="handleConfirm">确定</el-button>
  33. </div>
  34. </el-dialog>
  35. </div>
  36. </template>
  37. <script>
  38. import { mapActions, mapGetters } from 'vuex'
  39. import ClassTreeMixin from '@/components/Cache/modules/mx-classTree-translate-mixin'
  40. import ClassTreeForm from '@/views/system/user/profile/components/class-tree-form'
  41. import { getSchoolParams, getUserForms } from '@/api/webApi/form'
  42. import { updateUserGradeAndClasses } from '@/api/webApi/grade'
  43. import HeadteacherFormList from '@/views/system/user/profile/components/headteacher-form-list'
  44. import * as ext from '@/utils'
  45. import consts from '@/common/mx-const'
  46. export default {
  47. mixins: [ClassTreeMixin],
  48. name: 'school-detail',
  49. components: { HeadteacherFormList, ClassTreeForm },
  50. data() {
  51. return {
  52. model: {},
  53. rules: {},
  54. schoolSettings: {},
  55. applyDialogVisible: false,
  56. // form list
  57. dateRange: ext.getDefaultDateRange(1),
  58. queryFormTypes: [
  59. consts.enum.formType.addClass,
  60. consts.enum.formType.delClass,
  61. consts.enum.formType.updateClass
  62. ]
  63. }
  64. },
  65. computed: {
  66. ...mapGetters(['school', 'isFrontStudent', 'isFrontTeacher', 'isSenior']),
  67. allowClassSelect() {
  68. // allowSelectClass这个控制是给学生选班期间使用的
  69. return this.schoolSettings.allowSelectClass && this.isFrontStudent
  70. },
  71. formListOptions() {
  72. return {
  73. queryApi: getUserForms,
  74. queryParams: {
  75. begin: this.dateRange.first(),
  76. end: this.dateRange.last(),
  77. formType: this.queryFormTypes.toString()
  78. }
  79. }
  80. }
  81. },
  82. mounted() {
  83. this.loadSchoolSettings()
  84. },
  85. methods: {
  86. ...mapActions(['GetInfo']),
  87. translateClassTreeReady() {
  88. // 按年级建立动态监听
  89. this.classTree.forEach(grade => {
  90. // 需要动态组建model方便form交互
  91. const boundGrade = this.school.grade.find(g => g.gradeId == grade.grade)
  92. const boundClassList = boundGrade?.clazz.map(c => c.classId) || []
  93. this.model[grade.name] = boundClassList
  94. this.rules[grade.name] = [] // hht 22.1.27 因都涉及多对多,原来的校验规则已经失效
  95. })
  96. // 浅表拷贝,为了触发mxClassTreeForm watch
  97. this.model = {
  98. ...this.model
  99. }
  100. },
  101. loadSchoolSettings() {
  102. getSchoolParams().then(res => {
  103. this.schoolSettings = res.data
  104. })
  105. },
  106. handleExchange() {
  107. this.applyDialogVisible = true
  108. },
  109. handleClose() {
  110. this.applyDialogVisible = false
  111. },
  112. handleConfirm() {
  113. this.$refs.form.validate().then(data => {
  114. const submitModel = this.$refs.form.getModel()
  115. console.log('mx-float-form-page form valid:', data, submitModel)
  116. this.submit(submitModel)
  117. })
  118. },
  119. submit(submitModel) {
  120. // 因为data-checkbox只能选择value,所以最终要转化一下才能变成提交的格式
  121. const transferBounds = Object.keys(submitModel)
  122. .filter(gradename => submitModel[gradename].length)
  123. .map(gradename => {
  124. const boundClassIdList = submitModel[gradename]
  125. const matchGrade = this.classTree.find(g => g.name == gradename)
  126. const clone = {
  127. ...matchGrade
  128. }
  129. clone.classList = matchGrade.classList.filter(c => boundClassIdList.includes(c.classId))
  130. return clone
  131. })
  132. if (!transferBounds.length) {
  133. this.msgError('请至少选择1个班级进行绑定')
  134. return
  135. }
  136. this.handleClose()
  137. updateUserGradeAndClasses({
  138. gradeClass: transferBounds
  139. }).then(rp => {
  140. this.GetInfo().then(_ => {
  141. this.msgSuccess(this.isFrontStudent ? '保存成功' : '申请成功')
  142. this.translateClassTreeReady() // 重新绑定,有可能直接生效
  143. this.reloadFormList()
  144. })
  145. })
  146. },
  147. handleSelectClass() {
  148. this.$refs.studentForm.validate().then(data => {
  149. const submitModel = this.$refs.studentForm.getModel()
  150. console.log('mx-float-form-page student form valid:', data, submitModel)
  151. this.submit(submitModel)
  152. })
  153. },
  154. reloadFormList() {
  155. if (!this.isFrontTeacher) return
  156. this.$refs.formList.resetQuery()
  157. }
  158. }
  159. }
  160. </script>
  161. <style scoped>
  162. </style>