PartTimeTeachingApe.js 7.7 KB
//*
// 兼课模块
// */

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

const adminListTit = `<table width="100%" align="center" cellpadding="0" cellspacing="0" border="0" class="t_box">
                        <tbody>
                            <tr align="center" height="44" class="tr_center" bgcolor="#fff" bordercolor="#e6e6e6">
                                <th width="8%" class="tr_center">
                                    课堂主题
                                </th>
                                <th width="8%" class="tr_center">
                                    课堂号
                                </th>
                                <th width="8%" class="tr_center">
                                    老师
                                </th>
                                <th width="8%" class="tr_center">
                                    在线人数
                                </th>
                                <th width="8%" class="tr_center">
                                    课堂时间
                                </th>
                                <th width="8%" class="tr_center">
                                    课堂状态
                                </th>
                                <th width="10%" class="tr_center">
                                    操作
                                </th>
                            </tr>
`;
//管理首页
const adminList = `<tr align="center" bgcolor="#FFFFFF" height="44" bordercolor="#e6e6e6">
                                <td width="8%" class="tr_main tr_mainLeft">{_loginName}</td>
                                <td width="8%" class="tr_main">{_userName}</td>
                                <td width="8%" class="tr_main">{_course}</td>
                                <td width="8%" class="tr_main">{_totalNmu}</td>
                                <td width="8%" class="tr_main">

                                </td>
                                <td  width="10%" class="tr_main tr_mainRight" align="center">
                                    <a id="{_removeInd}" class="classHandlePort deleteClass" data="{_aboutMsg}" href="###">更改成员</a>
                                    <a id="{_joinInd}" class="classHandlePort" href="###" data="{_aboutMsg}">删除</a>
                                </td>
                            </tr>
`;
const adminListEnd = `</tbody></table>`;
let loger = Loger.getLoger('PC-PartTimeTeachingApe');
class PartTimeTeachingApe extends Ape {
    constructor() {
        super();
        this.isLocalStorage();
        this.data = 0;
        this.addEvent();
        this.init();
    }

    init() {
        $('#partTimeTeachingContent').on('click','.resolveBtn',this._switchresolveHandler.bind(this));

        $('#partTimeTeachingList li').on('click',this._userClassListHandler.bind(this));//用户列表

        $('#partTimeTeachingHomePage').on('click',this._homePageHandler.bind(this));//首页
        $('#partTimeTeachingUpPage').on('click',this._upPageHandler.bind(this));//上页
        $('#partTimeTeachingDownPage').on('click',this._downPageHandler.bind(this));//下页
        $('#partTimeTeachingEndPage').on('click',this._endPageHandler.bind(this));//尾页
        $('#partTimeTeachingSpecificPage').on('click',this._assignPageHandler.bind(this));//指定页
    }

    addEvent() {

    }
    isLocalStorage(){
        if(ClassDataProxy.userType == ClassDataProxy.USER_TYPE_32){
            $('#partTimeTeachingBox').show();
        }
    }
    //兼课列表中解决状态
    _switchresolveHandler(evt){
        if($(evt.target).html() == '已解决'){
            $(evt.target).addClass('classHandlePortCheck')
                .html('待解决')
        }else{
            $(evt.target).removeClass('classHandlePortCheck')
                .html('已解决')
        }
    }
    _switchover(evt){
        $(evt.currentTarget).addClass('liveInfoLeftLiCheck').siblings().removeClass('liveInfoLeftLiCheck');
    }
    _userClassListHandler(evt){
        this._switchover(evt);
        this.userAdminHandler(1);
    }
    //首页
    _homePageHandler(){
        this.presentInd = 1;
        this.userAdminHandler(this.presentInd);
    }
    //上页
    _upPageHandler(){
        if(this.presentInd >1){
            this.presentInd--;
            this.userAdminHandler(this.presentInd);
        }
    }
    //下页
    _downPageHandler(){
        if(this.presentInd < this.pageNo){
            this.presentInd++;
            this.userAdminHandler(this.presentInd);
        }
    }
    //尾页
    _endPageHandler(){
        this.presentInd = this.pageNo;
        this.userAdminHandler(this.presentInd);
    }
    //指定页
    _assignPageHandler(){
        let inputVal = $('#classHandlerPageInfoInput3').val();
        let val;
        if(parseInt(inputVal) > this.pageNo ){
            val = this.pageNo;
        }else if(parseInt(inputVal) < 1){
            val = 1;
        }else{
            val = parseInt(inputVal)
        }
        this.userAdminHandler(val);
        $('#classHandlerPageInfoInput3').val('');
    }
    //用户管理 创建用户界面
    userAdminHandler(ind){

        let _url = ClassDataProxy.locationProtocol + ClassDataProxy.locationProt + '/users/getUser';
        let that = this;
        let data = $('#userClassList3').find('.liveInfoLeftLiCheck').attr('data');
        let dataInfo = {
            siteId : ClassDataProxy.siteId,
            userType : data
        }
        $.ajax({
            type: "POST",
            url: _url,
            timeout:5000,
            data:dataInfo,
            headers: {siteId:ClassDataProxy.siteId,
                pageno:7,
                'page':ind,
                'token':ClassDataProxy.token},
            success:function(_data){
                //获取课堂数据
                if(_data && _data.code == 200){
                    //loger.log(_data,'创建用户界面用户列表数据')
                    that._gainUserClassData(_data.returnData.data);
                }
            },
            error:function(error){
                //alert('直播数据获取失败')
                loger.log(error,'直播数据获取失败')
            }
        })
    }
    _gainUserClassData(_data){
        let _dataList = _data.users;
        let courseContent = $('#courseContent3');
        courseContent.empty();
        let count = _data.count;
        let page = _data.page;
        let pageno = _data.pageno;
        let pagenum = Math.ceil(count / pageno);
        this.pageNo = pagenum;
        $('#classHandlerPageMsg3').html('第'+page+'页/共'+pagenum+'页,有'+count+'个记录');
        courseContent.append(adminListTit);
        if(_dataList){
            if(count <= 7){
                $('#classHandlerPageBox3').hide();
            }
            for(let i = 0;i<_dataList.length;i++){
                let _adminList = this._format(adminList,{
                    _loginName : _dataList[i].loginName,
                    _userName : _dataList[i].userName,
                    _course : '暂无',
                    _totalNmu : '2',
                    _latest : '1',
                    _removeInd : 'classDoc'+i,
                    _joinInd : 'classMedia'+i,
                    _aboutMsg : _dataList[i].id
                })
                courseContent.append(_adminList);
            }
            courseContent.append(adminListEnd);
        }
    }
    //工具类
    _format(str, obj) {
        return str.replace(/\{(\w+)\}/g, function (match, group, index) {
            return obj[group];
        });
    };
}
export default PartTimeTeachingApe;