<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	response.setHeader("Pragma","No-cache");    
	response.setHeader("Cache-Control","no-cache");    
	response.setDateHeader("Expires", -10);  
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@include file="/WEB-INF/views/base.jsp"%>
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>角色用户管理</title>
   	<%@include file="/WEB-INF/views/common_base_css.jsp"%>
</head>

<body>
	<input type="hidden" id="basePath" value="<%=basePath %>"  >
    <div id="wrapper">

    	<jsp:include page="../menu.jsp"></jsp:include>
			
        <div id="page-wrapper" class="gray-bg">
        	<jsp:include page="../head.jsp"></jsp:include>
        	<jsp:include page="../pageNav.jsp"></jsp:include>
        	
        	<input type="hidden" id="pageNo"  name="pageNo" value="1" >
            <!-- 页面 主题内容  开始-->
	        <div class="wrapper wrapper-content animated fadeInRight">
	        <div class="row">
	        	      
	            <!-- 查询条件 开始 -->
				<input type="hidden" value="${roleId }" name="roleID" id="roleID">
	            <div class="ibox-content m-b-sm border-bottom">
			        <div class="row">
			            <div class="col-sm-4">
			                <div class="form-group">
			                    <label class="control-label" for="username">姓名</label>
			                    <input type="text" id="Username" name="UserName" value="" placeholder="姓名" class="form-control">
			                </div>
			            </div>
			            <div class="col-sm-4">
			                <div class="form-group">
			                    <label class="control-label" for="employeeNo">员工号</label>
			                    <input type="text" id="Employeeno" name="employeeno" value="" placeholder="员工号" class="form-control">
			                </div>
			            </div>
			            <div class="col-sm-4">
			                <div class="form-group">
			                    <label class="control-label" for="search">查询</label>
			                    <button onclick="query()" class="btn btn-w-m btn-success form-control"><i class="fa fa-search"></i>&nbsp;&nbsp;查询</button>
			                </div>
			            </div>
			        </div>
				</div>
	            <!-- 查询条件 结束 -->
	            
				
				<!-- 用户列表开始 -->
	            <div class="ibox float-e-margins">
	            	<div class="ibox-title">
				       <div class="ibox-tools">
			                 <a href="javascript:void(0)" onclick="history.go(-1)">
			                     <i class="fa fa-mail-forward"></i>&nbsp;&nbsp;返回
			                 </a>
			           </div>
				    </div>
				    <div class="ibox-content" id="UserListPartial">
					</div>
	            </div>
	        </div>    
	        </div>
	        <!-- 页面主题内容 结束 -->
        </div>
    </div>


    <!-- Mainly scripts -->
    <%@include file="/WEB-INF/views/common_base_script.jsp"%>

<script type="text/javascript">
	var basePath = "<%=basePath %>";
    function initData(){
        var UserName = $("#Username").val();
	    var EmployeeNo = $("#Employeeno").val();
	    var pageNo = $("#pageNo").val();
	    var RoleID = $("#roleID").val();
		//第一次加载数据
		$.ajax({
			type : 'POST',
			async : false,
			url : basePath + 'sysRole/loadRoleUsers',
			data : {'pageNo' : pageNo, 'UserName':UserName, 'EmployeeNo': EmployeeNo,'RoleID':RoleID },
			dataType : 'html',
			success : function(data){
				$("#UserListPartial").html(data);
			}
		});
     }
	
    $(function(){
    	initData();
    	
    	//删除角色关联用户
    	$("#UserListPartial").delegate(".delete_role_user", "click", function(){
    		var roleid = $("#roleID").val();
    		var userid = $(this).attr("id");
    		var username = $(this).attr("username");
    		swal({
	            title: "删除角色关联用户【" + username + "】？",
	            text: "确认删除？",
	            type: "warning",
	            showCancelButton: true,
	            confirmButtonColor: "#DD6B55",
	            confirmButtonText: "确定",
	            cancelButtonText: "取消",
	            closeOnConfirm: false
	        }, function () {
	            $.post("deleteUserByRole", { "roleId": roleid, "userId": userid }, function (data) {
	                if (data == 0) {
	                    swal("删除失败!", "删除角色关联用户删除失败，请重试！", "error");
	                } else {
	                    //window.location.reload();
	                    swal("删除成功!", "删除角色关联用户删除完成！", "success");
	  					var trs = $("#main_data").find("tr");
						var pageNo = parseInt($("#pageNo").val());
						if(trs.length == 1){
							pageNo--;
						}
						queryEvent(pageNo);
	                }
	            })
	        });
    	})
    })
    
	
	function query(){
       $("#pageNo").val("1");
       initData();
    }
</script>   
</body>

</html>