var cityList = [];
var openId = $("#openId").val();
$(function () {
    var developId = $("#developId").val();
    var contextPath = $("#contextPath").val();
    var userMobile = $("#userMobile").val();
    // var userMobile = '17691355199';
    getProjectList(userMobile);
    //加载城市事件
    $('.container').show();
    //选择企业 start
    $('body').on('click', '.city-list p', function () {
        // alert($(this).html())
    });
    //点击索引查询城市
    $('body').on('click', '.letter a', function () {
        var s = $(this).html();
        $(window).scrollTop($('#' + s + '1').offset().top);
        $("#showLetter span").html(s);
        $("#showLetter").show().delay(500).hide(0);
    });
    //中间的标记显示
    $('body').on('onMouse', '.showLetter span', function () {
        $("#showLetter").show().delay(500).hide(0);
    });
    $("#searchName").bind("input propertychange", function (event) {
      getProjectList(userMobile);
    });
})

function getProjectList(userMobile) {
    $.ajax({
        url: $("#contextPath").val() + "/wechat/newneigou/companyList",
        type: "POST",
        dataType: "json",
        data: {
          userMobile: userMobile,
          virName: $("#searchName").val()
        },
        success: function (data) {
            if (data.code == "200") {
                console.log(data.data);
                cityList = data.data;
                $('.city').html('');
                $(".letter-list").html('');
                var html = '';
                var letter = '';
                $.each(cityList, function (i, item) {
                  if(item.data.length > 0){
                    html += '<div class="city-list"><span class="city-letter" id="' + item.key + '1">' + item.key + '</span>';
                    $.each(item.data, function (j, data) {
                      html += '<p data-mobile="'+data.userMobile+'" data-userid="'+data.userId+'" data-orgid="'+data.orgId+'" data-virid="' + data.virId + '" class="item" data-name="' + data.virName + '">' + data.virName + '</p>';
                    })
                    html += '</div>';
                    letter += '<li style="height: 18px;"><a href="javascript:;" style="font-size: 12px;">' + item.key + '</a></li>';  
                  }else{
                    letter += '<li style="height: 18px;"><a href="javascript:;" style="color: #999999;font-size: 12px;">' + item.key + '</a></li>';  
                  }             
                })
                $(".letter-list").append(letter);
                $('.city').append(html);
                $(".item").on("click", function () {
                    var virId = $(this).data("virid");
                    var orgId = $(this).data("orgid");
                    var userId = $(this).data("userid")
                    var userMobile = $(this).data("mobile");
                    window.location.href = $("#contextPath").val() + "/wechat/newneigou/indexPage?orgId="+orgId+"&virId="+virId+"&userId="+userId+"&userMobile="+userMobile+"&openId="+openId;
                })
            } else {
//                alert(data.msg)
            }
        },
        error: function (data) {
//            alert("系统繁忙..");
        }
    });
}