<template>
    <div class="my-course-container dark-iview-split">
        <Loading v-if="listLoading" bgColor="rgba(103, 103, 103, 0.27)"></Loading>
        <Split v-show="!isShowSchd" v-model="split1">
            <!--课程列表-->
            <div class="course-list" slot="left">
                <!-- 列表头部 -->
                <div class="course-list-header">
                    <Dropdown class="sort-dropdown" trigger="click" placement="bottom-start" @on-click="function(e){ listType = e }" @on-visible-change="dropdownStates">
                        <span style="cursor: pointer;">
                            <b class="title">{{ cusTypeLabel }}</b>
                            <Icon type="ios-arrow-down" style="margin-left:8px;"></Icon>
                        </span>
                        <DropdownMenu slot="list" v-for="(item,index) in cusType" :value="item.value" :key="index">
                            <DropdownItem :name="item.value">{{ item.label }}</DropdownItem>
                        </DropdownMenu>
                    </Dropdown>
                    <div style="margin-top:0px;float:right;">
                        <Icon type="md-add" v-show="listType == 'private'" class="add-icon" :title="$t('cusMgt.addCus')" @click="addCusStatus = true" />
                        <Icon type="md-create" v-show="listType == 'private' && courseListShow.length" class="add-icon" :title="$t('cusMgt.editCus')" @click="editCus()" />
                        <Icon custom="iconfont icon-schedule" v-show="listType == 'school' && courseListShow.length" class="add-icon" :title="$t('cusMgt.schdTable')" @click="showSchedule" />
                        <Icon type="md-trash" v-show="listType == 'private'" class="add-icon" :title="$t('cusMgt.delCus')" @click="delCourse" />
                    </div>
                </div>
                <!--列表内容-->
                <vuescroll>
                    <div class="dark-iview-tabs-line cus-list-tab">
                        <div v-for="(item,index) in courseListShow" :key="index" @click="selectCourse(index)" :class="index === curCusIndex ? 'course-list-item block-bg block-bg-active':'course-list-item block-bg'">
                            <p class="course-name">
                                {{item.name}}
                                <Icon type="ios-information-circle-outline" @click="toggleCusInfo" :title="$t('cusMgt.cusInfo')" />
                            </p>
                            <p class="course-code">
                                <Icon type="md-pricetags" />
                                {{item.no}}
                            </p>
                        </div>
                        <div v-if="courseListShow.length == 0">
                            <EmptyData :top="150" :textContent="$t('cusMgt.noScCus')"></EmptyData>
                        </div>
                    </div>
                </vuescroll>
            </div>
            <div class="course-info-wrap" slot="right">
                <Split v-model="split2">
                    <!--课程名单列表-->
                    <div class="course-classroom-list" slot="left">
                        <div class="course-classroom-list-header">
                            <span class="course-classroom-label">{{$t('courseManage.classroom.classroomList')}}</span>
                            <Icon type="md-add" v-show="listType == 'private'" class="add-icon" @click="newSlStatus = true" />
                            <!-- 暂未处理编辑个人自定义名单 -->
                            <!-- <Icon type="md-create" v-show="listType == 'private' && teaClassList.length" class="add-icon" @click="editClassStatus = true" /> -->
                            <Icon type="md-trash" v-show="listType == 'private' && teaClassList.length" class="add-icon" @click="removeStuList()" />
                        </div>
                        <div class="course-classroom-list-content">
                            <vuescroll>
                                <div v-for="(item,index) in teaClassList" :key="index" @click="changeClassroom(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.nameLabel')}}</span>
                                        <span :class="item.stulist ? 'class-name':'def-class-name'">{{item.stulist ? item.listName : $t('cusMgt.defaultList')}}</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>
                                    <Icon size="20" custom="iconfont icon-qr-code" class="qr-code-icon" @click="showQrCode" v-if="listType == 'private'" />
                                </div>
                                <EmptyData v-if="teaClassList.length == 0" :top="160" :textContent="$t('cusMgt.noClassList')"></EmptyData>
                            </vuescroll>
                        </div>
                    </div>
                    <div class="course-classroom-info" id="table-height" slot="right">
                        <div class="course-classroom-info-header" style="padding-right:30px;">
                            <span @click="selectTab('record')" :class="tabName == 'record' ? 'course-classroom-label line-bottom line-bottom-active':'course-classroom-label line-bottom'">{{$t('cusMgt.cusRecord')}}</span>
                            <span @click="selectTab('activity')" :class="tabName == 'activity' ? 'course-classroom-label line-bottom line-bottom-active':'course-classroom-label line-bottom'">{{$t('cusMgt.acRecord')}}</span>
                            <span @click="selectTab('stus')" :class="tabName == 'stus' ? 'course-classroom-label line-bottom line-bottom-active':'course-classroom-label line-bottom'">{{$t('courseManage.classroom.studentList')}}</span>
                            <!-- 个人课程时段设置暂不实做 -->
                            <!-- <span @click="selectTab('time')" :class="tabName == 'time' ? 'course-classroom-label line-bottom line-bottom-active':'course-classroom-label line-bottom'">{{$t('cusMgt.cusTime')}}</span> -->
                            <div style="float:right;color:white;" v-if="listType == 'private' && tabName == 'stus'">
                                <span class="action-btn-wrap" @click="delStudents">
                                    <Icon type="md-trash" size="16" />
                                    {{$t('cusMgt.delStu')}}
                                </span>
                                <span v-show="$store.state.userInfo.hasSchool" class="action-btn-wrap" @click="addStuStatus = true">
                                    <Icon type="md-add" size="16" />
                                    {{$t('cusMgt.addStu')}}
                                </span>
                            </div>
                            <div style="float:right;color:white;" v-if="tabName == 'activity'" class="dark-iview-select">
                                <span class="action-btn-wrap">
                                    {{$t('cusMgt.acType')}}
                                    <Select v-model="curAcType" style="width:160px" size="small" @on-change="getActivityList">
                                        <Option v-for="(item,index) in acTypeList" :disabled="index > 2" :value="item.value" :key="item.value">{{ item.label }}</Option>
                                    </Select>
                                </span>
                            </div>
                        </div>
                        <!-- 学生名单 -->
                        <div class="course-classroom-info-content dark-iview-table animated fadeIn" v-show="tabName == 'stus'">
                            <vuescroll style="height:100%;">
                                <Table :columns="isDefList ? classColumn : listColumn" :data="students" @on-selection-change="(selections)=>{delSelection = selections}" :height="tableHeight" class="system-classroom-table" :loading="stuLoading" :no-data-text="$t('cusMgt.noStu')">
                                    <Loading slot="loading" 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 : '--'}}</span>
                                    </template>
                                </Table>
                            </vuescroll>
                        </div>
                        <!-- 课堂记录 -->
                        <div v-show="tabName == 'record'" class="animated fadeIn class-record-wrap">
                            <vuescroll>
                                <List style="border-bottom:1px solid #606060">
                                    <ListItem v-for="(item,index) in itemNum" :key="index" style="border-color:#505050;">
                                        <ListItemMeta @click.native="toClassRecoerd">
                                            <p slot="title" class="record-name">力的组成</p>
                                            <span slot="avatar" style="margin-top:4px;display: inline-block;margin-left:10px;">
                                                <Icon custom="iconfont icon-whiteboard" size="30" color="white" />
                                            </span>
                                            <div slot="description" style="color:white;">
                                                <span class="hiteacher-version">
                                                    系统版本：3.0.32
                                                </span>
                                                <Time class="record-time" :time="((new Date()).getTime() - 60 * 3 * 1000)" />
                                                <div class="record-action-wrap">
                                                    <Icon class="action-icon" type="md-analytics" :title="$t('cusMgt.cusRecord')" @click="toClassRecoerd" />
                                                    <Icon class="action-icon" type="ios-stats" :title="$t('cusMgt.socrateReport')" @click="toClassRecoerd" />
                                                    <Icon class="action-icon" custom="iconfont icon-video" :title="$t('cusMgt.socrateMv')" @click="toClassRecoerd" />
                                                    <Icon class="action-icon" custom="iconfont icon-hi" :title="$t('cusMgt.elNotes')" @click="toClassRecoerd" />
                                                    <Icon class="action-icon" custom="iconfont icon-textbook" :title="$t('cusMgt.lessonContent')" @click="toClassRecoerd" />
                                                    <Icon class="action-icon" type="md-share" :title="$t('cusMgt.share')" @click="toClassRecoerd" />
                                                </div>
                                            </div>
                                        </ListItemMeta>
                                    </ListItem>
                                </List>
                                <EmptyData v-show="itemNum == 0" :textContent="$t('cusMgt.noRecord')" :top="150"></EmptyData>
                            </vuescroll>
                        </div>
                        <!-- 活动记录 -->
                        <div v-show="tabName == 'activity'" class="animated fadeIn class-record-wrap">
                            <vuescroll>
                                <List style="border-bottom:1px solid #606060">
                                    <ListItem v-for="(item,index) in acList" :key="index" style="border-color:#505050;cursor: pointer;">
                                        <ListItemMeta @click.native="toAcDetail(index)" class="ac-item-warp">
                                            <p slot="title" class="record-name">
                                                {{item.name}}
                                                <span class="evaluation-status-tag" :style="{ borderColor: item.progress == 'pending' ? '#0BADD4' : item.progress == 'going' ? '#1CC0F3' : '#ed4014', color: (item.progress == 'pending' ? '#0BADD4' : item.progress == 'going' ? '#1CC0F3' : '#ed4014')}">
                                                    {{ item.progress == 'pending' ? $t('learnActivity.mgtScEv.pending') : item.progress == 'going' ? $t('learnActivity.mgtScEv.going') : $t('learnActivity.mgtScEv.finish') }}
                                                </span>
                                                <span class="evaluation-status-tag" :style="{ borderColor: item.owner == 'school' ? '#0BADD4' : '#ff9900', color: (item.owner == 'school' ? '#0BADD4' : '#ff9900')}">
                                                    {{ item.owner == 'school' ? $t('cusMgt.school') : $t('cusMgt.private') }}
                                                </span>

                                            </p>
                                            <span slot="avatar" style="margin-top:12px;display: inline-block;margin-left:10px;">
                                                <Icon v-if="curAcType == 'ev'" custom="iconfont icon-test" size="24" color="#CCC" />
                                                <Icon v-else-if="curAcType == 'vote'" custom="iconfont icon-vote" size="24" color="#CCC" />
                                                <Icon v-else-if="curAcType == 'qu'" custom="iconfont icon-questionnaire" size="24" color="#CCC" />
                                                <Icon v-else-if="curAcType == 'hw'" custom="iconfont icon-hw" size="24" color="#CCC" />
                                                <Icon v-else custom="iconfont icon-learning-self" size="24" color="#CCC" />
                                            </span>
                                            <div slot="description">
                                                <span class="ev-attr-wrap">
                                                    <span class="attr-label">
                                                        <Icon type="md-time" size="16" />
                                                        {{$t('cusMgt.acTime')}}:
                                                    </span>
                                                    <span class="attr-value">
                                                        {{dateFormat(item.startTime)}}
                                                        -
                                                        {{dateFormat(item.endTime)}}
                                                    </span>
                                                </span>
                                                <!-- API返回列表数据 评测没有返回type -->
                                                <!-- <span class="ev-attr-wrap" v-show="curAcType == 'ev'">
                                                    <span class="attr-label">
                                                        <Icon type="ios-cube" size="14" />
                                                        {{$t('learnActivity.mgtScEv.evType')}}
                                                    </span>
                                                    <span class="attr-value">
                                                        {{getTypeLabel(item.type)}}
                                                    </span>
                                                </span> -->
                                            </div>
                                        </ListItemMeta>
                                    </ListItem>
                                </List>
                                <EmptyData v-show="acList.length == 0" :textContent="acTypeLabel + $t('cusMgt.noAc')" :top="150"></EmptyData>
                            </vuescroll>
                        </div>
                        <!-- 个人课程时段 暂不实做-->
                        <!-- <div v-show="tabName == 'time'" class="animated fadeIn class-record-wrap">
                            <vuescroll>
                                <h2 style="margin-top:120px;color:#ddd;text-align:center"> 
                                    1、如果教师没有加入学校，拿不到时段设置，不能渲染课表；
                                </h2>
                                <h2 style="margin-top:20px;color:#ddd;text-align:center">
                                    2、个人课程没有关联学段，不能确定使用哪个学段的时间；
                                </h2>
                                <h2 style="margin-top:20px;color:#ddd;text-align:center">
                                    3、如果支持老师个人创建时段管理，会不会变成学校可以用的老师都能用。
                                </h2>
                            </vuescroll>
                        </div>-->
                    </div>
                </Split>
            </div>
        </Split>
        <!-- 教师个人课程表 -->
        <div v-show="isShowSchd" class="priv-table-wrap">
            <vuescroll>
                <div class="table-header dark-iview-select">
                    <span v-show="cusPd.length  >  1">{{$t('cusMgt.pdLabel')}}</span>
                    <Select v-model="curPd" style="width:200px" v-show="cusPd.length  >  1">
                        <Option v-for="item in cusPd" :value="item.id" :key="item.id">{{ item.name }}</Option>
                    </Select>
                    <div class="cus-tips-wrap">
                        <Tooltip v-show="noClassCus.length">
                            <div slot="content">
                                <ul style="margin-left: 18px;">
                                    <li v-for="(item,index) in noClassCus" :key="index"> {{`${item.name}`}}</li>
                                </ul>
                            </div>
                            <span class="no-class-tips">{{$t('cusMgt.noClassCus')}}{{`${noClassCus.length}/${schdData.length}`}}</span>
                        </Tooltip>
                        <Tooltip v-show="noTimeCus.length" style="margin-left:15px;">
                            <div slot="content">
                                <ul style="margin-left: 18px;">
                                    <li v-for="(item,index) in noTimeCus" :key="index"> {{`${item.name}`}}</li>
                                </ul>
                            </div>
                            <span class="no-time-tips">{{$t('cusMgt.noTImeCus')}}{{`${noTimeCus.length}/${schdData.length}`}}</span>
                        </Tooltip>
                    </div>
                    <div class="action-btn-wrap">
                        <span @click="isShowSchd = !isShowSchd">
                            <Icon type="md-list" />
                            {{$t('cusMgt.listMode')}}
                        </span>
                    </div>
                </div>
                <TeaTable :schedData="schdData" :teacher="$store.state.userInfo.TEAMModelId" :periodId="curPd" mode="view"></TeaTable>
            </vuescroll>
        </div>
        <Drawer :title="$t('cusMgt.cusInfo')" class-name="dark-iview-drawer" width="450" :closable="false" v-model="showCusInfo" @on-close="baseEditStatus = true">
            <!--基础信息-->
            <div class="course-base-info-content dark-iview-form disabled-iview-select dark-wang-editor">
                <Form ref="courseBaseInfo" label-position="top">
                    <FormItem :label="$t('cusMgt.cusName')" prop="name" class="disabled-iview-select">
                        <Input v-if="listType == 'school' && courseListShow[curCusIndex]" v-model="courseListShow[curCusIndex].name" :disabled="true" style="width:100%" :placeholder="$t('cusMgt.cusName')" :clearable="true"></Input>
                        <Input v-else-if="listType == 'private' && courseListShow[curCusIndex]" v-model="courseListShow[curCusIndex].name" :disabled="baseEditStatus" style="width:100%" :placeholder="$t('cusMgt.cusName')" :clearable="true"></Input>
                    </FormItem>
                    <FormItem :label="$t('cusMgt.cusCode')" prop="no" class="disabled-iview-select">
                        <Input v-if="listType == 'school' && courseListShow[curCusIndex]" v-model="courseListShow[curCusIndex].no" :disabled="true" style="width:100%" :placeholder="$t('cusMgt.cusCode')" :clearable="true"></Input>
                        <Input v-else-if="listType == 'private' && courseListShow[curCusIndex]" v-model="courseListShow[curCusIndex].no" :disabled="baseEditStatus" style="width:100%" :placeholder="$t('cusMgt.cusCode')" :clearable="true"></Input>
                    </FormItem>
                    <FormItem :label="$t('courseManage.base.courseNotice')">
                        <!-- 暂时注释课程公告功能 -->
                        <span>课程公告暂未处理</span>
                        <!-- <div ref="courseNotice" v-show="!baseEditStatus"></div>
                        <div v-show="baseEditStatus" style="height:fit-content;color:white;font-size:16px;padding-left:10px;width:100%;">
                            <vuescroll>
                                <div v-if="listType == 'school' && courseListS[curCusIndex] && checkNotice(courseListS[curCusIndex].notice)" v-html="courseListS[curCusIndex][0].notice" style=""></div>
                                <div v-else-if="listType == 'private' && courseListP[curCusIndex] && checkNotice(courseListP[curCusIndex].notice)" v-html="courseListP[curCusIndex].notice" style=""></div>
                                <div v-else style="">{{$t('cusMgt.noNotice')}}</div>
                            </vuescroll>
                        </div> -->
                    </FormItem>
                    <FormItem label="">
                        <Button style="width:100%;margin-top:10px;" @click="edNotice">{{baseEditStatus ? $t('cusMgt.edit') : $t('cusMgt.save')}}</Button>
                    </FormItem>
                </Form>
            </div>
        </Drawer>
        <!-- 创建名单 -->
        <Modal v-model="newSlStatus" :title="$t('cusMgt.createList')" width="1200" @on-ok="confirmCreateList" 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 v-if="$store.state.userInfo.hasSchool" @getSelectInfo="(selction)=>{createStuList = selction}"></StudentList>
            <p v-else class="no-school-tips">
                您暂未加入学校无法添加学校学生，只能创建好名单，让学生通过扫码加入名单！
            </p>
        </Modal>
        <Modal v-model="addCusStatus" :title="$t('cusMgt.addCus')" @on-ok="confirmAddCus" class-name="dark-iview-modal dark-iview-form">
            <Form ref="addCusInfo" :model="addCusInfo" :rules="ruleAddCus">
                <FormItem prop="name" :label="$t('cusMgt.cusName')">
                    <Input type="text" v-model="addCusInfo.name" :placeholder="$t('cusMgt.nameHolder')"></Input>
                </FormItem>
            </Form>
            <Form ref="addCusInfo" :model="addCusInfo" :rules="ruleAddCus">
                <FormItem :label="$t('cusMgt.cusCode')">
                    <Input type="text" v-model="addCusInfo.no" :placeholder="$t('cusMgt.codeHolder')"></Input>
                </FormItem>
            </Form>
        </Modal>
        <Modal v-model="addStuStatus" :title="$t('cusMgt.addStu')" width="1200" @on-ok="confirmAddStu" class-name="dark-iview-modal">
            <StudentList @getSelectInfo="(selction)=>{selections = selction}"></StudentList>
        </Modal>
        <div class="qr-code-wrap" v-show="showQrStatus" @click="showQrStatus = false">
            <div id="qrcode" :class="showQrStatus ? 'animated fadeIn':'animated fadeOut'" ref="qrcode" style="padding:20px;background-color:white;width:320px;margin:auto;"></div>
        </div>
    </div>
</template>
<script>
import QRCode from 'qrcodejs2'
import PersonalPhoto from '@/components/public/personalPhoto/Index.vue'
import E from '@/utils/wangEditor.js'
import StudentList from '@/components/coursemgt/StudentList.vue'
import TeaTable from './TeaTable.vue'
export default {
    components: {
        StudentList, PersonalPhoto, TeaTable
    },
    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 {
            cusType: [],
            curPd: '',
            isShowSchd: false,
            schoolBase: {
                period: []
            },
            classList: [],
            split1: 0.2,
            split2: 0.2,
            acTypeList: [
                {
                    label: this.$t('cusMgt.ev'),
                    value: 'ev'
                },
                {
                    label: this.$t('cusMgt.vote'),
                    value: 'vote'
                },
                {
                    label: this.$t('cusMgt.qu'),
                    value: 'qu'
                },
                {
                    label: this.$t('cusMgt.hw'),
                    value: 'hw'
                },
                {
                    label: this.$t('cusMgt.sl'),
                    value: 'sl'
                }
            ],
            modalLoading: true,
            curAcType: 'ev',
            evList: [],//评测列表
            voteList: [],//投票列表
            quList: [],//问卷列表
            hwList: [],//作业列表
            slList: [],//自主学习
            delSelection: [],
            selections: [],
            createStuList: [],//创建自定义名单学生列表
            tableHeight: 100,
            classColumn: [
                {
                    title: ' ',
                    slot: 'picture',
                    align: 'left ',
                    width: '150'
                },
                {
                    title: this.$t('courseManage.classroom.studentTableC1'),
                    slot: 'no',
                    align: 'center',
                    sortable: true
                },
                {
                    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.studentTableC5'),
                //     slot: 'groupId',
                //     align: 'center',
                //     sortable: true
                // },
                // {
                //     title: this.$t('courseManage.classroom.studentTableC6'),
                //     slot: 'groupName',
                //     align: 'center'
                // }
            ],
            listColumn: [
                {
                    type: 'selection',
                    align: 'center ',
                    width: '150'
                },
                {
                    title: ' ',
                    slot: 'picture',
                    align: 'center ',
                    width: '150'
                },
                {
                    title: '序号',
                    type: 'index',
                    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'
                },
            ],
            itemNum: 0,
            editClassStatus: false,
            baseEditStatus: true,
            showQrStatus: false,
            showCusInfo: false,
            listLoading: false,
            newSlStatus: false,
            stuLoading: false,
            listType: 'private',
            tabName: 'record',
            addCusStatus: false,
            addStuStatus: false,
            joinQRcode: undefined,
            curCusIndex: 0,
            curClassIndex: 0,
            courseList: [],
            courseListShow: [],
            addCusInfo: {
                name: '',
                no: '',
                id: ''
            },
            listName: '',
            ruleAddCus: {
                name: [
                    { required: true, message: this.$t('cusMgt.nameHolder'), trigger: 'change' }
                ],
                no: [
                    { required: true, validator: validateCode, trigger: 'change' }
                ]
            },
            stuList: []
        }
    },
    methods: {
        initData() {
            this.cusType = [
                {
                    label: this.$t('cusMgt.privCus'),
                    value: 'private'
                }
            ]
            if (this.$store.state.userInfo.hasSchool) {
                this.cusType.unshift({
                    label: this.$t('cusMgt.scCus'),
                    value: 'school'
                })
                this.listType = 'school'
            }
        },
        selectTab(tab) {
            this.tabName = tab
            if (this.tabName == 'activity') {
                this.getActivityList()
            } else if (this.tabName == 'stus') {
                this.getStuList()
            }
        },
        dropdownStates(flag) {
            if (!flag) this.tabClick()
        },
        //课程选项卡点击事件
        tabClick() {
            this.curCusIndex = 0
            this.courseListShow = this.courseList.filter(item => {
                return item.scope == this.listType
            })
            this.selectCourse(0)
        },
        //显示课表模式
        showSchedule() {
            let promises = []
            this.listLoading = true
            this.isShowSchd = !this.isShowSchd
            this.courseListShow.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
                            res.courses[0].schedule = res.courses[0].schedule.filter(item => {
                                return item.teacherId == this.$store.state.userInfo.TEAMModelId
                            })
                            // 获取自定义名单信息
                            let ids = res.courses[0].schedule.map(item => {
                                return item.stulist
                            })
                            for (let i = 0; i < ids.length; i++) {
                                if (!ids[i]) {
                                    ids.splice(i, 1)
                                    i--
                                }
                            }
                            if (ids.length) {
                                try {
                                    let listRes = await this.getListInfo([...ids])
                                    if (listRes) this.stuList.push(...listRes.stuList)
                                } 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
                                    })
                                    item.classInfo = {
                                        id: item.classId,
                                        name: classInfo ? classInfo.name : '--'
                                    }
                                }
                                //补充名单信息
                                if (ids.length && item.stulist) {
                                    let listInfo = this.stuList.find(listItem => {
                                        return listItem.id == item.stulist
                                    })
                                    item.listName = listInfo ? listInfo.name : '--'
                                    item.students = listInfo ? listInfo.students : []
                                    item.fullStu = false
                                }
                            })
                        }
                        this.$set(this.courseListShow, index, res.courses[0])
                    })
                },
                err => {
                    this.$Message.error('API ERROR')
                }
            ).finally(() => {
                this.listLoading = false
            })
        },
        //获取学生名单
        getStuList() {
            let schedule = this.teaClassList[this.curClassIndex]
            //先判断自定义名单
            if (schedule && schedule.stulist && !schedule.fullStu) {
                //TODO 学生id换详细信息
                this.stuLoading = true
                this.$api.courseMgmt.findStuSummary({
                    students: schedule.students
                }).then(
                    res => {
                        res.stus = res.stus || []
                        res.stus.forEach(item => {
                            //TODO 设置班级名称
                            // item.source = '校内账号'
                            let curClass = this.classList.find(classItem => {
                                return classItem.id == item.classId
                            })
                            item.className = curClass ? curClass.name : '- -'
                        })
                        this.$set(this.courseListShow[this.curCusIndex].schedule[this.curClassIndex], 'students', res.stus)
                        this.$set(this.courseListShow[this.curCusIndex].schedule[this.curClassIndex], 'fullStu', true)
                    }
                ).finally(() => {
                    setTimeout(() => {
                        this.stuLoading = false
                    }, 500)
                })
                return
            }
            //教室默认名单
            // if (schedule && schedule.classId && !schedule.students) {
            //     //TODO 根据班级id查询学生信息 （处理课程就获取了）
            //     // this.findClassStu()
            // }
        },
        //查询班级学生名单
        findClassStu() {
            this.stuLoading = true
            let params = {
                'school_code': this.listType == 'school' ? this.$store.state.userInfo.schoolCode : this.$store.state.userInfo.TEAMModelId,
                'ids': [this.teaClassList[this.curClassIndex].classId],
                //school：校本班级 teacher：私人课程校本名单 private：私人课程动态名单
                'scope': this.listType
            }
            this.$api.schoolSetting.getClassroomStudent(params).then(
                (res) => {
                    if (!res.error) {
                        if (res.stus.length > 0) {
                            this.$set(this.courseListShow[this.curCusIndex].schedule[this.curClassIndex], 'students', res.stus[0])
                        }
                    } else {
                        this.$Message.error('API error!')
                    }
                },
                (err) => {
                    this.$Message.error('API error!')
                }
            ).finally(() => {
                setTimeout(() => {
                    this.stuLoading = false
                }, 500)
            })
        },
        //初始化课程课程信息时，根据班级ids查询名单信息
        getStuByClassIds(classIds) {
            let params = {
                'school_code': this.listType == 'school' ? this.$store.state.userInfo.schoolCode : this.$store.state.userInfo.TEAMModelId,
                'ids': classIds,
                //school：校本班级 teacher：私人课程校本名单 private：私人课程动态名单
                'scope': this.listType
            }
            return this.$api.schoolSetting.getClassroomStudent(params)
        },
        /**获取type对应的label */
        getTypeLabel(code) {
            for (let item of this.$GLOBAL.EV_TYPE()) {
                if (item.value == code) {
                    return item.label
                }
            }
        },
        //时间戳转换
        dateFormat(timestamp) {
            var date = new Date(timestamp)
            var Y = date.getFullYear() + '/'
            var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '/'
            var D = date.getDate() + ' '
            return Y + M + D;
        },
        //获取活动列表
        getActivityList() {
            switch (this.curAcType) {
                case 'ev':
                    if (this.evList.length) break //首次（数组为空）访问数据
                    this.findTchAc('Exam')
                    break
                case 'vote':
                    if (this.voteList.length) break
                    this.findTchAc('Vote')
                    break
                case 'qu':
                    if (this.quList.length) break
                    this.findTchAc('Survey')
                    break
                case 'hw':
                    if (this.hwList.length) break
                    this.findTchAc('Homework')
                    break
                case 'sl':
                    if (this.slList.length) break
                    this.findTchAc('Learn')
                    break
                default:
                    break
            }
        },
        //获取活动列表
        findTchAc(type) {
            let requestData = {
                school: this.$store.state.userInfo.schoolCode,
                classes: this.$store.state.userInfo.teachClasses,
                userid: this.$store.state.userInfo.TEAMModelId,
                pk: type
            }
            this.$api.courseMgmt.findTchAc(requestData).then(
                res => {
                    if (!res.error) {
                        switch (this.curAcType) {
                            case 'ev':
                                this.evList = res.datas
                                break
                            case 'vote':
                                this.voteList = res.datas
                                break
                            case 'qu':
                                this.quList = res.datas
                                break
                            case 'hw':
                                this.hwList = res.datas
                                break
                            case 'sl':
                                this.slList = res.datas
                                break
                            default:
                                break
                        }
                    }
                },
                err => {
                    this.$Message.error('API error')
                }
            )
        },
        //获取评测列表
        getEvList() {
            let requestData = {
                code: this.$store.state.userInfo.TEAMModelId
            }
            this.$api.learnActivity.FindExamInfo(requestData).then(
                res => {
                    if (!res.error) {
                        res.examInfo = res.examInfo.sort((a, b) => {
                            return a.createTime - b.createTime > 0 ? -1 : 1
                        })
                        this.evList = res.examInfo
                    } else {
                        this.$Message.error('API ERROR!')
                    }
                }
            )
        },
        //删除学生
        delStudents() {
            if (this.delSelection.length > 0) {
                let names = this.delSelection.map(item => {
                    return item.name
                })
                this.$Modal.confirm({
                    title: this.$t('cusMgt.delStu'),
                    content: `${this.$t('cusMgt.delStuContent')}${names.join(', ')}?`,
                    onOk: () => {
                        this.listLoading = true
                        let delIds = this.delSelection.map(item => {
                            return item.id
                        })
                        //删除学生更新stulist
                        // 当前名单对应的课程安排用于更新UI
                        let schedule = this.courseListShow[this.curCusIndex].schedule.find(item => {
                            return item.stulist == this.teaClassList[this.curClassIndex].stulist && item.classId == '' //只有自定名单能添加学生，所以classId == ‘’
                        })
                        //当前名单完整信息 用于更新名单API
                        let stulist = this.stuList.find(item => {
                            return item.id == this.teaClassList[this.curClassIndex].stulist
                        })
                        for (let i = 0; i < stulist.students.length; i++) {
                            if (delIds.indexOf(stulist.students[i].id) > -1) {
                                stulist.students.splice(i, 1)
                                i--
                            }
                        }
                        let params = {
                            stuList: stulist,
                            scope: "private"
                        }
                        this.$api.courseMgmt.upsertStulist(params).then(
                            res => {
                                this.$Message.success(this.$t('cusMgt.delOk'))
                                for (let i = 0; i < schedule.students.length; i++) {
                                    if (delIds.indexOf(schedule.students[i].id) > -1) {
                                        schedule.students.splice(i, 1)
                                        i--
                                    }
                                }
                            },
                            err => {
                                this.$Message.error(this.$t('cusMgt.delErr'))
                            }
                        ).finally(() => {
                            this.listLoading = false
                        })
                    }
                })
            } else {
                this.$Message.warning(this.$t('cusMgt.delStuTips'))
            }

        },
        //确认添加学生
        confirmAddStu() {
            if (this.selections.length > 0) {
                //这里会报错，应该是之前的结构，后面调整结构后没有进行处理 已经没有classes字段
                // if (!this.courseListShow[this.curCusIndex].classes[this.curClassIndex].students) {
                //     this.$set(this.courseListShow[this.curCusIndex].classes[this.curClassIndex], 'students', [])
                // }
                // let stuIds = this.courseListShow[this.curCusIndex].classes[this.curClassIndex].students.map(item => {
                //     return item.id
                // })
                // 当前名单对应的课程安排用于更新UI
                let schedule = this.courseListShow[this.curCusIndex].schedule.find(item => {
                    return item.stulist == this.teaClassList[this.curClassIndex].stulist && item.classId == '' //只有自定名单能添加学生，所以classId == ‘’
                })
                //当前名单完整信息 用于更新名单API
                let stulist = this.stuList.find(item => {
                    return item.id == this.teaClassList[this.curClassIndex].stulist
                })
                let stuIds = []
                if (schedule) {
                    stuIds = schedule.students.map(item => {
                        return item.id
                    })
                }
                let hasRepeat = false
                this.selections.forEach(item => {
                    if (stuIds.indexOf(item.id) == -1) { //如果已经有学生，根据账号去重
                        schedule.students.push({
                            id: item.id,
                            code: 'Base-' + this.$store.state.userInfo.schoolCode, //学生所在学校的编码，这里先传当前学校编码，暂无未考虑跨校名单
                            schoolId: this.$store.state.userInfo.schoolCode, //学生所在学校的编码，这里先传当前学校编码，暂无未考虑跨校名单
                            name: item.name,
                            className: item.className,
                            classId: item.classId
                        })
                        stulist.students.push({
                            id: item.id,
                            code: 'Base-' + this.$store.state.userInfo.schoolCode, //学生所在学校的编码，这里先传当前学校编码，暂无未考虑跨校名单
                            schoolId: this.$store.state.userInfo.schoolCode //学生所在学校的编码，这里先传当前学校编码，暂无未考虑跨校名单
                        })
                    } else {
                        hasRepeat = true
                    }
                })
                if (hasRepeat) {
                    //this.$Message.warning('已经自动帮您去掉账号重复的学生！')
                }

                this.listLoading = true
                this.saveStuList(stulist)
                //保存操作 过时的操作逻辑
                // this.courseListShow[this.curCusIndex].code = this.$store.state.userInfo.TEAMModelId
                // this.$api.schoolSetting.classUpsert({
                //     classroom: this.courseListShow[this.curCusIndex].classes[this.curClassIndex],
                //     option: 'update',
                //     'school_code': this.$store.state.userInfo.TEAMModelId
                // }).then(
                //     (res) => {
                //         if (!res.error) {
                //             this.selections.length = 0
                //             this.$Message.success(this.$t('cusMgt.addOk'))
                //         } else {
                //             this.$Message.error(this.$t('cusMgt.delErr'))
                //         }
                //     },
                //     (err) => {
                //         this.$Message.error(this.$t('cusMgt.delErr'))
                //     }
                // ).finally(() => {
                //     this.listLoading = false
                //     this.baseEditStatus = !this.baseEditStatus
                // })
            }
        },

        //检查课程是否为“空”
        checkNotice(content) {
            if (!content || content == '' || content == '<p><br></p>') {
                return false
            } else {
                return true
            }
        },
        //移除课程名单
        removeStuList() {
            let _this = this
            this.$Modal.confirm({
                title: this.$t('cusMgt.delClassTitle'),
                content: `${this.$t('cusMgt.delStuContent')}${this.teaClassList[this.curClassIndex].listName}?`,
                onOk: function () {
                    _this.listLoading = true
                    let index = _this.curClassIndex
                    _this.curClassIndex = 0
                    _this.courseListShow[_this.curCusIndex].schedule.splice(index, 1)
                    _this.updCusInfo()
                }
            })
        },
        editCus() {
            this.toggleCusInfo()
            this.edNotice()
        },
        toggleCusInfo() {
            this.showCusInfo = !this.showCusInfo
        },
        edNotice() {
            if (this.baseEditStatus) {
                this.baseEditStatus = !this.baseEditStatus
                this.initEditor()
            } else {
                this.updCusInfo()
                this.baseEditStatus = !this.baseEditStatus
            }
        },

        //初始化富文本编辑器
        initEditor() {
            if (!this.noticeEditor) {
                let noticeEditor = new E(this.$refs.courseNotice)
                noticeEditor.customConfig.onchange = (html) => {
                    //TODO 设置课程公告
                }
                noticeEditor.customConfig.menus = [
                    'bold', // 粗体
                    'italic', // 斜体
                    'underline', // 下划线
                    'list', // 列表
                    'link', // 插入链接
                    'image' // 插入图片
                ],
                    noticeEditor.customConfig.showLinkImg = false
                noticeEditor.customConfig.uploadFileName = 'files'
                noticeEditor.create()
                noticeEditor.txt.html(this.courseListShow[this.curCusIndex].notice)
                this.noticeEditor = noticeEditor
            } else {
                let schoolNotice = this.courseListShow[this.curCusIndex][0].notice ? this.courseListShow[this.curCusIndex][0].notice : ''
                this.noticeEditor.txt.html(this.listType == 'school' ? schoolNotice : this.courseListShow[this.curCusIndex].notice)
            }

        },
        //创建二维码
        createQRCode(url) {
            this.$nextTick(() => {
                // 此时已经渲染完成
                if (this.joinQRcode == undefined) {
                    let qrcode = new QRCode('qrcode', {
                        width: 280, // 设置宽度，单位像素
                        height: 280, // 设置高度，单位像素
                        text: url // 设置二维码内容或跳转地址
                    })
                    this.joinQRcode = qrcode
                } else {
                    this.joinQRcode.clear()
                    this.joinQRcode.makeCode(url)
                }
            })
        },
        showQrCode() {
            console.log(this.teaClassList)
            this.showQrStatus = true
            let tId = this.$store.state.userInfo.TEAMModelId
            let tName = this.$store.state.userInfo.name
            let cId = this.teaClassList[this.curClassIndex].stulist
            let cName = this.teaClassList[this.curClassIndex].listName
            this.createQRCode(`http://teammodelos-test.chinacloudsites.cn/joinclass?tId=${tId}&cId=${cId}&tName=${tName}&cName=${cName}`)
        },
        //确认添加自定义名单
        confirmCreateList() {
            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.TEAMModelId,
                    students: this.createStuList.map(item => {
                        return {
                            id: item.id,
                            code: 'Base-' + this.$store.state.userInfo.schoolCode, //学生所在学校的编码，这里先传当前学校编码，暂无未考虑跨校名单
                            schoolId: this.$store.state.userInfo.schoolCode, //学生所在学校的编码，这里先传当前学校编码，暂无未考虑跨校名单
                            name: item.name,
                            className: item.className,
                            classId: item.classId
                        }
                    }),
                    tmids: [],
                    course: null
                }

                this.saveStuList(stuList, true)
            }
        },
        // 保存名单
        saveStuList(stuList, isUpdCus) {
            let params = {
                stuList,
                scope: "private"
            }
            this.$api.courseMgmt.upsertStulist(params).then(
                res => {
                    this.newSlStatus = false
                    //TODO 添加到当前课程schedule
                    if (isUpdCus) {
                        this.courseListShow[this.curCusIndex].schedule = this.courseListShow[this.curCusIndex].schedule || []
                        this.courseListShow[this.curCusIndex].schedule.push({
                            classId: '',
                            notice: '',
                            listName: this.listName,
                            stulist: stuList.id,
                            teacherId: this.$store.state.userInfo.TEAMModelId,
                            teacherName: this.$store.state.userInfo.name,
                            students: stuList.students,
                            time: []
                        })
                        this.updCusInfo()
                    }
                },
                err => {
                    this.modalLoading = false
                    setTimeout(() => {
                        this.modalLoading = true
                    }, 0)
                }
            ).finally(() => {
                this.listLoading = false
            })
        },

        changeClassroom(index) {
            this.curClassIndex = index
            if (this.tabName == 'stus') this.getStuList()
        },
        //查看课堂记录详情
        toClassRecoerd() {
            this.listLoading = true
            setTimeout(() => {
                this.$router.push({ path: '/home/classRecord' })
            }, 500)
        },
        // 查看评测详情
        toAcDetail(index) {
            let acId = this.acList[index].id
            let acCode = this.acList[index].code
            let owner = this.acList[index].owner
            // 记录页面当前状态 通过配置keep-alive来设置是否保存路由状态，不需要session记录数据
            // sessionStorage.setItem('myCusType', this.listType)
            // sessionStorage.setItem('myCusTabName', this.tabName)
            switch (this.curAcType) {
                case 'ev':
                    this.$router.push({
                        path: '/home/evDetail',
                        query: {
                            examId: this.acList[index].id,
                            code: this.acList[index].code
                        }
                    })
                    break
                case 'vote':
                    this.$router.push({
                        path: owner == 'school' ? '/home/manageVote' : '/home/personalVote',
                        query: {
                            acId: acId
                        }
                    })
                    break
                case 'qu':
                    this.$router.push({
                        path: owner == 'school' ? '/home/manageQuestionnaire' : '/home/personalSurvey',
                        query: {
                            acId: acId
                        }
                    })
                    break
                case 'hw':
                    this.$router.push({
                        path: '/home/manageHomeWork',
                        query: {
                            acId: acId
                        }
                    })
                    break
                case 'sl':
                    this.$router.push({
                        path: '/home/SelfLearn',
                        query: {
                            acId: this.acList[index].id
                        }
                    })
                    break
                default:
                    break
            }

        },
        //删除个人课程
        delCourse() {
            this.$Modal.confirm({
                title: this.$t('cusMgt.delCus'),
                content: `${this.$t('cusMgt.delContent')}${this.courseListShow[this.curCusIndex].name}?`,
                onOk: () => {
                    this.$api.courseMgmt.deleteCourse({
                        id: this.courseListShow[this.curCusIndex].id,
                        code: this.courseListShow[this.curCusIndex].code.replace('Course-', ''),
                        scope: 'private'
                    }).then(
                        res => {
                            if (!res.error) {
                                let index = this.curCusIndex
                                this.curCusIndex = 0
                                this.courseListShow.splice(index, 1)
                                this.$Message.success(this.$t('cusMgt.delOk'))
                            } else {
                                this.$Message.error(this.$t('cusMgt.delErr'))
                            }
                        },
                        err => {
                            this.$Message.error(this.$t('cusMgt.delErr'))
                        }
                    )
                }
            })
        },
        selectCourse(index) {
            this.curClassIndex = 0
            this.curCusIndex = index
            if (this.courseListShow.length && !this.courseListShow[this.curCusIndex].schedule) {
                this.getCusInfo()
            } else {
                this.changeClassroom(0)
            }
        },
        // 新增个人课程
        confirmAddCus() {
            this.$refs['addCusInfo'].validate((valid) => {
                if (valid) {
                    let requestData = {
                        option: 'insert',
                        scope: 'private',
                        course: {
                            name: this.addCusInfo.name,
                            no: this.addCusInfo.no,
                            id: this.$tools.guid(),
                            code: this.$store.state.userInfo.TEAMModelId,
                            schedule: [],
                            scope: 'private',
                            // school: this.$store.state.userInfo.schoolCode,
                            creatorId: this.$store.state.userInfo.schoolCode
                        }
                    }
                    this.$api.courseMgmt.saveOrUpdateCourse(requestData).then(
                        (res) => {
                            if (res.error == null) {
                                this.$Message.success(this.$t('cusMgt.addOk'))
                                // this.courseListP.push(requestData.course)
                                this.courseList.push(requestData.course)
                                this.courseListShow.push(requestData.course)
                            } else {
                                this.$Message.success(this.$t('cusMgt.addErr'))
                            }
                        },
                        (err) => {

                        }
                    )
                } else {
                    this.$Message.error(this.$t('cusMgt.formTips'));
                }
            })
        },
        // 更新个人课程
        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 || 'private'
            }).then(
                res => {
                    this.$Message.success(this.$t('cusMgt.updateOk'))
                }
            ).catch(() => {
                this.$Message.error(this.$t('cusMgt.updateErr'))
            }).finally(() => {
                this.listLoading = false
                this.listName = ''
            })
        },
        //获取个人和校本课程列表，API调整后没有进行分开处理
        getCourseList() {
            this.listLoading = true
            let requestData = {
                'code': this.$store.state.userInfo.TEAMModelId,
                'schoolId': this.$store.state.userInfo.schoolCode,
                'scope': 'private'
            }
            this.$api.courseMgmt.findCourse(requestData).then(
                (res) => {
                    if (res.error == null) {
                        this.courseList = res.courses
                        //设置当前课程列表 
                        this.courseListShow = this.courseList.filter(item => {
                            return item.scope == this.listType
                        })
                        if (this.courseListShow.length == 0) { //如果没有标准课程，则设置默认为个人课程
                            this.listType = 'private'
                            this.courseListShow = this.courseList.filter(item => {
                                return item.scope == this.listType
                            })
                        }
                        if (this.courseListShow.length) {
                            this.getCusInfo()
                        }

                    } else {
                        this.$Message.error('API ERROR!')
                    }
                },
                (err) => {
                    this.$Message.error('API ERROR!')
                }
            ).finally(() => {
                this.listLoading = false
            })
        },
        //获取课程详细信息
        getCusInfo() {
            this.listLoading = true
            let requestData = {
                'code': this.listType == 'school' ? this.$store.state.userInfo.schoolCode : this.$store.state.userInfo.TEAMModelId,
                'scope': this.listType,
                'id': this.courseListShow[this.curCusIndex].id
            }
            this.$api.courseMgmt.findCusInfo(requestData).then(
                async (res) => {
                    if (!res.error) {
                        if (res.courses && res.courses.length > 0) {
                            res.courses[0].schedule = res.courses[0].schedule ? res.courses[0].schedule : []
                            //过滤当前教师的schedule 因为一个名单被安排到不同教室上课会出现重复数据，这里需要去重
                            res.courses[0].schedule = res.courses[0].schedule.filter(item => {
                                return item.teacherId == this.$store.state.userInfo.TEAMModelId
                            })
                            // 获取自定义名单信息
                            let ids = res.courses[0].schedule.map(item => {
                                return item.stulist
                            })
                            for (let i = 0; i < ids.length; i++) {
                                if (!ids[i]) {
                                    ids.splice(i, 1)
                                    i--
                                }
                            }
                            if (ids.length) {
                                try {
                                    let listRes = await this.getListInfo([...ids])
                                    if (listRes) this.stuList.push(...listRes.stuList)
                                } catch (e) {
                                    this.$Message.error('API ERROR')
                                }
                            }

                            //获取班级名单信息（为了列表显示学生人数）
                            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
                                    })
                                    item.classInfo = {
                                        id: item.classId,
                                        name: classInfo ? classInfo.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 (ids.length && item.stulist) {
                                    let listInfo = this.stuList.find(listItem => {
                                        return listItem.id == item.stulist
                                    })
                                    item.listName = listInfo ? listInfo.name : '--'
                                    item.students = listInfo ? listInfo.students : []
                                    item.fullStu = false
                                }
                            })
                        }
                        this.$set(this.courseListShow, this.curCusIndex, res.courses[0])
                        console.log(this.courseListShow[this.curCusIndex])
                        this.changeClassroom(0)
                        // if (sessionStorage.getItem('myCusTabName') && sessionStorage.getItem('myCusTabName') != 'record') {
                        //     this.selectTab(sessionStorage.getItem('myCusTabName'))
                        // }
                    }
                }
            ).finally(() => {
                this.listLoading = false
            })
        },
        //根据id获取stulist信息
        getListInfo(ids) {
            let requestData = {
                'code': this.listType == 'school' ? this.$store.state.userInfo.schoolCode : this.$store.state.userInfo.TEAMModelId,
                'scope': this.listType,
                'ids': ids
            }
            return this.$api.courseMgmt.findListSummary(requestData)
        }
    },
    created() {
        //直接读取登录成功拿到得学校基础信息
        this.$store.dispatch('user/getSchoolProfile').then(res => {
            this.classList = res.school_classes
            this.schoolBase = res.school_base
            this.isFirst = true
            this.getCourseList()
        })
        this.$nextTick(() => {
            let dom = document.getElementById('table-height')
            this.tableHeight = dom.offsetHeight - 50
        })
        this.initData()
    },
    computed: {
        //课程学段
        cusPd() {
            let pds = this.courseList.map(item => {
                return item.period
            })
            let res = []
            pds.forEach(item => {
                let r = res.find(resItem => {
                    return item && resItem && item.id == resItem.id
                })
                if (!r && item && item.id) {
                    res.push(item)
                }
            })
            if (res.length) {
                this.curPd = res[0].id
            }
            return res
        },
        //课程表当前显示的课程
        schdData() {
            let pdCus = []
            if (this.listType == 'school') {
                pdCus = this.courseListShow.filter(item => {
                    return item.period.id == this.curPd && item.schedule
                })
            }
            return pdCus
        },
        //无教室课程
        noClassCus() {
            return this.schdData.filter(item => {
                let res = item.schedule.find(schdItem => {
                    return schdItem.classId && schdItem.teacherId == this.$store.state.userInfo.TEAMModelId
                })
                return !res
            })
        },
        //无时段课程
        noTimeCus() {
            return this.schdData.filter(item => {
                let res = item.schedule.find(schdItem => {
                    return (schdItem.time && schdItem.time.length) && schdItem.teacherId == this.$store.state.userInfo.TEAMModelId
                })
                return !res
            })
        },
        //是否为默认名单
        isDefList() {
            if (this.teaClassList[this.curClassIndex] && this.teaClassList[this.curClassIndex].stulist) {
                return false //有stulist则不是默认名单
            } else {
                return true
            }
        },
        //课程名单 —— schedule
        teaClassList() {
            if (this.courseListShow.length > 0 && this.courseListShow[this.curCusIndex] && this.courseListShow[this.curCusIndex].schedule) {
                let list = this.courseListShow[this.curCusIndex].schedule.filter(item => {
                    return item.teacherId == this.$store.state.userInfo.TEAMModelId && (item.classId || item.stulist)
                })
                return list
            } else {
                return []
            }
        },
        students() {
            if (this.courseListShow[this.curCusIndex] && this.courseListShow[this.curCusIndex].schedule && this.courseListShow[this.curCusIndex].schedule[this.curClassIndex]) {
                return this.courseListShow[this.curCusIndex].schedule[this.curClassIndex].students
            } else {
                return []
            }
        },
        //当前班级活动列表
        acList() {
            let list = []
            let id = this.teaClassList[this.curClassIndex] ? this.teaClassList[this.curClassIndex].stulist || this.teaClassList[this.curClassIndex].classId : ''
            if (!id) {
                return []
            }
            switch (this.curAcType) {
                case 'ev':
                    list = this.evList.filter(item => {
                        return item.classes && item.classes.indexOf(id) > -1
                    })
                    break
                case 'vote':
                    list = this.voteList.filter(item => {
                        return item.classes && item.classes.indexOf(id) > -1
                    })
                    break
                case 'qu':
                    list = this.quList.filter(item => {
                        return item.classes && item.classes.indexOf(id) > -1
                    })
                    break
                case 'hw':
                    list = this.hwList.filter(item => {
                        return item.classes && item.classes.indexOf(id) > -1
                    })
                    break
                case 'sl':
                    list = this.slList.filter(item => {
                        return item.classes && item.classes.indexOf(id) > -1
                    })
                    break
                default:
                    break
            }
            return list
        },
        cusTypeLabel() {
            let curObj = this.cusType.find(item => {
                return item.value == this.listType
            })
            return curObj.label
        },
        acTypeLabel() {
            let curObj = this.acTypeList.find(item => {
                return item.value == this.curAcType
            })
            return curObj.label
        },
    }
}
</script>
<style scoped lang="less">
@import "./MyCourse.less";
</style>
<style>
.cus-list-tab .ivu-tabs-bar {
    height: 45px;
}
.cus-list-tab .ivu-tabs-nav {
    height: 45px;
    line-height: 30px;
}
.course-classroom-list-header .ivu-poptip-inner {
    background-color: #404040;
    color: white;
}

.course-classroom-list-header .ivu-poptip-arrow::after {
    display: none;
}

.course-classroom-list-header .ivu-poptip-title:after,
.course-classroom-list-header .ivu-poptip-title {
    display: none;
}
.course-classroom-info-content #loadingBox {
    margin-top: 0px !important;
}
.class-record-wrap .ivu-list-item:hover {
    background: #404040;
}
</style>