/**
 * 首页
 * 
 */
$(function () {
  // var mainContent = document.getElementById('mainContent');
	var ERROR_OK = 200;
	var openId = $("#openId").val();
	var developId = $("#developId").val(); //通过developId判断公众号

	var contextPath = $("#contextPath").val();
	var userStatus = $("#userStatus").val();
	var register = $("#register").val();
	var userId = $("#userId").val();
	var organId = $("#organId").val();
	var tpl = {
		bannerTpl: '<div class="swiper-container">\
			<div class="swiper-wrapper">\
				<% for(var i=0;i< data.length;i++){%>\
					<div class="swiper-slide">\
						<div style="background-image: url(<%=data[i].coverUrl%>)"  class="img"  data-url="<%=data[i].urlAddress%>"/>\
					</div>\
				<%}%>	\
			</div>\
		   <div class="swiper-pagination"></div>\
        </div>',
		serviceTpl: '<% for(var i=0;i<serviceMap0.length;i++){%>\
			<% if(i<4){%>\
				<div class="service-item" data-registerstatus = "<%=serviceMap0[i].registerStatus%>" data-skipaddress="<%=serviceMap0[i].skipAddress%>" data-servicecode="<%=serviceMap0[i].serviceCode%>" data-jumpaddress="<%=serviceMap0[i].jumpAddress%>" data-issigncontract = "<%=serviceMap0[i].isSignContract%>" data-serviceopeningstatus="<%=serviceMap0[i].serviceOpeningStatus%>">\
					<div class="service-img" >\
						<div class="img-icon" style="background-image: url(<%=serviceMap0[i].serviceIcon%>)"></div>\
					</div>\
					<span class="service-name"><%=serviceMap0[i].serviceName%></span>\
				</div>\
			<%}%>	\
        <%}%>',
		secondServiceTpl: '<% for(var i=0;i<serviceMap0.length;i++){%>\
        	<% var length=serviceMap0.length%>\
        	<%if(length>0 && length<8){%>\
				\
					<div class="s-service-item" data-registerstatus = "<%=serviceMap0[i].registerStatus%>" data-skipaddress="<%=serviceMap0[i].skipAddress%>" data-servicecode="<%=serviceMap0[i].serviceCode%>" data-jumpaddress="<%=serviceMap0[i].jumpAddress%>" data-issigncontract = "<%=serviceMap0[i].isSignContract%>" data-serviceopeningstatus="<%=serviceMap0[i].serviceOpeningStatus%>">\
						<div class="s-service-img" >\
							<div class="s-img-icon" style="background-image: url(<%=serviceMap0[i].serviceIcon%>)"></div>\
						</div>\
						<span class="s-service-name"><%=serviceMap0[i].serviceName%></span>\
					</div>\
				\
        	<%}else if(length>=8){%>\
	        	<% if(i<8){%>\
					<div class="s-service-item" data-registerstatus = "<%=serviceMap0[i].registerStatus%>" data-skipaddress="<%=serviceMap0[i].skipAddress%>" data-servicecode="<%=serviceMap0[i].serviceCode%>" data-jumpaddress="<%=serviceMap0[i].jumpAddress%>" data-issigncontract = "<%=serviceMap0[i].isSignContract%>" data-serviceopeningstatus="<%=serviceMap0[i].serviceOpeningStatus%>">\
						<div class="s-service-img" >\
							<div class="s-img-icon" style="background-image: url(<%=serviceMap0[i].serviceIcon%>)"></div>\
						</div>\
						<span class="s-service-name"><%=serviceMap0[i].serviceName%></span>\
					</div>\
				<%}%>	\
        	<%}%>\
        <%}%>',
		"inforTpl": '<% for(var i =0;i<items.length;i++){%>\
			<% if(i<2){%>\
				<div class="n-infor-item" data-url="<%=items[i].url_address%>">\
					<div class="n-item-img" style="background-image: url(<%=items[i].cover_url%>)"></div>\
					<div class="n-item-descript" >\
						<div class="n-item-desp"><%=items[i].summary_info%></div>\
						<div class="n-item-time">\
							<%if(!!items[i].createTime){%>\
								<span class="time" ><%=formatDate("MM-dd hh:mm",items[i].createTime)%></span>\
							<%}%>\
							<span class="read-num">阅读量：<%=RndNum(500)%></span>\
						</div>\
					</div>\
				</div>\
			<%}%>	\
			<%}%>',
		"secondInforTpl": '<% for(var i =0;i<items.length;i++){%>\
					<% if(i<5){%>\
						<div class="s-infor-item" data-url="<%=items[i].url_address%>">\
							<div class="s-item-img" style="background-image: url(<%=items[i].cover_url%>)"></div>\
							<div class="s-item-descript-wp">\
								<div class="s-item-title"><%=items[i].title%></div>\
								<div class="s-item-descrip"><%=items[i].summary_info%></div>\
							</div>\
						</div>\
					<%}%>	\
				<%}%>',
		"itemTpl": '<% for(var i=0;i<data.length;i++){%>\
				<div class="item" data-id="<%= data[i].id%>" data-name="<%= data[i].name%>">\
					<span class="icon"></span>\
					<span class="name"><%= data[i].name%></span>\
				</div>\
			<%}%>'
	};
	/**************************************时间格式化处理************************************/
	function dateFtt(fmt, date) { //author: meizz   
		var date = new Date(date);
		var o = {
			"M+": date.getMonth() + 1, //月份   
			"d+": date.getDate(), //日   
			"h+": date.getHours(), //小时   
			"m+": date.getMinutes(), //分   
			"s+": date.getSeconds(), //秒   
			"q+": Math.floor((date.getMonth() + 3) / 3), //季度   
			"S": date.getMilliseconds() //毫秒   
		};
		if (/(y+)/.test(fmt))
			fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
		for (var k in o)
			if (new RegExp("(" + k + ")").test(fmt))
				fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
		return fmt;
	};

	//产生随机数函数
	function RndNum(n) {
		return Math.floor(Math.random() * n);
	}
	//注冊函數
	template.helper('formatDate', dateFtt);
	template.helper('RndNum', RndNum);

	var Index = {
		init: function () {
			this.getFindUrl()
			this.render();
			this.bindEvent();
		},
		render: function () {
            sessionStorage.setItem("publicId", $("#publicId").val()); //存公众号ID
			sessionStorage.setItem("telephone", $("#telephone").val()); //存电话
			sessionStorage.setItem("nickName", $("#nickName").val()); //存昵称
			sessionStorage.setItem("nickPic", $("#nickPic").val()); //存头像
			sessionStorage.setItem("accountType", $("#accountType").val()); //存账号类型 0：企业   1：个人
			sessionStorage.setItem("passType", $("#passType").val()); //通行方式 1-face++  2-二维码
			sessionStorage.setItem("developId", developId); //
			sessionStorage.setItem("userStatus", userStatus); //
			sessionStorage.setItem("register", register); //
			sessionStorage.setItem("openId", openId); //
			//sessionStorage.setItem("userId", userId); //用户ID
			sessionStorage.setItem("orgId", organId); //项目ID
			sessionStorage.setItem("orgName", $("#orgName").val()); //项目ID
			localStorage.setItem(developId + "orgName", $("#orgName").val());//存储项目名称
			localStorage.setItem("homePage",window.location.href);
      

			var sOrgId = localStorage.getItem('wx' + developId);
			if (sOrgId) {
				var sOrgName = localStorage.getItem(developId + "orgName");
				sessionStorage.setItem('wx' + developId, sOrgId);
				sessionStorage.setItem("orgId", sOrgId);
				sessionStorage.setItem(developId + "orgName", sOrgName);
				$(".logo .org-name").html(sOrgName);
				$(".wx-org-name").html(sOrgName);
			}else{
				$(".wx-org-name").html($("#orgName").val());
			}
			if(organId == 663){
				$(".wx-index-top .logo-icon").addClass("fude-logo-home")
			}else if(organId == 691){
				$(".wx-index-top .logo-icon").addClass("suoke-logo-home")
			}else{
        $(".wx-index-top .logo-icon").removeClass("fude-logo-home")
        $(".wx-index-top .logo-icon").removeClass("suoke-logo-home")
      }
			// 判断关于我们有没有数据
			this.getAboutUs()
			// 获取天气
			this.getPosition(developId)
			//获取项目列表
			// this.getItemList();
			//获取用户id
//			this.getUserId();
			//获取banner
			this.getBanner();
			//获取资讯列表
			this.getInforList();
			//获取企业服务列表
			this.getServiceList();
			//获取用户信息
			this.getUserInfo();
			//判断是否显示商圈/发现
			this.judgeShow();

			
		},
		bindEvent: function () {
			var _this = this;
			//			sessionStorage.setItem("orgId", $("#organizationId").val());
			//跳转服务
			$(".nav-btn.service").on("click", function () {
				window.location.href = $("#contextPath").val() + "/wechat/index/serviceListPage?openId=" + openId + "&developId=" + developId + "&userStatus=" + userStatus + "&userId=" + $("#userId").val() + "&register=" + register + "&organId=" + organId;
			});
			//跳转更多
			$(".infortion-top .more").on("click", function () {
				window.location.href = $("#contextPath").val() + "/wechat/index/infoListPage?openId=" + openId;
			});
			//跳转服务
			$(".logo .icon_menu").on("click", function () {
				window.location.href = $("#contextPath").val() + "/wechat/index/serviceListPage?openId=" + openId + "&developId=" + developId + "&userStatus=" + userStatus + "&userId=" + $("#userId").val() + "&register=" + register + "&organId=" + organId;
			});

			// 跳转商圈
			$(".nav-btn.trade_area").on("click", function () {
				
				window.location.href = $("#contextPath").val() + "/wechat/index/tradeArea?openId=" + openId + "&developId=" + developId + "&userStatus=" + userStatus + "&userId=" + $("#userId").val() + "&register=" + register + "&organId=" + organId;			
//				var findUrl = sessionStorage.getItem('findUrl')
//				window.location.href = findUrl;
				
			});
			//重选项目
			$(".logo .org-name,.wx-index-top .address-icon").on("click", function () {
				// $(".second-wx-index").hide();
				window.location.href = $("#contextPath").val() + "/wechat/appUser/selectProject";
			})
			// $(".nav-btn.mine").on("click",function(){
			//     window.location.href=$("#contextPath").val()+"/wechat/index/serviceListPage;
			// });
			
		},
		getFindUrl: function(){
			var _this = this;
			_this.judgeShow(function(data){
				_this.getUserInfo(function(){
					var findUrl ;
					//console.log(sessionStorage.getItem("userId"));debugger
					if(sessionStorage.getItem("userId") && sessionStorage.getItem("userId") != ''){
						_this.getToken(function(token){
							findUrl = "https://s.phone580.com/center/platform/qhcjqt4411.html?token=" + token ;//生产
//							findUrl = "https://s.phone580.com/test/center/platform/qhcjqt4411.html?token=" + token ;//测试
							 //findUrl = "http://test.s.phone580.com:8000/service/test/center/platform/qhcjqt4411.html?token=" + token ;//测试-1
							sessionStorage.setItem('findUrl',findUrl)
							//window.location.href = findUrl;
						})	
					}else{
						//findUrl = 'http://test.s.phone580.com:8000/service/test/center/platform/qhcjqt4411.html';
						//findUrl = "https://s.phone580.com/test/center/platform/qhcjqt4411.html" ;
						findUrl = "https://s.phone580.com/center/platform/qhcjqt4411.html" ;
						sessionStorage.setItem('findUrl',findUrl)
						//window.location.href = findUrl ;
					}
					
				})
			})
		},
		//获取token
		getToken: function(callback){
			$.ajax({
				url: contextPath + "/wechat/index/createToken",
				type: "POST",
				dataType: "json",
				data: {
					userId: sessionStorage.getItem("userId")
				},
				success: function (data) {
					if(data && data.code==200 ){
						callback && callback(data.data);
					}
				},
				error: function (data) {
					// alert("系统繁忙..");
				}
			});
		},
		getAboutUs: function(){
			$.ajax({
				url: contextPath + "/wechat/aboutOrg/list",
				type: "POST",
				dataType: "json",
				data: {
					orgId: organId
				},
				success: function (data) {
					if(data && data.code==200 && data.data.length){
						$('.aboutUs').css({
							display: 'inline-block',
						});
					}
					// 跳转关于我们
					$(".aboutUs").on("click",function(){
						window.location.href = "/avicfile/super_wechat/aboutUs/index.html";
					})
				},
				error: function (data) {
					// alert("系统繁忙..");
				}
			});
		},
		/**
		 * 获取url的参数
		 * @param name 参数名
		 */
		GetQueryString: function (name) {
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
			var r = window.location.search.substr(1).match(reg);
			if (r != null) return unescape(r[2]);
			return null;
		},
		getPosition: function (developId) {
		  var _this = this
		  $.ajax({
		    url: $("#contextPath").val() + "/wechat/visitor/fenxiang",
		    type: "POST",
		    async: true,
		    cache: false,
		    dataType: "json",
		    data: {
		      url: location.href.split('#')[0],
		      developId: developId
		    },
		    success: function (data) {
		      wx.config({
		        debug: false, // 开启调试模式
		        appId: data.appid, // 必填，公众号的唯一标识
		        timestamp: data.timestamp, // 必填，生成签名的时间戳
		        nonceStr: data.nonceStr, // 必填，生成签名的随机串
		        signature: data.signature, // 必填，签名，见附录1
		        jsApiList: ['getLocation', 'hideOptionMenu'],
		        // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
		      });
		      //隐藏右上角菜单
		      wx.hideOptionMenu();
		      wx.ready(function () {
		        wx.checkJsApi({
		          jsApiList: [
		            'getLocation',
		            'hideOptionMenu'
		          ],
		          success: function (res) {
		            // alert(res.errMsg);  
		          }
		        });
		        wx.getLocation({
		          success: function (res) {
		            var latitude = res.latitude; // 纬度，浮点数，范围为90 ~ -90
		            var longitude = res.longitude; // 经度，浮点数，范围为180 ~ -180。
		            var speed = res.speed; // 速度，以米/每秒计
		            var accuracy = res.accuracy; // 位置精度

					_this.getDay(latitude,longitude);
		          },
		          fail: function (res) {
		          	_this.getDay();
		          }
		        });
		      });

		    },
		    error: function(error){

		    }

		  });

		},

//		getUserId: function (callback) {
//			$.ajax({
//				url: contextPath + "/wechat/appUser/getUserIdByOpenId",
//				type: "POST",
//				dataType: "json",
//				data: {
//					openId: openId,
//					developId: developId
//				},
//				success: function (data) {
//					if (data.code == ERROR_OK) {
//						$("#userId").val(data.data);
//						callback && callback();
//					} else {
//						alert(data.msg)
//					}
//				},
//				error: function (data) {
//					// alert("系统繁忙..");
//				}
//			});
//		},
		getBanner: function () {
			$.ajax({
				url: contextPath + "/wechat/notice/bannerList",
				type: "POST",
				dataType: "json",
				data: {
					openId: openId
				},
				success: function (data) {
					if (data.code == ERROR_OK) {
						$(".banner_up").html(template.render(tpl.bannerTpl)(data));
						var swiper = new Swiper('.swiper-container', {
							// autoHeight: true ,//高度随内容变化

							loop: true,

							autoplay: 3000,
							// 如果需要分页器
							pagination: '.swiper-pagination',
							autoplayDisableOnInteraction: false
						});
						$(".banner_up .img").on("click", function () {
							var url = $(this).data("url");
							if (!!url) {
								window.location.href = url;
							}
						})
					} else {
						alert(data.msg)
					}
				},
				error: function (data) {
					// alert("系统繁忙..");
				}
			});
		},
		getServiceList: function () {
			$.ajax({
				url: contextPath + "/wechat/index/serviceList",
				type: "POST",
				dataType: "json",
				data: {
					openId: openId,
					developId: developId,
					userStatus: userStatus
				},
				success: function (data) {
					if (data.code == ERROR_OK) {
						//serviceMap0.length secondServiceTpl
						if (data.data.serviceMap0 != null) {
							$(".second-service-wp").html(template.render(tpl.secondServiceTpl)(data.data));
							$(".second-service-wp .s-service-item").on("click", function () {
								var registerStatus = $(this).data("registerstatus");
								var skipAddress = $(this).data("skipaddress");
								var serviceCode = $(this).data("servicecode");
								var jumpAddress = $(this).data("jumpaddress");
								var isSignContract = $(this).data("issigncontract");
								var serviceOpeningStatus = $(this).data("serviceopeningstatus");
								sessionStorage.setItem('firstEnter',1);//标志首次进入服务，为1代表首次进入
								//${obj.registerStatus}','${obj.skipAddress }','${obj.serviceCode }','${obj.jumpAddress }','${obj.isSignContract }','${obj.serviceOpeningStatus }
								//跳转各个模块
								if(sessionStorage.getItem("isLogin") == 1){
									searchUrl(userStatus, registerStatus, skipAddress, serviceCode, jumpAddress, isSignContract, serviceOpeningStatus);
								} else {
									checkedPerm(serviceCode,function() {
										searchUrl(userStatus, registerStatus, skipAddress, serviceCode, jumpAddress, isSignContract, serviceOpeningStatus);
									})
								}
							})
							//						if(data.data.serviceMap0.length<3){
							//							$(".service-list").addClass("flex-start")
							//						}
							//						$(".service-list").html(template.render(tpl.serviceTpl)(data.data));
							//						$(".service-list .service-item").on("click", function () {
							//							var registerStatus = $(this).data("registerstatus");
							//							var skipAddress = $(this).data("skipaddress");
							//							var serviceCode = $(this).data("servicecode");
							//							var jumpAddress = $(this).data("jumpaddress");
							//							var isSignContract = $(this).data("issigncontract");
							//							var serviceOpeningStatus = $(this).data("serviceopeningstatus");
							//							//${obj.registerStatus}','${obj.skipAddress }','${obj.serviceCode }','${obj.jumpAddress }','${obj.isSignContract }','${obj.serviceOpeningStatus }
							//							//跳转各个模块
							//							searchUrl(userStatus, registerStatus, skipAddress, serviceCode, jumpAddress, isSignContract, serviceOpeningStatus);
							//						})
						}
					} else {
						alert(data.msg)
					}
				},
				error: function (data) {
					// alert("系统繁忙..");
				}
			});
		},
		getInforList: function () {
			var _this = this;
			// 页数
			var pageNo = 0;
			// 每页展示5个
			var pageSize = 5;
			$(".second-infor-wp").html('<div class="infor-list"></div>');
			$(".second-infor-wp").dropload({
				scrollArea: window,
				domDown: {
					domClass: "dropload-down",
					// domRefresh: '<div class="dropload-refresh">↑上拉加载更多</div>',
					domLoad: '<div class="dropload-load"><span class="loading"></span>加载中...</div>',
					domNoData: '<div class="dropload-noData">已经到底啦！</div>'
				},
				// 触发dropload的最小滑动距离
				distance: 200,
				loadDownFn: function (me) {
					pageNo++;
					// 拼接HTML
					var result = '';
					$.ajax({
						url: contextPath + "/wechat/notice/noticeList",
						type: "POST",
						data: {
							openId: openId,
							pageNo: pageNo,
							pageSize: pageSize
						},
						dataType: 'json',
						success: function (data) {
							if (data.code == '200') {
								var arrLen = data.data.items.length;
								// arrLen = 0
								if (arrLen > 0) {
									result = template.render(tpl.secondInforTpl)(data.data);
									// 如果没有数据
								} else {
									// 锁定
									me.lock();
									// 无数据
									me.noData();
								}
								$(".infor-list").append(result);
								//跳转详情
								$(".infor-list .s-infor-item").on("click", function () {
									var url = $(this).data("url");
									window.location.href = url;
								})
								me.resetload();
							}
						},
						error: function (xhr, type) {
							// alert('error!');
							// 即使加载出错，也得重置
							me.resetload();
						}
					});
				}
			})
		},
		getUserInfo: function (callback) {
			$.ajax({
				url: contextPath + "/wechat/appUser/getUserInfo",
				type: "POST",
				dataType: "json",
				data: {
					openId: openId,
					organizationId: organId
				},
				success: function (data) {
					if (data.code == ERROR_OK) {
						var result = data.data;
						sessionStorage.setItem("accId", result.accountId);
						//						sessionStorage.setItem("orgId", organId);
						sessionStorage.setItem("virId", result.compId);
						sessionStorage.setItem("virName", result.compName);
						sessionStorage.setItem("account", result.account);
						sessionStorage.setItem("mobile", result.mobile);
						sessionStorage.setItem("userName", result.userName);
						sessionStorage.setItem("isLogin",result.isLogin);
						$("#userId").val(result.userId);
						if (result.isLogin == 2) {//1-未登录 2-已登录
							sessionStorage.setItem("userId", userId);
						}else{
							sessionStorage.setItem("userId", '');
						}
						callback && callback()
					} else {
						alert(data.msg)
					}
				},
				error: function (data) {
					// alert("系统繁忙..");
				}
			});
		},
		judgeShow: function (callback) {
			// var isEnabled = sessionStorage.getItem("isEnabled");
			// var name = sessionStorage.getItem("name");
			// if (isEnabled == "true") {
			// 	$(".trade_area").show();
			// 	$(".trade_area .name").html(name);
			// } else if (isEnabled == "false") {
			// 	$(".trade_area").hide();
			// } else {
			$.ajax({
				url: contextPath + "/wechat/index/discoverCategory",
				type: "POST",
				data: {
					orgId: organId
				},
				success: function (data) {
					if (data.code == ERROR_OK) {
						var result = data.data;
						var isEnabled = result.isEnabled;
						var name = result.name;
						if (isEnabled == true) {
							$(".trade_area").show();
							$(".trade_area .name").html(name);
							callback && callback();
						}
						sessionStorage.setItem("isEnabled", isEnabled);
						sessionStorage.setItem("name", name);
					} else {
						alert(data.msg)
					}
				},
				error: function (data) {
					// alert("系统繁忙..");
				}
			});
			// }

		},
		getItemList: function () {
			$.ajax({
				url: contextPath + "/wechat/index/wechatPublicOrgList",
				type: "POST",
				dataType: "json",
				data: {
					developId: developId
				},
				success: function (data) {
					if (data.code == ERROR_OK) {
						// $(".item-list").html(template.render(tpl.itemTpl)(data));
						// $(".item").on("click",function(){
						// 	var orgId = $(this).data("id");
						// 	var name = $(this).data("name");
						// 	localStorage.setItem('wx'+developId, orgId );
						// 	localStorage.setItem("orgId", orgId );
						// 	localStorage.setItem(developId+"orgName", name );
						// 	sessionStorage.setItem('wx'+developId, orgId );
						// 	sessionStorage.setItem("orgId", orgId );
						// 	sessionStorage.setItem(developId+"orgName", name );
						// 	window.location.href = $("#contextPath").val() + "/wechat/index/homePageView?openId=" + openId + "&developId=" + developId + "&organizationId=" + orgId;
						// })
					} else {
						alert(data.msg)
					}
				},
				error: function (data) {
					// alert("系统繁忙..");
				}
			});
		},
		getDay: function (latitude,longitude) {
			var date = new Date();
			var text = '';
			var day = date.getDay();
			if (day == 0) {
				text = "星期日";
			} else if (day == 1) {
				text = "星期一";
			} else if (day == 2) {
				text = "星期二";
			} else if (day == 3) {
				text = "星期三";
			} else if (day == 4) {
				text = "星期四";
			} else if (day == 5) {
				text = "星期五";
			} else if (day == 6) {
				text = "星期六";
			};
			$(".wx-index-date").html(text + '  ' + dateFtt("MM月dd日", new Date()))
			if(latitude && longitude){
				$.ajax({
					type: 'GET',
					url: $("#contextPath").val() + '/wechat/index/getWeatherInfo',
					data: {
						'lon':longitude,
						'lat':latitude
					},
					dataType: 'JSON',
					success: function (res) {
						if(res && res.code == 200 && res.data){
							var str = res.data.nightTemp + "°C~" + res.data.dayTemp + '°C  ' + res.data.dayWeatherDes;
							$(".wx-index-date").html($(".wx-index-date").html() + '  ' + str) 
						}
					}
				});
			}
		},
		getCurrentProject: function (latitude, longitude, developId) {
			$.ajax({
				url: $("#contextPath").val() + "/wechat/index/initOrgSelect",
				type: "POST",
				dataType: "json",
				data: {
					latitude: latitude,
					longitude: longitude,
					developId: developId
				},
				success: function (data) {
					// console.log(data);
					if (data.code == "200") {
						sessionStorage.setItem("currentP", data.data.name);
						sessionStorage.setItem("currentPid", data.data.id);
						$(".projectName").html(data.data.name);
						$(".projectName").attr("data-id", data.data.id);
						$(".projectName").attr("data-name", data.data.name);
						$(".current i").html("当前定位");
					}
				},
				error: function (data) {
					// alert("系统繁忙..");
				}
			});
		},
		changeStyle(){
			var width = $('.wx-org-name').height()
			if(width == 72){
				$('.second-service-wp').css({
					'marginTop': '232px'
				});
			}
		}
	}
	Index.init();
	Index.changeStyle()

})

/**
链接跳转地址
 */

function getUserInfo(orgId) {
	var openId = $("#openId").val();
	var developId = $("#developId").val();
	var userId = $("#userId").val();
	var register = $("#register").val();
	var userStatus = $("#userStatus").val();

	var organId = $("#organId").val();
	// if(orgId==""||orgId==null){
	// 	orgId=sessionStorage.getItem("orgId");
	// }
	//	if(userId!=""){
	//		location.href=$("#contextPath").val()+"/wechat/appUser/userInfo?openId="+openId+"&developId="+developId+"&userId="+userId+"&organizationId="+orgId+"&register="+register;
	//	}else{
	//		window.location.href=$("#contextPath").val()+"/wechat/appUser/bindphone?openId="+openId+"&developId="+developId+"&register="+register;
	//	}
	$.ajax({
		url: $("#contextPath").val() + "/wechat/appUser/getUserInfo",
		type: "POST",
		dataType: "json",
		data: {
			openId: openId,
			organizationId: orgId
		},
		success: function (data) {
			if (data.code == "200") {
				var dataObj = data.data;
				console.log(dataObj);
				if (dataObj.isLogin == 2) {//1-未登录 2-已登录
					
					window.location.href = $("#contextPath").val() + "/wechat/appUser/newmine?openId=" + openId + "&developId=" + developId + "&userStatus=" + userStatus + "&userId=" + userId + "&register=" + register + "&organizationId=" + organId;
				} else {
					// if(dataObj.accountType == 1){
					window.location.href = $("#contextPath").val() + "/wechat/appUser/newmine?openId=" + openId + "&developId=" + developId + "&userStatus=" + userStatus + "&userId=" + userId + "&register=" + register + "&organizationId=" + organId;
					// }
					// else{
					// 	location.href = $("#contextPath").val() + "/wechat/appUser/virAccount?openId=" + openId + "&developId=" + developId + "&userStatus=" + userStatus + "&userId=" + userId + "&register=" + register + "&organizationId=" + organId;
					// }

				}
			} else {
				alert(data.msg)
			}
		},
		error: function (data) {
			// alert("系统繁忙,菜单加载失败..");
		}
	});
	//	if(userId!=""){
	//		location.href=$("#contextPath").val()+"/wechat/release/mine?openId="+openId+"&developId="+developId+"&userId="+userId+"&organizationId="+orgId;
	//	}else{
	//		window.location.href=$("#contextPath").val()+"/wechat/appUser/bindphone?openId="+openId+"&developId="+developId;
	//	}
}

function shoppingUrl() {
	window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx8f5a07e8746f85e3&redirect_uri=http%3a%2f%2fwww.avic-s.com%2fsuper_service%2fwechat%2ffrontSecurity%2fauth%3fredirectUrl%3d%2fwechat%2fsikpMall%2fsikpMallCterminal%26urlKey%3dCterminal&response_type=code&scope=snsapi_base&state=1#wechat_redirect";
}

function bannerUrl(linkUrl) {
	if (linkUrl != "") {
		window.location.href = linkUrl;
	}
}

/**
 * 跳转服务链接
 * @param userStatus
 * @param status
 * @param url
 * @param serviceCode
 * @param jumpAddress
 * @param isSignContract
 * @param serviceOpeningStatus
 */
function searchUrl(userStatus, status, url, serviceCode, jumpAddress, isSignContract, serviceOpeningStatus) {
  // if(url.indexOf("open.weixin.qq.com")==-1){//是外链
  //   $(".__layer-ball").css("display","block")
  //   $("#mainContent").css("display","block")
  // }
	var register = $("#register").val();
	var openId = $("#openId").val();
	var developId = $("#developId").val();
	var userId = sessionStorage.getItem("userId");
	var serviceUrl = "";
	sessionStorage.setItem("oldUrl", url);
  var urls = "";
	if (userStatus == 1) {
		urls = jumpAddress;
    console.log("1:" + urls);
		if (isSignContract == 1 && serviceOpeningStatus == 0) {
			layer.open({
				title: '温馨提示',
				style: 'font-size: 18px;',
				content: '您的企业暂未开通此服务,立即了解服务详情。',
				btn: ['确定', '取消'],
				yes: function (index) {
					layer.close(index);
					urls = url;
					var urlStr = urls.split("?");
					if (urlStr.length > 1) {
						serviceUrl = urls + "&openId=" + openId + "&developId=" + developId + "&serviceCode=" + serviceCode + "&userId=" + userId + "&resStatus=" + status;
					} else {
						serviceUrl = urls + "?openId=" + openId + "&developId=" + developId + "&serviceCode=" + serviceCode + "&userId=" + userId + "&resStatus=" + status;
					}
          console.log("2:" + serviceUrl);
          // if(url.indexOf("open.weixin.qq.com")==-1){//是外链
          //   mainContent.src = serviceUrl;
          // }else{
	        //   location.href = serviceUrl;
          // }
          location.href = serviceUrl;
				},
				no: function (index) {
					layer.close(index);
				}
			});
		} else {
			var urlStr = urls.split("?");
			if (urlStr.length > 1) {
				serviceUrl = urls + "&openId=" + openId + "&developId=" + developId + "&serviceCode=" + serviceCode + "&userId=" + userId + "&resStatus=" + status;
			} else {
				serviceUrl = urls + "?openId=" + openId + "&developId=" + developId + "&serviceCode=" + serviceCode + "&userId=" + userId + "&resStatus=" + status;
			}
      console.log("3:" + serviceUrl);
      // if(url.indexOf("open.weixin.qq.com")==-1){//是外链
      //   mainContent.src = serviceUrl;
      // }else{
      //   location.href = serviceUrl;
      // }
			location.href = serviceUrl;

		}
	} else {
		urls = url;
		var urlStr = urls.split("?");
		if (urlStr.length > 1) {
			serviceUrl = urls + "&openId=" + openId + "&developId=" + developId + "&serviceCode=" + serviceCode + "&userId=" + userId + "&resStatus=" + status;
		} else {
			serviceUrl = urls + "?openId=" + openId + "&developId=" + developId + "&serviceCode=" + serviceCode + "&userId=" + userId + "&resStatus=" + status;
		}
		if (status == 1) {
			if (register == 1) {
        console.log("4:" + serviceUrl);
        // if(url.indexOf("open.weixin.qq.com")==-1){//是外链
        //   mainContent.src = serviceUrl;
        // }else{
        //   location.href = serviceUrl;
        // }
				location.href = serviceUrl;
			} else {
				console.log("5:" + urls + "&resStatus=" + status);
				doRegister(urls + "&resStatus=" + status);
			}
		} else {
			sessionStorage.setItem('serviceCode',serviceCode)
			serviceUrl = serviceUrl + "&resStatus=" + status + "&serviceCode=" + serviceCode;
			console.log("6:" + serviceUrl);
      console.log(status,userStatus)
      // if(url.indexOf("open.weixin.qq.com")==-1){//是外链
      //   setTimeout(function(){
      //     mainContent.src = serviceUrl;
      //   }, 100);
      // }else{
      //   location.href = serviceUrl;
      // }
			location.href = serviceUrl;
		}

	}
}

function handoverProject() {
	var userStatus = $("#userStatus").val();
	if (userStatus == 1) {
		return;
	}
	location.href = $("#contextPath").val() + "/wechat/index/choiceOrgAddressIndex?openId=" + $("#openId").val() + "&developId=" + $("#developId").val() + "&userId=" + $("#userId").val();
}

//进入注册界面
function doRegister(serviceUrl) {
	window.location.href = serviceUrl;
}
/**
 校验用户权限
 */

function checkedPerm(serviceCode,callback) {
	// var userId = $("#userId").val();
	var accountType = 1
	if(sessionStorage.getItem("accountType")) {
		accountType = sessionStorage.getItem("accountType")
	}
	var id
	if(accountType == 1) {
		id = sessionStorage.getItem("userId")
	}else{
		id = sessionStorage.getItem("accId")
	}
    if (id){
        id = ""
    }
	// alert(id,'id')
	// alert(serviceCode,'serviceCode')
	// alert(accountType,'accountType')
	$.ajax({
		url: $("#contextPath").val() + "/wechat/index/checkedHasFuncPerm",
		type: "POST",
		dataType: "json",
		data: {
			id: id,
			serviceCode: serviceCode,
			accountType: accountType
		},
		success: function (data) {
			if (data.code == "200") {
				// alert(data.data)
				if(data.data){
					callback()
				}else{
					layer.open({
            content: '抱歉，你暂无该功能的使用权限，请联系企业管理员或客服人员！',
            skin: 'msg',
            time: 2
          });
				}
			} else {
				alert(data.msg)
			}
		},
		error: function (data) {
//			alert("系统繁忙,菜单加载失败..");
		}
	});
}