/**
 * 选择校区
 */

$(function () {
	var ERROR_OK = 200;
	var openId = $("#openId").val();
	var developId = $("#developId").val();
	var contextPath = $("#contextPath").val();
	var tpl = {
			"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>\
				<%}%>'
	}
	var Item = {
		init: function () {
			this.render();
			this.bindEvent();
		},
		render: function () {

			//获取校区列表
			this.getItemList();
			
		},
		bindEvent: function () {
			
		},
		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")
							sessionStorage.setItem("orgId", orgId );
							sessionStorage.setItem("orgName", name );
							window.location.href = $("#contextPath").val() + "/wechat/index/homePageView?openId=" + openId + "&developId=" + developId + "&organizationId=" + orgId;
						})
					} else {
						alert(data.msg)
					}
				},
				error: function (data) {
					// alert("系统繁忙..");
				}
			});
		}
	}
	Item.init();
});
