<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>岗位管理</title>
	<meta name="decorator" content="default"/>
	<%@include file="/webpage/include/treeview.jsp" %>
	<style>
		.form-group{
			padding-top:18px;
		}
        .lw9 .layui-item .layui-form-label{
            width:80px;
        }
	</style>
	<script type="text/javascript">
        var validateForm;
        function doSubmit(){//回调函数，在编辑和保存动作时，供openDialog调用提交表单。
            if(validateForm.form()){
                loading('正在提交，请稍等...');
                $("#inputForm").submit();
                return true;
            }

            return false;
        }

        $(document).ready(function(){
            $("#name").focus();

            validateForm= $("#inputForm").validate({
                rules: {
                    enname: {remote: "${ctx}/sys/role/checkEnname?oldEnname=" + encodeURIComponent("${role.enname}")}
                },
                messages: {
                    enname: {remote: "英文名已存在"}
                },
                submitHandler: function(form){
                    var ids = [], nodes = tree.getCheckedNodes(true);
                    for(var i=0; i<nodes.length; i++) {
                        ids.push(nodes[i].id);
                    }
                    console.log("----ids:"+ids);
                    $("#menuIds").val(ids);
                    loading('正在提交，请稍等...');
                    form.submit();
                },
                errorContainer: "#messageBox",
                errorPlacement: function(error, element) {
                    $("#messageBox").text("输入有误，请先更正。");
                    if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
                        error.appendTo(element.parent().parent());
                    } else {
                        error.insertAfter(element);
                    }
                }
            });
            var setting = {check:{enable:true,nocheckInherit:true},view:{selectedMulti:false},
                data:{simpleData:{enable:true}},callback:{beforeClick:function(id, node){
                        tree.checkNode(node, !node.checked, true, true);
                        return false;
                    }}};

            // 用户-菜单
            var zNodes=[
                    <c:forEach items="${menuList}" var="menu">{id:"${menu.id}", pId:"${not empty menu.parent.id?menu.parent.id:0}", name:"${not empty menu.parent.id?menu.name:'权限列表'}"},
                </c:forEach>];
            // 初始化树结构
            var tree = $.fn.zTree.init($("#menuTree"), setting, zNodes);
            // 不选择父节点
            tree.setting.check.chkboxType = { "Y" : "ps", "N" : "s" };
            // 默认选择节点
            var ids = "${role.menuIds}".split(",");
            for(var i=0; i<ids.length; i++) {
                var node = tree.getNodeByParam("id", ids[i]);
                try{tree.checkNode(node, true, false);}catch(e){}
            }
            // 默认展开全部节点
            tree.expandAll(false);
        });
        $(function(){
            $('#menuTree_1_switch').removeClass('root_close').addClass('root_open');
            $('#menuTree_1_ul').css('display','block');
            $('#menuTree_1_switch').click(function () {
                $('#menuTree_1_switch').toggleClass('root_open').toggleClass('root_close');
                if($('#menuTree_1_switch').is('.root_open')){
                    $('#menuTree_1_ul').css('display','block');
                }else{
                    $('#menuTree_1_ul').css('display','none');
                }
            })
        })
	</script>
</head>
<body>
<div class="single-form" style="display:flex;">
	<div class="container view-form" style="width:90%;display:flex;">
		<div class="form-group layui-row first lw9" style="width:70%;">
			<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.company.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.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="${fns:getDictLabel(role.dataScope, 'sys_data_scope', '')}" />
				</div>
			</div>
			<%--<div class="layui-item layui-col-sm12">
				<label class="layui-form-label">岗位类型：</label>
				<div class="layui-input-block">
					<input readonly="true" htmlEscape="false" class="layui-input form-control" value="<c:choose><c:when test="${role.roleType eq 'assignment'}">任务分配</c:when><c:when test="${role.roleType eq 'security-role'}">管理岗位</c:when><c:otherwise>普通岗位</c:otherwise></c:choose>" />
					<span class="help-inline" title="activiti有3种预定义的组类型：security-role、assignment、user 如果使用Activiti Explorer，需要security-role才能看到manage页签，需要assignment才能claim任务">
						工作流组用户组类型（任务分配：assignment、管理岗位：security-role、普通岗位：user）</span>
				</div>
			</div>
			<div class="layui-item layui-col-sm12">
				<label class="layui-form-label">是否系统数据：</label>
				<div class="layui-input-block">
					<input readonly="true" htmlEscape="false" class="layui-input form-control" value="${fns:getDictLabel(role.sysData, 'yes_no', '')}" />
					<span class="help-inline">“是”代表此数据只有超级管理员能进行修改，“否”则表示拥有岗位修改人员的权限都能进行修改</span>
				</div>
			</div>
			<div class="layui-item layui-col-sm12">
				<label class="layui-form-label">是否可用：</label>
				<div class="layui-input-block">
					<input readonly="true" htmlEscape="false" class="layui-input form-control" value="${fns:getDictLabel(role.useable, 'yes_no', '')}" />
					<span class="help-inline">“是”代表此数据可用，“否”则表示此数据不可用</span>
				</div>
			</div>--%>
			<div class="layui-item layui-col-sm12 with-textarea">
				<label class="layui-form-label">备注：</label>
				<div class="layui-input-block">
					<textarea readonly="true" path="remarks" htmlEscape="false" rows="4" maxlength="200" class="form-control ">${role.remarks}</textarea>
				</div>
			</div>
			<div class="form-group layui-row ">
				<div class="form-group-label"><h2>关联角色</h2></div>
				<div class="layui-item layui-col-sm12">
					<div class="layui-input-block with-icon" style="margin-left:0;">
						<%--<c:if test="${not empty role.id}">
							<sys:treeselectroles id="roleActivityIds" name="roleActivityIds" value="${role.roleActivityIds}" labelName="roleActivityNames" labelValue="${role.roleActivityNames}"
												 title="选择角色" url="sys/office/treeDataRoleActivitys" checked="true" cssClass="form-control required" allowClear="true" notAllowSelectParent="true"/>
						</c:if>--%>
						<table id="contentTable" class="table details table-bordered table-condensed">
							<thead>
							<tr>
								<th  class="sort-column name">角色名称</th>
								<th  class="sort-column type">角色类型</th>
								<th  class="sort-column remarks">备注信息</th>
								<th width="100">操作</th>
							</tr>
							</thead>
							<tbody id="roleActivityList">
							<c:forEach items="${role.roleActivityList}" var="roleActivity" varStatus="index">
								<tr id="${roleActivity.id}">
									<td >
											${roleActivity.name}
									</td>
									<td>
											${fns:getDictLabel(roleActivity.type, 'sys_role_type', '')}
									</td>
									<td>
											${roleActivity.remarks}
									</td>
									<td>
										<a href="javascript:void(0)" onclick="delRowData(this,'${roleActivity.id}')"   class="btn btn-danger btn-xs"><i class="glyphicon glyphicon-remove"></i>&nbsp;删除</a>
									</td>
								</tr>
							</c:forEach>
							</tbody>
						</table>
						<%-- <sys:treeselectRole id="roleActivityIds" name="roleActivityIds" value="${role.roleActivityIds}" labelName="roleActivityNames" labelValue="${role.roleActivityNames}"
                                                title="选择角色" url="/sys/office/treeDataRoleActivity?type=3&isAll=false&role=${role.id}" cssClass="form-control layui-input" notAllowSelectParent="true" checked="true"/>
                            <label id="roleIdList-error" class="error" for="roleActivityList"></label>--%>
					</div>
				</div>
			</div>
		</div>
        <div class="form-group layui-row " style="margin-left:10%;width:20%;">
            <div class="form-group-label"><h2>关联菜单</h2></div>
            <div id="menuTree" class="ztree" style="margin-top:3px;float:left;"></div>
        </div>
	</div>

</div>
</body>
</html>