<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html>
<html>
<head>
<title>员工信息管理</title>
<meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
<!-- bootstrap 3.0.2 -->
<link href="<c:url value='/styles/lib/bootstrap.min.css'/>" rel="stylesheet" type="text/css" />
<!-- font Awesome -->
<link href="<c:url value='/styles/lib/font-awesome.min.css'/>" rel="stylesheet" type="text/css" />
<!-- Ionicons -->
<link href='<c:url value='/styles/lib/ionicons.min.css' />' rel="stylesheet" type="text/css" />
<!-- DATA TABLES -->
<link href="<c:url value='/styles/lib/datatables/dataTables.bootstrap.css' />" rel="stylesheet" type="text/css" />
<!-- Theme style -->
<link href="<c:url value='/styles/AdminLTE.css'/>" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<c:url value='/scripts/lib/jquery-1.8.2.min.js'/>"></script>
<script type="text/javascript">
	$(function(){
		$("#btn-search").bind("click",function(){
			$("#conditionform").submit();
		});
		//初始化校区
		initOrganization()
	});
	
	function dele(id){
		if(confirm("确定删除员工信息？")){
			window.location.href="delete/"+id+"&"+$("#funcid").val();
		}	
	}
	
	//修改员工信息
	function update(staffId,funcid){
		window.location.href="form?staffId="+staffId+"&funcid="+funcid;
	}
	
	//修改员工信息
	function add(funcid){
		window.location.href="form?funcid="+funcid;
	}
	
	//初始化校区列表
	function initOrganization(){
		var contextPath=$("#contextPath").val();
		var companyId = $("#companyId").val();
		if(companyId!=null&&companyId!=""){
			$.ajax({
				url: contextPath+"/busi/property/getOrganizationListByCompId",
				type: "POST",
				data:{companyId:companyId},
				success: function(data){
					var htmStr="";
					var organizationId=$("#organizationId");
					var organizationId_=$("#organizationId_").val();
					organizationId.empty();
					if(data.length>0){
						htmStr+="<option value=''>请选择校区</option>";
						$.each(data,function(index,obj){
							if(obj.id==organizationId_){
								htmStr+="<option value='"+obj.id+"' selected='selected'>"+obj.name+"</option>";
							}
							else{
								htmStr+="<option value='"+obj.id+"' >"+obj.name+"</option>";
							}
						});
					}
					else{
						htmStr="<option value='' >当前运营中心暂无校区</option>";
					}
					organizationId.append(htmStr);
				},
				error: function(data){
				}
			});
		}
		else{
			var organizationId=$("#organizationId");
			organizationId.empty();
			var htmStr="<option value=''>请选择校区</option>";
			organizationId.append(htmStr);
		}
	}
	
	//翻页
	function goPage(pageNo){
		showBlock();
		if(pageNo=="gopage"){
			$("#pageNo").val($("#gopage").val());
		}else{
			$("#pageNo").val(pageNo);
		}
		$("#conditionform").submit();
	}
</script>
</head>
<body>
	<input type="hidden" value="${ctx}" id="contextPath">
	<input type="hidden" id="funcid" value="${funcid}">
	<input type="hidden" id="organizationId_" value="${organizationId}">
	<section class="">
		<div class="row">
			<div class="col-xs-12">
				<div class="boxlist">
					<!-- /.box-header -->
					<div class="box-body table-responsive">
						<form action="<c:url value='/admin/staff/list?funcid=${funcid}' />" method="POST" id="conditionform">
							<input type="hidden" id="pageNo" name="pageNo" />
							<div class="form-group">
                                <label>运营中心</label>
								<select name="companyId"  id="companyId" style="width:160px;margin-left:5px;" onchange="initOrganization()">
                                	<option value="">请选择运营中心</option>
                                	<c:forEach items="${companys}" var="company">
                                		<option value="${company.id }" <c:if test="${company.id == companyId }">selected="selected"</c:if>>${company.name }</option>
                                	</c:forEach>
                                </select>
                                ~
                                <label>校区</label>
								<select name="organizationId"  id="organizationId" style="width:160px;margin-left:5px;">
                                	<option value="">请选择校区</option>
                                </select>
                                
                                <label>关键字</label>
                                <input type="text" name="keyword" value="${keyword}" placeholder="请输入员工姓名/工号/电话号码" style="width:260px;">
                               	
                               	<label>在职状态</label>
                                <select name="staffStatus">
                                	<option value="">请选择</option>
                                	<c:forEach items="${staffStatusGroup}" var="obj">
                                		<c:if test="${obj.itemcode==staffStatus }">
                                			<option value="${obj.itemcode }" selected="selected">${obj.itemname}</option>
                                		</c:if>
                                		<c:if test="${obj.itemcode!=staffStatus }">
                                			<option value="${obj.itemcode }" >${obj.itemname}</option>
                                		</c:if>
                                	</c:forEach>
                                </select>
                            </div>
                            <span style="float:right;">
                               	<a class="btn btn-default" href="#" id='btn-search'>查询</a>
                               	<c:if test="${addAct =='1' }">
                               	<a class="btn btn-success" href="#" onclick="add(${funcid});">新增</a>
                               	</c:if>
                       		</span>
						</form>
						<table id="example2" class="table table-bordered table-hover">
							<thead>
								<tr>
									<th>序号</th>
									<th>工号</th>
									<th>姓名</th>
									<th>手机</th>
									<th>职位</th>
									<th>运营中心</th>
									<th>状态</th>
									<th>操作</th>
								</tr>
							</thead>
							<tbody>
								<c:forEach items="${page.items}" var="model" varStatus="status">
									<tr>
										<td>${ (page.currentPage-1)*page.pageSize+(status.index+1)}</td>
										<td>${model.staffNo}</td>
										<td>${model.name}</td>
										<td>${model.userMobile}</td>
										<td>
											<c:forEach items="${staffPostGroup}" var="obj">
												<c:if test="${model.position == obj.itemcode}">${obj.itemname }</c:if>
											</c:forEach>
										</td>
										<td>${model.companyName}-${model.deptName }</td>
										<td>
											<c:forEach items="${staffStatusGroup}" var="obj">
												<c:if test="${model.status == obj.itemcode}">${obj.itemname }</c:if>
											</c:forEach>
										</td>
										<td>
											<c:if test="${updateAct =='1' }">
											<a href="#" onclick="update(${model.id},funcid=${funcid});" title="修改">
                                        		修改
                                    		</a>
                                    		</c:if>
                                    		<c:if test="${deleteAct =='1' }">
                                    		<a href="javascript:dele('${model.id}');" title="删除">
                                    			删除
                                    		</a>
                                    		</c:if>
                                    	</td>
									</tr>
								</c:forEach>
							</tbody>
						</table>
						<div class="btn-page">
		                    <!-- 页码 -->
		                    <div align="center" class="pages clearfix">
		                           <c:forEach items="${page.iterPages }" var="pageNo">
									<c:choose>
										<c:when test="${pageNo == page.currentPage }">
											<span class='current'>${pageNo }</span>
										</c:when>
										<c:when test="${pageNo != null}">
											<a href="javascript:void(0);" onclick='goPage(${pageNo});'>${pageNo}</a>
										</c:when>
										<c:otherwise>
											<em>...</em>
										</c:otherwise>
									</c:choose>
								</c:forEach>
								<strong>共<span style="color:black;font-weight:bold;font-size:16px;">${page.totalCount}</span>条</strong>
								<strong>跳转到第</strong><input type="text" id="gopage" style="width: 40px;" onkeyup="this.value=this.value.replace(/\D/g,'')" onkeypress="this.value=this.value.replace(/\D/g,'')"/><strong>页</strong>
								<a class="btn-sm btn-success" href="javascript:goPage('gopage');" id='bindBtn'>确定</a>
		                	</div>
			            </div>
					</div>
					<!-- /.box-body -->
				</div>
			</div>
		</div>
	</section>
</body>
</html>