/**********************************************
 * @Object      注册登录
 * @Authors     Foxs
 * @Link        http://www.yehuli.vip
***********************************************/
var loadfile = ['common'];
    base.autoloadJs('','main/login_',loadfile);
var login = {
	/**
     * 注册登录：电话登录
     * @param  string 	respondUrl 	请求地址
     * @param  string 	redirect 	跳转方式
     * @return Json result
     */
	tellogin:function(respondUrl,redirect=""){
		var postdata = login_common.getPostData();
		$.post(respondUrl,postdata,function(result){
			if(result.code == 1){
				if(redirect == "reload"){
    				location.reload();
				}else{
					location.href=result.url;
				}
			}else{
				$('.login-form .captcha img').attr('src',result.url+'?tm='+Math.random())
				dialog.error(result.msg);
			}
		},'json')
	},
	/**
     * 注册登录：获取手机验证码
     * @param  string 	style 		验证方式
     * @param  string 	respondUrl 	请求地址
     * @return Json result
     */
	getVerify:function(style,respondUrl){
		var tel = $('#'+style+' input[name=tel]').val().replace(/\s*/g,"");
		if(tel == ''){
			dialog.error('电话不能为空');
			return false;
		}
		var data = {tel:tel}
		$.post(respondUrl,data,function(result){
			if(result.code == 1){
				if(result.data.Code == 'OK'){
					dialog.msg('请查收短信');
					var efftime = $('#'+style+' #getVerify').attr('data-efftime');
					timer = setInterval(function(){
						efftime -= 1;
						if(efftime <= 0){
							clearInterval(timer);
							$('#'+style+' #getVerify').css({'background':'#ff2d55'})
							$('#'+style+' #getVerify').text('发送验证码');
							$('#'+style+' #getVerify').removeAttr('disabled');
						}else{
							$('#'+style+' #getVerify').css({'background':'#aaa'})
							$('#'+style+' #getVerify').attr('disabled','disabled');
							$('#'+style+' #getVerify').text(efftime+'秒后重发');
						}
					}, 1000);
				}else if(result.data.Code == 'isv.BUSINESS_LIMIT_CONTROL'){
					dialog.error('亲！您操作太频繁了，稍后再试');
				}else{
					dialog.error('位置错误,稍后再试');
				}
			}else{
				dialog.error(result.msg)
			}
		},'json')
	},
	/**
     * 注册登录：验证是否登录
     * @param  string 	respondUrl 	请求地址
     * @param  string 	url 		跳转地址
     */
	islogin:function(respondUrl,url=''){
	    $.post(respondUrl,{},function(result){
	        if(result.code == 1){
	            window.open(url)
	        }else{
	            dialog.loginConfirm(result.msg,result.url)
	        }
	    })
	},
	/**
     * 注册登录：退出登录
     * @param  string 	respondUrl 	请求地址
     */
	signout:function(respondUrl){
	    $.post(respondUrl,{},function(result){
	        if(result.code == 1){
	            location.reload();
	        }else{
	            dialog.error(result.msg)
	        }
	    })
	}
}