<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>分配岗位</title>
	<meta name="decorator" content="default"/>
</head>
<body>
<div class="single-form">
	<sys:message content="${message}"/>
	<div class="container">
		<div class="form-group layui-row first">
			<div class="form-group-label"><h2>基本信息</h2></div>
			<div class="layui-item layui-col-sm6">
				<label class="layui-form-label">岗位名称：</label>
				<div class="layui-input-block">
					<input readonly="true" htmlEscape="false" class="layui-input form-control" value="${role.name}" />
				</div>
			</div>
			<div class="layui-item layui-col-sm6">
				<label class="layui-form-label">归属机构：</label>
				<div class="layui-input-block">
					<input readonly="true" htmlEscape="false" class="layui-input form-control" value="${role.office.name}" />
				</div>
			</div>
			<div class="layui-item layui-col-sm6">
				<label class="layui-form-label">英文名称：</label>
				<div class="layui-input-block">
					<input readonly="true" htmlEscape="false" class="layui-input form-control" value="${role.enname}" />
				</div>
			</div>
			<div class="layui-item layui-col-sm6">
				<label class="layui-form-label">岗位类型：</label>
				<div class="layui-input-block">
					<input readonly="true" htmlEscape="false" class="layui-input form-control" value="${role.roleType}" />
				</div>
			</div>
			<div class="layui-item layui-col-sm6">
				<label class="layui-form-label">数据范围：</label>
				<div class="layui-input-block">
					<c:set var="dictvalue" value="${role.dataScope}" scope="page" />
					<input readonly="true" htmlEscape="false" class="layui-input form-control" value="${fns:getDictLabel(dictvalue, 'sys_data_scope', '')}" />
				</div>
			</div>
		</div>
		<div class="form-group layui-row">
			<div class="form-group-label"><h2>人员信息</h2></div>
			<form id="assignRoleForm" action="${ctx}/sys/role/assignrole" method="post" class="hide">
				<input type="hidden" name="id" value="${role.id}"/>
				<input type="hidden" name="office.id" value="${role.office.id}"/>
				<input id="idsArr" type="hidden" name="idsArr" value=""/>
			</form>
			<div class="layui-item nav-btns">
				<a href="javascript:void(0);" id="assignButton" class="nav-btn nav-btn-add" title="添加人员"><i class="fa fa-plus"></i>&nbsp;新增</a>
			</div>
			<div class="layui-item layui-col-xs12 form-table-container" >
				<table id="contentTable" class="table table-bordered table-condensed details">
					<thead><tr><th>归属公司</th><th>归属部门</th><th>登录名</th><th>姓名</th><th>电话</th><th>手机</th><shiro:hasPermission name="sys:user:edit"><th width="80">操作</th></shiro:hasPermission></tr></thead>
					<tbody>
					<c:forEach items="${userList}" var="user">
						<tr>
							<td>${user.company.name}</td>
							<td>${user.office.name}</td>
							<td><a href="${ctx}/sys/user/form?id=${user.id}">${user.loginName}</a></td>
							<td>${user.name}</td>
							<td>${user.phone}</td>
							<td>${user.mobile}</td>
							<shiro:hasPermission name="sys:role:edit"><td class="op-td">
								<a href="${ctx}/sys/role/outrole?userId=${user.id}&roleId=${role.id}&office=${role.office.id}"
									onclick="return confirmx('确认要将用户<b>[${user.name}]</b>从<b>[${role.name}]</b>岗位中移除吗？', this.href)" class="op-btn op-btn-add"><i class="glyphicon glyphicon-remove"></i> 移除</a>
							</td></shiro:hasPermission>
						</tr>
					</c:forEach>
					</tbody>
				</table>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
	$("#assignButton").click(function(){

		top.layer.open({
			type: 2,
			area: ['90%','90%'],
			title:"选择用户",
			skin:"two-btns",
			maxmin: true, //开启最大化最小化按钮
			content: "${ctx}/sys/role/usertorole?id=${role.id}&office.id=${role.office.id}" ,
			btn: ['确定', '关闭'],
			yes: function(index, layero){
				var pre_ids = layero.find("iframe")[0].contentWindow.pre_ids;
				var ids = layero.find("iframe")[0].contentWindow.ids;
				if(ids[0]==''){
					ids.shift();
					pre_ids.shift();
				}
				if(pre_ids.sort().toString() == ids.sort().toString()){
					top.$.jBox.tip("未给岗位【${role.name}】分配新成员！", 'info');
					return false;
				};
				// 执行保存
				loading('正在提交，请稍等...');
				var idsArr = "";
				for (var i = 0; i<ids.length; i++) {
					idsArr = (idsArr + ids[i]) + (((i + 1)== ids.length) ? '':',');
				}
				$('#idsArr').val(idsArr);
				$('#assignRoleForm').submit();
				top.layer.close(index);
			},
			cancel: function(index){
			}
		});
	});
</script>
</body>
</html>
