<template>
    <div class="el-schedule_show_fixrecord_pc_1">
        <div class="schedule_show_fixrecord_pc_1">
            <div class="container">
                <div class="row">
                    <div class="col-lg-12 col-md-12 col-sm-12 col-xs">
                        <div class="learningtool-title">
                            <span class="sp1">在线课表</span>
                        </div>
                        <div class="liveshow-tab">
                            <ul>
                                <li :class="scheduletab==0?'on':''" @click="getCurDate(0)">今日课表（{{today}} 周{{weekDay4Today}}）</li>
                                <li :class="scheduletab==1?'on':''" @click="getCurDate(1)">明日课表（{{tomorrow}} 周{{weekDay4Tomorrow}}）</li>
                            </ul>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                        <div class="schedule-table" v-if="scheduleList">
                            <table>
                                <tr>
                                    <th>线下班名称</th>
                                    <th>讲师</th>
                                    <th>时间</th>
                                    <th>开班机构</th>
                                    <!--                <th>教室</th>-->
                                </tr>
                                <tr v-for="(item,index) in scheduleList" :key="index">
                                    <td>{{item.czName}}</td>
                                    <td>{{item.scMainName}}</td>
                                    <td>{{item.startDate | formatDate}}~{{item.endDate | formatDate}}</td>
                                    <td>{{item.siteName}}</td>
                                    <!--                <td>书法培训教师(1)</td>-->
                                </tr>
                            </table>
                            <span class="moreclass"><a href="">更多课表</a></span>
                        </div>
                        <div class="schedule-table" v-if="!scheduleList">
                            <table>
                                <tr>
                                    <th>暂无课表~~</th>
                                </tr>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    import $ from 'fy-kit';
    import {httpPost} from '../../../src/utils/utils';
    import formMixin from '../../../src/mixins/formMixin';
    import lenye_base from 'lenye_base';

    export default {
        name: 'ElScheduleShowFixrecordPc1',
        mixins: [formMixin],
        model: {},
        data() {
            return {
                scheduleList: [],
                scheduletab: 0,
                startTime: $.date.moment(new Date()).format('YYYY-MM-DD') + ' 00:00:00',
                endTime: $.date.moment(new Date()).format('YYYY-MM-DD') + ' 23:59:59',
                currentPage4: 1,
                totalCount: 0,
                rows: 6,
                page: 1,
                today: $.date.moment(new Date()).format('YYYY.MM.DD'),
                tomorrow: $.date.moment(this.addDate(new Date(), 1)).format('YYYY.MM.DD'),
                weekDay4Today: this.getWeek(new Date()),
                weekDay4Tomorrow: this.getWeek(this.addDate(new Date(), 1))
            };
        },
        // 过滤
        filters: {
            formatDate: function (value) {
                var datavalue = value.replace(/\-/g, '/');
                let date = new Date(datavalue);
                // let y = date.getFullYear();
                // let MM = date.getMonth() + 1;
                // MM = MM < 10 ? ('0' + MM) : MM;
                // let d = date.getDate();
                // d = d < 10 ? ('0' + d) : d;
                let h = date.getHours();
                h = h < 10 ? ('0' + h) : h;
                let m = date.getMinutes();
                m = m < 10 ? ('0' + m) : m;
                // let s = date.getSeconds();
                // s = s < 10 ? ('0' + s) : s;
                return h + ':' + m;
            }
        },
        mounted() {
            console.log(httpPost);
            this.getScheduleList();
        },
        computed: {},
        methods: {
            getScheduleList() {
                let clzTabList = [];
                let that = this;
                let czList = [];
                let czIds = '';
                httpPost(lenye_base.base_data.getapiUrl() + '/schoolclass-service/common/clzClazzSchedule/queryScheduleList4front.do',
                    lenye_base.base_data.getformatting({
                        startDate: this.startTime,
                        endDate: this.endTime,
                        page: this.page,
                        rows: this.rows
                    }),
                    function (data) {
                        console.log(data);
                        clzTabList = data.data;
                        if (data.totalCount > 0) {
                            clzTabList.forEach((a) => {
                                if (a.czId) {
                                    czIds += a.czId + ',';
                                }
                            });
                            httpPost(lenye_base.base_data.getapiUrl() + '/schoolclass-service/common/clzClazz/queryByIds.do',
                                lenye_base.base_data.getformatting({ids: czIds})
                            ).then((data) => {
                                czList = data.data;
                                clzTabList.forEach((schedule) => {
                                    czList.forEach((clazz) => {
                                        if (schedule.czId == clazz.czId) {
                                            schedule.czName = clazz.czName;
                                            schedule.siteName = clazz.siteName;
                                            return;
                                        }
                                    });
                                });
                                that.scheduleList = clzTabList;
                            });
                        } else {
                            that.scheduleList = '';
                        }
                    });
            },
            addDate(date, days) {
                return new Date((new Date() / 1000 + 86400 * days) * 1000);
            },
            getWeek(date) {
                if (date.getDay() == 0) {
                    return '日';
                } else if (date.getDay() == 1) {
                    return '一';
                } else if (date.getDay() == 2) {
                    return '二';
                } else if (date.getDay() == 3) {
                    return '三';
                } else if (date.getDay() == 4) {
                    return '四';
                } else if (date.getDay() == 5) {
                    return '五';
                } else if (date.getDay() == 6) {
                    return '六';
                }
            },
            getCurDate(i) {
                this.scheduletab = i;
                if (i == 0) {
                    this.startTime = $.date.moment(new Date()).format('YYYY-MM-DD') + ' 00:00:00';
                    this.endTime = $.date.moment(new Date()).format('YYYY-MM-DD') + ' 23:59:59';
                    this.getScheduleList();
                } else {
                    this.startTime = $.date.moment(this.addDate(new Date(), 1)).format('YYYY-MM-DD') + ' 00:00:00';
                    this.endTime = $.date.moment(this.addDate(new Date(), 1)).format('YYYY-MM-DD') + ' 23:59:59';
                    this.getScheduleList();
                }
            }
        }
    };
</script>
