choose-class.vue 5.4 KB

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