CreateUserApe.js 23.4 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642
//*
// 用户管理模块
// */

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

let loger = Loger.getLoger('PC-CreateUserApe');
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="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">{_latest}</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>`;
class CreateUserApe extends Ape {
    constructor() {
        super();
        this.pageNo = 0;
        this.presentInd = 1;
        this.addEvent();
        this.init();
    }

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

        //用户管理
        $('#addUserBtn').on('click',this._addUserBtnHandler.bind(this));//创建用户按钮
        $('#createUserYes').on('click',this._createUserYesHandler.bind(this));//进入创建用户界面
        $('#createUserConfirm').on('click',this._createUserConfirmHandler.bind(this));//创建用户按钮
        $('#createUserA').on('click',this._closeUserClassHandler.bind(this));//关闭创建课堂
        $('#createUserCancel').on('click',this._closeUserClassHandler.bind(this));//关闭创建课堂

        $('#classHandlerHomePage3_0').on('click',this._homePageHandler.bind(this));//首页
        $('#classHandlerUpPage3_0').on('click',this._upPageHandler.bind(this));//上页
        $('#classHandlerDownPage3_0').on('click',this._downPageHandler.bind(this));//下页
        $('#classHandlerEndPage3_0').on('click',this._endPageHandler.bind(this));//尾页
        $('#classHandlerSpecificPage3_0').on('click',this._assignPageHandler.bind(this));//指定页

        $('#classHandlerHomePage3_1').on('click',this._homePageHandler.bind(this));//首页
        $('#classHandlerUpPage3_1').on('click',this._upPageHandler.bind(this));//上页
        $('#classHandlerDownPage3_1').on('click',this._downPageHandler.bind(this));//下页
        $('#classHandlerEndPage3_1').on('click',this._endPageHandler.bind(this));//尾页
        $('#classHandlerSpecificPage3_1').on('click',this._assignPageHandler.bind(this));//指定页

        $('#classHandlerHomePage3_2').on('click',this._homePageHandler.bind(this));//首页
        $('#classHandlerUpPage3_2').on('click',this._upPageHandler.bind(this));//上页
        $('#classHandlerDownPage3_2').on('click',this._downPageHandler.bind(this));//下页
        $('#classHandlerEndPage3_2').on('click',this._endPageHandler.bind(this));//尾页
        $('#classHandlerSpecificPage3_2').on('click',this._assignPageHandler.bind(this));//指定页

        $('#courseContent3').on('click','.deleteClass',this._deleteClass.bind(this));//删除课堂

    }

    addEvent() {

    }

    _switchover(evt){
        $(evt.currentTarget).addClass('liveInfoLeftLiCheck').siblings().removeClass('liveInfoLeftLiCheck');
    }
    _userClassListHandler(evt){
        this._switchover(evt);
        this.manageUserList();
    }
    //首页
    _homePageHandler(){
        this.presentInd = 1;
        let ind = $('#classHandlerPageBox3').attr('data');
        switch (parseInt(ind)){
            case 1:
                this._manageTeacher(this.presentInd);
                break;
            case 8:
                this._manageStudent(this.presentInd);
                break;
            case 2:
                this._manageSupervise(this.presentInd);
                break;
            default:
                return;
        }
    }
    //上页
    _upPageHandler(){
        if(this.presentInd > 1){
            this.presentInd--;
            let ind = $('#classHandlerPageBox3').attr('data');
            switch (parseInt(ind)){
                case 1:
                    this._manageTeacher(this.presentInd);
                    break;
                case 8:
                    this._manageStudent(this.presentInd);
                    break;
                case 2:
                    this._manageSupervise(this.presentInd);
                    break;
                default:
                    return;
            }
        }
    }
    //下页
    _downPageHandler(){
        if(this.presentInd < this.pageNo){
            this.presentInd++;
            let ind = $('#classHandlerPageBox3').attr('data');
            switch (parseInt(ind)){
                case 1:
                    this._manageTeacher(this.presentInd);
                    break;
                case 8:
                    this._manageStudent(this.presentInd);
                    break;
                case 2:
                    this._manageSupervise(this.presentInd);
                    break;
                default:
                    return;
            }
        }
    }
    //尾页
    _endPageHandler(){
        this.presentInd = this.pageNo;
        let ind = $('#classHandlerPageBox3').attr('data');
        switch (parseInt(ind)){
            case 1:
                this._manageTeacher(this.presentInd);
                break;
            case 8:
                this._manageStudent(this.presentInd);
                break;
            case 2:
                this._manageSupervise(this.presentInd);
                break;
            default:
                return;
        }
    }
    //指定页
    _assignPageHandler(){
        let val;
        let ind = $('#classHandlerPageBox3').attr('data');
        let card = $('#userClassList3 .liveInfoLeftLiCheck').index();
        let inputVal = $('#classHandlerPageInfoInput3_'+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 1:
                this._manageTeacher(val);
                break;
            case 8:
                this._manageStudent(val);
                break;
            case 2:
                this._manageSupervise(val);
                break;
            default:
                return;
        }

        $('#classHandlerPageInfoInput3_'+card).val('')
    }
    //公用ajax请求
    publicAjax(data,num,ind,callback){
        let _url = ClassDataProxy.locationProtocol + ClassDataProxy.locationProt + '/users/getUser';
        let that = this;
        $.ajax({
            type: "POST",
            url: _url,
            timeout:5000,
            data : data,
            headers: {siteId:ClassDataProxy.siteId,pageno:num, page:ind,
                'token':ClassDataProxy.token},
            success:function(_data){
                if(_data && _data.code == 200){
                    if(callback){
                        callback(_data);
                    }
                }else{
                    if(callback){
                        callback(null);
                    }
                }
            },
            error:function(error){
                if(callback){
                    callback(null);
                }
                loger.log(error,'管理员用户获取失败')
            }
        })
    }
    //用户管理 列表
    manageUserList(){
        let ind = $('#userClassList3 .liveInfoLeftLiCheck').attr('data');
        let card = $('#userClassList3 .liveInfoLeftLiCheck').index();
        $('#classHandlerPageBox3').attr('data',ind)
        let status = parseInt(ind);
        $('#classHandlerPageBox3_'+card).show().siblings().hide();
        this.presentInd = 1;
        switch (status){
            case 1:
                //老师  列表
                this._manageTeacher(1);
                break;
            case 8:
                //学生  列表
                this._manageStudent(1);
                break;
            case 2:
                //兼课  列表
                this._manageSupervise(1);
                break;
            default:
                return;
        }
    }
    //老师 列表
    _manageTeacher(ind){
        let data = {siteId:ClassDataProxy.siteId,userType:1};
        let that = this;
        this.publicAjax(data,7,ind,function(_data){
            if(_data){
                that._teacherPage(_data.returnData.data);
                that._userCourse(_data.returnData.data);
            }
        })
    }
    //学生  列表
    _manageStudent(ind){
        let data = {siteId:ClassDataProxy.siteId,userType:8};
        let that = this;
        this.publicAjax(data,7,ind,function(_data){
            if(_data){
                that._studentPage(_data.returnData.data);
                that._userCourse(_data.returnData.data);
            }
        })
    }
    //兼课  列表
    _manageSupervise(ind){
        let data = {siteId:ClassDataProxy.siteId,userType:2};
        let that = this;
        this.publicAjax(data,7,ind,function(_data){
            if(_data){
                that._supervisePage(_data.returnData.data);
                that._userCourse(_data.returnData.data);
            }
        })
    }
    _userCourse(_data){
        let _dataList = _data.users;
        let courseContent = $('#courseContent3');
        courseContent.empty();
        courseContent.append(adminListTit);
        if(_dataList.length > 0){
            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);
        }else{
            this._gainUserClassDataErr();
        }
    }
    _gainUserClassDataErr(){
        let courseContent = $('#courseContent3');
        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);
    }
    _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;
            console.log('sssssssss',count)
            $('#classHandlerPageMsg3_0').html('第'+page+'页/共'+pagenum+'页,有'+count+'个记录');
            if(count <=7){
                $('#classHandlerPageBox3_0').hide();
            }

        }
    }
    _studentPage(_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;
            console.log('sssssssss',count)
            $('#classHandlerPageMsg3_1').html('第'+page+'页/共'+pagenum+'页,有'+count+'个记录');
            if(count <=7){
                $('#classHandlerPageBox3_1').hide();
            }
        }
    }
    _supervisePage(_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;
            console.log('sssssssss',count)
            $('#classHandlerPageMsg3_2').html('第'+page+'页/共'+pagenum+'页,有'+count+'个记录');
            if(count <=7){
                $('#classHandlerPageBox3_2').hide();
            }
        }
    }

    //用户管理 创建用户界面
    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('直播数据获取失败')
                that._gainUserClassDataErr();
                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);
        }
    }
    _gainUserClassDataErr(){
        let courseContent = $('#courseContent3');
        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);

    }
    //用户管理
    _addUserBtnHandler(){
        ClassDataProxy.getMarginTopHandler($('#createUserAccount'));//显示预约成功弹框
        $('#createUserAccountBox').show();
    }
    _createUserYesHandler(){
        $('#createUserAccountBox').hide();
        ClassDataProxy.getMarginTopHandler($('#createUser'));//显示预约成功弹框
        $('#createUserBox').show();
        let val = $('#createUserRole').val();
        let name = '';
        switch (parseInt(val)){
            case 0:
                name = '老师';
                break;
            case 1:
                name = '兼课';
                break;
            default:
                return;
        }
        $('#createUserTitle').html('添加'+name)
        $("input[name='createUserTeacher']").get(val).checked = true;//创建身份
    }
    //创建用户
    _createUserConfirmHandler(){
        let _name = document.getElementById("createUserName");//老师名字
        let _passWord = document.getElementById("createUserPassWord");//密码
        let createUserRealName = document.getElementById("createUserRealName");//真实姓名
        let  createCharacter = $("input[name='createUserTeacher']:checked").val();//角色
        let phone = document.getElementById("createUserPhone");//手机号
        let identity = document.getElementById("createUserIdentity");//身份证号
        let mail = document.getElementById("createUserMail");//邮箱

        let createUserRole = $('#createUserRole').val();

        let createUserNote = $('#createUserNote').val();//备注信息
        let createUserAbortTime = $('#createUserAbortTime').html();//有效期

        if(_name.value && createUserRealName.value && phone.value && mail.value){
            let createUserList = {
                "loginName": _name.value, // 登录名
                "password": parseInt(_passWord.value),  //登录密码
                "companyName":null,  //公司名字
                "userName":createUserRealName.value, //用户名
                "userRole":3, // 用户角色 0超级管理员,1管理员,2监课,3老师,4学生
                "userType": parseInt(createUserRole),
                "userEmail":mail.value, // 用户邮箱
                "userMobile":parseInt(phone.value), // 用户手机号
                "content":createUserNote, // 用户简介
                "groupId":1, //用户组id
                "IDcard":123123,
                "time":1,
                "siteId":ClassDataProxy.siteId
            }
            let that = this;
            let _url = ClassDataProxy.locationProtocol + ClassDataProxy.locationProt + '/users/addUser';
            $.ajax({
                type: "POST",
                url: _url,
                data: createUserList,
                timeout:5000,
                headers: {siteId:ClassDataProxy.siteId},
                success:function(_data){
                    //注册成功后 跳转登录界面
                    if(_data && _data.code == 200){
                        loger.log(_data,'注册老师账号成功')
                        ClassDataProxy.getMarginTopHandler($('#warnHintBox'));//修改信息输入框
                        ErrorApe.showWarnError('注册成功');
                        $('#createUserBox').hide();
                        that._manageTeacher(1);
                    }else{
                        ClassDataProxy.getMarginTopHandler($('#warnHintBox'));//修改信息输入框
                        ErrorApe.showWarnError(_data.returnData.data.msg);
                    }
                },
                error:function(error){
                    console.log(error,'失败')
                }
            })
        }else{
            this._signMail(mail);//判断邮箱
            this._signIdentity(identity);
            this._signPhone(phone);//判断手机号
            this._signName(createUserRealName);//判断用户名
            this._signName(_name);//判断登录名
        }
    }

    _deleteClass(evt){
        let id = $(evt.target).attr('data');
        loger.log('删除',id)
        let _url = ClassDataProxy.locationProtocol + ClassDataProxy.locationProt + '/users/delUserByUserId/' + id;
        let that = this;
        $.ajax({
            type: "PUT",
            url: _url,
            headers: {siteId:ClassDataProxy.siteId,
                'token':ClassDataProxy.token},
            success:function(_data){
                loger.log('删除成功',_data)
                if(_data && _data.code == 200){

                //    that.detailPage();
                    // that._gainClassData(_data.returnData.data);
                }
            },
            error:function(error){
                that._gainUserClassDataErr();
                loger.log(error,'用户列表数据获取失败')
            }
        })
    }
    _signName(_name){
        if(!_name.value){
            _name.focus();
            return false;
        }
    }
    _signPhone(phone){
        let reg = "^1[3|4|5|8][0-9]\\d{8}$";
        let re = new RegExp(reg);
        if(!phone.value){
            phone.focus();
            return false;
        }
        if (re.test(phone.value)) {
            $('#createUserPhone').css('color','#000');
        } else {
            $('#createUserPhone').val('手机号输入不合法')
                .css('color','#d95136');
            phone.focus();
            return false;
        }
    }
    _signMail(mail){
        let filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
        if(!mail.value){
            mail.focus();
            return false;
        }
        if (filter.test(mail.value)){
            $('#createUserMail').css('color','#000');
        }
        else {
            $('#createUserMail').val('电子邮箱输入不合法')
                .css('color','#d95136');
            mail.focus();
            return false;
        }
    }
    _signIdentity(identity){
        let reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
        if(!identity.value){
            identity.focus();
            return false;
        }
        if (reg.test(identity.value)){
            $('#createUserIdentity').css('color','#000');
        }
        else {
            $('#createUserIdentity').val('身份证号码输入不合法')
                .css('color','#d95136');
            identity.focus();
            return false;
        }
    }
    _closeUserClassHandler(){
        $('#createUserBox').hide();
        this._clearUserClssMsg();
    }
    _clearUserClssMsg(){
        $('#createUserName').val('');
        $('#createUserPassWord').val('');
        $('#createUserRealName').val('');
        $('#createUserPhone').val('');
        $('#createUserIdentity').val('');
        $('#createUserMail').val('');
        $('#createUserNote').val('');
    }

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