classroom-setting.vue 8.4 KB

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