$('.mui-scroll').css('background', 'url(http://img.juzi199.com/static/app2/img/user_center.png) no-repeat center top');
$('.mui-scroll').css('background-size', '100%');

mui.plusReady(function() {
	window.addEventListener('reload', function(e) { //执行刷新
		location.reload();
	});
	var token = localStorage.getItem('token');
	var authType = 0; //0 未认证 1 个人认证  2 合作认证
	var userId = 0;
	var authTypeText = "";
	var authTypeStatus = "";
	var reasonsForRefusal = "";
	// $('.nblock').on('tap',function () {
	// 	
	// })
var localAuthType = localStorage.getItem("authType");

	// if (token) {
	// console.log(token);

	JZL.ajax(qlgUrl('app/users/getIndex'), {}, function(data) {
		// console.log(data); //服务器返回响应,根据响应结果,分析是否登录成功;  
		var data = toJson(data, 1);
		if (data.status == 1) {
			userId = parseInt(data.data.user.userId);
			authType = parseInt(data.data.user.authType);
			localStorage.setItem("userId", userId);
			localStorage.setItem("userName", data.data.user.userName)
			var imgurl = data.data.user.userPhoto ? hyhImgUrl(data.data.user.userPhoto) : '../img/mujiimg.png';
			if(1 == localAuthType){
				//本地申请亲人认证
				JZL.ajax(qlgUrl('app/auth/getAuthInfo'), {}, function(result) {
									authTypeText = "个人认证"
									if (0 == result.data.status) {
										authTypeStatus = "待审核"
									} else if (1 == result.data.status) {
										authTypeStatus = "已通过"
										localStorage.setItem("authType","0")
									} else if (2 == result.data.status) {
										$('.mydata').on('tap', '.cooperative', function() {
											JZL.openWindow('cooperative.html', 'cooperative.html')
										})
										$('.mydata').on('tap', '.individual', function() {
											JZL.openWindow('individual.html', 'individual.html')
										})
										
										authTypeStatus = "已拒绝";
										reasonsForRefusal = result.data.reasonsForRefusal;
										var html1 = '<img src="' + imgurl + '" /><div class="left"><p>' + data.data.user.loginName +
											'</p><p><span>' + authTypeText +
											'</span><span>' + authTypeStatus +
											'</span></p><p><span>' + reasonsForRefusal +
											'</span></p></div>';
											$('.con1').html(html1);
									}
				
								})
			}else if(2 == localAuthType){
				//本地申请合作认证
				JZL.ajax(qlgUrl('app/auth/getAuthInfo'), {
									isCompany: 1
								}, function(res) {
									console.log(res);
									authTypeText = "合作认证"
									if (0 == res.data.status) {
										authTypeStatus = "待审核"
									} else if (1 == res.data.status) {
										authTypeStatus = "已通过"
										localStorage.setItem("authType","0")
									
									} else if (2 == res.data.status) {										
										$('.mydata').on('tap', '.cooperative', function() {
											JZL.openWindow('cooperative.html', 'cooperative.html')
										})
										$('.mydata').on('tap', '.individual', function() {
											JZL.openWindow('individual.html', 'individual.html')
										})
										authTypeStatus = "已拒绝";
										reasonsForRefusal = res.data.reasonsForRefusal;
										var html1 = '<img src="' + imgurl + '" /><div class="left"><p>' + data.data.user.loginName +
											'</p><p><span>' + authTypeText +
											'</span><span>' + authTypeStatus +
											'</span></p><p><span>' + reasonsForRefusal +
											'</span></p></div>';
											$('.con1').html(html1);
									}
				
								})
			}else{
				if(1 == authType){
					//个体认证
					authTypeText = "个人认证"
					authTypeStatus = "已通过"
					$('.cooperative img').attr('src', "../img/trade1.png")
					$('.mydata').on('tap', '.cooperative', function() {
						mui.alert('已认证 无需再次认证')
					})
					$('.mydata').on('tap', '.individual', function() {
						JZL.openWindow('individual.html', 'individual.html')
					})
					
				}else if(2 == authType){
					//合作认证
					authTypeText = "合作认证"
					authTypeStatus = "已通过"
					$('.individual img').attr('src', "../img/renzheng1.png")
					$('.mydata').on('tap', '.individual', function() {
						mui.alert('已认证 无需再次认证')
					})
					$('.mydata').on('tap', '.cooperative', function() {
						JZL.openWindow('cooperative.html', 'cooperative.html')
					})
				}else{
					//未申请认证
					if (userId > 0) {
						authTypeText = "未认证 请认证"
						$('.mydata').on('tap', '.cooperative', function() {
							JZL.openWindow('cooperative.html', 'cooperative.html')
						})
						$('.mydata').on('tap', '.individual', function() {
							JZL.openWindow('individual.html', 'individual.html')
						})
					}
				}
			}
// 	if (2 == authType) {
// 				JZL.ajax(qlgUrl('app/auth/getAuthInfo'), {
// 					isCompany: 1
// 				}, function(res) {
// 					console.log(res);
// 					authTypeText = "合作认证"
// 					if (0 == res.data.status) {
// 						authTypeStatus = "待审核"
// 					} else if (1 == res.data.status) {
// 						authTypeStatus = "已通过"
// 					
// 					} else if (2 == res.data.status) {
// 						authTypeStatus = "已拒绝";
// 						reasonsForRefusal = res.data.reasonsForRefusal;
// 					}
// 
// 				})
// 			} else if (1 == authType) {
// 				JZL.ajax(qlgUrl('app/auth/getAuthInfo'), {}, function(result) {
// 					console.log(result);
// 					authTypeText = "个人认证"
// 					if (0 == result.data.status) {
// 						authTypeStatus = "待审核"
// 					} else if (1 == result.data.status) {
// 						authTypeStatus = "已通过"
// 						
// 					} else if (2 == result.data.status) {
// 						authTypeStatus = "已拒绝";
// 						reasonsForRefusal = result.data.reasonsForRefusal;
// 					}
// 
// 				})
// 			}
		 // setTimeout(function () {
		 	var html1 = '<img src="' + imgurl + '" /><div class="left"><p>' + data.data.user.loginName +
		 		'</p><p><span>' + authTypeText +
		 		'</span><span>' + authTypeStatus +
		 		'</span></p><p><span>' + reasonsForRefusal +
		 		'</span></p></div>';
				$('.con1').html(html1);
		 // },200)			
			$('.header').html("");
			// $('.header').html(html);
			$('.con .login').css('display', 'none')
			
			$('.nav').css('display', 'none')
			$('.myYouhuiquan_con').addClass("myYouhuiquan_con1")
			$('.myYouhuiquan').removeClass("shadown_wai")
			$('#expectedProductNum').html(+data.data.expectedProductNum);
			$('#expectedCouponsNum').html(+data.data.expectedCouponsNum);
			$('#expectedWangNum').html(+data.data.expectedWangNum);
			$('#couponsNum').html(+data.data.user.couponsNum);
			$('#productNum').html(+data.data.user.productNum);
			$('#wangNum').html(+data.data.user.wangNum);

			mui.ajax(qlgUrl('app/users/getFavoritesNum'), {
				headers: {
					"HYH-Token": token
				},
				data: {},
				dataType: 'json', //服务器返回json格式数据  
				type: 'post', //HTTP请求类型  
				timeout: 10000, //超时时间设置为10秒;  
				success: function(data) { //服务器返回响应,根据响应结果,分析是否登录成功;  
					//					//console.log(data.data.goodsFavoritesNum)
					var data = toJson(data, 1);
					if (data.status == 1) {
						//				//console.log(data.data.goodsFavoritesNum)
						var html = '<div class="nblock" data-href="collect_commodity.html"><p>' + data.data.goodsFavoritesNum +
							'</p><p>收藏夹</p></div><div class="nblock" data-href="collect_store.html"><p>' + data.data.shopFavoritesNum +
							'</p><p>关注店铺</p></div><div class="nblock" data-href="share_user_list.html"><p>' + data.data.shareNum +
							'</p><p>我的分享</p></div>';
						$('.nav').html(html);
					} else {
						mui.alert(data.msg)
					}
				},
				error: function(xhr, type, errorThrown) { //异常处理;  
					//					mui.alert(type);      
				}
			});
			// 订单个数
			mui.ajax(qlgUrl('app/users/getOrderNum'), {
				headers: {
					"HYH-Token": token
				},
				data: {},
				dataType: 'json', //服务器返回json格式数据  
				type: 'post', //HTTP请求类型  
				timeout: 10000, //超时时间设置为10秒;  
				success: function(data) { //服务器返回响应,根据响应结果,分析是否登录成功;  
					// console.log(data);
					//					//console.log(data.data.goodsFavoritesNum)
					var data = toJson(data, 1);
					if (data.status == 1) {

						var html = '<div class="order_cb indent_btn" data-href="waitPay"><div class="num">' + data.data.order.waitPay +
							'</div><div class="orderimg"><img src="../img/daifukuan.png" /></div><p>待付款</p></div><div class="order_cb indent_btn" data-href="waitDeliver"><div class="num">' +
							data.data.order.waitSend +
							'</div><div class="orderimg"><img src="../img/daifahuo.png" /></div><p>待发货</p></div><div class="order_cb indent_btn" data-href="waitReceive"><div class="num">' +
							data.data.order.waitReceive +
							'</div><div class="orderimg"><img src="../img/daishouhuo.png" /></div><p>待收货</p></div><div class="order_cb indent_btn" data-href="waitAppraise"><div class="num">' +
							data.data.order.waitAppraise +
							'</div><div class="orderimg"><img src="../img/pingjia.png" /></div><p>待评价</p></div><div class="order_cb indent_btn" data-href="abnormal"><div class="num">' +
							data.data.order.cancelNum +
							'</div><div class="orderimg"><img src="../img/orderdetail.png" /></div><p>退款/售后</p></div>';
						$('.order .order_con').html(html);
						$('.num').each(function() {
							if ($(this).html() == '0') {
								$(this).css('display', 'none');
							}
						})
					} else {
						mui.alert(data.msg)
					}
				},
				error: function(xhr, type, errorThrown) { //异常处理;  
					//					mui.alert(type);      
				}
			});

			$('.mydata-content').on('tap', '.friends', function() {
				if ("undefined" != typeof(cooperativeData) && "undefined" != typeof(individualData)) {
					mui.alert('请先进行认证')
					return;
				} else {
					JZL.openWindow('friends.html', 'friends.html')
				}

			})

			$('.mydata-content').on('tap', '.applicationopen', function() {
				if (authType > 0) {
					JZL.openWindow('applicationopen.html', 'applicationopen.html')
				} else {
					mui.alert('请先进行认证')
				}

			})
			$('.mydata-content').on('tap', '.myshops', function() {
				if (authType > 0) {
					JZL.openWindow('myshops.html', 'myshops.html')
				} else {
					mui.alert('请先进行认证')
				}

			})
			$('.mydata-content').on('tap', '.setting', function() {
				JZL.openWindow('setting.html', 'setting.html')
			})
			$('.mydata-content').on('tap', '.shoppingcart', function() {
				JZL.openWindow('shoppingcart_warp.html', 'shoppingcart_warp.html')
			})
			$('.mydata-content').on('tap', '.shangdu', function() {
				if (authType == 2) {
					JZL.openWindow('shangdu.html', 'shangdu.html')
				} else if (authType == 0) {
					mui.alert('请先进行认证')
				} else if (authType == 1) {
					mui.alert('只有合作认证才可以申请商都')
				}
			})
			$('.mydata-content').on('tap', '.supermarket', function() {
				if (2 == authType) {
					JZL.openWindow('supermarket.html', 'supermarket.html')
				} else if (0 == authType) {
					mui.alert('请先进行认证')
				} else if (1 == authType) {
					mui.alert('只有合作认证才可以申请商超')
				}
			})
			$('.mydata-content').on('tap', '.commercial', function() {
				if (2 == authType) {
					JZL.openWindow('commercial.html', 'commercial.html')
				} else if (0 == authType) {
					mui.alert('请先进行认证')
				} else if (1 == authType) {
					mui.alert('只有合作认证才可以申请商厦')
				}
			})
			$('.mydata-content').on('tap', '.help_sale', function() {
				JZL.openWindow('my_help_sale.html', 'my_help_sale.html')
			})
// 			setTimeout(function() {
// 				//console.log(authType);
// 				if (2 == authType) { // 合作认证
// 					$('.individual img').attr('src', "../img/renzheng1.png")
// 					$('.mydata').on('tap', '.individual', function() {
// 						mui.alert('已认证 无需再次认证')
// 					})
// 					$('.mydata').on('tap', '.cooperative', function() {
// 						JZL.openWindow('cooperative.html', 'cooperative.html')
// 					})
// 				} else if (1 == authType) { // 个体认证
// 					$('.cooperative img').attr('src', "../img/trade1.png")
// 					$('.mydata').on('tap', '.cooperative', function() {
// 						mui.alert('已认证 无需再次认证')
// 					})
// 					$('.mydata').on('tap', '.individual', function() {
// 						JZL.openWindow('individual.html', 'individual.html')
// 					})
// 				} else if (userId > 0) {
// 					$('.mydata').on('tap', '.cooperative', function() {
// 						JZL.openWindow('cooperative.html', 'cooperative.html')
// 					})
// 					$('.mydata').on('tap', '.individual', function() {
// 						JZL.openWindow('individual.html', 'individual.html')
// 					})
// 				}
// 
// 			}, 500)


		} else {
			// mui.alert(data.msg)
			//console.log(data.status)
		}

	})

	// 	} else {
	// 		// $('.con').attr('display','block')
	// 
	// 		// JZL.openWindow('login.html', 'login.html');
	// 	}

	$('.mydata-content').on('tap', '.zhuweiba', function() { //助威吧
		// JZL.openWindow('essay.html', 'essay.html')
		mui.alert("功能开发中......")

	})
	let CoUnTeR = 0
	$('.mydata-content').on('tap', '.essaylist', function() { //烂笔头
		// JZL.openWindow('essaylist.html', 'essaylist.html')
		if(CoUnTeR < 5){
			CoUnTeR ++;
			mui.alert("功能开发中......")
		}else{
			JZL.openWindow('notepad.html', 'notepad.html')
			CoUnTeR = 0;
		}

	})

	$('.mydata-content').on('tap', '.touzi', function() { //投资
		 // JZL.openWindow('invest.html', 'invest.html')
		// mui.alert("功能开发中......")

	})
	$('.mydata-content').on('tap', '.shenqingweiba', function() { //申请微吧
		// JZL.openWindow('essay.html', 'essay.html')
		mui.alert("功能开发中......")

	})
	$('.moneycon').on('tap', '.moneycon_', function() {

		if ($(this).children('p').attr('id') == 'userECT') {
			mui.openWindow({
				url: 'ect_index.html',
				id: 'ect_index.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, //等待框背景区域高度,默认根据内容自动计算合适高度
						//						......
					}
				}
			})
		}

	})
	// 跳转到券值
	$('.myYouhuiquan').on('tap', '.indent_btn', function() { //预获 已获优惠券
		var data_href = $(this).attr('data-href')
		var data_type = $(this).attr('data-type')
		var data_expect = $(this).attr('data-expect')
		// var data_href = this.attributes["data-href"].nodeValue;
		//console.log(data_href);
		JZL.openWindow("vouchers.html", "vouchers.html", {
			data_href: data_href,
			data_type: data_type,
			data_expect: data_expect
		})

	})
	//跳转到劵包
	$('.moneycon').on('tap', '.moneycon_', function() {
		if ($(this).children('p').attr('id') == 'userJuan') {
			mui.openWindow({
				url: 'juan_index.html',
				id: 'juan_index.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, //等待框背景区域高度,默认根据内容自动计算合适高度
						//						......
					}
				}
			})
		}

	})

	$('.mydata-content').on('tap', '.userPaymentvoucher', function() { //首页付款凭证
		// JZL.openWindow('paymentvoucher.html', 'paymentvoucher.html')
		mui.alert("功能开发中......")

	})
	//订单按钮
	mui('.order').on('tap', '.indent_btn', function() {
		var data_href = this.attributes["data-href"].nodeValue;
		//							//console.log(this.attributes["data-id"].nodeValue);
		mui.openWindow({
			url: 'indent.html',
			id: data_href,
			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, //等待框背景区域高度,默认根据内容自动计算合适高度
					//						......
				}
			}
		})
	})
	mui('.my').on('tap', '.share', function() {
		mui.openWindow({
			url: 'share.html',
			id: 'share.html',
			styles: {
				top: '0px', //新页面顶部位置
				bottom: '0px', //新页面底部位置
				width: '100%', //新页面宽度,默认为100%
				height: '100%' //新页面高度,默认为100%
			},
			extras: {
				//										data_userId: 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, //等待框背景区域高度,默认根据内容自动计算合适高度
					//						......
				}
			}
		})
	})

	mui(".nav").on('tap', '.nblock', function() {
		//			var tj = plus.webview.create('search.html');
		//			tj.show();
		//			mui.alert(e.target.attributes["data-id"].nodeValue);
		// 		var data_href = this.attributes["data-href"].nodeValue;
		// 		var url = 'collect.html';
		// 		if (data_href == 'share_user_list.html') {
		// 			url = 'share_user_list.html';
		// 		}
		// 		//							//console.log(this.attributes["data-id"].nodeValue);
		// 		mui.openWindow({
		// 			url: url,
		// 			id: url,
		// 			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, //等待框背景区域高度,默认根据内容自动计算合适高度
		// 					//						......
		// 				}
		// 			}
		// 		})
	})


	window.addEventListener('refresh', function(e) { //执行刷新
		location.reload();
	});

	// 
	mui('.my').on('tap', '.seeting', function() {
		JZL.openWindow('setting.html', 'setting.html')
	})

	// 登录
	$('.my').on('tap', '.login', function() {
		mui.openWindow({
			url: 'login.html',
			id: 'login.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, //等待框背景区域高度,默认根据内容自动计算合适高度
					//						......
				}
			}
		})
	})



})