AboutClassApe.js 14.4 KB
//*
// 约课模块
// */

import Loger from "../Loger";
import Ape from "./Ape";
import $ from "jquery";
import ClassDataProxy from "proxy/ClassDataProxy";
import dateUI from 'libs/laydate';

let loger = Loger.getLoger('PC-AboutClassApe');
const adminListTit = `<table width="100%" align="center" cellpadding="0" cellspacing="0" border="0" id="t_box" class="t_box">
                        <tbody>
                            <tr align="center" height="44" class="tr_center" bgcolor="#fff" bordercolor="#e6e6e6">
                                <th width="6%" class="tr_center">
                                    姓名
                                </th>
                                <th width="7%" class="tr_center">
                                    电话
                                </th>
                                <th width="8%" class="tr_center">
                                    年龄
                                </th>
                                <th width="7%" class="tr_center">
                                    所约课程
                                </th>
                                <th width="9%" class="tr_center">
                                    操作
                                </th>
                            </tr>
`;
//管理首页
const adminList = `<tr align="center" bgcolor="#FFFFFF" height="44" bordercolor="#e6e6e6">
                                <td width="7%" class="tr_main tr_mainLeft">{_userName}</td>
                                <td width="8%" class="tr_main">{_phone}</td>
                                <td width="8%" class="tr_main">{_age}</td>
                                <td width="8%" class="tr_main">{_course}</td>
                                <td  width="10%" class="tr_main tr_mainRight" align="center" >
                                <a class="classHandlePort" href="javascript:void(0)">&nbsp;</a>
                                    <a id="{_removeInd}" class="classHandlePort" href="javascript:void(0)">删除</a>
                                    <a class="classHandlePort" href="javascript:void(0)">&nbsp;</a>
                                    <a id="{_stay}" class="classHandlePort" data="{_aboutMsg}" href="javascript:void(0)">待回访</a>
                                    <a class="classHandlePort" href="javascript:void(0)">&nbsp;</a>
                                </td>
                            </tr>
`;
const adminListEnd = `</tbody></table>`;

const adminListTit1 = `<table width="100%" align="center" cellpadding="0" cellspacing="0" border="0" id="t_box" class="t_box">
                        <tbody>
                            <tr align="center" height="44" class="tr_center" bgcolor="#fff" bordercolor="#e6e6e6">
                                <th width="7%" class="tr_center">
                                    姓名
                                </th>
                                <th width="7%" class="tr_center">
                                    电话
                                </th>
                                <th width="6%" class="tr_center">
                                    年龄
                                </th>
                                <th width="7%" class="tr_center">
                                    约课老师
                                </th>
                                <th width="9%" class="tr_center">
                                    操作
                                </th>
                            </tr>
`;
//管理首页
const adminList1 = `<tr align="center" bgcolor="#FFFFFF" height="44" bordercolor="#e6e6e6">
                                <td width="7%" class="tr_main tr_mainLeft">{_userName}</td>
                                <td width="7%" class="tr_main">{_phone}</td>
                                <td width="6%" class="tr_main">{_age}</td>
                                <td width="7%" class="tr_main">{_course}</td>
                                <td  width="9%" class="tr_main tr_mainRight" align="center" >
                                    <a class="classHandlePort1" href="javascript:void(0)">&nbsp;&nbsp;</a>
                                    <a id="{_removeInd}" class="classHandlePort" href="javascript:void(0)">删除</a>
                                    <a class="classHandlePort1" href="javascript:void(0)">&nbsp;&nbsp;</a>
                                </td>
                            </tr>
`;
class AboutClassApe extends Ape {
    constructor() {
        super();
        this.pageNo = 1;
        this.presentInd = 1;
        this.addEvent();
        this.init();
    }

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

        $('#classHandlerHomePage4_0').on('click',this._homePageHandler.bind(this));//首页
        $('#classHandlerUpPage4_0').on('click',this._upPageHandler.bind(this));//上页
        $('#classHandlerDownPage4_0').on('click',this._downPageHandler.bind(this));//下页
        $('#classHandlerEndPage4_0').on('click',this._endPageHandler.bind(this));//尾页
        $('#classHandlerSpecificPage4_0').on('click',this._assignPageHandler.bind(this));//指定页

        $('#classHandlerHomePage4_1').on('click',this._homePageHandler.bind(this));//首页
        $('#classHandlerUpPage4_1').on('click',this._upPageHandler.bind(this));//上页
        $('#classHandlerDownPage4_1').on('click',this._downPageHandler.bind(this));//下页
        $('#classHandlerEndPage4_1').on('click',this._endPageHandler.bind(this));//尾页
        $('#classHandlerSpecificPage4_1').on('click',this._assignPageHandler.bind(this));//指定页
    }

    addEvent() {

    }
    //首页
    _homePageHandler(){
        this.presentInd = 1;
        let ind = $('#classHandlerPageBox4').attr('data');
        switch (parseInt(ind)){
            case 0:
                this._manageCourse(this.presentInd);
                break;
            case 1:
                this._manageTeacher(this.presentInd);
                break;
            default:
                return;
        }
    }
    //上页
    _upPageHandler(){
        if(this.presentInd > 1){
            this.presentInd--;
            let ind = $('#classHandlerPageBox4').attr('data');
            switch (parseInt(ind)){
                case 0:
                    this._manageCourse(this.presentInd);
                    break;
                case 1:
                    this._manageTeacher(this.presentInd);
                    break;
                default:
                    return;
            }
        }
    }
    //下页
    _downPageHandler(){
        if(this.presentInd < this.pageNo){
            this.presentInd++;
            let ind = $('#classHandlerPageBox4').attr('data');
            switch (parseInt(ind)){
                case 0:
                    this._manageCourse(this.presentInd);
                    break;
                case 1:
                    this._manageTeacher(this.presentInd);
                    break;
                default:
                    return;
            }
        }
    }
    //尾页
    _endPageHandler(){
        this.presentInd = this.pageNo;
        let ind = $('#classHandlerPageBox4').attr('data');
        switch (parseInt(ind)){
            case 0:
                this._manageCourse(this.presentInd);
                break;
            case 1:
                this._manageTeacher(this.presentInd);
                break;
            default:
                return;
        }
    }
    //指定页
    _assignPageHandler(){
        let val;
        let ind = $('#classHandlerPageBox4').attr('data');
        let card = $('#aboutClassList4 .liveInfoLeftLiCheck').index();
        let inputVal = $('#classHandlerPageInfoInput4_'+card).val();
        if(parseInt(inputVal) > this.pageNo ){
            val = this.pageNo;
        }else if(parseInt(inputVal) < 1){
            val = 1;
        }else{
            val = parseInt(inputVal)
        }
        switch (parseInt(ind)){
            case 0:
                this._manageCourse(val);
                break;
            case 1:
                this._manageTeacher(val);
                break;
            default:
                return;
        }
        $('#classHandlerPageInfoInput4_'+card).val('')
    }
    // 约课界面
    aboutClass(){
        let ind = $('#aboutClassList4 .liveInfoLeftLiCheck').attr('data');
        let card = $('#aboutClassList4 .liveInfoLeftLiCheck').index();
        $('#classHandlerPageBox4').attr('data',ind)
        let status = parseInt(ind);
        $('#classHandlerPageBox4_'+card).show().siblings().hide();
        this.presentInd = 1;
        switch (status){
            case 0:
                //课程  列表
                this._manageCourse(1);
                break;
            case 1:
                //老师  列表
                this._manageTeacher(1);
                break;

            default:
                return;
        }
    }
    //课程  列表
    _manageCourse(ind){
        let that = this;
        this.publicAjax(8,ind,function(_data){
            if(_data){
                that._coursePage(_data.returnData.data);
                that._userCourse(_data.returnData.data);
            }
        })
    }
    //老师  列表
    _manageTeacher(ind){
        let that = this;
        this.publicAjax(8,ind,function(_data){
            if(_data){
                that._teacherPage(_data.returnData.data);
                that._teacherCourse(_data.returnData.data);
            }
        })
    }
    _userCourse(_data){
        let courseContent = $('#courseContent4');
        courseContent.empty();
        if(_data){
            courseContent.append(adminListTit);
            let _dataList = _data.studentMeeting;
            for(let i =0;i<_dataList.length;i++){
                let item = _dataList[i];
                if(item){
                    let _adminList = this._format(adminList,{
                        _userName : item.user_name,
                        _phone : item.user_mobile,
                        _age : '女',
                        _totalNmu : '2',
                        _course : item.meeting_name,
                        _removeInd : 'classDoc'+i,
                        _stay : 'classMedia'+i,
                        _aboutMsg : item.id
                    })
                    courseContent.append(_adminList);
                }
                courseContent.append(adminListEnd);
            }
        }else{
            this._gainUserClassDataErr();
        }
    }
    _teacherCourse(_data){
        let courseContent = $('#courseContent4');
        courseContent.empty();
        if(_data){
            let _dataList = _data.studentMeeting;
            courseContent.append(adminListTit1);
            for(let i =0;i<_dataList.length;i++){
                let item = _dataList[i];
                if(item){
                    let _adminList = this._format(adminList1,{
                        _userName : item.user_name,
                        _phone : item.user_mobile,
                        _age : '女',
                        _totalNmu : '2',
                        _course : item.teacherName,
                        _removeInd : 'classDoc'+i,
                        _stay : 'classMedia'+i,
                        _aboutMsg : item.id
                    })
                    courseContent.append(_adminList);
                }
                courseContent.append(adminListEnd);
            }
        }else{
            this._gainUserClassDataErr();
        }
    }
    _coursePage(_data){
        if(_data){
            let count = _data.count;
            let page = _data.page;
            let pageno = _data.pageno;
            let pagenum = Math.ceil(count / pageno);
            this.pageNo = pagenum;
            $('#classHandlerPageMsg4_0').html('第'+page+'页/共'+pagenum+'页,有'+count+'个记录');
            if(count <=4){
                $('#classHandlerPageBox4_0').hide();
            }

        }
    }
    _teacherPage(_data){
        if(_data){
            let count = _data.count;
            let page = _data.page;
            let pageno = _data.pageno;
            let pagenum = Math.ceil(count / pageno);
            let _dataList = _data.meetingInfo;
            this.pageNo = pagenum;
            $('#classHandlerPageMsg4_1').html('第'+page+'页/共'+pagenum+'页,有'+count+'个记录');
            if(count <=4){
                $('#classHandlerPageBox4_1').hide();
            }
        }
    }
    _gainUserClassDataErr(){
        let courseContent = $('#courseContent4');
        courseContent.empty();
        courseContent.append(adminListTit);
        let _adminList = '<tr align="center" bgcolor="#FFFFFF" height="44" bordercolor="#e6e6e6">' +
            '<td class="tr_main tr_mainNone">' +
            '该课堂暂无约课数据~'+
            '</td>>'+
            '</tr>'
        courseContent.append(_adminList);
        courseContent.append(adminListEnd);
    }
    publicAjax(num,ind,callback){
        if(ClassDataProxy.id == ''){
            return;
        }
        let _url = ClassDataProxy.locationProtocol + ClassDataProxy.locationProt + '/studentMeeting/getStudentMeetingBySite/'+ClassDataProxy.siteId;
        let that = this;
        $.ajax({
            type: "GET",
            url: _url,
            timeout:5000,
            headers: {siteId:ClassDataProxy.siteId,pageno:num,page:ind,id:ClassDataProxy.id,
                'token':ClassDataProxy.token},
            success:function(_data){
                //   loger.log('预约信息斯柯达开始',_data)
                //获取我的课程数据
                if(_data && _data.code == 200){
                    if(callback){
                        callback(_data);
                    }
                }else{
                    if(callback){
                        callback(null);
                    }
                }
            },
            error:function(error){
                //alert('直播数据获取失败')
                if(callback){
                    callback(null);
                }
                loger.log(error,'直播数据获取失败')
            }
        })
    }
    _switchover(evt){
        $(evt.currentTarget).addClass('liveInfoLeftLiCheck').siblings().removeClass('liveInfoLeftLiCheck');
    }
    _userClassListHandler(evt){
        this._switchover(evt);
        this.aboutClass();
    }
    //工具类
    _format(str, obj) {
        return str.replace(/\{(\w+)\}/g, function (match, group, index) {
            return obj[group];
        });
    };
}
export default AboutClassApe;