var objAjax=new JAjax();
function pageLoad(){
	 loadBodyclick();
	 var tools=new toolsClass();
	 tools.add("","过期未签收","singnFor.runSign(2)","超过签收时间未完成签收");
	 tools.add("","未签收","singnFor.runSign(1)","是在签收时间内未完成签收");
	 tools.add("","全部未签收","singnFor.runSign(0)","超过签收时间未完成和是在签收时间内未完成签收");
	 tools.add("","生成Excel","singnFor.runExcel()","生成Excel");
	 tools.add("","清空签收表","singnFor.clearSign()","清空签收表");
	 tools.create(toolsDiv);
	 var dt=new Date();		
	 var nowDateSystem=dt.toLocaleString();
	 var index=nowDateSystem.indexOf("月");
	 var indexD=nowDateSystem.indexOf("日");
	 $("selectTime").value=nowDateSystem.substring(0,4)+"-"+(nowDateSystem.substring(5,index)-1)+"-"+nowDateSystem.substring(index+1,indexD);         
	 writeFettleLeft("提示:用鼠标选择行,然后进行相应的操作"); //状态栏提示
	 singnFor.nowPage=1;
	 singnFor.pageSize=13;//每页的大小
	 singnFor.create(); 
}

function selDate(thisObj){
	var d=openSelectDate("../../");
	if(d!="" & d!=null&typeof d!="undefined"){  
		if(thisObj.type=="button"){                  
			thisObj.previousSibling.value=d;
			singnFor.nowPage=1;
			singnFor.create();
		}
	}
}  

function singnForJS(){//基础参数
	var pageCount=0;//总记录数
	var pageSize=20;//每页的大小
	var nowPage=1;//当前页码
	var saveDateArray=new Array();
	var selArray=new Array();//当前被选择的行
}

singnForJS.prototype.clearSign=function(){//清空签收表
	if(confirm("此操作会清空所有的用户签收记录\r\n\n你确定要这么做吗?")){
		var out=objAjax.getText("post","signStatistics.aspx?type=clearSign",null,null);
		if(out=="ok"){
			alert("清空成功");
			this.create();
		}else{
			alert(out)
		}
	}
}

singnForJS.prototype.runExcel=function(){//生成Excel
	if(singnFor.selArray){
		if($("selectTime").value!=""&&$("selectTime").value!=null){
			var isShow=1;//不显示
			if(selectTime.nextSibling.nextSibling.checked){
				isShow=0;	
			}
			var objResponse=new JHttpResponse();
			objResponse.write("selDate",$("selectTime").value);	
			objResponse.write("isShow",isShow);	
			var out=objAjax.getText("post","signStatistics.aspx?type=runExcel",objResponse,null);
			if(out.indexOf(".xls")>-1){
				$("runExcel").href=out;
				$("runExcel").click();
			}else{
				alert(out)
			}
		}else{
			alert("非法进入");	
		}
	}else{
		alert("当前无任务数据\r\n请点击选择进行查找");	
	}
}
singnForJS.prototype.checkCilck=function(){
    this.nowPage=1;
    this.create();
}
singnForJS.prototype.runSign=function(type){//签收正常需要签收的
	if(singnFor.selArray){
		if(singnFor.selArray.length>0){
			var signUser="";
			for(var i=0;i<singnFor.selArray.length;i++){
				signUser+=singnFor.selArray[i].id+c1;
			}
			if(signUser.indexOf(c1)>-1){
				signUser=signUser.substring(0,signUser.lastIndexOf(c1));
				var objnum=parent.win.objNum;
				par="wNum="+objnum+"&runType="+type+"&signUser="+signUser+"&nowTime="+$("selectTime").value;
				parent.win.pCreate("p-signed",par,"",true);
			}
		}else{
			alert("请选择要签收的单位");	
		}
	}else{
		alert("当前无任务数据\r\n请点击选择进行查找");	
	}
}

singnForJS.prototype.create=function(){//读取消息
	this.saveDateArray=new Array();
	var cTable=$("bodyDiv");
	var divPages=$("divPages");
	var selectTime=$("selectTime");
	if(selectTime.value==""&&selectTime.value==null){
		return;	
	}
	var isShow=1;//不显示
	if(selectTime.nextSibling.nextSibling.checked){
		isShow=0;	
	}
	var objResponse=new JHttpResponse();
	objResponse.write("nowPage",this.nowPage);	
    objResponse.write("pageSize",this.pageSize);
	objResponse.write("selTime",selectTime.value);
	objResponse.write("isShow",isShow);	
	var out=objAjax.getText("post","signStatistics.aspx?type=readSingnFor",objResponse,null);
	if(out.indexOf(c3)>-1){
		this.selArray=new Array();
		out=out.split(c3);
		this.pageCount=out[1];//总页数
		this.saveDateArray=out[0].split(c2);
		if(cTable.childNodes.length>0){
			cTable.firstChild.removeNode(true);
		}
		divPages.innerHTML="";		
		var t=new createOurTitle();
		t.add("签收用户名","left","380");
		t.add("共需签收量","center","80");
		t.add("已签收","center","80");
		t.add("过期已签收","center","80");
		t.add("过期未签收","center","80");
		t.add("未签收","center","80");
		t.table=cTable;
		t.create();
		var tr=null;
		for(var i=0;i<this.saveDateArray.length;i++){
			tr=cTable.insertRow();
			var tSplit=this.saveDateArray[i].split(c1);
			tr.setAttribute("id",tSplit[0]);
			for(var j=0;j<tSplit.length;j++){
				var createTD=tr.insertCell();
				if(j==0){
					createTD.style.cssText="text-align:left;padding-left:10px;height:23px;width:380px;";
				}else{
					createTD.style.cssText="text-align:center;height:23px;width:100px;";
				}
				createTD.appendChild(document.createTextNode(tSplit[j]));
			}
			tr.onmouseover=function(){
				for(var i=0;i<this.childNodes.length;i++){
					this.childNodes[i].className="listTitleOption_1Other";	
				}
			}
			tr.onmouseout=function(){
			   var isBool=false;
			   if(singnFor.selArray!=null){
				   for(var j=0;j<singnFor.selArray.length;j++){
						if(singnFor.selArray[j]==this){
							isBool=true;	
							break;
						}
					}
			   }
			   if(isBool==false){
					for(var i=0;i<this.childNodes.length;i++){
						this.childNodes[i].className="listBodyOptionOther";	
					}
				}
			}
			tr.onclick=function(){
				var isBool=false;
				if(parseInt(this.childNodes[4].innerText)==0&&parseInt(this.childNodes[5].innerText)==0){
					return;	
				}
				if(singnFor.selArray==null||singnFor.selArray==""){
					singnFor.selArray=new Array();
					singnFor.selArray.push(this);
					return ;
				}
				for(var i=0;i<singnFor.selArray.length;i++){
					if(singnFor.selArray[i]==this){
							singnFor.selArray.splice(i,1);
							isBool=true;
							break;
					}
				}
				if(isBool==false){
					singnFor.selArray.push(this);
				}
			}
		}
		//分页写入开始
		var pages=parseInt(this.pageCount/this.pageSize);
		if(this.pageCount%this.pageSize>0){
			pages=pages+1;	
		}
		divPages.appendChild(document.createTextNode("一共有"+this.pageCount+"条,分"+pages+"页,第"+this.nowPage+"页"));
		
		var cPage=document.createElement("span");
		cPage.setAttribute("title","首  页");
		cPage.style.cssText="padding-left:10px;cursor:hand;";
		cPage.innerHTML="首  页";	
		if(pages>1&&this.nowPage>1){
		   cPage.onclick=function(){
			   singnFor.nowPage=1;
			   singnFor.create();
		   }
		}else{
			cPage.style.cssText="padding-left:10px;color:#C0C0C0;";
		}
		divPages.appendChild(cPage);
		
		cPage=document.createElement("span");
		cPage.setAttribute("title","下一页");
		cPage.style.cssText="padding-left:10px;cursor:hand;";
		cPage.innerHTML="下一页";
		if(pages>1&&this.nowPage<pages){
		   cPage.onclick=function(){
			   singnFor.nowPage=parseInt(singnFor.nowPage)+1;
			   singnFor.create();
		   }
		}else{
			cPage.style.cssText="padding-left:10px;color:#C0C0C0;";
		}
		divPages.appendChild(cPage);
		
		cPage=document.createElement("span");
		cPage.setAttribute("title","上一页");
		cPage.style.cssText="padding-left:10px;cursor:hand;";
		cPage.innerHTML="上一页";
		if(pages>1&&this.nowPage>1){
		   cPage.onclick=function(){
			   singnFor.nowPage=parseInt(singnFor.nowPage)-1;
			   singnFor.create();
		   }
		}else{
			cPage.style.cssText="padding-left:10px;color:#C0C0C0;";
		}
		divPages.appendChild(cPage)
		
		cPage=document.createElement("span");
		cPage.setAttribute("title","尾  页");
		cPage.style.cssText="padding-left:10px;cursor:hand;";
		cPage.innerHTML="尾  页";
		if(pages>1&&this.nowPage<pages){
		   cPage.onclick=function(){
			   singnFor.nowPage=pages;
			   singnFor.create();
		   }
		}else{
			cPage.style.cssText="padding-left:10px;color:#C0C0C0;";
		}
		divPages.appendChild(cPage)
		var runTime=document.createElement("span");
		runTime.style.cssText="color:#FF0000;padding-left:25px;"
		runTime.innerHTML="页面运行总时间"+out[2]+"毫秒";
		divPages.appendChild(runTime);
		
	}else{
		if(cTable.childNodes.length>0){
			cTable.firstChild.removeNode(true);
		}
		divPages.innerHTML="<p style='color:#FF0000;'>从"+$("selectTime").value+"到现在没有相应的信息</p>";		
	}
}

function createOurTitle(){//创建表头
   var title=new Array();  
   this.setW=0;
   var wAll=0;
   var table=null;
   this.add=function(titleText,clickText,width){
	   var l=title.length;
	   title[l]=new Array();
	   title[l][0]= titleText;
	   title[l][1]=clickText;
	   title[l][2]=width;
   }
   this.create=function(){
		if (this.table==null){
			  return  null;
		}
		var createTR=this.table.insertRow();
		for (var i=0;i<title.length;i++){
			
			var createTD=createTR.insertCell();
			createTD.appendChild(document.createTextNode(title[i][0]));
			if(i==0){
			createTD.style.cssText="width:"+title[i][2]+"px;text-align:"+title[i][1]+";padding-left:10px;";
			}else{
			createTD.style.cssText="width:"+title[i][2]+"px;text-align:"+title[i][1]+";";
			}
			createTD.className="titleRow";
			createTD.onmouseover=function(){
				this.className="listTitleOption_1Other";
			}
			createTD.onmouseout=function(){
				this.className="titleRow";
			}
		}
	}
}
