choose-class.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <div>
  3. <el-form :rules="rules" ref="form" :model="form" label-width="80px" @submit.native.prevent>
  4. <el-form-item label-width="0">
  5. <el-checkbox-group
  6. v-model="tmpClassIds"
  7. :max="roundGroup.classCount"
  8. >
  9. <el-checkbox style="margin-bottom: 20px" v-for="item in classList"
  10. :disabled="item.disabled" :label="item.classId" :key="item.classId"
  11. >{{ item.className }}
  12. </el-checkbox>
  13. </el-checkbox-group>
  14. </el-form-item>
  15. <el-form-item label="输入班级" prop="name" v-if="inputVisible" >
  16. <el-tooltip class="item" effect="dark" content="输入班级名称后回车创建班级" :hide-after="1500" placement="bottom-start">
  17. <el-input
  18. style="width:60%"
  19. class="input-new-tag"
  20. v-model="form.name"
  21. ref="saveTagInput"
  22. size="small"
  23. @keyup.enter.native="handleInputEnter"
  24. >
  25. </el-input>
  26. </el-tooltip>
  27. <div class="size-icon" @click="handleInputConfirm">
  28. <i class="icon el-icon-circle-close"></i>
  29. </div>
  30. </el-form-item>
  31. <el-button v-else type="primary" size="small" @click="showInput">新增班级</el-button>
  32. </el-form>
  33. </div>
  34. </template>
  35. <script>
  36. import MxClassTreeTranslateMixin from '@/components/Cache/modules/mx-classTree-translate-mixin.js'
  37. import * as busiClass from '@/api/webApi/busi-classes.js'
  38. export default {
  39. name: 'choose-class',
  40. props: {
  41. year: {
  42. type: Number
  43. },
  44. },
  45. mixins: [MxClassTreeTranslateMixin],
  46. data() {
  47. return {
  48. tmpClasses: [],
  49. roundGroup: {},
  50. settingContainer: [],
  51. inputVisible: false,
  52. form: {
  53. name: '',
  54. type: 1, // 默认为行政班
  55. year: '', // 学年
  56. gradeId: '', // 年级
  57. subjectId: '1,2,3,4,5,6,7,8,9' // 默认为全科目
  58. },
  59. rules: {
  60. name: [
  61. { required: true, message: '班级名称不能为空', trigger: 'blur' }
  62. ]
  63. },
  64. tmpClassIds: []
  65. }
  66. },
  67. computed: {
  68. classList() {
  69. if (!this.classTree?.length) return []
  70. if (!this.year) return []
  71. // 获取该年份下的年级
  72. const classTree = this.classTree[this.classTree.findIndex(i => i.year = this.year)]
  73. this.form.gradeId = classTree.gradeId
  74. this.form.year = classTree.year
  75. return this.classTree[this.classTree.findIndex(i => i.year = this.year)].classList.map(item => {
  76. item['disabled'] = this.settingContainer.some(c => c.classId == item.classId && c.groupId !== this.roundGroup.groupId)
  77. return item
  78. })
  79. }
  80. },
  81. methods: {
  82. close() {
  83. this.handleInputConfirm()
  84. },
  85. validate() {
  86. //
  87. if (this.tmpClassIds.length !== this.roundGroup.classCount) return false
  88. return true
  89. },
  90. open(roundGroup, settingContainer) {
  91. this.roundGroup = roundGroup
  92. this.settingContainer = settingContainer
  93. this.tmpClasses = settingContainer.filter(setting => setting.groupId == roundGroup.groupId)
  94. this.tmpClassIds = this.tmpClasses.map(c => c.classId)
  95. },
  96. confirm() {
  97. const mergeClasses = this.tmpClassIds.map(id => {
  98. return this.tmpClasses.find(c => c.classId == id) || {
  99. classId: id, // 班级Id
  100. roundId: this.roundGroup.roundId, // 轮次Id
  101. groupId: this.roundGroup.groupId, // 组合Id
  102. actualCount: 0, // 应用才产生 实际人数
  103. expectedCount: 0, // 期望人数
  104. actualCountInMale: 0, // 应用才产生 实际男生
  105. actualCountInFemale: 0 // 应用才产生 实际女生
  106. }
  107. })
  108. console.log(mergeClasses)
  109. this.tmpClasses.forEach(c => this.settingContainer.remove(c))
  110. mergeClasses.forEach(c => this.settingContainer.push(c))
  111. this.handleInputConfirm()
  112. return this.settingContainer
  113. },
  114. handleInputConfirm() {
  115. this.inputVisible = false
  116. },
  117. handleInputEnter() {
  118. console.log('回车')
  119. this.$refs.form.validate(valid => {
  120. if (valid) {
  121. console.log('提交')
  122. this.addClass()
  123. }
  124. })
  125. },
  126. showInput() {
  127. this.inputVisible = true
  128. this.$nextTick(_ => {
  129. this.$refs.saveTagInput.$refs.input.focus()
  130. })
  131. },
  132. addClass() {
  133. busiClass.add(this.form).then(res => {
  134. this.form.name = ''
  135. this.msgSuccess('保存成功')
  136. // this.getClassTreeByCache(false)
  137. this.refreshClassTree()
  138. }).finally()
  139. },
  140. refreshClassTree() {
  141. this.$store.dispatch('GetInfo') // 借机清除了用户缓存 // clear cache
  142. this.loadTranslateClassTree()
  143. }
  144. }
  145. }
  146. </script>
  147. <style scoped>
  148. .size-icon {
  149. font-size: 25px;
  150. cursor: pointer;
  151. display: inline-block;
  152. height: 100%;
  153. position: absolute;
  154. }
  155. .icon {
  156. margin-left: 20px;
  157. color: red;
  158. }
  159. </style>