mui.init({
	beforeback: function() { //获得父页面的webview
		var list = plus.webview.currentWebview().opener(); //触发父页面的自定义事件(refresh),从而进行刷新
		mui.fire(list, 'refresh');
		//返回true,继续页面关闭逻辑
		return true;
	}
});

mui.plusReady(function() {
	var wait = 120;
	// 	var html =
	// 		'<div class="row"><img src="../img/icon_pwd1.png" /><span class="s1">验证码:</span><input class="tpyzm" type="text" maxlength="4" placeholder="请输入图片验证码" /><img class="yzmhh" src = "'+ hyhUrl('mobile/users/getverify?rnd='+Math.random())+'"/></input></div>';
	// 
	// 	$('.con').append(html);
	// 判断用户名是否存在
	$('#loginName').on('blur', function() {
		var loginName = $('#loginName').val();
		if ('' == loginName) {
			mui.mui.alert('用户名不能为空')
			return;
		}
		if (6 > loginName.length) {
			mui.alert('用户名不能小于6个字符')
			return;
		}
		JZL.ajax(qlgUrl('app/users/check_login_name'), {
			loginName: loginName
		}, function(data) {
			// //console.log(data);
			if (1 != data.status) {
				mui.alert(data.msg)
			}
		})
	})
	// 推荐人信息
	$('.pNameCode').hide();

	var PName = "";
	$('#pName').on('blur', function() {
		pName = $('#pName').val();
		if ('' != pName) {
			
			if (!(
					/^134[0-8]\d{7}$|^13[^4]\d{8}$|^14[5-9]\d{8}$|^15[^4]\d{8}$|^16[6]\d{8}$|^17[0-8]\d{8}$|^18[\d]{9}$|^19[8,9]\d{8}$/
					.test(pName))) {
				mui.alert("手机号码有误，请重填!");
				return;
			}
			$('.pNameCode').show();
			mui('.row').on('tap', '#getMobileCode', function() {
				var that=$(this)
				that.attr("disabled", true);
				JZL.ajax(qlgUrl('app/users/getPhoneVerifyCode'), {
					userPhone: pName
				}, function(data) {
					if (1 == data.status) {
						time()
					} else {
						mui.alert(data.msg);
					}
				that.removeAttr('disabled');

				})
			})



		} else {
			$('.pNameCode').hide();
		}

	})

	function time() {
		if (wait == 0) {
			$('#getMobileCode').removeAttr("disabled");
			$('#getMobileCode').val("重新发送");
			wait = 120;
		} else {
			$('#getMobileCode').attr("disabled", true);
			$('#getMobileCode').val("重新发送(" + wait + ")");
			wait--;
			setTimeout(function() {
					time()
				},
				1000)
		}
	}

	//注册协议
	mui.ajax(qlgUrl('app/Tags/articleDetail'), {
		data: {
			articleId: 114
		},
		dataType: 'json', //服务器返回json格式数据
		type: 'post', //HTTP请求类型
		timeout: 10000, //超时时间设置为10秒；
		success: function(data) {
			//console.log(data);
			// if(data.status==1){
			// //console.log(1);

			$('.zcxycontent').html(data.articleContent)
			// }
		},
		error: function(xhr, type, errorThrown) {

		}
	});
	//上传图片
	$(".photos").on("tap", '.regConfirm', function() {
		// UP.init("accountBookImg", "test", "accountBookImgTag")

		UP.init("regConfirmImg", "test", "regConfirm")
		openCamera()
	})


	mui('.down').on('tap', '.btn', function() {
		var loginName = $('#loginName').val();
		// var mobileCode = $('.yzm').val();
		var loginPwd = $('#loginPwd').val();
		var reUserPwd = $('#reUserPwd').val();
		var mobileCode = $('#mobileCode').val() ? $('#mobileCode').val() : ""; //推荐人验证码
		var payPwd = $('#loginPaywd').val();
		var reUserPaywd = $('#reUserPaywd').val();
		var pName = $('#pName').val();

		// var verifyCode = $('.tpyzm').val();
		var regConfirmImg = $('#regConfirmImg').val();
		if (loginName == '') {
			mui.alert('用户名不能为空！');
			return;
		}
		if (loginPwd.length < 6) {
			mui.alert('登录密码不能小于6位！');
			return;
		}
		if (!(loginPwd == reUserPwd)) {
			mui.alert('两次登录密码不一致！');
			return;
		}
		if (payPwd.length < 6) {
			mui.alert('操作密码不能小于6位！');
			return;
		}
		if (payPwd != reUserPaywd) {
			mui.alert('两次操作密码不一致！');
			return;
		}
		if (regConfirmImg == '') {
			mui.alert('请上传确认书照片');
			return;
		}
		if (pName != '') {
			if ('' == mobileCode) {
				mui.alert('请输入推荐人验证码');
				return;
			}
		}
		var ajaxData={
				loginName: loginName,
				// mobileCode: mobileCode,
				loginPwd: loginPwd,
				payPwd: payPwd,
				 pName: pName,
				// nameType: 3,
				regConfirmImg: regConfirmImg,
				 mobileCode: mobileCode
			};
		
		var that =	$(this)
		that.attr("disabled", true);
		
		mui.ajax(qlgUrl('app/users/register'), {
			data:ajaxData,
			dataType: 'json', //服务器返回json格式数据
			type: 'post', //HTTP请求类型
			timeout: 10000, //超时时间设置为10秒
			success: function(data) {
				//服务器返回响应，根据响应结果，分析是否登录成功;
				mui.alert(data.msg);

				if (data.status == 1) {
					mui.back();
				} else {
					// $('.yzmhh').attr('src', hyhUrl('mobile/users/getverify?rnd=' + Math.random()));
				}
				that.removeAttr('disabled');
			},

			error: function(xhr, type, errorThrown) {
				//异常处理;
				//						mui.alert(type);      
			}
		});

	})

})
