<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>首页</title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<!-- 加载公共的样式，主要作用是清除浏览器的一些默认样式，页面公共排版，包括头部以及一些组件样式   -->
<%@ include file="/include/header2.jsp"%>
<%@ include file="/include/taglib.jsp" %>
<link type="text/css" rel="stylesheet" href="${ctx}/css/index.css" />
<link type="text/css" rel="stylesheet" href="${ctx}/css/baseFrame.css" />
<!-- 加载树-->
<%@ include file="/include/zTree.jsp" %>
<!-- 模块化框架配置 -->
<script type="text/javascript">
    // seajs 的简单配置
    seajs.config({
        base: "${ctx}/js",
        alias: {

        }
    });
</script>
<style type="text/css">
div#rMenu {position:absolute; visibility:hidden; top:0; background-color: #555;text-align: left;padding: 2px;}
div#rMenu ul li{
	margin: 1px 0;
	padding: 0 5px;
	cursor: pointer;
	list-style: none outside none;
	background-color: #DFDFDF;
}
	.page a {
		color: #333;
	}
	input.page_input{
		border:1px solid #ddd;
	}
</style>
</head>
<body>
	<div id="menuContent" class="menuContent" style="display:none; position: absolute;background-color: white;">
		<ul id="treeDemo" class="ztree" style="margin-top:0; width:160px;"></ul>
	</div>
	
	<div>
  		<div class="b_box">
		<form id="sysUserForm" action="post">
		   	<input type="hidden" name="checkId" id="checkId" value="" style="width:100%;height:180px"/>
		   	<input type="hidden" name="checkId" id="checkId2" value="" style="width:100%;height:180px"/>
		    <input type="hidden" name="deptId" id="deptId" value="" />
		    <input type="hidden" name="deleteFlag" id="deleteFlag" value="-1" />

		</form>

		<div class="action_box m_t10 t_c" id="queryDiv" style="overflow:hidden;">
			<!-- 查询条件 : 注意加上 data-qname -->
			<!-- 行政级别编码: <input type="text" data-qname="code" class="input_txt" /> -->
				<div style="text-align:left;">
					<span>
					用户名:
					<input type="text" name="username" id="username" value=""  class="input_txt"/>
					</span>
				
					<span>
					<input type="button" class="btn btn-primary addBtn" value="搜索"  id="searchBtn"/>
					</span>
				</div>
				<div class="action_box m_t10 t_r">
					<span class="action_tit">用户信息:${SysRole.roleName}</span>
				</div>
		</div>

		<div class="action_box m_t10 t_c" id="queryDiv2" style="overflow:hidden;display:none">
			<!-- 查询条件 : 注意加上 data-qname -->
			<!-- 行政级别编码: <input type="text" data-qname="code" class="input_txt" /> -->
			<div style="text-align:left;">
				<span>
					P13账号：
					<input id="username2"type="text" name="roleName" class="input_txt"/>
				</span>
				<span>
			<!--	<hna:permission privilege="sysRole.toAddUser"></hna:permission>-->
					<input type="button" class="btn btn-primary addBtn" value="搜索"  id="searchBtn2"/>
					
				</span>
				<!--<span>
					<input type="button" class="a_btn" value="查询" id="searchBtn" />
				</span>-->
			</div>
			<div class="action_box m_t10 t_r">
			<span class="action_tit1">角色信息/选择用户<!--：${sysUserQueryVo.userCnName}[${sysUserQueryVo.username}]--></span>
			<input type="button" value="保存" id="saveBtn" class="b_btn"/>
			<input type="button" value="取消" id="cancelBtn" class="b_btn"/>
			</div>
		</div>

		<div class="action_box m_t10 t_c" id="queryDiv3" style="overflow:hidden;display:none">
			<!-- 查询条件 : 注意加上 data-qname -->
			<!-- 行政级别编码: <input type="text" data-qname="code" class="input_txt" /> -->
			<div style="text-align:left;">
				<span>
					P13账号：
					<input id="username3"type="text" name="roleName" class="input_txt" value="" data-value=""/>
				</span>
				<span>
			<!--	<hna:permission privilege="sysRole.toAddUser"></hna:permission>-->
					<input type="button" class="btn btn-primary addBtn" value="搜索"  id="searchBtn3"/>
					
				</span>
				<!--<span>
					<input type="button" class="a_btn" value="查询" id="searchBtn" />
				</span>-->
			</div>
			<div class="action_box m_t10 t_r">
			<span class="action_tit2">角色信息/选择用户<!--：${sysUserQueryVo.userCnName}[${sysUserQueryVo.username}]--></span>
			<input type="button" value="保存" id="saveBtn2" class="b_btn"/>
			<input type="button" value="取消" id="cancelBtn2" class="b_btn"/>
			</div>
		</div>
		<table id="tbwrap" class="table_list"></table>
		<div class="page eui-pager-custom" id="j_pager"></div>
		</div>
	</div>
	<script type="text/html" id="tb_template">
	    <thead>
			<tr>
				<th>用户名</th>
				<th>用户中文名称</th>
			</tr>
		</thead>
		<tbody data-type="body" id="queryTable">
    		<!if(list.length>0) { !>
        		<!for(var i=0,len=list.length-1;i<len;i++){
            		var item = list[i],classItem = (i%2!=0)?"odd td_odd":"even";
            		var role=list[list.length-1];
          		!>
		    	<tr class="gradeA <!=classItem!>">
			    	<td><!=item["username"]!></td>
					<td>
						<!=item["userCnName"]!>
						<!if(role["roleName"]=="分中心反欺诈团队长"){!>
							<span style="float: right;">
								<hna:permission privilege="teamUserConfig">
								<button class="btn btn-primary btn-xs addUser"  data-value="<!=role['roleId']!>"  data-id="<!=item['userId']!>"
								data-name="<!=item['username']!>">
								<span class="glyphicon glyphicon-plus" aria-hidden="ture"></span>新增成员</button>
								</hna:permission>
								<hna:permission privilege="teamUserConfig">
								<button class="btn btn-primary btn-xs updateUser"  data-value="<!=role['roleId']!>"  data-id="<!=item['userId']!>" data-name="<!=item['username']!>">
								<span class="glyphicon glyphicon-edit" aria-hidden="ture"></span>更改成员</button>
								</hna:permission>
							</span>
						<!}!>
					</td>
		   		</tr>
        	<!}!>
    		<!}else{!>
				<tr>
		    		<td colspan="2"> 暂无数据</td>
				</tr>
    		<!}!>
 		</tbody>
	</script>

	<script type="text/html" id="tb_template2">
	    <thead>
			<tr>
				<th>操作</th>
				<th>P13账号</th>
			</tr>
		</thead>
		<tbody data-type="body" id="queryTable">
    		<!if(list.length>0) { !>
        		<!for(var i=0,len=list.length;i<len;i++){
            		var item = list[i],classItem = (i%2!=0)?"odd td_odd":"even";
          		!>
		    	<tr class="gradeA <!=classItem!>">
					<td>
						<input type="checkbox" value="<!=item["userId"]!>" class="isChecked" name="roleArry"/>
					</td>
			    	<td><!=item["username"]!></td>
		   		</tr>
        	<!}!>
    		<!}else{!>
				<tr>
		    		<td colspan="2">暂无数据</td>
				</tr>
    		<!}!>
 		</tbody>
	</script>

	<script type="text/html" id="tb_template3">
	    <thead>
			<tr>
				<th>操作</th>
				<th>P13账号</th>
			</tr>
		</thead>
		<tbody data-type="body" id="queryTable">
    		<!if(list.length>0) { !>
        		<!for(var i=0,len=list.length;i<len;i++){
            		var item = list[i],classItem = (i%2!=0)?"odd td_odd":"even";
          		!>
		    	<tr class="gradeA <!=classItem!>">
					<td>
						<input type="checkbox" value="<!=item["userId"]!>" class="isChecked2" name="roleArry"/>
					</td>
			    	<td><!=item["username"]!></td>
		   		</tr>
        	<!}!>
    		<!}else{!>
				<tr>
		    		<td colspan="2">暂无数据</td>
				</tr>
    		<!}!>
 		</tbody>
	</script>

	<script type="text/javascript">
		$(function(){
			//查看用户
			var parentUserId="";
			$("#tbwrap").delegate(".addUser", "click", function () {
				parentUserId=$(this).data("id");
				$("#queryDiv").hide();
				$("#queryDiv2").show();
				$(".action_tit1").html($(this).data("name")+" :新增成员");
				searchtwo();
			});

			$("#tbwrap").delegate(".updateUser", "click", function () {
				parentUserId=$(this).data("id");
				$("#username3").data("value",parentUserId);
				$("#queryDiv").hide();
				$("#queryDiv3").show();
				$(".action_tit2").html($(this).data("name")+" :更改成员");
				searchthree();
			});
			//1、复选框，选中坚挺
			$("#tbwrap").delegate(".isChecked", "click", function () {
				var roleId = $(this).val();//$(this).data("value");
			    if(this.checked == true){
			    	 var aa =  $("#checkId").val();
			    	 aa += roleId + ",";
			    	 $("#checkId").val(aa);// 把记录的ID数组字符串赋给隐藏传递的chBoxId
			     }
			     else{
			    	 var aa =  $("#checkId").val();
			    	 var strTemp=roleId+",";//临时变量
			    	 aa=aa.replace(strTemp,"");
			    	 $("#checkId").val(aa);
			     }
			});

			$("#tbwrap").delegate(".isChecked2", "click", function () {
				var roleId = $(this).val();//$(this).data("value");
			    if(this.checked == true){
			    	 var aa =  $("#checkId2").val();
			    	 aa += roleId + ",";
			    	 $("#checkId2").val(aa);// 把记录的ID数组字符串赋给隐藏传递的chBoxId
			     }
			     else{
			    	 var aa =  $("#checkId2").val();
			    	 var strTemp=roleId+",";//临时变量
			    	 aa=aa.replace(strTemp,"");
			    	 $("#checkId2").val(aa);
			     }
			});

			$("#cancelBtn").click(function(){
				$("#queryDiv2").hide();
				$("#queryDiv").show();
				search();
			})
			$("#cancelBtn2").click(function(){
				$("#queryDiv3").hide();
				$("#queryDiv").show();
				search();
			})
			//2、保存角色用户关系。
			$("#saveBtn").click(function(){
				// 验证
				if($("#checkId").val() == "")
				{
					alert("请至少选中一个用户.");
					return;
				} 
				//提交数值
				$.post("${ctx}/sysRole/toSetTeamId.do", {
					 UserId: $("#checkId").val(),
					 parentUserId:parentUserId
					}, 
					function (result) {
		            if ("succ" == result) {
		            	alert("操作成功");
						$("#cancelBtn").click();
		            }else if ("notThroughSecurityCheck" == result["isThroughSecurityCheck"]) {// 如果不通过安全检查
		                var mess = result["mess"];
		                $.post("${ctx}/common/notThroughSecurityCheck.do?ts="+new Date().getTime(), mess, function(res){
		                    alert(res);
		                },"json");
		            }else {
		            	alert(result);
		            }
		        }, "json");
			});

			$("#saveBtn2").click(function(){
				//提交数值
				$.post("${ctx}/sysRole/toSetTeamIdtwo.do", {
					 userId: $("#checkId2").val(),
					 parentUserId:parentUserId
					}, 
					function (result) {
		            if ("succ" == result) {
		            	alert("操作成功");
						// 刷新列表页面
		                //parent.location.replace("${ctx}/sysRole/list.do"); //如果发表成功则跳到列表界面 
						// 关闭弹窗窗口
		    			//parent.sysDeptDialog.close();
		    			$("#cancelBtn2").click();
		            }else if ("notThroughSecurityCheck" == result["isThroughSecurityCheck"]) {// 如果不通过安全检查
		                var mess = result["mess"];
		                $.post("${ctx}/common/notThroughSecurityCheck.do?ts="+new Date().getTime(), mess, function(res){
		                    alert(res);
		                },"json");
		            }else {
		            	alert(result);
		            }
		        }, "json");
			});
		});
	
		// 5、查询
		$("#searchBtn").click(function () {

			search();
        });
        $("#searchBtn2").click(function () {
			searchtwo();
        });
        $("#searchBtn3").click(function () {

			searchthree();
        });
	</script>
	
	<script type="text/javascript">
		var zTree, rMenu;
		$(function () {
	        search();
	    });
		
		//检查浏览器
		function checkIE(){
			var Sys = {};
        	var ua = navigator.userAgent.toLowerCase();
        	if (window.ActiveXObject){ //ie
           		return '1';
        	}
        	else if (document.getBoxObjectFor){ //firfox
           		return '2';
        	}
        	else if (navigator.userAgent.toLowerCase().match(/chrome/)!= null){ //chrome
           		return '3';
        	}
        	else if (window.opera){//opera
           		return '4';
			}
        	else if (window.openDatabase){ //safari
        		return '5';
        	}
		}
	
		$(function () {
			//1、查询
	        search();
	    });
		
		//根据checkId渲染复选框
		function initChecked(){
			 var id = $("#checkId").val();
			 if(checkIE()=='3'){
			 	roleArry=$(".isChecked");
			 }
			 var data = id.split(",");
	         for(var i = 0; i < data.length; i++){
	             for(var j = 0; j < roleArry.length; j++){
	            	 if(data[i] == roleArry[j].value){
	                	 roleArry[j].checked = true;
	            	 }
	             }
	         }
		}

		function initChecked2(){
			 var id = $("#checkId2").val();
			 if(checkIE()=='3'){
			 	roleArry=$(".isChecked2");
			 }
			 var data = id.split(",");
	         for(var i = 0; i < data.length; i++){
	             for(var j = 0; j < roleArry.length; j++){
	            	 if(data[i] == roleArry[j].value){
	                	 roleArry[j].checked = true;
	            	 }
	             }
	         }
	         
		}
		
		function search() {
	        seajs.use(["component/table"], function (uiTable) {
		        $.post("${ctx}/sysUser/ajaxPageByRoleId.do",
		        {
		        	page: 1,
		        	//deptId:$("#deptId").val(),
		        	roleId:"${SysRole.roleId}",
		        	username:$("#username").val(),
		        	deleteFlag:$("#deleteFlag").val()
		        	
		        }, function (result) {
	            	var table = new uiTable({
	                	"con": "#tbwrap",
	                    "data": {
	                         "list": result.dataList
	                    },
	                    "template": "tb_template",
	                    "pager": {
	                    	"con": "#j_pager",
	                        "data": {
	                        	"currentPage": result.currentPage,
	                            "pageCount": result.pageCount,
	                            "rowCount": result.rowCount
	                        },
	                        template: '<ul class="pagination" style="margin: 0;"><li><a title="首页" class="page_first" data-role="first" href="#">首页</a></li><li><a title="上一页" class="page_prev" href="#" data-role="prev">上一页</a></li><li class="pageNum" data-value="pageNum"><a></a></li><li><a title="下一页" class="page_next" href="#" data-role="next">下一页</a></li><li><a title="尾页" class="page_last" href="#" data-role="last">尾页</a></li></ul><div class="pageGo">共<span data-role="rowCount"></span>条 跳转到 <input  type="text" data-target="input" class="input_txt" style="width:80px;"/><a href="#" data-role="go" class="btn btn-primary go" style="color:#fff;">GO</a></div>'
	                    }
	                });
	                table.getPager().bind("changePage", function (event, page, hander) {
						var paramData = {
							page: page,
	    		        	//deptId:$("#deptId").val(),
	    		        	roleId:"${SysRole.roleId}",
	    		        	username:$("#username").val(),
	    		        	deleteFlag:$("#deleteFlag").val()
						};
	                	$.post("${ctx}/sysUser/ajaxPageByRoleId.do", paramData,function (change) {//ajaxPageByDeptId
	                    	table.render({ "list": change.dataList });
		                    hander({
								"currentPage": change.currentPage, 
								"pageCount": change.pageCount, 
								"rowCount": change.rowCount 
							});
		                   // fullRows("queryTable")
	    		        }, "json");
	                });
	        	}, "json");
	      	});
		}

		function searchtwo() {
	        seajs.use(["component/table"], function (uiTable) {
		        $.post("${ctx}/sysUser/ajaxPageExceptRoleIdtwo.do",
		        {
		        	page: 1,
		        	username:$("#username2").val(),
					roleId:"${sysRole.roleId}",
					deleteFlag:$("#deleteFlag").val()
		        }, function (result) {
	            	var table = new uiTable({
	                	"con": "#tbwrap",
	                    "data": {
	                         "list": result.dataList
	                    },
	                    "template": "tb_template2",
	                    "pager": {
	                    	"con": "#j_pager",
	                        "data": {
	                        	"currentPage": result.currentPage,
	                            "pageCount": result.pageCount,
	                            "rowCount": result.rowCount
	                        },
	                         //翻页样式
							 template: '<ul class="pagination" style="margin: 0;"><li><a title="首页" class="page_first" data-role="first" href="#">首页</a></li><li><a title="上一页" class="page_prev" href="#" data-role="prev">上一页</a></li><li class="pageNum" data-value="pageNum"><a></a></li><li><a title="下一页" class="page_next" href="#" data-role="next">下一页</a></li><li><a title="尾页" class="page_last" href="#" data-role="last">尾页</a></li></ul><div class="pageGo">共<span data-role="rowCount"></span>条 跳转到 <input  type="text" data-target="input" class="input_txt" style="width:80px;"/><a href="#" data-role="go" class="btn btn-primary go">GO</a></div>'
	                    }
	                });
	            	if(result.dataList.length>0){
	            		initChecked();//初始化勾选
	            	}
	                table.getPager().bind("changePage", function (event, page, hander) {
						console.log($("#userCnName").val());
	                	$.post("${ctx}/sysUser/ajaxPageExceptRoleIdtwo.do",  {
	    		        	page: page,
	    		        	username:$("#username2").val(),
							roleId:"${sysRole.roleId}",
							deleteFlag:$("#deleteFlag").val()
	    		        },
	                    function (result) {
	                    	table.render({"list": result.dataList});
		                    hander({"currentPage": result.currentPage, "pageCount": result.pageCount, "rowCount": result.rowCount });
		                   // fullRows("queryTable");
	    		        }, "json");
	                });
	        	}, "json");
	      	});
		}

		function searchthree() {
	        seajs.use(["component/table"], function (uiTable) {
		        $.post("${ctx}/sysUser/ajaxPageExceptRoleIdthree.do",
		        {
		        	page: 1,
		        	username:$("#username3").val(),
		        	userId:$("#username3").data("value"),
					roleId:"${sysRole.roleId}",
					deleteFlag:$("#deleteFlag").val()
		        }, function (result) {
	            	var table = new uiTable({
	                	"con": "#tbwrap",
	                    "data": {
	                         "list": result.pager.dataList
	                    },
	                    "template": "tb_template3",
	                    "pager": {
	                    	"con": "#j_pager",
	                        "data": {
	                        	"currentPage": result.pager.currentPage,
	                            "pageCount": result.pager.totalPage,
	                            "rowCount": result.pager.total
	                        },
	                         //翻页样式
							 template: '<ul class="pagination" style="margin: 0;"><li><a title="首页" class="page_first" data-role="first" href="#">首页</a></li><li><a title="上一页" class="page_prev" href="#" data-role="prev">上一页</a></li><li class="pageNum" data-value="pageNum"><a></a></li><li><a title="下一页" class="page_next" href="#" data-role="next">下一页</a></li><li><a title="尾页" class="page_last" href="#" data-role="last">尾页</a></li></ul><div class="pageGo">共<span data-role="rowCount"></span>条 跳转到 <input  type="text" data-target="input" class="input_txt" style="width:80px;"/><a href="#" data-role="go" class="btn btn-primary go">GO</a></div>'
	                    }
	                });
	            	if(result.pager.dataList.length>0){
	            		var userId="";
	            		for(var i=0;i<result.pager2.dataList.length;i++){
	            			userId=result.pager2.dataList[i].userId+','+userId;
	            		}
	            		$("#checkId2").val(userId);
	            		initChecked2();//初始化勾选
	            	}
	                table.getPager().bind("changePage", function (event, page, hander) {
						console.log($("#userCnName").val());
	                	$.post("${ctx}/sysUser/ajaxPageExceptRoleIdthree.do",  {
	    		        	page: page,
	    		        	username:$("#username3").val(),
	    		        	userId:$("#username3").data("value"),
							roleId:"${sysRole.roleId}",
							deleteFlag:$("#deleteFlag").val()
	    		        },
	                    function (result) {
	                    	table.render({"list": result.pager.dataList});
		                    hander({"currentPage": result.pager.currentPage, "pageCount": result.pager.totalPage, "rowCount": result.pager.total });
		                   // fullRows("queryTable");
		                   if(result.pager.dataList.length>0){
								initChecked2();//初始化勾选
							}
	    		        }, "json");
	                });
	        	}, "json");
	      	});
		}
	</script>
</body>
</html>