$('#newPass').attr('type','text');
$('#newPass2').attr('type','text');

mui.plusReady(function() {
	var token = localStorage.getItem('token');
	var wait = 120;

	function time() {

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

	}

	mui.ajax(hyhUrl('app/users/backPayPass'), { 
		headers: { 
			"HYH-Token": token
		},
		data: {},
		dataType: 'json', //服务器返回json格式数据  
		type: 'post', //HTTP请求类型  
		timeout: 10000, //超时时间设置为10秒;  
		success: function(data) {           //服务器返回响应,根据响应结果,分析是否登录成功;  
			var data = toJson(data);
			if(data.status == 1) {
				data = data.data;
				if(data.userPhone) {
					$('#userPhone').val(data.userPhone);
					$('#userPhone').attr('disabled', 'disabled');
				} else {
					alert('未绑定手机请先绑定手机!');
					mui.openWindow({
						url: 'setting_phone.html',
						id: 'setting_phone.html',
						styles: {
							top: '0px', //新页面顶部位置
							bottom: '0px', //新页面底部位置
							width: '100%', //新页面宽度,默认为100%
							height: '100%' //新页面高度,默认为100%
						},
						extras: {
							//						data_href: data_href
							//					..... //自定义扩展参数,可以用来处理页面间传值
						},
						createNew: false, //是否重复创建同样id的webview,默认为false:不重复创建,直接显示
						show: {
							//					autoShow: true, //页面loaded事件发生后自动显示,默认为true
							//					aniShow: animationType, //页面显示动画,默认为”slide-in-right“;
							//					duration: animationTime, //页面动画持续时间,Android平台默认100毫秒,iOS平台默认200毫秒;
							//					event: 'titleUpdate', //页面显示时机,默认为titleUpdate事件时显示
							//					extras: {} //窗口动画是否使用图片加速
						},
						waiting: {
							autoShow: true, //自动显示等待框,默认为true
							title: '正在加载...', //等待对话框上显示的提示内容
							options: {
								//						width: waiting - dialog - widht, //等待框背景区域宽度,默认根据内容自动计算合适宽度
								//						height: waiting - dialog - height, //等待框背景区域高度,默认根据内容自动计算合适高度
								//						......
							}
						}
					})
				}
			} else {
				alert(data.msg);
			}

		},
		error: function(xhr, type, errorThrown) {           //异常处理;  
			//					alert(type);      
		}  
	}); 
	mui('.row').on('tap', '#mobileCode', function() {
		var that = $(this);

		$(this).attr("disabled", true);
		mui.ajax(hyhUrl('app/users/backpayCode'), { 

			data: {},
			dataType: 'json', //服务器返回json格式数据
			type: 'post', //HTTP请求类型
			timeout: 10000, //超时时间设置为10秒
			success: function(data) {
				var data = toJson(data);
				//服务器返回响应,根据响应结果,分析是否登录成功;
				if(data.status == 1) {
					time();
				} else {
					alert(data.msg)
				}
				that.removeAttr('disabled');
			},

			error: function(xhr, type, errorThrown) {
				//异常处理;
				//							alert(type)
				//						alert(type);      
			}
		}); 
	})
	mui('.down').on('tap', '#true', function() {
		var phoneCode = $('#phoneCode').val();
		var that = $(this);
		if(phoneCode == '') {
			alert('验证码不能为空!');
			return;
		} else if(phoneCode.length < 4) {
			alert('验证码格式不正确!');
			return;
		}

		that.attr('disabled', 'disabled');
		mui.ajax(hyhUrl('app/users/verifybackPay'), { 
			headers: { 
				"HYH-Token": token
			},
			data: {
				phoneCode: phoneCode
			},
			dataType: 'json', //服务器返回json格式数据  
			type: 'post', //HTTP请求类型  
			timeout: 10000, //超时时间设置为10秒;  
			success: function(data) {           //服务器返回响应,根据响应结果,分析是否登录成功;  
				//					console.log(data.data.goodsFavoritesNum)
				//					console.log(data.data.Rows)
				var data = toJson(data);
				if(data.status == 1) {
					$('#con1').css('display', 'none');
					$('#down1').css('display', 'none');
					$('#con2').css('display', 'block');
					$('#down2').css('display', 'block');
				} else {
					alert(data.msg);
				}
				that.removeAttr('disabled')

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

	})
	mui('.down').on('tap', '#true2', function() {
		var newPass = $('#newPass').val();
		var newPass2 = $('#newPass2').val();
		var that = $(this);
		if(newPass == '') {
			alert('支付密码不能为空!');
			return;
		} else if(newPass.length != 6) {
			alert('支付密码为6位!');
			return;
		} else if(newPass != newPass2) {
			alert('两次支付密码不相同!');
			return;
		}

		that.attr('disabled', 'disabled');
		mui.ajax(hyhUrl('app/users/resetbackPay'), { 
			headers: { 
				"HYH-Token": token
			},
			data: {
				newPass: newPass
			},
			dataType: 'json', //服务器返回json格式数据  
			type: 'post', //HTTP请求类型  
			timeout: 10000, //超时时间设置为10秒;  
			success: function(data) {           //服务器返回响应,根据响应结果,分析是否登录成功;  
				//					console.log(data.data.goodsFavoritesNum)
				//					console.log(data.data.Rows)
				var data = toJson(data);
				if(data.status == 1) {
					alert(data.msg);
					mui.back();
				} else {
					alert(data.msg);
				}
				that.removeAttr('disabled')
			},
			error: function(xhr, type, errorThrown) {           //异常处理;  
				//					alert(type);      
			}  
		}); 

	})

})