var pageCount;//总页数
var currentPage;//当前页

//用户信息列表
function userInfoList(page)
{
	currentPage = page;
	$('#currentPage').text(currentPage);//显示当前页码
	var supermanstatus = $('#supermanstatus').val();
	var userNickName = $('#userNickName').val();
	var unionId = $('#unionId').val();
	var cardAccount = $('#cardAccount').val();
	var realName = $('#realName').val();
	var idCardNumber = $('#idCardNumber').val();
	var userTel = $('#userTel').val();
	var bank = $('#bank').val();
	var loginTimes = $('#loginTimes').val();
	$.ajax
	({
		url:'././userInfoAction.do?action=userInfoList&page='+page+'&userNickName='+encodeURIComponent(userNickName)+'&cardAccount='+encodeURIComponent(cardAccount)+'&realName='+encodeURIComponent(realName)+'&idCardNumber='+idCardNumber+'&userTel='+userTel+"&bank="+encodeURIComponent(bank)+"&unionId="+unionId+"&loginTimes="+loginTimes+"&supermanstatus="+encodeURIComponent(supermanstatus),
		type:'GET',
		error:function(){alert('网络连接异常！！！')},
		success:function(data)
		{
			data = eval("("+data+")");
			var items = data.items;//对应Action层的json的数据格式,属性是items,记录对象
			var count = data.count;//对应Action层的json的数据格式,属性是count,总记录数
			pageCount = data.pageCount;//对应Action层的json的数据格式,属性是pageCount,每页显示的记录数
			$('#num_id').text(count);//总记录数
			$('#pageNum').text("共"+pageCount+"页");//共多少页
			$('.context').empty();
			for(var i=0; i<items.length; i++)
			{
				var trNode ="";
				if(userName=='cpzg360'|| userName=='cpzg362'){
					 trNode =
						"<tr>"+
						"<input type='hidden' value='"+items[i].userNickName+"' id='userNickName'/>"+
						"<td align='center' class='tab_content'>"+items[i].userId+"</td>"+
						"<td align='center' class='tab_content'>"+items[i].userNickName+"</td>"+
						"<td align='center' class='tab_content'>"+items[i].realName+"</td>"+
						"<td align='center' class='tab_content'>"+items[i].idCardNumber+"</td>"+
						"<td align='center' class='tab_content'>"+items[i].cardAccount+"</td>"+
						"<td align='center' class='tab_content'>"+items[i].bank+"</td>"+
						"<td align='center' class='tab_content'>"+items[i].userTel+"</td>"+
						"<td align='center' class='tab_content'>"+items[i].loginTimes+"</td>"+
						"<td align='center' class='tab_content'>"+items[i].supermanstatus+"</td>"+
						"<td align='center' class='tab_content'>"+items[i].unionId+"</td>"+
						"<td align='center' class='tab_content'>"+
						"<input type='button' value='修改用户' onclick='getUserInfo(this)'/>"+
						"</td>"+
						"</tr>";
				}
				else{
					 trNode =
						"<tr>"+
						"<input type='hidden' value='"+items[i].userNickName+"' id='userNickName'/>"+
						"<td align='center' class='tab_content'>"+items[i].userId+"</td>"+
						"<td align='center' class='tab_content'>"+items[i].userNickName+"</td>"+
						"<td align='center' class='tab_content'>"+items[i].realName+"</td>"+
						"<td align='center' class='tab_content'>"+items[i].idCardNumber+"</td>"+
						"<td align='center' class='tab_content'>"+items[i].cardAccount+"</td>"+
						"<td align='center' class='tab_content'>"+items[i].bank+"</td>"+
						"<td align='center' class='tab_content'>"+items[i].userTel+"</td>"+
						"<td align='center' class='tab_content'>"+items[i].loginTimes+"</td>"+
						"<td align='center' class='tab_content'>"+items[i].supermanstatus+"</td>"+
						"<td align='center' class='tab_content'>"+items[i].unionId+"</td>"+
						"<td align='center' class='tab_content'>"+
						"<input type='button' value='修改用户' disabled='disabled'/>"+
						"</td>"+
						"</tr>";
				}
				$('.context').append(trNode);
			}
			$('#data tbody tr:even').css("backgroundColor","#CCCCCC");
		}
	});
}

//页数操作
function checkPage(_this)
{
	var tmpPage = 1;
	if($(_this).attr('id')=='aa'){
		tmpPage = pageCount;
	}else if($(_this).attr('id')=='back'){
		if (currentPage > 1){
			tmpPage = currentPage-1;
		}
	}else if($(_this).attr('id')=='next'){
		if (currentPage < pageCount){
			tmpPage = currentPage+1;	
		}
		if (currentPage >= pageCount){
			tmpPage = pageCount;	
		}
	}
	userInfoList(tmpPage);
}

function load()
{
	userInfoList(1);
}
//Excel导出所有的用户列表  左国斌 2014-5-20
function exportUserInfoList()
{
	
	var supermanstatus = $('#supermanstatus').val();
	var userNickName = $('#userNickName').val();
	var cardAccount = $('#cardAccount').val();
	var realName = $('#realName').val();
	var idCardNumber = $('#idCardNumber').val();
	var userTel = $('#userTel').val();
	var bank = $('#bank').val();
	var loginTimes = $('#loginTimes').val();
	
	window.location.href='././userInfoAction.do?action=ExportUserInfoList&userNickName='+encodeURIComponent(userNickName)+'&cardAccount='+cardAccount+'&realName='+encodeURIComponent(realName)+'&idCardNumber='+idCardNumber+'&userTel='+userTel+"&bank="+bank+"&loginTimes="+loginTimes+"&supermanstatus="+encodeURIComponent(supermanstatus);
}

//获取用户
function getUserInfo(_this){
	var trNode = $(_this).parent().parent();
	var userNickName = trNode.find("#userNickName").val();
	userNickName =encodeURI(userNickName);//用户昵称
	//alert(userNickName);
	$.ajax({
		url:'././userInfoAction.do?action=getUserInfo&userNickName='+userNickName+'&r='+Math.random(),
		type:'GET',
		error:function(){alert('无此用户！！！')},
		success:function(w_list){
			//alert(w_list)
			//var items= w_list.items;

			var Item=eval("("+w_list+")");

			//alert(Item);
			
			var items=Item.items;
			
			//alert(items);
			
			$('#userNickName_').val(items[0].userNickName);
			$('#cardAccount_').val(items[0].cardAccount);
			$('#bank_').val(items[0].bank);
			$('#idCardNumber_').val(items[0].idCardNumber);
			$('#userTel_').val(items[0].userTel);
			$('#refId').val(items[0].refId);
			$('#refOrderDate').val(items[0].refOrderDate);
			$('#refRegisterDate').val(items[0].refRegisterDate);
			$('#refCallBack').val(items[0].refCallBack);
			$('#refRate').val(items[0].refRate);
			$('#userType').val(items[0].userType);
			$('.userInfo_div').show();
		}
});
}
function cannel(){
	$('.userInfo_div').hide();
}
//修改用户和密码
function update(){
	var userNickName= $('#userNickName_').val();
	var cardAccount=$('#cardAccount_').val();
	var bank=$('#bank_').val();
	var idCardNumber=$('#idCardNumber_').val();
	var userTel=$('#userTel_').val();
	var passWord=$('#passWord').val();
	var refId = $('#refId').val();
	var refOrderDate= $('#refOrderDate').val();
	var refRegisterDate= $('#refRegisterDate').val();
	var refCallBack= $('#refCallBack').val();
	var refRate= $('#refRate').val();
	var userType =  $('#userType').val();
	
	$.ajax
	({
		url:'././userInfoAction.do?action=update&userNickName='+encodeURIComponent(userNickName)+'&cardAccount='+encodeURIComponent(cardAccount)+'&bank='+encodeURIComponent(bank)+'&idCardNumber='+idCardNumber+'&userTel='+userTel+'&passWord='+passWord+'&refId='+refId+'&refOrderDate='+refOrderDate+'&refRegisterDate='+refRegisterDate+'&refCallBack='+refCallBack+'&refRate='+refRate+'&userType='+userType,
		type:'GET',
		error:function(){alert('修改用户失败！！！')},
		success:function(data)
		{
			if (data == '0000')
			{
				alert("修改成功！！！");
				cannel();	
			}
			
			userInfoList(currentPage);
		}
	 });
}
