|  | @@ -5,10 +5,11 @@
 | 
	
		
			
				|  |  |        inline
 | 
	
		
			
				|  |  |        ref="form"
 | 
	
		
			
				|  |  |        label-suffix=": "
 | 
	
		
			
				|  |  | -      label-width="100px"
 | 
	
		
			
				|  |  | +      label-width="110px"
 | 
	
		
			
				|  |  |      >
 | 
	
		
			
				|  |  |        <el-form-item
 | 
	
		
			
				|  |  |          label="主教老师"
 | 
	
		
			
				|  |  | +        prop="coreTeacher"
 | 
	
		
			
				|  |  |          :rules="[{ required: true, message: '请选择主教老师' }]"
 | 
	
		
			
				|  |  |        >
 | 
	
		
			
				|  |  |          <el-select
 | 
	
	
		
			
				|  | @@ -46,14 +47,17 @@
 | 
	
		
			
				|  |  |        </el-form-item>
 | 
	
		
			
				|  |  |        <el-collapse v-model="collapses" @change="collapseChange">
 | 
	
		
			
				|  |  |          <el-collapse-item
 | 
	
		
			
				|  |  | -          v-for="(item, index) in courseTypeList"
 | 
	
		
			
				|  |  | -          :title="item.label"
 | 
	
		
			
				|  |  | +          v-for="(item, key, index) in form.classs"
 | 
	
		
			
				|  |  |            :name="index"
 | 
	
		
			
				|  |  | -          :key="index"
 | 
	
		
			
				|  |  | +          :key="key"
 | 
	
		
			
				|  |  |          >
 | 
	
		
			
				|  |  | +          <template #title>
 | 
	
		
			
				|  |  | +            <p>{{courseTypeListByName[key]}}, 剩余可排课时长{{surplustime[key]}}分钟</p>
 | 
	
		
			
				|  |  | +          </template>
 | 
	
		
			
				|  |  |            <courseItem
 | 
	
		
			
				|  |  | -            :key="index"
 | 
	
		
			
				|  |  | -            :form="form.classs[item.value]"
 | 
	
		
			
				|  |  | +            :surplustime="surplustime[key]"
 | 
	
		
			
				|  |  | +            :type="key"
 | 
	
		
			
				|  |  | +            :form="item"
 | 
	
		
			
				|  |  |            />
 | 
	
		
			
				|  |  |          </el-collapse-item>
 | 
	
		
			
				|  |  |        </el-collapse>
 | 
	
	
		
			
				|  | @@ -65,10 +69,38 @@
 | 
	
		
			
				|  |  |    </div>
 | 
	
		
			
				|  |  |  </template>
 | 
	
		
			
				|  |  |  <script>
 | 
	
		
			
				|  |  | -import { getMusicCourseSettingsWithStudents, classGroupUpdate } from '@/api/buildTeam'
 | 
	
		
			
				|  |  | +import { getMusicCourseSettingsWithStudents, classGroupUpdate, revisionClassGroup, revisionAddClassGroup } from '@/api/buildTeam'
 | 
	
		
			
				|  |  |  import courseItem from "./classroom-setting-item";
 | 
	
		
			
				|  |  | +import { classTimeList } from '@/utils/searchArray'
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +const classTimeListByType = {}
 | 
	
		
			
				|  |  | +for (const item of classTimeList) {
 | 
	
		
			
				|  |  | +  classTimeListByType[item.value] = item.label
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +const formatClassGroupTeacherMapperList = (core, ass) => {
 | 
	
		
			
				|  |  | +  const list = []
 | 
	
		
			
				|  |  | +  if (core) {
 | 
	
		
			
				|  |  | +    list.push({ userId: core, teacherRole: "BISHOP" })
 | 
	
		
			
				|  |  | +  }
 | 
	
		
			
				|  |  | +  if (ass) {
 | 
	
		
			
				|  |  | +    for (const item of ass) {
 | 
	
		
			
				|  |  | +      list.push({ userId: item, teacherRole: "TEACHING" })
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +  }
 | 
	
		
			
				|  |  | +  return list
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +const plusNum = (items = [], key) => {
 | 
	
		
			
				|  |  | +  let money = 0
 | 
	
		
			
				|  |  | +  for (const item of items) {
 | 
	
		
			
				|  |  | +    money += parseFloat(parseFloat(item[key] || 0).toFixed(2) || 0)
 | 
	
		
			
				|  |  | +  }
 | 
	
		
			
				|  |  | +  return money
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  export default {
 | 
	
		
			
				|  |  | -  props: ["teacherList", "activeType", "courseTypeList", 'cooperationList', 'musicGroupId', 'detail', 'studentSubmitedData'],
 | 
	
		
			
				|  |  | +  props: ["teacherList", "activeType", "courseTypeList", 'cooperationList', 'musicGroupId', 'detail', 'studentSubmitedData', 'classType'],
 | 
	
		
			
				|  |  |    components: {
 | 
	
		
			
				|  |  |      courseItem,
 | 
	
		
			
				|  |  |    },
 | 
	
	
		
			
				|  | @@ -80,58 +112,105 @@ export default {
 | 
	
		
			
				|  |  |          classs: {}
 | 
	
		
			
				|  |  |        },
 | 
	
		
			
				|  |  |        collapses: [0],
 | 
	
		
			
				|  |  | -      courseTimes: {}
 | 
	
		
			
				|  |  | +      courseTimes: {},
 | 
	
		
			
				|  |  | +      courseTypeListByName: {},
 | 
	
		
			
				|  |  | +      classTimeListByType
 | 
	
		
			
				|  |  |      };
 | 
	
		
			
				|  |  |    },
 | 
	
		
			
				|  |  | -  created() {
 | 
	
		
			
				|  |  | -    const classs = {}
 | 
	
		
			
				|  |  | -    for (const item of this.courseTypeList) {
 | 
	
		
			
				|  |  | -      classs[item.value] = {
 | 
	
		
			
				|  |  | -        cycle: [{}]
 | 
	
		
			
				|  |  | +  watch: {
 | 
	
		
			
				|  |  | +    courseTypeList() {
 | 
	
		
			
				|  |  | +      this.setCourseTypeListByName()
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +    studentSubmitedData() {
 | 
	
		
			
				|  |  | +      this.formatClasss()
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +    detail() {
 | 
	
		
			
				|  |  | +      this.formatClasss()
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +  },
 | 
	
		
			
				|  |  | +  computed: {
 | 
	
		
			
				|  |  | +    surplustime() {
 | 
	
		
			
				|  |  | +      const _ = {}
 | 
	
		
			
				|  |  | +      for (const key in this.form.classs) {
 | 
	
		
			
				|  |  | +        if (this.form.classs.hasOwnProperty(key)) {
 | 
	
		
			
				|  |  | +          const item = this.form.classs[key];
 | 
	
		
			
				|  |  | +          _[key] = item.courseTotalMinuties - plusNum(item.cycle, 'time')
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  | +      return _
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | -    this.form.classs = classs
 | 
	
		
			
				|  |  |    },
 | 
	
		
			
				|  |  |    async mounted() {
 | 
	
		
			
				|  |  | -    try {
 | 
	
		
			
				|  |  | -      const studentIds = this.detail ? this.detail.subjectIdList : this.studentSubmitedData.seleched.join(',')
 | 
	
		
			
				|  |  | -      const res = await getMusicCourseSettingsWithStudents({
 | 
	
		
			
				|  |  | -        musicGroupId: this.musicGroupId,
 | 
	
		
			
				|  |  | -        studentIds: studentIds
 | 
	
		
			
				|  |  | -      })
 | 
	
		
			
				|  |  | -      const classs = {}
 | 
	
		
			
				|  |  | -      const courseTimes = {}
 | 
	
		
			
				|  |  | -      for (const item of res.data) {
 | 
	
		
			
				|  |  | -        courseTimes[item.courseType] = item
 | 
	
		
			
				|  |  | +    this.setCourseTypeListByName()
 | 
	
		
			
				|  |  | +    this.formatClasss()
 | 
	
		
			
				|  |  | +  },
 | 
	
		
			
				|  |  | +  methods: {
 | 
	
		
			
				|  |  | +    setCourseTypeListByName() {
 | 
	
		
			
				|  |  | +      const courseTypeListByName = {}
 | 
	
		
			
				|  |  | +      for (const item of this.courseTypeList) {
 | 
	
		
			
				|  |  | +        courseTypeListByName[item.value] = item.label
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  | -      for (const key in this.form.classs) {
 | 
	
		
			
				|  |  | -        if (this.form.classs.hasOwnProperty(key)) {
 | 
	
		
			
				|  |  | -          const item = this.form.classs[key]
 | 
	
		
			
				|  |  | +      this.courseTypeListByName = courseTypeListByName
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +    async formatClasss() {
 | 
	
		
			
				|  |  | +      try {
 | 
	
		
			
				|  |  | +        const res = await getMusicCourseSettingsWithStudents({
 | 
	
		
			
				|  |  | +          musicGroupId: this.musicGroupId,
 | 
	
		
			
				|  |  | +          studentIds: (this.detail ? undefined : this.studentSubmitedData?.seleched.join(',')),
 | 
	
		
			
				|  |  | +          classGroupId: this.detail?.id
 | 
	
		
			
				|  |  | +        })
 | 
	
		
			
				|  |  | +        const classs = {}
 | 
	
		
			
				|  |  | +        const courseTimes = {}
 | 
	
		
			
				|  |  | +        for (const item of res.data) {
 | 
	
		
			
				|  |  | +          courseTimes[item.courseType] = item
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        for (const item of this.courseTypeList) {
 | 
	
		
			
				|  |  | +          const key = item.value
 | 
	
		
			
				|  |  |            if (courseTimes[key]) {
 | 
	
		
			
				|  |  | -            classs[key] = item
 | 
	
		
			
				|  |  | +            classs[key] = {
 | 
	
		
			
				|  |  | +              courseTotalMinuties: courseTimes[key].courseTotalMinuties,
 | 
	
		
			
				|  |  | +              cycle: [{
 | 
	
		
			
				|  |  | +                time: classTimeListByType[key]
 | 
	
		
			
				|  |  | +              }]
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  |            }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +        this.$set(this.form, 'classs', classs)
 | 
	
		
			
				|  |  | +        // this.courseTimes = courseTimes
 | 
	
		
			
				|  |  | +      } catch (error) {
 | 
	
		
			
				|  |  | +        console.log(error)
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  | -      console.log(classs)
 | 
	
		
			
				|  |  | -      this.$set(this.form, 'classs', classs)
 | 
	
		
			
				|  |  | -      this.courseTimes = courseTimes
 | 
	
		
			
				|  |  | -    } catch (error) {}
 | 
	
		
			
				|  |  | -  },
 | 
	
		
			
				|  |  | -  methods: {
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  |      submit() {
 | 
	
		
			
				|  |  | +      for (const key in this.surplustime) {
 | 
	
		
			
				|  |  | +        if (this.surplustime.hasOwnProperty(key)) {
 | 
	
		
			
				|  |  | +          const item = this.surplustime[key];
 | 
	
		
			
				|  |  | +          if (item > 0) {
 | 
	
		
			
				|  |  | +            this.$message.error(`${this.courseTypeListByName[key]},还剩余${item}分钟剩余可排时长`)
 | 
	
		
			
				|  |  | +            return
 | 
	
		
			
				|  |  | +          }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +      }
 | 
	
		
			
				|  |  |        this.$refs.form.validate(async valid => {
 | 
	
		
			
				|  |  |          if (valid) {
 | 
	
		
			
				|  |  | -          console.log({...this.form})
 | 
	
		
			
				|  |  |            const list = []
 | 
	
		
			
				|  |  |            for (const key in this.form.classs) {
 | 
	
		
			
				|  |  |              if (this.form.classs.hasOwnProperty(key)) {
 | 
	
		
			
				|  |  |                const item = this.form.classs[key];
 | 
	
		
			
				|  |  |                list.push({
 | 
	
		
			
				|  |  |                  type: key,
 | 
	
		
			
				|  |  | +                courseType: key,
 | 
	
		
			
				|  |  | +                classGroupName: (this.studentSubmitedData?.name || this.detail?.classGroupName),
 | 
	
		
			
				|  |  |                  classGroupId: this.detail?.id,
 | 
	
		
			
				|  |  | +                musicGroupId: this.musicGroupId,
 | 
	
		
			
				|  |  |                  startDate: item.courseTime,
 | 
	
		
			
				|  |  | -                coreTeacher: this.form.coreTeacher,
 | 
	
		
			
				|  |  | -                assistant: this.form.assistant,
 | 
	
		
			
				|  |  | +                classGroupTeacherMapperList: formatClassGroupTeacherMapperList(
 | 
	
		
			
				|  |  | +                  this.form.coreTeacher,
 | 
	
		
			
				|  |  | +                  this.form.assistant
 | 
	
		
			
				|  |  | +                ),
 | 
	
		
			
				|  |  | +                holiday: item.holiday,
 | 
	
		
			
				|  |  | +                students: this.studentSubmitedData.seleched,
 | 
	
		
			
				|  |  | +                courseTimes: item.cycle.length,
 | 
	
		
			
				|  |  |                  courseTimeDtoList: item.cycle.map(_ => ({
 | 
	
		
			
				|  |  |                    courseType: key,
 | 
	
		
			
				|  |  |                    dayOfWeek: _.dayOfWeek,
 | 
	
	
		
			
				|  | @@ -142,9 +221,23 @@ export default {
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |            }
 | 
	
		
			
				|  |  |            try {
 | 
	
		
			
				|  |  | -            await classGroupUpdate(list)
 | 
	
		
			
				|  |  | -            tthis.$message.success('排课成功')
 | 
	
		
			
				|  |  | -          } catch (error) {}
 | 
	
		
			
				|  |  | +            if (this.detail) {
 | 
	
		
			
				|  |  | +              await classGroupUpdate(list)
 | 
	
		
			
				|  |  | +              this.$message.success('排课修改成功')
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +              if (this.classType === 1) {
 | 
	
		
			
				|  |  | +                await revisionClassGroup(list)
 | 
	
		
			
				|  |  | +                this.$message.success('排课成功')
 | 
	
		
			
				|  |  | +              } else if (this.classType === 2 || this.classType === 3) {
 | 
	
		
			
				|  |  | +                await revisionAddClassGroup(list)
 | 
	
		
			
				|  |  | +                this.$message.success('排课成功')
 | 
	
		
			
				|  |  | +              }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            this.$listeners.submited()
 | 
	
		
			
				|  |  | +            this.$listeners.close()
 | 
	
		
			
				|  |  | +          } catch (error) {
 | 
	
		
			
				|  |  | +            console.log(error)
 | 
	
		
			
				|  |  | +          }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |        })
 | 
	
		
			
				|  |  |      },
 |