var cityList = [];
$(function () {
  var openId = GetQueryString("openId");
  var developId = GetQueryString("developId");
  if (!openId) {
    openId = $("#openId").val();
  }
  if (!developId) {
    developId = $("#developId").val();
  }
  getProjectList(openId, developId);
  //加载企业事件
  $('.container').show();
  //选择企业 start
  $('body').on('click', '.city-list p', function () {
    // alert($(this).html())
  });
})

function getProjectList(openId, developId) {
  $.ajax({
    url: $("#contextPath").val() + "/wechat/index/getWhiteVirList",
    type: "POST",
    dataType: "json",
    data: {
      developId: developId,
      openId: openId
    },
    success: function (data) {
      if (data.code == "200") {
        console.log(data.data);
        cityList = data.data;
        $('.city').html('');
        $(".letter-list").html('');
        var html = '';
        $.each(cityList, function (i, item) {
          html += '<p class="item" data-userId="'+item.userId+'" data-orgId="' + item.organizationId + '" data-virId="' + item.virId + '">' + item.virName + '</p>';
        })
        $('.city').append(html);
        $(".item").on("click", function () {
          var name = $(this).data("name");
          var virId = $(this).data("virid");
          var orgId = $(this).data("orgid");
          var userId = $(this).data("userid");
            console.log('name='+name + ',virId='+virId+ ',orgId='+orgId+ ',userId='+userId);
          window.location.href = $("#contextPath").val() + "/wechat/assets/indexPage?openId=" + openId + "&developId=" + developId + "&orgId=" + orgId+ "&virId=" + virId+ "&userId=" + userId +"&pageType=innerShoppingMall";
        })
      } else {
        alert(data.msg)
      }
    },
    error: function (data) {
      alert("系统繁忙..");
    }
  });
}
/**
 * 获取url的参数
 * @param name 参数名
 */
function GetQueryString(name) {
  var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  var r = window.location.search.substr(1).match(reg);
  if (r != null) return unescape(r[2]);
  return null;
};