MyCenterApe.js 11.3 KB
//*
// 首页模块
// */

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

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-MyCenterApe');
class MyCenterApe extends Ape {
    constructor() {
        super();
        this.isLocalStorage();
        this.data = 0;
        this.addEvent();
        this.init();
    }

    init() {
        $('#personageInfo').on('click',this._myCenterBoxHandler.bind(this));//个人中心

        $('#teacherUI li').on('click',this._recordLiHandler.bind(this));//课堂分类

        $('#updateInputYes').on('click',this._updateInputYesHandler.bind(this));//确定时把输入的信息存入数据中

        $('#accountInfoSaveBtn').on('click',this._accountInfoSaveBtnHandler.bind(this));//更新用户信息按钮

        $('#updateInputBoxA').on('click',this._hideInputBox.bind(this));//关闭弹框
        $('#updateInputNo').on('click',this._hideInputBox.bind(this));//关闭弹框
        //修改账户信息
        $('#accountPassWordBtn').on('click',this._accountPassWordBtnHandler.bind(this));//密码
        $('#accountEmailBtn').on('click',this._accountEmailBtnHandler.bind(this));//邮箱
        $('#accountMobilelBtn').on('click',this._accountMobilelBtnHandler.bind(this));//手机号
    }

    addEvent() {

    }
    _curriculumInfo(){
        let _url = ClassDataProxy.locationProtocol + ClassDataProxy.locationProt + '/meeting/getMeeting';
        let that = this;
        $.ajax({
            type: "POST",
            url: _url,
            timeout:5000,
            data:{siteId:ClassDataProxy.siteId,userType:1},
            headers: {siteId:ClassDataProxy.siteId,
                'token':'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IlhXQnJlRU00T0swYTVqUUIyUTFicGtObHlxOUFWbXZkIiwibmFtZSI6ImFkbWluIiwiY29kZSI6MSwiaWF0IjoxNTAzNDUxODU0LCJleHAiOjIyODEwNTE4NTR9.3kTVzKd_jbP7l69nxOpNaFeSjVnnjZkagYMzRB8fjNo'},
            success:function(_data){
                 loger.log(_data,'个人中心用户列表数据')
                //获取课堂数据
                //that._gainClassData(_data);
            },
            error:function(error){
                //alert('直播数据获取失败')
                loger.log(error,'直播数据获取失败')
            }
        })
    }
    isLocalStorage(){
        if(ClassDataProxy.userType == ClassDataProxy.USER_TYPE_1){
            this._curriculumInfo();
        }
        $('#teacherMyCenterName').text(ClassDataProxy.loginName);
        $('.myCenterContentBox').eq(0).show().siblings().hide();
        let newDate = new Date();
        let newHours = newDate.getHours();
        let text = newHours>12?'下午好,':'上午好,'
        $('#teacherMyCenterTime').text(text);
        $('.recordLi2').eq(0).addClass('recordLiCheck').siblings().removeClass('recordLiCheck');
        $('#oneselfInfoLoginName').val( ClassDataProxy.loginName);//登录名
        $('#oneselfInfoUserName').val(ClassDataProxy.monicker);//用户名
        let setMail = $('#setMail');//邮箱
        let setPhone = $('#setPhone');//手机号
        let userEmail = this.updateEmail(ClassDataProxy.userEmail);
        let userMobile = this.updateMobile(ClassDataProxy.userMobile);
        setMail.attr('data',ClassDataProxy.userEmail);
        setPhone.attr('data',ClassDataProxy.userMobile);
        setMail.html(userEmail)
        setPhone.html(userMobile)
    }
    _recordLiHandler(evt){
        let ind = $(evt.currentTarget).attr('data');
        $(evt.currentTarget).addClass('recordLiCheck').siblings().removeClass('recordLiCheck');
        $('.myCenterContentBox').eq(ind).show().siblings().hide();
        switch (parseInt(ind)){
            case 0:
                //首页
                break;
            case 1:
                //我的课程
                break;
            case 2:
                //我的预约
                break;
            case 3:
                //个人信息
                this._updatMessage();
                break;
            default:
                return;
        }
    }

    //提交用户信息修改
    _accountInfoSaveBtnHandler(){
        let id = ClassDataProxy.id;//id

        let loginName = ClassDataProxy.loginName;//登录名
        let userMobile = ClassDataProxy.userMobile;//手机号
        let userEmail = ClassDataProxy.userEmail;//邮箱
        let monicker = ClassDataProxy.monicker;//用户名
        let passWord = ClassDataProxy.password;//密码

        let oneselfInfoLoginName = $('#oneselfInfoLoginName').val();//登录名
        let oneselfInfoUserName = $('#oneselfInfoUserName').val();//用户名
        let oneselfInfoMan = $('#oneselfInfoMan');//性别
        let setPassWord = $('#setPassWord').attr('data');//密码
        let setMail = $('#setMail').attr('data');//邮箱
        let setPhone = $('#setPhone').attr('data');//手机号
        let signInfo = {};
        if(oneselfInfoLoginName != loginName){
            signInfo.loginName = oneselfInfoLoginName;
        }
        if(oneselfInfoUserName != monicker){
            signInfo.userName = oneselfInfoUserName;
        }
        if(!setPassWord){
            // signInfo.loginName = oneselfInfoLoginName;
        }
        if(setMail != userEmail){
            signInfo.userEmail = setMail;
        }
        if(setPhone != userMobile){
            signInfo.userMobile = setPhone;
        }
        let that = this;
        let _url = ClassDataProxy.locationProtocol + ClassDataProxy.locationProt + '/users/updateUserByUserId/' + id;
        $.ajax({
            type: "PUT",
            url: _url,
            timeout:5000,
            headers: {siteId:ClassDataProxy.siteId,
                'token':'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IlhXQnJlRU00T0swYTVqUUIyUTFicGtObHlxOUFWbXZkIiwibmFtZSI6ImFkbWluIiwiY29kZSI6MSwiaWF0IjoxNTAzNDUxODU0LCJleHAiOjIyODEwNTE4NTR9.3kTVzKd_jbP7l69nxOpNaFeSjVnnjZkagYMzRB8fjNo'},
            data:signInfo,
            success:function(_data){
                loger.log('修改信息',_data)
                //获取个人信息数据
                if(_data && _data.code == 200){
                    loger.log('修改信息成功',_data)
                    ErrorApe.showWarnError('修改信息成功');
                    ClassDataProxy.loginName =_data.returnData.data.loginName;
                    ClassDataProxy.monicker = _data.returnData.data.userName;
                    ClassDataProxy.userEmail = _data.returnData.data.userEmail;
                    ClassDataProxy.userMobile = _data.returnData.data.userMobile;
                    window.localStorage.setItem('loginName',  ClassDataProxy.loginName);
                    window.localStorage.setItem('monicker',  ClassDataProxy.monicker);
                    window.localStorage.setItem('userEmail',  ClassDataProxy.userEmail);
                    window.localStorage.setItem('userMobile',  ClassDataProxy.userMobile);

                }else if(_data.code == 400){
                    ErrorApe.showWarnError('账号未修改');
                }else{
                    ErrorApe.showWarnError(_data.returnData.data.msg);
                }
            },
            error:function(error){
                //  alert('老师界面获取数据失败')
                loger.log(error,'修改信息失败')
            }
        })
    }
    clearLocalStorage(){
        window.localStorage.clear();
        ClassDataProxy.userType = ClassDataProxy.USER_TYPE_0;
        ClassDataProxy.loginName ="";
        ClassDataProxy.password =""
        ClassDataProxy.token ="";
        ClassDataProxy.status = false;

    }
    //个人信息
    _updatMessage(){
        $('#oneselfInfoLoginName').val( ClassDataProxy.loginName);//登录名
        $('#oneselfInfoUserName').val(ClassDataProxy.monicker);//用户名
    }
    //修改密码
    _accountPassWordBtnHandler(){
        this.data = 0;
        this._showInputBox(this.data);
    }
    //修改邮箱
    _accountEmailBtnHandler(){
        this.data = 1;
        this._showInputBox(this.data);
    }
    //修改手机号
    _accountMobilelBtnHandler(){
        this.data = 2;
        this._showInputBox(this.data);
    }
    _myCenterBoxHandler(){
        if(ClassDataProxy.userType == ClassDataProxy.USER_TYPE_2){
            return;
        }
        if(ClassDataProxy.userType == ClassDataProxy.USER_TYPE_8){
            $('#slideshow').hide();
            $('#defaultBox').hide();
            $('#classifyListBox').hide();
            $('#lanclassBox').hide();
        }
        $('#myCenterBox').show();
    }
    _updateInputYesHandler(evt){
        let updateInput = $('#updateInput').val();
        switch (parseInt(this.data)){
            case 0:
                //密码
                let reg = /^[0-9a-zA-Z]{8,12}$/;
                if(!updateInput || !(reg.test(updateInput))){
                    ErrorApe.showWarnError('密码格式不正确,请重新输入');
                    return;
                }
                $('#setPassWord').attr('data',updateInput);
                this._hideInputBox();
                break;
            case 1:
                //邮箱
                let filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
                if(!updateInput || !(filter.test(updateInput))){
                    ErrorApe.showWarnError('邮箱格式不正确,请重新输入');
                    return;
                }
                $('#setMail').attr('data',updateInput);
                $('#setMail').html(this.updateEmail(updateInput))
                this._hideInputBox();
                break;
            case 2:
                //手机号
                let reg1 = /^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0,5-9]))\\d{8}$/;
                let regPhone = "^1[3|4|5|8][0-9]\\d{8}$";
                let re = new RegExp(regPhone);
                if(!updateInput || !(re.test(updateInput))){
                    ErrorApe.showWarnError('手机格式不正确,请重新输入');
                    return;
                }
                $('#setPhone').attr('data',updateInput);
                $('#setPhone').html(this.updateMobile(updateInput))
                this._hideInputBox();
                break;
            default:
                return;
        }

    }
    _hideInputBox(){
        $('#updateInput').val('');
        $('#updateInputShade').hide();
    }
    _showInputBox(ind){
        let arr = ['请输入新密码 :','请输入新邮箱 :','请输入新手机号 :']
        $('#updateInputShade').show();
        $('#updateInputText').text(arr[ind])
    }
    updateEmail(userEmail){
        return userEmail.replace(/(\d{2})\d{2}(\d{1})/, '$1****$2')
    }
    updateMobile(userMobile){
        return userMobile.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')
    }
    //工具类
    _format(str, obj) {
        return str.replace(/\{(\w+)\}/g, function (match, group, index) {
            return obj[group];
        });
    };
}
export default MyCenterApe;