classroom-setting.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <template>
  2. <div>
  3. <el-form
  4. :model="form"
  5. inline
  6. ref="form"
  7. label-suffix=": "
  8. label-width="130px"
  9. >
  10. <el-form-item
  11. label="主教老师"
  12. prop="coreTeacher"
  13. :rules="[{ required: true, message: '请选择主教老师' }]"
  14. >
  15. <el-select
  16. v-model.trim="form.coreTeacher"
  17. placeholder="请选择主教老师"
  18. clearable
  19. filterable
  20. >
  21. <el-option
  22. v-for="(item, index) in teacherList"
  23. :key="index"
  24. :label="item.realName"
  25. :value="item.id"
  26. ></el-option>
  27. </el-select>
  28. </el-form-item>
  29. <el-form-item
  30. label="助教老师"
  31. prop="assistant"
  32. >
  33. <el-select
  34. v-model.trim="form.assistant"
  35. placeholder="请选择助教老师"
  36. filterable
  37. clearable
  38. multiple
  39. >
  40. <el-option
  41. v-for="(item, index) in cooperationList"
  42. :key="index"
  43. :label="item.realName"
  44. :value="item.id"
  45. ></el-option>
  46. </el-select>
  47. </el-form-item>
  48. <el-alert
  49. v-if="isEmpty"
  50. :closable="false"
  51. style="margin-bottom: 20px"
  52. title="暂无可排课时长"
  53. type="warning">
  54. </el-alert>
  55. <el-collapse v-model="collapses" @change="collapseChange">
  56. <el-collapse-item
  57. v-for="(item, key, index) in form.classs"
  58. :name="index"
  59. :key="key"
  60. >
  61. <template #title>
  62. <p class="title">{{courseTypeListByName[key]}}, <span>可排课时长{{musicCourseSettings[key]}}分钟</span></p>
  63. </template>
  64. <courseItem
  65. :surplustime="surplustime[key]"
  66. :type="key"
  67. :form="item"
  68. />
  69. </el-collapse-item>
  70. </el-collapse>
  71. </el-form>
  72. <div slot="footer" class="dialog-footer">
  73. <el-button @click="$listeners.close">取 消</el-button>
  74. <el-button type="primary" v-if="!isEmpty" @click="submit">确 定</el-button>
  75. </div>
  76. </div>
  77. </template>
  78. <script>
  79. import { getMusicCourseSettingsWithStudents, classGroupUpdate, revisionClassGroup, revisionAddClassGroup } from '@/api/buildTeam'
  80. import courseItem from "./classroom-setting-item";
  81. import { classTimeList } from '@/utils/searchArray'
  82. import { isEmpty } from 'lodash'
  83. const classTimeListByType = {}
  84. for (const item of classTimeList) {
  85. classTimeListByType[item.value] = item.label
  86. }
  87. const formatClassGroupTeacherMapperList = (core, ass) => {
  88. const list = []
  89. if (core) {
  90. list.push({ userId: core, teacherRole: "BISHOP" })
  91. }
  92. if (ass) {
  93. for (const item of ass) {
  94. list.push({ userId: item, teacherRole: "TEACHING" })
  95. }
  96. }
  97. return list
  98. }
  99. const plusNum = (items = [], key) => {
  100. let money = 0
  101. for (const item of items) {
  102. money += parseFloat(parseFloat(item[key] || 0).toFixed(2) || 0)
  103. }
  104. return money
  105. }
  106. export default {
  107. props: ["teacherList", "activeType", "courseTypeList", 'cooperationList', 'musicGroupId', 'detail', 'studentSubmitedData', 'classType'],
  108. components: {
  109. courseItem,
  110. },
  111. data() {
  112. return {
  113. form: {
  114. coreTeacher: '',
  115. assistant: '',
  116. classs: {}
  117. },
  118. collapses: [0],
  119. courseTimes: {},
  120. courseTypeListByName: {},
  121. classTimeListByType,
  122. musicCourseSettings: {}
  123. };
  124. },
  125. watch: {
  126. courseTypeList() {
  127. this.setCourseTypeListByName()
  128. },
  129. studentSubmitedData() {
  130. this.formatClasss()
  131. },
  132. detail() {
  133. this.formatClasss()
  134. }
  135. },
  136. computed: {
  137. surplustime() {
  138. const _ = {}
  139. for (const key in this.form.classs) {
  140. if (this.form.classs.hasOwnProperty(key)) {
  141. const item = this.form.classs[key];
  142. _[key] = item.courseTotalMinuties - plusNum(item.cycle, 'time')
  143. }
  144. }
  145. return _
  146. },
  147. isEmpty() {
  148. return isEmpty(this.form.classs)
  149. }
  150. },
  151. async mounted() {
  152. this.setCourseTypeListByName()
  153. this.formatClasss()
  154. },
  155. methods: {
  156. setCourseTypeListByName() {
  157. const courseTypeListByName = {}
  158. for (const item of this.courseTypeList) {
  159. courseTypeListByName[item.value] = item.label
  160. }
  161. this.courseTypeListByName = courseTypeListByName
  162. },
  163. async formatClasss() {
  164. const studentIds = (this.detail ? undefined : this.studentSubmitedData?.seleched.join(','))
  165. const classGroupId = this.detail?.id
  166. if (!studentIds && !classGroupId) {
  167. return
  168. }
  169. try {
  170. const res = await getMusicCourseSettingsWithStudents({
  171. musicGroupId: this.musicGroupId,
  172. studentIds,
  173. classGroupId
  174. })
  175. this.musicCourseSettings = res.data
  176. const classs = {}
  177. for (const item of this.courseTypeList) {
  178. const key = item.value
  179. if (res.data[key]) {
  180. classs[key] = {
  181. courseTotalMinuties: res.data[key],
  182. cycle: [{
  183. time: classTimeListByType[key]
  184. }]
  185. }
  186. }
  187. }
  188. this.$set(this.form, 'classs', classs)
  189. // this.courseTimes = courseTimes
  190. } catch (error) {
  191. console.log(error)
  192. }
  193. },
  194. submit() {
  195. // for (const key in this.surplustime) {
  196. // if (this.surplustime.hasOwnProperty(key)) {
  197. // const item = this.surplustime[key];
  198. // if (item > 0) {
  199. // this.$message.error(`${this.courseTypeListByName[key]},还剩余${item}分钟剩余可排时长`)
  200. // return
  201. // }
  202. // }
  203. // }
  204. this.$refs.form.validate(async valid => {
  205. if (valid) {
  206. const list = []
  207. for (const key in this.form.classs) {
  208. if (this.form.classs.hasOwnProperty(key)) {
  209. const item = this.form.classs[key];
  210. list.push({
  211. type: (this.detail ? undefined : this.activeType),
  212. courseType: key,
  213. classGroupName: (this.studentSubmitedData?.name || this.detail?.classGroupName),
  214. classGroupId: this.detail?.id,
  215. musicGroupId: this.musicGroupId,
  216. startDate: item.courseTime,
  217. classGroupTeacherMapperList: formatClassGroupTeacherMapperList(
  218. this.form.coreTeacher,
  219. this.form.assistant
  220. ),
  221. holiday: item.holiday,
  222. students: this.studentSubmitedData?.seleched,
  223. courseTimes: item.cycle.length,
  224. courseTimeDtoList: item.cycle.map(_ => ({
  225. courseType: key,
  226. dayOfWeek: _.dayOfWeek,
  227. endClassTime: _.endClassTime,
  228. startClassTime: _.startClassTime
  229. }))
  230. })
  231. }
  232. }
  233. try {
  234. if (this.detail) {
  235. await classGroupUpdate(list)
  236. this.$message.success('排课修改成功')
  237. } else {
  238. if (this.classType === 1) {
  239. await revisionClassGroup(list)
  240. this.$message.success('排课成功')
  241. } else if (this.classType === 2 || this.classType === 3) {
  242. await revisionAddClassGroup(list)
  243. this.$message.success('排课成功')
  244. }
  245. }
  246. this.$listeners.submited()
  247. this.$listeners.close()
  248. } catch (error) {
  249. console.log(error)
  250. }
  251. } else {
  252. this.$message.error('请先填写所有表单')
  253. }
  254. })
  255. },
  256. collapseChange(val) {
  257. this.collapses = val
  258. }
  259. },
  260. };
  261. </script>
  262. <style lang="less" scoped>
  263. .dialog-footer{
  264. margin-top: 20px;
  265. display: block;
  266. text-align: right;
  267. }
  268. .title{
  269. font-size: 16px;
  270. padding: 10px;
  271. font-weight: normal;
  272. >span{
  273. color: tomato;
  274. font-size: 14px;
  275. }
  276. }
  277. </style>