LiveClassApe.js 7.8 KB
//*
// 互动课堂模块
// */

import Loger from "../Loger";
import Ape from "./Ape";
import $ from "jquery";
import ClassDataProxy from "proxy/ClassDataProxy";
let loger = Loger.getLoger('PC-LanclassApe');

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>`;

class LanclassApe extends Ape {
    constructor() {
        super();
        this.classDateList = {};//课堂的所有数据
        this.addEvent();
        this.init();
    }

    init() {
        //判断列表在右侧时取消边距
        this._judgeListPlace();
        $('#collectYes').hide();

        $('#liveBtn').on('click',this._lanclassBtnHandler.bind(this));//直播课堂
        $('#liveBtnMove').on('click',this._lanclassBtnHandler.bind(this));//直播课堂

        $('#classifyListBox').on('click','.pageNumBtn',this._pageNumBtnHandler.bind(this));//点击翻页
    }

    addEvent() {

    }
    _judgeListPlace(){
        let i=(i%4);
        $('#classifyListContent').find('.classifyList').eq(i==3).addClass('classifyListR');
    }
    _lanclassBtnHandler(evt){
        this._clearListContent();
        this._showLoadingImg();
        loger.log('互动',ClassDataProxy.userType)
        let _ele = $(evt.target);
        if(_ele.attr('data')){
            $('.header_listMsg').eq(_ele.attr('data')).addClass('header_listMsgCheck').siblings().removeClass('header_listMsgCheck');
        }
        $(evt.target).addClass('header_listMsgCheck').siblings().removeClass('header_listMsgCheck');
        $('#slideshow').hide();
        $('#defaultBox').hide();
        $('#classifyListBox').show();
        $('#teacherDetailBox').hide();
        $('#lanclassBox').hide();
        this.detailPage();
    }
    //点击翻页
    _pageNumBtnHandler(evt){
        let _url = ClassDataProxy.locationProtocol + ClassDataProxy.locationProt + '/meeting/getMeeting';
        let _ele = $(evt.target);
        let that = this;
        if(_ele.siblings().length > 0 && _ele.text()!= '...' ){
            _ele.addClass('pageNumBtnCheck').siblings().removeClass('pageNumBtnCheck');
            $.ajax({
                type: "POST",
                url: _url,
                timeout:5000,
                headers: {'page':_ele.text(),
                    siteId:'markettest',
                    'token':'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IlhXQnJlRU00T0swYTVqUUIyUTFicGtObHlxOUFWbXZkIiwibmFtZSI6ImFkbWluIiwiY29kZSI6MSwiaWF0IjoxNTAzNDUxODU0LCJleHAiOjIyODEwNTE4NTR9.3kTVzKd_jbP7l69nxOpNaFeSjVnnjZkagYMzRB8fjNo',
                },
                data:{siteId:'markettest'},
                success:function(_data){
                    if(_data != 200 ){
                        // loger.warn(_data.data.msg)
                    }
                    that.classDateList = _data.returnData.data;
                    //切换列表内容
                    that._classDateContent(that.classDateList);
                    loger.log(_data,'成功')
                },
                error:function(error){
                    //alert('直播翻页数据获取失败')
                    loger.log(error,'直播翻页数据获取失败')
                }
            })
        }else{
            return;
        }
    }
    detailPage(){
        let _url = ClassDataProxy.locationProtocol + ClassDataProxy.locationProt + '/meeting/getMeeting';
        let that = this;
        $.ajax({
            type: "POST",
            url: _url,
            timeout:5000,
            data:{siteId:'markettest'},
            headers: {siteId:'markettest',
                'token':'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IlhXQnJlRU00T0swYTVqUUIyUTFicGtObHlxOUFWbXZkIiwibmFtZSI6ImFkbWluIiwiY29kZSI6MSwiaWF0IjoxNTAzNDUxODU0LCJleHAiOjIyODEwNTE4NTR9.3kTVzKd_jbP7l69nxOpNaFeSjVnnjZkagYMzRB8fjNo'},
            success:function(_data){
                // loger.log(_data,'成功')
                //获取课堂数据
                that._gainClassData(_data);
            },
            error:function(error){
                //alert('直播数据获取失败')
                loger.log(error,'直播数据获取失败')
            }
        })
    }
    _gainClassData(_data){
        if(_data || _data.code == 200){
            this.classDateList = _data.returnData.data;
            let classifyListContent = $('#classifyListContent');
            classifyListContent.empty();
            //切换列表分类的标题
            this._classDateTitle();
            //切换列表内容
            this._classDateContent(this.classDateList);
            //页码
            this._classDatepageNum(this.classDateList);
        }
    }
    _classDateTitle(){
        $('#classifyListTitle').html($('.header_listMsgCheck').attr('data'));
    }
    //清楚列表数据
    _clearListContent(){
        let classifyListContent = $('#classifyListContent');
        classifyListContent.empty();
        let classifyListTitle = $('#classifyListTitle');
        classifyListTitle.empty();
        let pageNumContentBox = $('#pageNumContentBox');
        pageNumContentBox.empty();
    }
    //列表显示loading
    _showLoadingImg(){
        let loadingImg = `<img class="loadingImg" src="images/loading.gif" alt="">`;
        $('#classifyListContent').append(loadingImg);
    }
    _classDateContent(_data){
        let classifyListContent = $('#classifyListContent');
        classifyListContent.empty();
        let _dataList = _data.meetingInfo;
        if(_dataList){
            for(let i = 0;i<_dataList.length;i++){
                let j = (i%4)==3;
                let _getTime = ClassDataProxy.getTimeDifference(_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 : '0人已预约'
                })
                classifyListContent.append(_classifyList);
            }
        }
    }
    _classDatepageNum(_data){ //page
        let _pageContent = _data.count;
        let _pageNum = Math.ceil(_pageContent / _data.pageno);

        this.pagingConstruct(1,_pageNum);
    }
    pagingConstruct(paging,total){
        let pageNumContentBox = $('#pageNumContentBox');
        pageNumContentBox.empty();
        let pagingDivInnerHTML = '<div class="pageNumContent">';
        let isHiddenExist = 0;
        for(let i =1 ;i<=total;i++){
            if(i == paging){
                pagingDivInnerHTML +='<span class="pageNumBtn pageNumBtnCheck">'+i+'</span>';
            }else{
                if (i < 4 || i < (paging + 4) && i > (paging - 2) && i < (total / 2 + 2) || i > (total - 2)) {
                    pagingDivInnerHTML +='<span class="pageNumBtn">'+i+'</span>';
                    isHiddenExist = 0;
                }else{
                    if(isHiddenExist == 0){
                        pagingDivInnerHTML += '<span class="pageNumBtn">...</span>';
                        isHiddenExist = 1;
                    }
                }
            }
        }
        pagingDivInnerHTML += '</div>';
        pageNumContentBox.append(pagingDivInnerHTML);
    }
    //工具类
    _format(str, obj) {
        return str.replace(/\{(\w+)\}/g, function (match, group, index) {
            return obj[group];
        });
    };
}
export default LanclassApe;