<template>
    <div class="manage-course-container dark-iview-split">
        <Loading v-if="listLoading" bgColor="rgba(103, 103, 103, 0.27)"></Loading>
        <!-- 头部 -->
        <div class="mgt-course-header">
            <Dropdown class="sort-dropdown" trigger="click" placement="bottom-start" @on-click="function(e){ filterPeriod = e }" @on-visible-change="dropdownStates" v-if="$store.state.user.schoolProfile.school_base">
                <span style="cursor: pointer;">
                    {{$t('schoolBaseInfo.pdLabel')}}
                    <b class="title" style="color:white">{{ filterPeriodName }}</b>
                    <Icon type="ios-arrow-down" style="margin-left:8px;"></Icon>
                </span>
                <DropdownMenu slot="list" v-for="(item,index) in schoolBase.period" :value="item.id" :key="index">
                    <DropdownItem :name="item.id">{{ item.name }}</DropdownItem>
                </DropdownMenu>
            </Dropdown>
            <div class="action-btn-wrap">
                <span v-if="$access.can('admin.*|course-upd')" @click="toggleView()" class="action-btn" style="margin-right:40px">
                    <Icon custom="iconfont icon-schedule" size="16" />
                    <span>{{$t('cusMgt.schdTable')}}</span>
                </span>
            </div>
        </div>
        <Split v-model="split1">
            <!-- 课程列表 -->
            <div slot="left" class="cus-list-box">
                <div class="cus-list-header dark-iview-input">
                    <span>{{$t('cusMgt.course')}}</span>
                    <div v-if="!isSearch" style="float:right;">
                        <Icon class="action-btn-icon" v-if="$access.can('admin.*|course-upd')" type="md-trash" @click.stop="showConfirmDel(curCusIndex)" />
                        <Icon class="action-btn-icon" v-if="$access.can('admin.*|course-upd')" type="md-create" @click.stop="editCus(curCusIndex)" />
                        <Icon class="action-btn-icon" v-if="$access.can('admin.*|course-upd')" type="md-add" @click="showAddCourse(0)" />
                        <Icon class="action-btn-icon" type="ios-search" @click="isSearch = true" />
                    </div>
                    <Input v-else icon="ios-close" v-model="keyWord" :placeholder="$t('cusMgt.searchHolder')" @on-click="closeSearch" size="small" style="float:right;width: 150px;" @on-change="searchCourse" />
                </div>
                <div class="cus-list-content">
                    <vuescroll>
                        <div v-for="(item,index) in courseListShow" :key="index" @click="selectCus(index)" :class="['block-bg','cus-item',curCusIndex == index ? 'block-bg-active':'']">
                            <p class="cus-name">
                                <span class="cus-id">
                                    {{item.no}}
                                </span>
                                {{item.name}}
                            </p>
                            <p class="cus-subject">
                                <span class="attr-label">
                                    {{$t('cusMgt.tableCol5')}}:
                                </span>
                                <span>{{item.subject.name}}</span>
                            </p>
                        </div>
                    </vuescroll>
                </div>
            </div>
            <div slot="right" class="cus-schd-box">
                <Split v-model="split2">
                    <!-- 授课教师列表 -->
                    <div slot="left" class="teacher-list">
                        <div class="teacher-list-header">
                            <span>{{$t('cusMgt.teaLabel')}}</span>
                            <Icon type="md-add" size="16" class="tea-action-icon" @click="toggleAddTea" />
                            <Icon type="md-trash" size="16" class="tea-action-icon" @click="removeTeacher" />
                        </div>
                        <div class="tea-list-content">
                            <vuescroll v-show="teaList.length > 0">
                                <div v-for="(item,index) in teaList" :key="index" @click="selectTea(index)" :class="['block-bg','tea-item',curTeaIndex == index ? 'block-bg-active':'']">
                                    <PersonalPhoto :name="item.name" />
                                    <div class="tea-info">
                                        <p class="tea-name">{{item.name}}</p>
                                        <p class="tea-id">{{item.id}}</p>
                                    </div>
                                </div>
                            </vuescroll>
                            <EmptyData v-show="teaList.length == 0" :textContent="$t('cusMgt.noTeacher')" style="margin-top:0px"></EmptyData>
                        </div>
                    </div>
                    <!-- 上课名单、上课时段设置 -->
                    <div slot="right" class="class-setting" v-show="!addListStatus && !addTeaStatus">
                        <div class="teacher-list-header">
                            <span class="tab-label" style="padding-left:10px">
                                {{$t('cusMgt.cusNameList')}}
                            </span>
                            <div class="action-btn-wrap">
                                <span class="action-btn" style="margin-right:30px" @click="updCusInfo()" v-if="isUpd">
                                    <Icon type="ios-albums-outline" size="16" />
                                    <span>{{$t('cusMgt.saveLabel')}}</span>
                                </span>
                                <span class="action-btn" v-show="curTab == 0" :style="{marginRight:isUpd ? '20px':'30px'}" @click="addNameList">
                                    <Icon type="md-add" size="16" />
                                    <span>{{$t('cusMgt.addStuList')}}</span>
                                </span>
                                <span class="action-btn" v-show="curTab == 0" @click="removeStuList">
                                    <Icon type="md-remove-circle" size="16" />
                                    <span>{{$t('cusMgt.removeList')}}</span>
                                </span>
                            </div>
                        </div>
                        <div class="cus-time-setting">
                            <!-- 设置上课班级/名单 -->
                            <div class="set-cus-class" v-show="curTab == 0">
                                <Split v-model="split3" v-show="schdList.length > 0">
                                    <!-- 名单列表 -->
                                    <div slot="left" class="class-list">
                                        <div v-for="(item,index) in schdList" :key="index" @click="selectClass(index)" :class="['block-bg','tea-class-item',curClassIndex == index ? 'block-bg-active':'']">
                                            <!-- 上课班级/名单 -->
                                            <p class="class-attr-item">
                                                <span class="attr-label">{{$t('cusMgt.nameLabel')}} </span>
                                                <span class="class-name">{{item.classId ? item.classInfo.name : item.listName }}</span>
                                            </p>
                                            <p class="class-attr-item">
                                                <span class="attr-label">{{$t('cusMgt.stuCount')}}</span>
                                                <span class="class-name">{{item.students ? item.students.length : 0}}{{$t('unit.text7')}}</span>
                                            </p>
                                        </div>
                                    </div>
                                    <!-- 设置班级名单 -->
                                    <div slot="right" class="set-stu-list dark-iview-table dark-el-cascader" v-if="schdList[curClassIndex]">
                                        <vuescroll>
                                            <Table v-if="schdList[curClassIndex]" :columns="schdList[curClassIndex].stulist ? listColumn : classColumn" :data="students" class="stu-list-table" :loading="stuLoading" :no-data-text="$t('cusMgt.noStu')">
                                                <Loading slot="loading" :top="0" bgColor="rgba(103, 103, 103, 0.27)"></Loading>
                                                <template slot-scope="{ row }" slot="picture">
                                                    <PersonalPhoto :name="row.name" :picture="row.picture" />
                                                </template>
                                                <template slot-scope="{ row,index }" slot="no">
                                                    <span>{{row.no}}</span>
                                                </template>
                                                <template slot-scope="{ row ,index}" slot="action">
                                                    <div class="item-tools" v-if="$access.can('admin.*|student-upd')">
                                                        <Icon type="md-create" size="18" color="white" @click="resetNo(index)" :title="$t('schoolBaseInfo.editSeat')" />
                                                        <Icon type="md-remove-circle" size="18" color="white" style="margin-left:10px" @click="removeStudent(index)" :title="$t('schoolBaseInfo.delStuBtn')" />
                                                    </div>
                                                </template>
                                                <template slot-scope="{ row, index }" slot="groupId">
                                                    <span>{{row.groupId ? row.groupId : '- -'}}</span>
                                                </template>
                                                <template slot-scope="{ row, index }" slot="groupName">
                                                    <span>{{row.groupName ? row.groupName : $t('cusMgt.noGroup')}}</span>
                                                </template>
                                            </Table>
                                        </vuescroll>
                                    </div>
                                </Split>
                                <EmptyData v-show="schdList.length == 0" :textContent="$t('cusMgt.noListTips')"></EmptyData>
                            </div>
                            <!-- 教师课表 标准课程取消根据老师设置上课时段的功能，保留以教室为单位设置时段-->
                            <vuescroll v-show="curTab == 1">
                                <TeaTable style="height: calc(100% - 45px)" :tableLoading="tableLoading" :courseId="courseId" v-if="hasTimeTable" :teaRoomList="schdRoomList" :teacher="teaList[curTeaIndex] ? teaList[curTeaIndex].id : ''" :periodId="filterPeriod" :schedData="schdData" @selectCell="selectCell" @cancelCell="cancelCell"></TeaTable>
                                <div v-else>
                                    <p class="no-time-table-tips">
                                        {{filterPeriodName}}{{$t('cusMgt.notime1')}}
                                        <span @click="showTime = true">{{$t('cusMgt.notime2')}}</span>
                                        {{$t('cusMgt.notime3')}}
                                    </p>
                                </div>
                            </vuescroll>
                        </div>
                    </div>
                    <!-- 添加班级名单UI 批量添加-->
                    <div slot="right" class="class-setting dark-iview-input dark-iview-select dark-iview-table" v-show="addListStatus">
                        <vuescroll>
                            <div class="add-tea-header">
                                <RadioGroup v-model="addType" type="button" button-style="solid" size="small">
                                    <Radio label="class">{{$t('cusMgt.listType1')}}</Radio>
                                    <Radio label="stulist">{{$t('cusMgt.listType2')}}</Radio>
                                </RadioGroup>
                                <div class="action-btn-wrap">
                                    <span class="action-btn" style="margin-right:40px" @click="confirmAddSchd">
                                        <Icon type="md-add" size="16" />
                                        <span>{{$t('cusMgt.confirmAdd')}}</span>
                                    </span>
                                    <span class="action-btn" @click="cancelAddSchd">
                                        <Icon type="md-close" size="16" />
                                        <span>{{$t('cusMgt.cancelAdd')}}</span>
                                    </span>
                                </div>
                            </div>
                            <Table ref="sltClass" v-show="addType == 'class'" :columns="classroomCol" :data="classTableList" style="margin-top:10px" @on-selection-change="(selection)=>{sltClass = selection}">
                                <template slot-scope="{ row }" slot="grade">
                                    <span>{{$jsFn.getGradeNameByYear(schoolBase, filterPeriod, row.year)}}</span>
                                </template>
                            </Table>
                            <Table ref="sltList" v-show="addType == 'stulist'" :columns="listCol" :data="stuList" style="margin-top:10px" @on-selection-change="(selection)=>{sltList = selection}">
                                <template slot-scope="{ row }" slot="count">
                                    <span>{{row.students.length}}</span>
                                </template>
                            </Table>
                        </vuescroll>
                    </div>
                    <!-- 添加授课教师UI -->
                    <div slot="right" class="class-setting dark-iview-input dark-iview-table" v-show="addTeaStatus">
                        <vuescroll>
                            <div class="add-tea-header">
                                <!-- <Input search :placeholder="$t('cusMgt.searchHolder')" style="width:240px;margin-top:4px" size="small" /> -->
                                <div class="action-btn-wrap">
                                    <span class="action-btn" style="margin-right:40px" @click="confirmAddTea">
                                        <Icon type="md-add" size="16" />
                                        <span>{{$t('cusMgt.confirmAdd')}}</span>
                                    </span>
                                    <span class="action-btn" @click="cancelAddTea">
                                        <Icon type="md-close" size="16" />
                                        <span>{{$t('cusMgt.cancelAdd')}}</span>
                                    </span>
                                </div>
                            </div>
                            <Table ref="sltTea" :columns="teaCol" :data="teacherList" style="margin-top:10px" @on-selection-change="(selection)=>{sltTeachers = selection}">
                                <template slot-scope="{ row }" slot="picture">
                                    <PersonalPhoto :name="row.name" :picture="row.picture" />
                                </template>
                                <template slot-scope="{ row }" slot="job">
                                    <span>{{row.job || '--'}}</span>
                                </template>
                            </Table>
                        </vuescroll>
                    </div>
                </Split>
            </div>
        </Split>
        <!-- 添加课程表单 -->
        <Modal v-model="addCourseStatus" :title="actionType == 0 ? $t('cusMgt.addCus'):$t('cusMgt.editCus')" class-name="dark-iview-form dark-iview-modal" @on-ok="addCourse">
            <Form ref="courseBaseInfo" :model="courseBaseInfo" :rules="courseBaseValidate" label-position="right" label-colon :label-width="100">
                <FormItem :label="$t('cusMgt.cusName')" prop="name">
                    <Input v-model="courseBaseInfo.name" :placeholder="$t('cusMgt.nameHolder')"></Input>
                </FormItem>
                <FormItem :label="$t('cusMgt.cusCode')">
                    <Input v-model="courseBaseInfo.no" :placeholder="$t('cusMgt.codeHolder')"></Input>
                </FormItem>
                <FormItem :label="$t('cusMgt.cusPd')" prop="period.id">
                    <Select v-model="courseBaseInfo.period.id" :placeholder="$t('cusMgt.pdHolder')">
                        <Option v-for="(item,index) in schoolBase.period" :value="item.id" :key="index" @click.native="courseBaseInfo.period = { id: item.id, name: item.name }">
                            {{ item.name }}
                        </Option>
                    </Select>
                </FormItem>
                <FormItem :label="$t('cusMgt.cusSubject')" prop="subject.id">
                    <Select v-model="courseBaseInfo.subject.id" :placeholder="$t('cusMgt.sjHolder')">
                        <Option v-for="(item,index) in $jsFn.getPeriod(schoolBase, courseBaseInfo.period.id).subjects" :value="item.id" :key="index" @click.native="courseBaseInfo.subject = {name: item.name, id:item.id}">
                            {{ item.name }}
                        </Option>
                    </Select>
                </FormItem>
            </Form>
        </Modal>
        <!-- 创建名单stulist -->
        <Modal v-model="addStuListStatus" :title="$t('cusMgt.createList')" width="1200" @on-ok="confirmAddStuList" class-name="dark-iview-modal" :loading="modalLoading">
            <div class="dark-iview-input list-name-box">
                <span>{{$t('cusMgt.name')}}</span>
                <Input v-model="listName" :placeholder="$t('cusMgt.nameHolder')" style="width: 300px" />
            </div>
            <StudentList @getSelectInfo="(selction)=>{listSelections = selction}"></StudentList>
        </Modal>
    </div>
</template>
<script>
import PersonalPhoto from '@/components/public/personalPhoto/Index.vue'
import TimeSetting from './TimeSetting.vue'
import TeaTable from './TeaTable.vue'
import StudentList from '@/components/coursemgt/StudentList.vue'
export default {
    components: {
        PersonalPhoto, TimeSetting, TeaTable, StudentList
    },
    data() {
        // 验证只能是字母和数字
        const validateCode = (rule, value, callback) => {
            if (!value) {
                return callback(new Error(this.$t('cusMgt.codeErr1')))
            }
            let zg = /^[0-9a-zA-Z]+$/
            if (zg.test(value)) {
                callback()
            } else {
                callback(new Error(this.$t('cusMgt.codeErr2')))
            }
        }
        return {
            tableLoading: false,
            listLoading: false,
            roomList: [],  //教室列表
            classList: [],  //班级列表
            addType: 'class',
            listName: '',
            addStuListStatus: false,
            modalLoading: false,
            listSelections: [],
            isUpd: false,
            props: {
                value: 'id',
                label: 'name',
                emitPath: false
            },
            setCurClass: '',
            addTeaStatus: false,
            preDefault: true,
            addListStatus: false,
            isSearch: false,
            stuLoading: false,
            preStus: [],
            stuList: [],
            teacherList: [],
            sltTeachers: [],
            sltClass: [],
            sltList: [],
            teaCol: [
                {
                    type: 'selection',
                    width: 60,
                    align: 'center'
                },
                {
                    title: ' ',
                    slot: 'picture',
                    align: 'center ',
                    width: '120'
                },
                {
                    title: this.$t('cusMgt.teaName'),
                    key: 'name',
                    align: 'center '
                },
                {
                    title: 'id',
                    key: 'id',
                    align: 'center '
                },
                {
                    title: this.$t('cusMgt.job'),
                    slot: 'job',
                    align: 'center '
                }
            ],
            listCol: [
                {
                    type: 'selection',
                    width: 60,
                    align: 'center'
                },
                {
                    title: this.$t('cusMgt.listName'),
                    key: 'name',
                    align: 'center '
                },
                {
                    title: this.$t('cusMgt.stuCount'),
                    slot: 'count',
                    align: 'center '
                }
            ],
            classroomCol: [
                {
                    type: 'selection',
                    width: 60,
                    align: 'center'
                },
                {
                    title: this.$t('cusMgt.listName'),
                    key: 'name',
                    align: 'center '
                },
                {
                    title: this.$t('cusMgt.code'),
                    key: 'no',
                    align: 'center '
                }
            ],
            classColumn: [
                {
                    title: ' ',
                    slot: 'picture',
                    align: 'left ',
                    width: '150'
                },
                {
                    title: this.$t('courseManage.classroom.studentTableC2'),
                    key: 'name',
                    align: 'center '
                },
                {
                    title: this.$t('courseManage.classroom.studentTableC7'),
                    key: 'id',
                    align: 'center',
                    sortable: true
                },
                {
                    title: this.$t('courseManage.classroom.studentTableC1'),
                    slot: 'no',
                    align: 'center',
                    sortable: true
                },
                // {
                //     title: this.$t('courseManage.classroom.studentTableC5'),
                //     slot: 'groupId',
                //     align: 'center',
                //     sortable: true
                // },
                // {
                //     title: this.$t('courseManage.classroom.studentTableC6'),
                //     slot: 'groupName',
                //     align: 'center'
                // }
            ],
            listColumn: [
                {
                    title: ' ',
                    slot: 'picture',
                    align: 'center ',
                    width: '150'
                },
                {
                    title: this.$t('courseManage.classroom.studentTableC2'),
                    key: 'name',
                    align: 'center '
                },
                {
                    title: this.$t('courseManage.classroom.studentTableC7'),
                    key: 'id',
                    align: 'center',
                    sortable: true
                },
                {
                    title: this.$t('cusMgt.className'),
                    key: 'className',
                    align: 'center'
                },
            ],
            curClassIndex: 0,
            hasTimeTable: false,
            selections: [],
            addStuStatus: false,
            showTime: false,
            curTeaIndex: 0,
            curTab: 0,
            curCusIndex: 0,
            filterPeriod: '',
            split1: 0.2,
            split2: 0.2,
            split3: 0.2,
            schoolBase: {
                period: []
            },
            actionType: 0, //0新增 1编辑
            delCusList: [],
            courseBaseInfo: {
                code: '',
                id: '',
                no: '',
                name: '',
                period: {
                    id: '',
                    name: ''
                },
                subject: {
                    id: '',
                    name: ''
                }
            },
            courseBaseValidate: {
                no: [
                    { required: true, validator: validateCode, trigger: 'change' }
                ],
                name: [
                    { required: true, message: this.$t('cusMgt.codeHolder'), trigger: 'change' }
                ],
                'period.id': [
                    { required: true, message: this.$t('cusMgt.pdHolder'), trigger: 'change' }
                ],
                'subject.id': [
                    { required: true, message: this.$t('cusMgt.sjHolder'), trigger: 'change' }
                ]
            },
            addCourseStatus: false,
            keyWord: '',
            courseList: [],
            courseListShow: [],
            schedule: {
                classId: '',
                classInfo: {
                    id: '',
                    name: ''
                },
                teacherId: '',
                teacherName: '',
                stulist: '',
                time: [],
                notice: ''
            },
            teaSchds: {}
        }
    },
    methods: {
        //查询教师课表数据
        async getTeaSchd() {
            let teaId = this.teaList[this.curTeaIndex].id
            try {
                this.tableLoading = true
                let cusList = await this.getTeaCourse(teaId)
                let cusSchd = await this.getTeaDetail(cusList)
                this.$set(this.teaSchds, teaId, [])
                cusSchd.forEach(item => {
                    this.teaSchds[teaId].push(...item.courses)
                })
                this.tableLoading = false
            } catch (e) {
                this.$Message.error('API ERROR!')
                this.tableLoading = false
            }
        },
        //获取教师所有课程列表
        getTeaCourse(teaId) {
            return new Promise((r, j) => {
                let requestData = {
                    'code': teaId,
                    'schoolId': this.$store.state.userInfo.schoolCode,
                    'scope': 'private'
                }
                this.$api.courseMgmt.findCourse(requestData).then(
                    (res) => {
                        if (res.error == null) {
                            let schoolCus = res.courses.filter(item => {
                                return item.scope == 'school'
                            })
                            r(schoolCus)
                        } else {
                            j(res.error)
                        }
                    },
                    (err) => {
                        j(res.error)
                    }
                )
            })
        },
        //获取教师所有课程详细信息
        getTeaDetail(cusList) {
            return new Promise((r, j) => {
                let promises = []
                cusList.forEach(item => {
                    let requestData = {
                        'code': this.$store.state.userInfo.schoolCode,
                        'scope': 'school',
                        'id': item.id
                    }
                    promises.push(this.$api.courseMgmt.findCusInfo(requestData))
                })
                Promise.all(promises).then(
                    resAll => {
                        resAll.forEach(async (res, index) => {
                            if (res.courses && res.courses.length > 0) {
                                res.courses[0].schedule = res.courses[0].schedule ? res.courses[0].schedule : []
                                //过滤当前教师的schedule
                                let teaId = this.teaList[this.curTeaIndex].id
                                res.courses[0].schedule = res.courses[0].schedule.filter(item => {
                                    return item.teacherId == teaId
                                })
                                res.courses[0].schedule.forEach(item => {
                                    //补充教室信息
                                    if (item.classId) {
                                        let classInfo = this.roomList.find(classItem => {
                                            return classItem.id == item.classId
                                        })
                                        item.classInfo = {
                                            id: item.classId,
                                            name: classInfo ? classInfo.name : '--'
                                        }
                                    }
                                })
                            }
                        })
                        r(resAll)
                    },
                    err => {
                        j(err)
                    }
                )
            })

        },
        toggleAddTea() {
            this.initStatus()
            this.addTeaStatus = true
        },
        initStatus() {
            this.addListStatus = false
            this.addTeaStatus = false
        },
        confirmAddStuList() {
            if (!this.listName) {
                this.$Message.warning(this.$t('cusMgt.nameWarning'))
                this.modalLoading = false
                setTimeout(() => {
                    this.modalLoading = true
                }, 0)
            } else {
                let stuList = {
                    name: this.listName,
                    id: this.$tools.guid(),
                    code: this.$store.state.userInfo.schoolCode,
                    students: this.listSelections.map(item => { //这里没有学生名字， 需要先查看id集合再查学生信息？
                        return {
                            id: item.id,
                            code: item.code //学生所在学校的编码，这里先传当前学校编码，暂无未考虑跨校名单
                        }
                    }),
                    tmids: [],
                    course: null
                }
                this.saveStuList(stuList)
            }
        },
        // 保存名单
        saveStuList(stuList) {
            let params = {
                stuList,
                scope: "school"
            }
            this.$api.courseMgmt.upsertStulist(params).then(
                res => {
                    this.$Message.success(this.$t('cusMgt.addOk'))
                    this.addStuStatus = false
                    this.stuList.unshift(params.stuList)
                    this.listName = ''
                },
                err => {
                    this.modalLoading = false
                    setTimeout(() => {
                        this.modalLoading = true
                    }, 0)
                }
            )
        },
        clearTable() {
            this.$refs.sltTea.selectAll(false)
            this.$refs.sltList.selectAll(false)
            this.$refs.sltClass.selectAll(false)
        },
        selectCus(index) {
            this.selectClass(0)
            this.selectTea(0)
            this.cancelAddTea()
            this.cancelAddSchd()
            this.curCusIndex = index

        },
        selectTab(index) {
            this.curTab = index
            let teaId = this.teaList[this.curTeaIndex].id
            if (index == 1 && teaId && !this.teaSchds[teaId]) {
                this.getTeaSchd()
            }
        },
        //设置课程时段
        selectCell(data) {
            let teacher = this.teaList[this.curTeaIndex] ? this.teaList[this.curTeaIndex].id : ''
            if (!teacher) {
                this.$Message.warning(this.$t('cusMgt.setWarning1'))
                return
            }
            if (!data.setClass) {
                this.$Message.warning(this.$t('cusMgt.setWarning2'))
                return
            }
            let schedule = this.courseListShow[this.curCusIndex].schedule.find(item => {
                return item.room == data.setClass && item.teacherId == this.teaList[this.curTeaIndex].id
            })
            if (schedule) {
                schedule.time.push({
                    week: data.col,
                    id: data.row.id
                })
                this.isUpd = true
            }
            //更新课程表数据
            if (this.teaList[this.curTeaIndex] && this.teaSchds[this.teaList[this.curTeaIndex].id]) {
                let tableData = this.teaSchds[this.teaList[this.curTeaIndex].id].find(item => {
                    return item.id == this.courseListShow[this.curCusIndex].id
                })
                if (tableData) {
                    let s = tableData.schedule.find(item => {
                        return item.room == data.setClass && item.teacherId == this.teaList[this.curTeaIndex].id
                    })
                    if (s) {
                        s.time.push({
                            week: data.col,
                            id: data.row.id
                        })
                    }
                } else {
                    this.teaSchds[this.teaList[this.curTeaIndex].id].push(this._.cloneDeep(this.courseListShow[this.curCusIndex]))
                }
            }
        },
        //取消课程时段设置
        cancelCell(data) {
            let schedule = this.courseListShow[this.curCusIndex].schedule.find(item => {
                return item.room == data.setClass && item.teacherId == this.teaList[this.curTeaIndex].id
            })
            if (schedule) {
                for (let index in schedule.time) {
                    if (schedule.time[index].week == data.col && schedule.time[index].id == data.row.id) {
                        schedule.time.splice(index, 1)
                        this.isUpd = true
                        break
                    }
                }
            }
            //更新课程表数据
            if (this.teaList[this.curTeaIndex] && this.teaSchds[this.teaList[this.curTeaIndex].id]) {
                let tableData = this.teaSchds[this.teaList[this.curTeaIndex].id].find(item => {
                    return item.id == this.courseListShow[this.curCusIndex].id
                })
                if (tableData) {
                    let s = tableData.schedule.find(item => {
                        return item.room == data.setClass && item.teacherId == this.teaList[this.curTeaIndex].id
                    })
                    if (s) {
                        for (let index in s.time) {
                            if (s.time[index].week == data.col && s.time[index].id == data.row.id) {
                                s.time.splice(index, 1)
                                break
                            }
                        }
                    }
                }
            }
        },

        //关闭搜索状态
        closeSearch() {
            this.isSearch = false
            this.keyWord = ''
            this.filterByPeriod()
        },
        //添加课程名单
        addNameList() {
            this.addListStatus = true
            this.schedule.teacherId = this.teaList[this.curTeaIndex].id
            this.schedule.teacherName = this.teaList[this.curTeaIndex].name
        },
        //查询名单列表
        findStuList() {
            let params = {
                code: this.$store.state.userInfo.schoolCode,
                scope: 'school'
            }
            this.$api.courseMgmt.findStulist(params).then(
                res => {
                    this.stuList = res.stuList
                },
                err => {
                    this.$Message.error('API error')
                }
            )
        },
        //选择课程名单列表
        selectClass(index) {
            this.curClassIndex = index
            this.findCurStuList()
            this.initStatus()
        },
        //教师列表选择事件
        selectTea(index) {
            this.curClassIndex = 0
            this.curTeaIndex = index
            this.initStatus()
            //获取老师所有授课数据渲染课程表
            if (this.teaList.length) {
                let teaId = this.teaList[this.curTeaIndex].id
                if (this.curTab == 1 && teaId && !this.teaSchds[teaId]) {
                    this.getTeaSchd()
                }
            }
        },
        /**
         * 添加名单的时候获取名单对应的学生信息
         */
        getStuList(listName) {
            this.schedule.listName = listName
            let curList = this.stuList.find(item => {
                return item.id == this.schedule.stulist
            })
            if (curList) {
                if (curList.full) {
                    this.preStus = curList.students
                } else {
                    this.$api.courseMgmt.findStuSummary({
                        students: curList.students
                    }).then(
                        res => {
                            res.stus.forEach(item => {
                                let classInfo = this.roomList.find(classItem => {
                                    return classItem.id == item.classId
                                })
                                if (classInfo) {
                                    item.className = classInfo.name
                                }
                            })
                            curList.students = res.stus
                            curList.full = true
                            this.preStus = res.stus
                        }
                    )
                }
            }
        },

        //确认添加名单
        confirmAddSchd() {
            if (!this.schedule.teacherId) {
                return
            }
            if (this.addType == 'class' && this.sltClass.length > 0) {
                //先判断是否有空的schedule（只是添加了老师，没有教室和名单）
                let emptyIndex = -1
                this.courseListShow[this.curCusIndex].schedule.forEach((item, index) => {
                    if (item.teacherId == this.schedule.teacherId && !item.stulist && !item.classId) {
                        // this.courseListShow[this.curCusIndex].schedule.splice(index, 1) //直接删除会改变顺序，产生bug错觉
                        emptyIndex = index
                    }
                })
                this.sltClass.forEach(item => {
                    let exist = this.courseListShow[this.curCusIndex].schedule.find(schdItem => {
                        return schdItem.classId == item.id && schdItem.teacherId == this.schedule.teacherId
                    })
                    if (!exist) {
                        this.schedule.classId = item.id
                        this.schedule.classInfo = {
                            id: item.id,
                            name: item.name
                        }
                        if (emptyIndex > -1) {
                            this.courseListShow[this.curCusIndex].schedule.splice(emptyIndex, 1, JSON.parse(JSON.stringify(this.schedule))) //直接删除会改变顺序，产生bug错觉
                            emptyIndex = -1
                        } else {
                            this.courseListShow[this.curCusIndex].schedule.push(JSON.parse(JSON.stringify(this.schedule)))
                        }

                    }
                })
                this.sltClass = []
            } else if (this.addType == 'stulist' && this.sltList.length > 0) {
                //先判断是否有空的schedule（只是添加了老师，没有教室和名单）
                let emptyIndex = -1
                this.courseListShow[this.curCusIndex].schedule.forEach((item, index) => {
                    if (item.teacherId == this.schedule.teacherId && !item.stulist && !item.classId) {
                        // this.courseListShow[this.curCusIndex].schedule.splice(index, 1)
                        emptyIndex = index
                    }
                })
                this.sltList.forEach(item => {
                    let exist = this.courseListShow[this.curCusIndex].schedule.find(schdItem => {
                        return schdItem.stulist == item.id && schdItem.teacherId == this.schedule.teacherId
                    })
                    if (!exist) {
                        this.schedule.stulist = item.id
                        this.schedule.listName = item.name
                        if (emptyIndex > -1) {
                            this.courseListShow[this.curCusIndex].schedule.splice(emptyIndex, 1, JSON.parse(JSON.stringify(this.schedule))) //直接删除会改变顺序，产生bug错觉
                            emptyIndex = -1
                        } else {
                            this.courseListShow[this.curCusIndex].schedule.push(JSON.parse(JSON.stringify(this.schedule)))
                        }
                    }
                })
                this.sltList = []
            } else {
                this.$Message.warning(this.$t('cusMgt.sltListTips'))
                return
            }
            this.addListStatus = false
            this.updCusInfo()
            this.initSchedule()
            this.clearTable()
        },
        //取消添加Schd
        cancelAddSchd() {
            this.addListStatus = false
            this.initSchedule()
            this.clearTable()
        },
        //确认或取消添加后初始化数据
        initSchedule() {
            this.schedule = {
                classInfo: {
                    id: '',
                    name: ''
                },
                teacherId: '',
                teacherName: '',
                stulist: '',
                time: [],
                notice: ''
            }
        },
        //取消添加老师
        cancelAddTea() {
            this.addTeaStatus = false
            this.clearTable()
        },
        //确认添加教师
        confirmAddTea() {
            this.addTeaStatus = false
            if (this.sltTeachers.length > 0) {
                let ids = this.teaList.map(item => {
                    return item.id
                })
                this.sltTeachers.forEach(item => {
                    if (ids.indexOf(item.id) == -1) {
                        this.courseListShow[this.curCusIndex].schedule.push({
                            classId: '',
                            teacherName: item.name,
                            teacherId: item.id,
                            stulist: '',
                            time: [],
                            notice: ''
                        })
                    }
                })
                this.updCusInfo()
                this.sltTeachers = []
                this.clearTable()
            }
        },
        // 更新课程数据
        updCusInfo() {
            this.courseListShow[this.curCusIndex].code = this.courseListShow[this.curCusIndex].code.replace('Course-', '')
            this.$api.courseMgmt.saveOrUpdateCourse({
                course: this.courseListShow[this.curCusIndex],
                option: 'update',
                scope: this.courseListShow[this.curCusIndex].scope || 'school'
            }).then(
                res => {
                    this.$Message.success(this.$t('cusMgt.updateOk'))
                    this.isUpd = false
                }
            ).catch(() => {
                this.$Message.error(this.$t('cusMgt.updateErr'))
            })
        },
        //移除名单
        removeStuList() {
            this.$Modal.confirm({
                title: this.$t('cusMgt.remvListTitle'),
                content: `${this.$t('cusMgt.remvListConten')}${this.schdList[this.curClassIndex].listName || this.schdList[this.curClassIndex].classInfo.name}?`,
                onOk: () => {
                    let index = this.curClassIndex
                    this.curClassIndex = 0
                    let curSchd = this.schdList[index]
                    //如果只有一个名单的时候移除名单则为清空名单，不能真的删除
                    if (this.schdList.length == 1) {
                        for (let i in this.courseListShow[this.curCusIndex].schedule) {
                            if (this.courseListShow[this.curCusIndex].schedule[i].classId == curSchd.classId && this.courseListShow[this.curCusIndex].schedule[i].stulist == curSchd.stulist) {
                                this.courseListShow[this.curCusIndex].schedule[i].classId = ''
                                this.courseListShow[this.curCusIndex].schedule[i].stulist = ''
                                this.courseListShow[this.curCusIndex].schedule[i].time = []
                                break
                            }
                        }
                    } else {
                        for (let i = 0; i < this.courseListShow[this.curCusIndex].schedule.length; i++) {

                            if (this.courseListShow[this.curCusIndex].schedule[i].classId == curSchd.classId && this.courseListShow[this.curCusIndex].schedule[i].stulist == curSchd.stulist) {
                                this.courseListShow[this.curCusIndex].schedule.splice(i, 1)
                                i--
                                // break
                            }
                        }
                    }
                    this.updCusInfo()
                    this.selectClass(0)
                }
            })
        },
        //移除授课老师
        removeTeacher() {
            this.$Modal.confirm({
                title: this.$t('cusMgt.remvTeaTitle'),
                content: `${this.$t('cusMgt.remvTeaContent')}${this.teaList[this.curTeaIndex].name}?`,
                onOk: () => {
                    let curTeacher = this.teaList[this.curTeaIndex]
                    for (let i in this.courseListShow[this.curCusIndex].schedule) {
                        if (this.courseListShow[this.curCusIndex].schedule[i].teacherId == curTeacher.id) {
                            this.courseListShow[this.curCusIndex].schedule.splice(i, 1)
                            i -= 1
                        }
                    }
                    this.curTeaIndex = 0
                    this.updCusInfo()
                },
                onCancel: () => { }
            })
        },
        // 切换课表模式和课程模式
        toggleView() {
            this.$router.push({
                name: 'CoursePlan'
            })
        },
        dropdownStates(flag) {
            if (!flag) this.filterByPeriod()
        },
        filterByPeriod() {
            this.courseListShow = this.courseList.filter(item => {
                return item.period.id == this.filterPeriod
            })
            this.selectCus(0)

            let curGd = this.schoolBase.period.find(item => {
                return item.id == this.filterPeriod
            })
            if (curGd) {
                let filters = curGd.grades.map((item, index) => {
                    return {
                        label: item.name,
                        value: index + 1
                    }
                })
                //年级筛选条件
                this.classroomCol[this.classroomCol.length - 1].filters = filters
            }
            this.getCusInfo()
        },
        //关键字搜索课程
        searchCourse() {
            this.courseListShow = this.courseList.filter((item, index) => {
                return item.name.indexOf(this.keyWord) != -1
            })
        },
        //获取课程列表
        getCourseList() {
            this.listLoading = true
            let requestData = {
                'code': this.$store.state.userInfo.schoolCode,
                'scope': 'school'
            }
            this.$api.courseMgmt.findCourse(requestData).then(
                (res) => {
                    if (res) {
                        this.courseList = res.courses
                        if (this.courseList.length > 0) {
                            if (this.filterPeriod) {
                                this.filterByPeriod()
                            } else {
                                this.courseListShow = [...this.courseList]
                                this.getCusInfo()
                            }
                        }

                    }
                }
            ).finally(() => {
                setTimeout(() => {
                    this.listLoading = false
                }, 500)
            })
        },
        //获取课程完整信息
        getCusInfo() {
            if (this.courseListShow[this.curCusIndex]) {
                this.listLoading = true
                let requestData = {
                    'code': this.$store.state.userInfo.schoolCode,
                    'scope': 'school',
                    'id': this.courseListShow[this.curCusIndex].id
                }
                this.$api.courseMgmt.findCusInfo(requestData).then(
                    async (res) => {
                        if (!res.error && res.courses && res.courses.length > 0) {
                            res.courses[0].schedule = res.courses[0].schedule ? res.courses[0].schedule : []
                            //获取班级名单信息（方便列表显示学生人数）
                            let classIds = res.courses[0].schedule.map(item => {
                                return item.classId
                            })
                            for (let i = 0; i < classIds.length; i++) {
                                if (!classIds[i]) {
                                    classIds.splice(i, 1)
                                    i--
                                }
                            }
                            let classStus = null
                            if (classIds.length) {
                                try {
                                    classStus = await this.getStuByClassIds(classIds)
                                } catch (e) {
                                    this.$Message.error('API ERROR')
                                }
                            }

                            res.courses[0].schedule.forEach(item => {
                                //补充班级信息
                                if (item.classId) {
                                    let classInfo = this.classList.find(classItem => {
                                        return classItem.id == item.classId
                                    })
                                    if (classInfo) {
                                        item.classInfo = {
                                            id: item.classId,
                                            name: classInfo.name
                                        }
                                    } else {
                                        item.classInfo = {
                                            id: item.classId,
                                            name: '--'
                                        }
                                    }
                                    //根据上面查看班级学生的返回结果补充学生名单
                                    if (classStus && classStus.stus) {
                                        classStus.stus.forEach(stuItem => {
                                            if (stuItem.length > 0 && stuItem[0].classId == item.classId) {
                                                item.students = stuItem
                                                item.fullStu = true
                                            }
                                        })
                                    }
                                }
                                // 补充动态名单信息
                                if (item.stulist) {
                                    let listInfo = this.stuList.find(listItem => {
                                        return listItem.id == item.stulist
                                    })
                                    item.listName = listInfo ? listInfo.name : '--'
                                    item.students = listInfo ? listInfo.students : []
                                }
                                // 补充教室信息
                                if (item.room) {
                                    let roomInfo = this.roomList.find(roomItem => {
                                        return roomItem.id == item.room
                                    })
                                    if (roomInfo) {
                                        item.roomInfo = {
                                            id: item.room,
                                            name: roomInfo.name
                                        }
                                    } else {
                                        item.roomInfo = {
                                            id: item.room,
                                            name: '--'
                                        }
                                    }
                                }
                            })
                            this.$set(this.courseListShow, this.curCusIndex, res.courses[0])
                            this.selectTea(0)
                        }
                    }
                ).finally(() => {
                    setTimeout(() => {
                        this.listLoading = false
                    }, 500)
                })
            }
        },
        //初始化课程课程信息时，根据班级ids查询名单信息
        getStuByClassIds(classIds) {
            let params = {
                'school_code': this.$store.state.userInfo.schoolCode,
                'ids': classIds,
                //school：校本班级 teacher：私人课程校本名单 private：私人课程动态名单
                'scope': 'school'
            }
            return this.$api.schoolSetting.getClassroomStudent(params)
        },
        //显示新增/编辑课程对话框
        showAddCourse(type) {
            this.addCourseStatus = true
            this.actionType = type
            this.courseBaseInfo = {
                code: '',
                id: '',
                name: '',
                period: {
                    id: '',
                    name: ''
                },
                subject: {
                    id: '',
                    name: ''
                },
                teachers: [],
                option: 'insert'
            }
        },
        //显示确认删除对话框
        showConfirmDel(index) {
            this.delCusList.length = 0
            if (index == -1) {//批量删除
                if (this.selections.length == 0) {
                    this.$Message.warning(this.$t('cusMgt.sltCusTips'))
                } else {
                    this.delCusList.push(...this.selections)
                }
            } else {
                this.delCusList.push(this.courseListShow[index])
            }
            let cusNames = this.delCusList.map(item => {
                return item.name
            })
            this.$Modal.confirm({
                title: this.$t('cusMgt.delCus'),
                content: `${this.$t('cusMgt.delContent')}${cusNames.join(', ')}?`,
                onOk: () => {
                    this.confirmDelCus()
                }
            })
        },
        //确认删除课程
        confirmDelCus() {
            if (this.delCusList.length) {
                let ids = this.delCusList.map((item) => {
                    return item.id
                })
                let code = this.$store.state.userInfo.schoolCode
                this.$api.courseMgmt.deleteCourse({
                    id: this.courseListShow[this.curCusIndex].id,
                    code: this.courseListShow[this.curCusIndex].code.replace('Course-', ''),
                    scope: this.courseListShow[this.curCusIndex].scope || 'school',
                }).then(
                    res => {
                        if (res.error == null) {
                            this.$Message.success(this.$t('cusMgt.delOk'))
                            let ids = this.delCusList.map((item) => {
                                return item.id
                            })
                            for (let index in this.courseList) {
                                if (ids.indexOf(this.courseList[index].id) !== -1) {
                                    this.courseList.splice(index, 1)
                                }
                            }
                            this.keyWord = ''
                            this.filterByPeriod()
                        } else {
                            this.$Message.error(this.$t('cusMgt.delErr'))
                        }
                    },
                    err => {
                        this.$Message.error(this.$t('cusMgt.delErr'))
                    }
                ).finally(() => {
                    // this.tableLoading = false
                })
            }

        },
        //编辑课程
        editCus(index) {
            this.actionType = 1
            if (index == -1) {//‘批量编辑’
                if (this.selections.length == 0) {
                    this.$Message.warning(this.$t('cusMgt.sltCusTips'))
                } else {
                    this.courseBaseInfo = this.selections[0]
                    this.addCourseStatus = true
                }
            } else {
                this.courseBaseInfo = this.courseListShow[index]
                this.addCourseStatus = true
            }
        },
        /**新增/修改课程 */
        addCourse() {
            this.$refs['courseBaseInfo'].validate((valid) => {
                if (valid) {
                    let option = this.courseBaseInfo.option
                    if (!option) {
                        option = 'update'
                    }
                    this.courseBaseInfo.code = this.$store.state.userInfo.schoolCode
                    this.courseBaseInfo.id = this.courseBaseInfo.id || this.$tools.guid()
                    this.courseBaseInfo.scope = this.courseBaseInfo.scope || 'school'
                    this.courseBaseInfo.school = this.$store.state.userInfo.schoolCode
                    this.courseBaseInfo.creatorId = this.$store.state.userInfo.schoolCode
                    this.$api.courseMgmt.saveOrUpdateCourse({
                        course: this.courseBaseInfo,
                        option: option,
                        scope: 'school'
                    }).then(
                        (res) => {
                            if (res.error == null) {
                                if (this.actionType == 0) {
                                    this.courseList.push(this.courseBaseInfo)
                                    this.$Message.success(this.$t('cusMgt.addOk'))
                                } else {
                                    this.$Message.success(this.$t('cusMgt.editOk'))
                                }
                                this.keyWord = ''
                                this.searchCourse()
                                this.filterByPeriod()
                            } else {
                                this.$Message.error('API ERROR!')
                            }
                        },
                        (err) => {
                            this.$Message.error('API ERROR!')
                        }
                    )
                } else {
                    this.$Message.error(this.$t('cusMgt.formTips'))
                    setTimeout(() => {
                        this.addCourseStatus = true
                    }, 100)
                }
            })
        },
        //获取当前动态学生名单
        findCurStuList() {
            if (this.schdList[this.curClassIndex] && this.schdList[this.curClassIndex].stulist) {            //自定义名单学生
                let stulist = this.stuList.find(item => {
                    return item.id == this.schdList[this.curClassIndex].stulist
                })
                if (stulist) { //有对应的自定义名单
                    if (stulist.full) {
                        // this.students = stulist.students
                    } else {
                        this.stuLoading = true
                        this.$api.courseMgmt.findStuSummary({
                            students: stulist.students
                        }).then(
                            res => {
                                res.stus.forEach(item => {
                                    let classInfo = this.roomList.find(classItem => {
                                        return classItem.id == item.classId
                                    })
                                    if (classInfo) {
                                        item.className = classInfo.name
                                    }
                                })
                                stulist.students = res.stus
                                stulist.full = true
                                // this.students = res.stus
                                this.schdList[this.curClassIndex].students = res.stus
                            }
                        ).finally(() => {
                            this.stuLoading = false
                        })
                    }
                }
            }
            //系统班级学生（初始化课程的时候就获取了这里就不用获取了）
            else {
            }
        },
        //查询班级学生
        findClassStu(classId) {
            let params = {
                'school_code': this.$store.state.userInfo.schoolCode,
                'ids': [classId],
                'scope': 'school'
            }
            this.$api.schoolSetting.getClassroomStudent(params).then(
                (res) => {
                    if (!res.error) {
                        // this.students = res.stus.length ? res.stus[0] : []
                        this.schdList[this.curClassIndex].students = res.stus.length ? res.stus[0] : []
                    } else {
                        this.$Message.error('API error!')
                    }
                },
                (err) => {
                    this.$Message.error('API error!')
                }
            )
        }
    },
    created() {
        //直接读取登录成功拿到得学校基础信息
        this.$store.dispatch('user/getSchoolProfile').then(
            res => {
                this.schoolBase = res.school_base
                if (this.schoolBase && this.schoolBase.period) {
                    this.filterPeriod = this.schoolBase.period[0].id
                    this.hasTimeTable = this.schoolBase.period[0].timetable ? true : false
                }
                this.roomList = JSON.parse(JSON.stringify(this.$store.state.user.schoolProfile.school_rooms))
                this.classList = JSON.parse(JSON.stringify(this.$store.state.user.schoolProfile.school_classes))
                let curGd = this.schoolBase.period[0].grades
                let filters = curGd.map((item, index) => {
                    return {
                        label: item.name,
                        value: index + 1
                    }
                })
                //年级筛选条件 现在教室没有年级属性，这里调整为筛选是否有设置上课班级
                this.classroomCol.push({
                    title: this.$t('cusMgt.gradeLabel'),
                    slot: 'grade',
                    align: 'center ',
                    filters: filters,
                    filterMultiple: false,
                    filterMethod(value, row) {
                        let date = new Date()
                        let curYear = date.getFullYear()
                        if (this.schoolBase && this.schoolBase.period.length && this.filterPeriod) {
                            let pData = this.schoolBase.period.find(item => {
                                return item.id == this.filterPeriod
                            })
                            if (pData) {
                                let month = date.getMonth() + 1
                                let start = pData.semesters.find(item => {
                                    return item.start == 1
                                })
                                // 根据入学月份确定当前年级和学级的关系
                                if (start && month < start.month) {
                                    curYear--
                                }
                            }
                        }
                        return row.year == curYear - value
                    }
                })
            },
            err => {
                this.$Message.warning(this.$t('cusMgt.noSchool'))
            }
        )
        //清空缓存，保证拿到最新数据
        this.$store.commit('teachers/setTeacherList', [])
        this.$store.dispatch('teachers/getTeacherList').then(res => {
            this.teacherList = this.$store.state.teachers.teacherList.filter(item => {
                return item.status == 'join'
            })
        })
        this.getCourseList()
        this.findStuList()
    },
    computed: {
        //当前学段班级列表
        classTableList() {
            let data = []
            data = this.classList.filter(item => {
                return item.periodId == this.filterPeriod
            })
            return data
        },
        //当前课程id
        courseId() {
            return this.courseListShow[this.curCusIndex] ? this.courseListShow[this.curCusIndex].id : ''
        },
        //课表数据
        schdData() {
            if (this.teaList[this.curTeaIndex]) {
                return this.teaSchds[this.teaList[this.curTeaIndex].id] || []
            }
            return []
        },
        filterPeriodName() {
            let data = this.schoolBase.period
            let pId = this.filterPeriod
            let name = ''
            if (pId !== '') {
                let temp = data.filter(item => {
                    return pId == item.id
                })
                if (temp.length > 0) {
                    name = temp[0].name
                    this.hasTimeTable = temp[0].timetable ? true : false
                }
            }
            return name
        },
        //当前老师的课程安排
        schdList() {
            if (this.courseListShow && this.courseListShow[this.curCusIndex] && this.courseListShow[this.curCusIndex] && this.teaList.length) {
                let schds = this.courseListShow[this.curCusIndex].schedule.filter(item => {
                    return item.teacherId == this.teaList[this.curTeaIndex].id
                })
                //一个班级在不同的教室上课会出现重复的情况，这里用map去重
                const ids = new Map()
                return schds.filter(item => {
                    // return (item.classId || item.stulist) && (!ids.has(item.room) && ids.set(item.room, 1))
                    return (item.classId && !ids.has(item.classId) && ids.set(item.classId, 1)) || (item.stulist && !ids.has(item.stulist) && ids.set(item.stulist, 1))
                })
            } else {
                return []
            }
        },
        //当前老师课程安排，有设置教室的
        schdRoomList() {
            return this.schdList.filter(item => {
                return item.room
            })
        },
        //当前课程的授课老师列表
        teaList() {
            if (this.courseListShow && this.courseListShow[this.curCusIndex] && this.courseListShow[this.curCusIndex].schedule) {
                let all = this.courseListShow[this.curCusIndex].schedule.map(item => {
                    return {
                        id: item.teacherId,
                        name: item.teacherName
                    }
                })
                const res = new Map()
                let removeRep = all.filter((a) => !res.has(a.id) && res.set(a.id, 1))
                return removeRep
            } else {
                return []
            }
        },
        students() {
            if (this.schdList && this.schdList[this.curClassIndex]) {
                return this.schdList[this.curClassIndex].students
            } else {
                return []
            }
        },
    },
    watch: {
        curCusIndex() {
            this.getCusInfo()
        }
    }
}
</script>
<style scoped lang="less">
@import "./NewCusMgt.less";
</style>
<style>
.class-setting thead {
    background: #505050;
}
.add-list-header .el-input--small .el-input__inner {
    height: 26px;
    line-height: 26px;
}
.add-tea-header
    .ivu-radio-group-button-solid
    .ivu-radio-wrapper-checked:not(.ivu-radio-wrapper-disabled) {
    background: white;
    border-color: white;
    color: #515a6e;
}
.add-tea-header .ivu-radio-group-button .ivu-radio-wrapper {
    background: #606060;
    color: white;
    border-color: #606060;
}
.add-tea-header .ivu-radio-group-button .ivu-radio-wrapper-checked,
.add-tea-header
    .ivu-radio-group-button
    .ivu-radio-wrapper-checked.ivu-radio-focus {
    box-shadow: none;
}
.add-tea-header .ivu-radio-group-button .ivu-radio-wrapper:after {
    height: 0px;
}
</style>