mui.plusReady(function() {
	window.addEventListener('reload', function(e) { //执行刷新
		location.reload();
	});
	var authType = localStorage.getItem('authType')
	var supermarket = '',
		commercial = '',
		shangdu = '';
	var scinfo = '',
		ssinfo = '',
		sdinfo = '';
	var shopName = '';
	var scshopId = '',
		ssshopId = "",
		sdshopId = '';
	var scid = '',
		ssid = '',
		sdid = '';
	$('.nc').hide();
	$('.ic').hide();
	// 获取商超商厦申请记录
	// //console.log(authType);
	JZL.ajax(qlgUrl('app/shops/getUserUpdate'), {
		applyLevel: 2
	}, function(data) { //shangchang
		// console.log(data)
		if ("undefined" != typeof(data.data)) {
			scshopId = data.data.shopId;
			scid = data.data.id;

			if (0 == data.data.status) {
				scinfo = "待审核"
			}
			if (1 == data.data.status) {
				scinfo = "已通过"
			}
			if (2 == data.data.status) {
				scinfo = "已拒绝"
			}

		}else{
			JZL.ajax(qlgUrl('app/shops/getUserUpdate'), {
				applyLevel: 2,
				status:1
			}, function(data) { //shangchang
				// console.log(data)
				if ("undefined" != typeof(data.data)) {
					scshopId = data.data.shopId;
					scid = data.data.id;
			
					if (0 == data.data.status) {
						scinfo = "待审核"
					}
					if (1 == data.data.status) {
						scinfo = "已通过"
					}
					if (2 == data.data.status) {
						scinfo = "已拒绝"
					}
			
				}
			
			
			})
			}


	})
	JZL.ajax(qlgUrl('app/shops/getUserUpdate'), {
		applyLevel: 3
	}, function(data) { //xiaodian
		// console.log(data)
		if ("undefined" != typeof(data.data)) {

			if (0 == data.data.status) {
				ssinfo = "待审核"
			}
			if (1 == data.data.status) {
				ssinfo = "已通过"
			}
			if (2 == data.data.status) {
				ssinfo = "已拒绝"
			}
			ssid = data.data.id;

			ssshopId = data.data.shopId;
			// ssinfo=data.data.status;

		}else{
			JZL.ajax(qlgUrl('app/shops/getUserUpdate'), {
				applyLevel: 3,
				status:1
			}, function(data) { //xiaodian
				// console.log(data)
				if ("undefined" != typeof(data.data)) {
			
					if (0 == data.data.status) {
						ssinfo = "待审核"
					}
					if (1 == data.data.status) {
						ssinfo = "已通过"
					}
					if (2 == data.data.status) {
						ssinfo = "已拒绝"
					}
					ssid = data.data.id;
			
					ssshopId = data.data.shopId;
					// ssinfo=data.data.status;
			
				}
			})
		}
	})
	JZL.ajax(qlgUrl('app/shops/getUserUpdate'), {
		applyLevel: 4
	}, function(data) { //shangchangkefu
		// console.log(data)
		if ("undefined" != typeof(data.data)) {

			if (0 == data.data.status) {
				sdinfo = "待审核"
			}
			if (1 == data.data.status) {
				sdinfo = "已通过"
			}
			if (2 == data.data.status) {
				sdinfo = "已拒绝"
			}
			sdid = data.data.id;

			sdshopId = data.data.shopId;
			// sdinfo = data.data.status;
			// shangdu = '<img src="../img/shangchangkefu.png">'
		}else{
			JZL.ajax(qlgUrl('app/shops/getUserUpdate'), {
				applyLevel: 4,
				status:1
			}, function(data) { //shangchangkefu
				// console.log(data)
				if ("undefined" != typeof(data.data)) {
			
					if (0 == data.data.status) {
						sdinfo = "待审核"
					}
					if (1 == data.data.status) {
						sdinfo = "已通过"
					}
					if (2 == data.data.status) {
						sdinfo = "已拒绝"
					}
					sdid = data.data.id;
			
					sdshopId = data.data.shopId;
					// sdinfo = data.data.status;
					// shangdu = '<img src="../img/shangchangkefu.png">'
				}
			})
		}
	})
	JZL.ajax(qlgUrl('app/shops/userShopList'), {}, function(data) {
		if (1 == data.status) {
			var data = data.data;
			var html = '';
			var info = "",
				infotext;
			$.each(data, function() {
				if (this.status == 0) {
					info = "待审核",
						infotext = "编辑"
				} else if (this.status == 1) {
					info = "已通过";
					infotext = "进入店铺"

				} else if (this.status == 2) {
					info = "已拒绝";
					infotext = "编辑"
				}
				html = '<div class="list shadown_wai" data-id="' + this.shopId + ' " data-info="' + this.status +
					'"><div class="listleft"><div class="listimg"><img src="../img/icon_7.png" alt=""></div></div><div class="listcenter"><div class="lctop"><div class="shopname"><p class="shopname namecom ">' +
					this.shopName + '</p><p class="infocom shopinfo">' + info +
					'</p></div><div class="shopname supermaket nc "><p class=" namecom ">商超</p><p class="infocom scinfo ">' +
					scinfo +
					'</p></div><div class="shopname commercial nc"><p class=" namecom ">商厦</p><p class="infocom ssinfo ">' +
					ssinfo + '</p></div><div class="shopname shangdu nc"><p class=" namecom ">商都 </p><p class="infocom sdinfo">' +
					sdinfo + '</p></div></div><div class="listright"><p class="bj">' + infotext +
					'</p><p class="del">删除</p></div></div></div>';
				// 				html = '<div class="list shadown_wai" data-id="' + this.shopId + ' " data-info="' + this.status +
				// 					'"><div class="listleft"><div class="listimg"><img src="../img/icon_7.png" alt=""></div></div><div class="listcenter"><div class="name"><span class="shopname namecom ">' +
				// 					this.shopName +
				// 					'</span><span class="supermaket namecom nc"></span><span class="commercial namecom nc"></span><span class="shangdu nc namecom"></span></div><div class="info"><p class="infocom shopinfo">' +
				// 					info +
				// 					'</p><p class="scinfo ic infocom"></p><p class="ssinfo ic infocom"></p><p class="sdinfo ic infocom"></p></div><div class="listright"><p class="bj">' +
				// 					infotext +
				// 					'</p><p class="del">删除</p></div></div></div>';
				// 
				$('.con').append(html);
			})
		}else{
					mui.alert(data.msg)
				}
	})
	setTimeout(function() {
		$.each($(".list"), function() {
			var shop_id = $(this).attr("data-id");
			if (shop_id == scshopId) {
				$(this).find($('.listcenter .supermaket')).show()
				// $(this).find($('.listcenter .supermaket .namecom')).html('商超')
				// $(this).find($('.listcenter .shopname .scinfo')).show()
				$(this).find($('.listcenter .shopname .scinfo')).html(scinfo)
			}
			if (shop_id == ssshopId) {
				$(this).find($('.listcenter .commercial')).show()
				// $(this).find($('.listcenter .commercial .namecom')).html('商厦')
				// $(this).find($('.listcenter .shopname .ssinfo')).show()
				$(this).find($('.listcenter .shopname .ssinfo')).html(ssinfo)
			}
			if (shop_id == sdshopId) {
				$(this).find($('.listcenter .shangdu')).show()

				// $(this).find($('.listcenter .shangdu .namecom')).html('商都')
				// $(this).find($('.listcenter .shopname .sdinfo')).show()	

				$(this).find($('.listcenter .shopname .sdinfo')).html(sdinfo)
			}
		})
	}, 1000)
	// 申请店铺
	$('.add1').on('tap', function() {
		JZL.openWindow('applicationopen.html', 'applicationopen.html');
	})

	//编辑店铺
	var shopId = '';
	mui('.con').on('tap', '.bj', function() {
		shopId = $(this).parents().parents().parents().attr("data-id");
		var status = $(this).parents().parents().parents().attr("data-info");

		if (1 == status) {
			JZL.openWindow('myshop.html', shopId, {
				'shopId': shopId
			});

			// JZL.openWindow('storeout.html', shopId);
		} else {
			JZL.openWindow('applicationopen.html', shopId, {
				'status': status,
				'shopId': shopId
			});
			// JZL.openWindow('myshop.html', shopId);

		}
	})
	mui('.con').on('tap', '.supermaket', function() {
		if (scinfo != "已通过") {
			JZL.openWindow('supermarket.html', 'supermarket.html', {
				scid: scid
			})
		}
	})
	mui('.con').on('tap', '.commercial', function() {
		if (ssinfo != "已通过") {
			JZL.openWindow('commercial.html', 'commercial.html', {
				ssid: ssid
			})
		}
	})
	mui('.con').on('tap', '.shangdu', function() {
		if (sdinfo != "已通过") {
			JZL.openWindow('shangdu.html', 'shangdu.html', {
				sdid: sdid
			})
		}
	})
	//删除店铺 
	mui('.con').on('tap', '.del', function() {

		shopId = $(this).parents().parents().parents().attr("data-id");

		if (confirm('确认删除？')) {
			var lxy_div =
				'<div class="mui-backdrop lxy_home_zz" style="display: block;background-color: rgba(0,0,0,.7);" id="home_zhezhao">	<div class="lxy_zz clearfix"><h3>请输入操作密码</h3><div style="background:linear-gradient(to right,#48D1CC,#FFD700,#D2691E);height:2px; margin:10px auto"></div><input class="payword" type="password" placeholder="请输入操作密码"><div class="lxy_zz_btn"><button class="cancle" type="button">取消</button><button class="sure"  type="button">确定</button></div></div></div>';
			$('body').append(lxy_div);
			$('.lxy_zz').on('tap', function(e) {
				e.preventDefault();
				e.stopPropagation()
			})
			mui('.lxy_zz_btn').on('tap', '.cancle', function() {
				$('#home_zhezhao').remove();
				return;
			})

			mui('.lxy_zz_btn').on('tap', '.sure', function() {
				var payPwd = $('.payword').val();
				if (payPwd == '') {
					mui.alert("请输入密码")
				}
				JZL.ajax(qlgUrl('app/shops/delShop'), {
					shopId: shopId,
					payPwd: payPwd
				}, function(data) { //服务器返回响应，根据响应结果，分析是否登录成功；  
					// var data = toJson(data, 1);
                    console.log(data);
					if (data.status == 1) {
						$('#home_zhezhao').remove();
						mui.toast(data.msg)
						location.reload()
					}else{
					mui.alert(data.msg)
				}
				})

			})
		}
	})
})
