/*
*	2020.5.4  
*	对报名提交方法进行改进,此报名文件以后不能在这里添加其它的方法函数,
*	如需要添加时,在调时进行添加即可,添加调用的格式请参考  ShowDoc  在线文档内有标明调用的方法格式
*/

/*·······································································*/
var PublicAction = {
    /* AjaxSend-----Ajax发送*/
    "AjaxSend" :function(e,fnEnd){
        var _this = this, result;
        var i = e.CORID,_url = '/enrollch/signup',_post = "POST",_async = true;  

        $('.'+ i).on('click',function(){
            var $this = $(this);
			var _getData = _this.getData($this);	
            if(_getData.ControlSwitch){
                $.ajax({type:_post,url:_url,data:_getData,async:_async,dataType:'json',
                    error : function(request) {
						if(fnEnd){
							if(typeof fnEnd === 'object'){fnEnd.error();}
						}else{
							_this.hint('未提交成功!');
						}
                    },
                    success : function(data) {
                        if(data.code == 200){
							if(fnEnd){
								if(typeof fnEnd === 'object'){
									fnEnd.success();
								}else{
									fnEnd();
								}
							}else{
								_this.hint(data.msg);
							}
                        }else if(data.code == 300){
                            _this.hint(data.msg);
                        }
                    }
                });
                event.preventDefault();        
                return false;
            }
        })
    },
	// 获取参数
	"getData" : function($this){
		var _this = this;
		var that = $this.parents('form.submit_area');     
		var data = {};                                      
		data.ControlSwitch = true;							
		that.find('input').each(function () {               
		    var name = $(this).attr('name');                
		    if(typeof name == 'string'){                    
		        var txt = $(this).val();                    
		        var InputName = $(this).attr('name');       
		        txt = _this.FilterHTMLTag(txt);              
		        if(InputName == 'mobile'){
		            if(txt != ""){
		                if(! _this.PhoneVerification(txt)){         
		                    _this.hint('请输入正确的手机号码!');
							data.ControlSwitch = false;	       
		                    return false;
		                }
		            }else {
		                _this.hint('电话号码不能为空!');
		                data.ControlSwitch = false;   
		                return false;
		            }
		        }
		        data[InputName]=txt;
		    }
		})
		return data;
	},
    //过滤代码标签
    "FilterHTMLTag" : function(htmlStr){
        var msg = htmlStr.replace(/<\/?[^>]*>/g, ''); 
        return msg;
    },
    //电话验证
    "PhoneVerification" : function (tel) {
        var pattern = /(13\d|14[57]|15[^4,\D]|17[678]|18\d)\d{8}$|170[059]\d{7}$/,
            str = tel;
        return pattern.test(tel);
    },
    //提示
    "hint":function(txt){
		if($('body .alert-container')){
			$('body .alert-container').remove();      
		}
        var M = {};
        if(M.dialog1){
            return M.dialog1.show();
        }
        M.dialog1 = jqueryAlert({
            'content' : txt,              
            'closeTime' : 2000,
        })
    },


}