TeacherDetailApe.js 7.4 KB
//*
// 老师模块
// */

import Loger from "../Loger";
import Ape from "./Ape";
import $ from "jquery";
import ClassDataProxy from "proxy/ClassDataProxy";

let loger = Loger.getLoger('PC-TeacherDetailApe');

const classifyList = `<div class="classifyList {_classifyListR}" data="{_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 TeacherDetailApe extends Ape {
    constructor() {
        super();
        this.addEvent();
        this.init();
    }

    init() {
        $('#collectYes').hide();

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

    }

    addEvent() {

    }
    isLocalStorage(){
        this.studentClickTeacher();//学生点击老师模块
        this.detailPage();
    }
    //点击翻页
    _pageNumBtnHandler(evt){
        loger.log('点击翻页')
        let _ele = $(evt.target);
        let _url = ClassDataProxy.locationProtocol + ClassDataProxy.locationProt + '/users/getUserByUserType';
        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:ClassDataProxy.siteId,
                    'token':ClassDataProxy.token
                },
                data:{siteId:ClassDataProxy.siteId,userType : 1},
                success:function(_data){
                    loger.log('点击翻页返回数据',_data)
                    if(_data != 200 ){
                        loger.warn(_data.returnData.data.msg)
                    }
                    if(_data && _data.code ==200){
                        //切换列表内容
                        that._classDateContent(_data.returnData.data);
                    }
                },
                error:function(error){
                    //alert('老师翻页数据获取失败')
                    loger.log(error,'老师翻页数据获取失败')
                }
            })
        }else{
            return;
        }
    }
    detailPage(){
        let that = this;
        let _url = ClassDataProxy.locationProtocol + ClassDataProxy.locationProt + '/users/getUserByUserType';
        $.ajax({
            type: "POST",
            url: _url,
            timeout:5000,
            headers: {siteId:ClassDataProxy.siteId,
                userType : 1,
                'token':ClassDataProxy.token},
            data:{siteId:ClassDataProxy.siteId,userType : 1},
            success:function(_data){
                //获取课堂数据
                if(_data && _data.code == 200){
                    that._gainClassData(_data.returnData.data);
                }

            },
            error:function(error){
              //  alert('老师界面获取数据失败')
                that._gainClassDataErr();
                loger.log(error,'老师界面获取数据失败')
            }
        })
    }
    _gainClassDataErr(){
        let teacherIntroContent = $('#teacherIntroContent');
        teacherIntroContent.empty();
        let _classifyList = '<div class="dataErrorTitle">数据获取失败~</div>'
        teacherIntroContent.append(_classifyList)
    }
    //清除列表数据
    _clearListContent(){
        let teacherIntroContent = $('#teacherIntroContent');
        teacherIntroContent.empty();
        let teacherIntroPageBox = $('#teacherIntroPageBox');
        teacherIntroPageBox.empty();
    }
    //列表显示loading
    _showLoadingImg(){
        let loadingImg = `<img class="loadingImg" src="images/loading.gif" alt="">`;
        $('#teacherIntroContent').append(loadingImg);
    }
    _gainClassData(_data){
        if(_data){
            this._clearListContent();
            //切换列表内容
            this._classDateContent(_data);
            //页码
            this._classDatepageNum(_data);
        }
    }
    _classDateContent(_data){
        let teacherIntroContent = $('#teacherIntroContent');
        teacherIntroContent.empty();
        let _dataList = _data.users;
        for(let i = 0;i<_dataList.length;i++){
            let j = (i%4)==3;
            let _getTime = ClassDataProxy.getTimeDifference(_dataList[i].create_time,_dataList[i].end_time)
            let _img = '../images/u373.png';
            let _classImg = _dataList[i].meetingPhoto;
            let _classifyList = this._format(classifyList,{
                _classifyListR : j?'classifyListR':'',
                _id : _dataList[i].id,
                _msgImg :_classImg?_classImg:_img,
                _classroomTitle : _dataList[i].user_name,
                _schoolTime : _getTime.split('-')[0],
                _subscribeNum :_dataList[i].reservationNumber+'人预约'
            })
            teacherIntroContent.append(_classifyList);
        }
    }
    _classDatepageNum(_data){ //page
        let _pageContent = _data.count;
        let _pageNum = Math.ceil(_pageContent / _data.pageno);

        this.pagingConstruct(1,_pageNum);
    }
    pagingConstruct(paging,total){
        let teacherIntroPageBox = $('#teacherIntroPageBox');
        teacherIntroPageBox.empty();
        let pagingDivInnerHTML = '<div class="pageNumContent">';
        let isHiddenExist = 0;
        if(total > 1){
            for(let i =1 ;i<=total;i++){

                if(i == paging){
                    pagingDivInnerHTML +='<span class="pageNumBtn pageNumBtnCheck">'+i+'</span>';
                }else{
                    if (i < 4 || i < (paging + 3) && i > (paging - 2) || i > (total / 2 - 2) && i < (total / 2 + 2) || i > (total - 3)) {
                        pagingDivInnerHTML +='<span class="pageNumBtn">'+i+'</span>';
                        isHiddenExist = 0;
                    }else{
                        if(isHiddenExist == 0){
                            pagingDivInnerHTML += '<span class="pageNumBtn">...</span>';
                            isHiddenExist = 1;
                        }
                    }
                }
            }
        }
        pagingDivInnerHTML += '</div>';
        teacherIntroPageBox.append(pagingDivInnerHTML);
    }
    _teacherHome(){
        $('#slideshow').hide();
        $('#defaultBox').hide();
        $('.curriculumBox').hide();
        $('#header_list').show();
        $('#header_seek').show();
        $('#androidDownload').show();
        $('#classManagementBox').hide();
        $('#classifyListBox').show();
    }
    //学生点击老师模块
    studentClickTeacher(){
        $('#slideshow').hide();
        $('#defaultBox').hide();
        $('.curriculumBox').hide();
        $('#teacherDetailBox').hide();
        $('#lanclassBox').hide();
        $('#myCenterBox').hide();

        $('#defaultBox').hide();
        $('#liveContentAllBox').hide();
        $('#lanclassAllBox').hide();
        $('#teacherIntroAllBox').show();
    }

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