123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- <template>
- <div>
- <el-form
- :model="form"
- inline
- ref="form"
- label-suffix=": "
- label-width="130px"
- >
- <el-form-item
- label="主教老师"
- prop="coreTeacher"
- :rules="[{ required: true, message: '请选择主教老师' }]"
- >
- <el-select
- v-model.trim="form.coreTeacher"
- placeholder="请选择主教老师"
- clearable
- filterable
- >
- <el-option
- v-for="(item, index) in teacherList"
- :key="index"
- :label="item.realName"
- :value="item.id"
- ></el-option>
- </el-select>
- </el-form-item>
- <el-form-item
- label="助教老师"
- prop="assistant"
- >
- <el-select
- v-model.trim="form.assistant"
- placeholder="请选择助教老师"
- filterable
- clearable
- multiple
- >
- <el-option
- v-for="(item, index) in cooperationList"
- :key="index"
- :label="item.realName"
- :value="item.id"
- ></el-option>
- </el-select>
- </el-form-item>
- <el-alert
- v-if="isEmpty"
- :closable="false"
- style="margin-bottom: 20px"
- title="暂无可排课时长"
- type="warning">
- </el-alert>
- <el-collapse v-model="collapses" @change="collapseChange">
- <el-collapse-item
- v-for="(item, key, index) in form.classs"
- :name="index"
- :key="key"
- >
- <template #title>
- <p class="title">{{courseTypeListByName[key]}}, <span>可排课时长{{musicCourseSettings[key]}}分钟</span></p>
- </template>
- <courseItem
- :surplustime="surplustime[key]"
- :type="key"
- :form="item"
- />
- </el-collapse-item>
- </el-collapse>
- </el-form>
- <div slot="footer" class="dialog-footer">
- <el-button @click="$listeners.close">取 消</el-button>
- <el-button type="primary" v-if="!isEmpty" @click="submit">确 定</el-button>
- </div>
- </div>
- </template>
- <script>
- import { getMusicCourseSettingsWithStudents, classGroupUpdate, revisionClassGroup, revisionAddClassGroup } from '@/api/buildTeam'
- import courseItem from "./classroom-setting-item";
- import { classTimeList } from '@/utils/searchArray'
- import { isEmpty } from 'lodash'
- 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', 'classType'],
- components: {
- courseItem,
- },
- data() {
- return {
- form: {
- coreTeacher: '',
- assistant: '',
- classs: {}
- },
- collapses: [0],
- courseTimes: {},
- courseTypeListByName: {},
- classTimeListByType,
- musicCourseSettings: {}
- };
- },
- 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 _
- },
- isEmpty() {
- return isEmpty(this.form.classs)
- }
- },
- async mounted() {
- this.setCourseTypeListByName()
- this.formatClasss()
- },
- methods: {
- setCourseTypeListByName() {
- const courseTypeListByName = {}
- for (const item of this.courseTypeList) {
- courseTypeListByName[item.value] = item.label
- }
- this.courseTypeListByName = courseTypeListByName
- },
- async formatClasss() {
- const studentIds = (this.detail ? undefined : this.studentSubmitedData?.seleched.join(','))
- const classGroupId = this.detail?.id
- if (!studentIds && !classGroupId) {
- return
- }
- try {
- const res = await getMusicCourseSettingsWithStudents({
- musicGroupId: this.musicGroupId,
- studentIds,
- classGroupId
- })
- this.musicCourseSettings = res.data
- const classs = {}
- for (const item of this.courseTypeList) {
- const key = item.value
- if (res.data[key]) {
- classs[key] = {
- courseTotalMinuties: res.data[key],
- cycle: [{
- time: classTimeListByType[key]
- }]
- }
- }
- }
- this.$set(this.form, 'classs', classs)
- // this.courseTimes = courseTimes
- } catch (error) {
- console.log(error)
- }
- },
- 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) {
- const list = []
- for (const key in this.form.classs) {
- if (this.form.classs.hasOwnProperty(key)) {
- const item = this.form.classs[key];
- list.push({
- type: (this.detail ? undefined : this.activeType),
- courseType: key,
- classGroupName: (this.studentSubmitedData?.name || this.detail?.classGroupName),
- classGroupId: this.detail?.id,
- musicGroupId: this.musicGroupId,
- startDate: item.courseTime,
- 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,
- endClassTime: _.endClassTime,
- startClassTime: _.startClassTime
- }))
- })
- }
- }
- try {
- 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)
- }
- } else {
- this.$message.error('请先填写所有表单')
- }
- })
- },
- collapseChange(val) {
- this.collapses = val
- }
- },
- };
- </script>
- <style lang="less" scoped>
- .dialog-footer{
- margin-top: 20px;
- display: block;
- text-align: right;
- }
- .title{
- font-size: 16px;
- padding: 10px;
- font-weight: normal;
- >span{
- color: tomato;
- font-size: 14px;
- }
- }
- </style>
|