var contextPath="";
var visitPrefix="";
var currentPage=1;
$(document).ready(function(){
	contextPath = $("#contextPath").val();
	var userId = $("#userId").val();
	var organizationId = $("#organizationId").val();
	var virtualArchitectureId = $("#virtualArchitectureId").val();
	
	//跳转新签约
	$("#addSignContract").click(function(){
		var userId = $("#userId").val();
//		if(virtualArchitectureId == null || virtualArchitectureId == ""){
//			window.location.href=contextPath+"/wechat/signContract/signEnterprise?userId="+userId
//		}else{
//			window.location.href=contextPath+"/wechat/signContract/toOrderSeviceselectitem?userId="+userId+"&organizationId="+organizationId+"&virtualArchitectureId="+virtualArchitectureId;
//		}
		window.location.href=contextPath+"/wechat/signContract/enterpriseContractInquiry?userId="+userId;
	});
	
	//默认加载
	query('1',userId);
	visitPrefix=$("#visitPrefix").val();
    refresher.init({
        id:"wrapper",
        pullDownAction:Refresh,
        pullUpAction:Load               
    });
   
// 下拉刷新                                                   
function Refresh() {
    setTimeout(function () {    // <-- Simulate network congestion, remove setTimeout from production!
    	currentPage=1;
    	query('1',userId);
        
        document.getElementById("wrapper").querySelector(".pullDownIcon").style.display="none";     
        document.getElementById("wrapper").querySelector(".pullDownLabel").innerHTML="<img class='refresh-img' src='"+contextPath+"/plugin/refresher/refresher_images/ok.png'/>刷新成功";
        setTimeout(function () {
        	wrapper.refresh();
            document.getElementById("wrapper").querySelector(".pullDownLabel").innerHTML="";                                
            },1000);
    }, 1000);
}
// 上拉加载
function Load() {
    setTimeout(function () {
        query('2',userId);
//        wrapper.refresh();
    },2000);    
}
});

/**
 * @param actType   操作类型，默认0，下拉刷新1，上拉加载2
 * @param userId    用户ID
 */
function query(actType,userId){

	var userId = $("#userId").val();
	$.ajax({
		url :contextPath+"/wechat/signContract/contractList",
		type : "POST",
		data : {"userId":userId,"pageNo":currentPage},
		dataType:"json",
		success : function(data) {
			var ulcontainer=$('#ulcontainer');
			if(data.page == null || data.page == ""){
				return;
			}
			if("1"==actType){
				ulcontainer.html("");
			}
			var items=data.page.pageList;
			if(items.length>0){
				currentPage=currentPage+1;
			}
			var strHTML="";
			if(items.length <= 0 && actType != 2){
				$('#wrapper').hide();
				$('.nothing').remove();
				$('.pullUp').hide();
				strHTML ="<div class='nothing' style='height: 26rem; background: #fff;text-align:center;'>"
					+"<img src="+contextPath+"/images/nothingapply.png alt='' /><br>"
					+"<span>暂无数据</span></div>";
				$('.div_net').after(strHTML);
				return;
			}
			$('#wrapper').show();
			$('.nothing').remove();
			$('.pullUp').show();
			$.each(items,function(index,item){
				var customerNumber=item.customerNumber;
				var effectiveTime=item.effectiveTime;
				var serviceName=item.serviceName;
				var name=item.name;
				strHTML+="<li><div class='enterpriseContent'><div class='enterpriseId'>"
					   +"<span class='item_title'>企业编号:</span>"
					   +"<div class='contractContent'>"+customerNumber+"</div>"
					   +"<div class='enterTime'>"+effectiveTime+"</div></div>"
					   +"<div class='enterpriseName'>"
					   +"<span class='item_title'>企业名称:</span>"
					   +"<div class='contractContent'>"+name+"</div></div>"
					   +"<div class='enterpriseSevice'>"
					   +"<span class='item_title'>签约服务:</span>"
					   +"<div class='contractContent'>"+serviceName+"</div></div>"
					   +"</div></li>";
			});
			ulcontainer.append(strHTML);
			
			wrapper.refresh();
		},
		error : function(data) {
			// alert("系统繁忙，请稍后再试.");
		}
	});

}