<template>
    <div class="schedule">
        <!-- <m-header :backUrl="backUrl" /> -->
        <van-dropdown-menu :close-on-click-outside="false" active-color="#01C1B5"> 
      <van-dropdown-item
        v-model="value1"
        @change="onTypeChange" 
        title="课程类型"
        :options="option1"
      />
    
    </van-dropdown-menu>
        <van-list v-model="loading" v-if="dataShow" key="data"
            :finished="finished"
            :immediate-check="false"
            finished-text="- 没有更多内容 -"
            @load="getDailySchedule">
            <course-detail :dataList="dataList" @onDetail="onDetail" />
        </van-list>
        <m-empty class="empty" v-else  />
    </div>
</template>
<script>
import MHeader from '@/components/MHeader'
import dayjs from 'dayjs'
import MEmpty from '@/components/MEmpty'
import { attendanceErrorList }  from './api'

import setLoading from '@/common/loading'
// import { getCourseScheduleDateByMonth } from '@/api/teacher'
import CourseDetail from '@/components/CourseDetail'
export default {
    name: 'schedule',
    components: { MHeader, MEmpty, CourseDetail },
    data() {
        return {
            loading: false,
            finished: false,
            value1:'全部',
            params: {
                page: 1,
                rows: 10
            },
            dataShow: true, // 是否有数据
            dataList: [],
            backUrl: {
                status: true,
                path: '/home'
            },
            getMonthDay: [],
            option1: [
        { text: "全部", value: "全部" },
        { text: "声部课", value: "SINGLE" },
        { text: "集训声部课", value: "TRAINING_SINGLE" },
        { text: "合奏课", value: "MIX" },
        { text: "集训合奏课", value: "TRAINING_MIX" },
        { text: "基础技能课", value: "HIGH" },
        { text: "线上基础技能课", value: "HIGH_ONLINE" },
        { text: "课堂课", value: "CLASSROOM" },
        { text: "综合课", value: "COMPREHENSIVE" },
        { text: "VIP课", value: "VIP" },
        { text: "网管课", value: "PRACTICE" },
        { text: "试听课", value: "DEMO" },
      ],
        }
    },
    mounted() {
        this.getDailySchedule()
        // this.getCourseMonth(this.params.date)
    },
    methods: {
        onDetail(item) {
            this.$router.push({
                path: '/attendScheduleDetail',
                query: {
                    id: item.id,
                    studentNum: item.studentNum,
                    teacherName: item.teacherName,
                    leaveStudentNum: item.leaveStudentNum,
                    totalStudentNum: item.totalStudentNum,
                    startClassTime: item.startClassTime,
                    endClassTime: item.endClassTime,
                    teachMode: item.teachMode,
                    type: item.type,
                    name: item.name
                }
            })
        },
        async getDailySchedule() {
            let params = this.params
            if(this.value1 =='全部'){
                params.courseType = null 
            }else{
                params.courseType = this.value1 
            }
            await attendanceErrorList(params).then(res => {
                this.dataShow = true;
                let result = res.data
                this.loading = false
                if(res.code == 200) {
                    params.page = result.pageNo
                    this.dataList = this.dataList.concat(result.rows)
                    if(params.page >= result.totalPage) {
                        this.finished = true
                    }
                    this.params.page++
                } else {
                    this.finished = true
                }
                // 判断是否有数据
                if(this.dataList.length <= 0) {
                    this.dataShow = false
                }
            })
        },
        onTypeChange(){
            this.purposeStatus = true;
          this.getDailySchedule()
        }
        // async getCourseMonth(month) {
        //     setLoading(true)
        //     try {
        //         await getCourseScheduleDateByMonth({ month: month }).then(res => {
        //             let result = res.data
        //             if(result.code == 200) {
        //                 this.getMonthDay = []
        //                 result.data.forEach(item => {
        //                     this.getMonthDay.push(dayjs(item).format('DD'))
        //                 })
        //             }
        //         })
        //         setLoading(false)
        //     } catch(err) {
        //         setLoading(false)
        //     }
        // }
    }
}
</script>
<style lang='less' scoped>
@import url("../../assets/commonLess/variable.less");
.schedule {
    min-height: 100vh;
}
.link { color: @whiteColor; }
/deep/.empty {
    .icon {
        margin-top: .2rem;
    }
}

</style>