HomeApe.js 4.9 KB
//*
// 首页模块
// */

import Loger from "../Loger";
import Ape from "./Ape";
import xdysdk from "libs/xdysdk";
import DrawTool from "./DrawTool";
import LaserPen from "./LaserPen";
import $ from "jquery";
import ClassDataProxy from "proxy/ClassDataProxy";

const classifyList = `<div class="classifyList {_classifyListR}" id="{_id}">
                            <img class="curriculumListImg" src="{_msgImg}" alt="">
                            <p class="curriculumListTit">{_classroomTitle}</p>
                            <p class="curriculumListInfo">
                                <span class="curriculumListTime">{_schoolTime}</span>
                                <span class="curriculumListNum">{_subscribeNum}</span>
                            </p>
                        </div>`;


let loger = Loger.getLoger('PC-HomeApe');
class HomeApe extends Ape {
    constructor() {
        super();
        this.classDateList = {};//课堂的所有数据
        //判断列表在右侧时取消边距
        this._judgeListPlace();
        this.addEvent();
        this.init();
    }

    init() {
        this.detailPage();
        $('#defaultBtn').on('click',this._lanclassBtnHandler.bind(this));
    }

    addEvent() {

    }
    _judgeListPlace(){
        let i;
        let curriculumList = document.getElementsByClassName('curriculumList');
        for(i=0;i<curriculumList.length;i++){
            if((i%4) == 3){
                $(curriculumList[i]).addClass('classifyListR');
            }
        }
    }
    _lanclassBtnHandler(evt){
        $(evt.target).addClass('header_listMsgCheck').siblings().removeClass('header_listMsgCheck');
        $('#slideshow').show();
        $('#defaultBox').show();
        $('#classifyListBox').hide();
        $('#teacherDetailBox').hide();
        $('#lanclassBox').hide();
    }
    detailPage(){
        let that = this;
        let _url = ClassDataProxy.locationProtocol + ClassDataProxy.locationProt + '/meeting/getMeeting';
        $.ajax({
            type: "POST",
            url: _url,
            data:{siteId:'markettest'},
            headers: {siteId:'markettest',
                'token':'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IlhXQnJlRU00T0swYTVqUUIyUTFicGtObHlxOUFWbXZkIiwibmFtZSI6ImFkbWluIiwiY29kZSI6MSwiaWF0IjoxNTAzNDUxODU0LCJleHAiOjIyODEwNTE4NTR9.3kTVzKd_jbP7l69nxOpNaFeSjVnnjZkagYMzRB8fjNo'},
            success:function(_data){
                // loger.log(_data,'成功')
                //获取课堂数据
                if(_data || _data.code == 200){
                    that._gainClassData(_data.returnData.data);
                }
            },
            error:function(error){
                console.log(error,'失败')
            }
        })
    }
    _gainClassData(_data){
        let liveList = $('#liveList');
        let lanclassList = $('#lanclassList');
        let teacherIntro = $('#teacherIntro');
        liveList.empty();
        lanclassList.empty();
        teacherIntro.empty();
        if(_data){
        let _dataList = _data.meetingInfo;
            for(let i = 0;i<_dataList.length;i++){
                if(i<8){
                    let j = (i%4)==3;
                    let _getTime = this.getTime(_dataList[i].beginTime,_dataList[i].endTime)
                    let _classifyList = this._format(classifyList,{
                        _classifyListR : j?'classifyListR':'',
                        _id : _dataList[i].id,
                        _msgImg :'../images/u373.png',
                        _classroomTitle : _dataList[i].meetingName,
                        _schoolTime :  _getTime,
                        _subscribeNum : _dataList[i].reservationNumber+'人已预约'
                    })
                    liveList.append(_classifyList);
                    lanclassList.append(_classifyList);
                    teacherIntro.append(_classifyList);
                }
            }
        }

    }
    getTime(start,end){

        let newStart = new Date(start)
        let newEnd = new Date(end)

        let day =1000*3600*24;

        let timer = parseInt((newEnd.getTime() - newStart.getTime()) / parseInt(day));
        let newEndHours = newEnd.getHours()<10?'0'+newEnd.getHours():newEnd.getHours();
        let newStartHours = newStart.getHours()<10?'0'+newStart.getHours():newStart.getHours();

        let newStartDate = newStart.getDate()<10?'0'+newStart.getDate():newStart.getDate();
        let newStartDay = newStart.getDay()<10?'0'+newStart.getDay():newStart.getDay();
        if(timer == 0){
            return '今天  ' + ' '+newStartHours + ':00' + ' - ' + newEndHours+':00';
        }else{
            return newStartDate+1 + '月' + newStartDay +'日  ' +  ' '+newStartHours + ':00' + ' - ' + newEndHours+':00';
        }

    }
    //工具类
    _format(str, obj) {
        return str.replace(/\{(\w+)\}/g, function (match, group, index) {
            return obj[group];
        });
    };
}
export default HomeApe;