<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>用户管理</title>
	<meta name="decorator" content="default"/>
	<style type="text/css">
		img {
			max-width: 30px;
			max-height: 30px;
		}
	</style>
	<script type="text/javascript">
		$(document).ready(function() {
		});

        function openDialogreUser(title,url,width,height,target){

            if(navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)){//如果是移动端，就使用自适应大小弹窗
                width='auto';
                height='auto';
            }else{//如果是PC端，根据用户设置的width和height显示。

            }
            top.layer.open({
                type: 2,
                area: ['90%','90%'],
                title:title,
                skin:"two-btns",
                name:'friend',
                content: encodeURI("${ctx}/sys/office/gridSelectUser?url=${ctx}/sys/office/gridSelectUser&isAll=true&type=4&isSingle=false") ,
                btn: ['确定', '关闭'],
                yes: function(index, layero){
                    var iframeWin = layero.find('iframe')[0].contentWindow; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                    var item = iframeWin.getSelectedItem();
                    if(item == "-1"){
                        return;
                    }
                    var userIds; ;
                    if(false){//单选
                        userIds = item.userId;
                        //selectUserInfo(item.userId);
                    }else{//多选
                        var ids = [], names = [];
                        for (var i=0;i<item.length;i++){
                            ids.push(item[i].userId);
                        }
                        var arr=ids.join(",").replace(/u_/ig,"");
                        userIds = arr;
                        //setUserInfo(arr);
                    }
                    console.log(userIds);
                    console.log($("#id").val());
                    $.ajax({
                        type:"post",
                        url:'${ctx}/sys/role/assignRoleUsers',
                        data:{"ids":userIds,"roleId":$("#id").val()},
                        dataType:"json",
                        success:function(data){
                            if(data.success) {
                                parent.layer.msg(data.msg,{icon:1});
                                search();
                            }else {
                                parent.layer.msg(data.msg,{icon:2});
                            }
                        },
                        error:function () {
                            parent.layer.msg("关联用户岗位失败！！！",{icon:2});
                        }
                    })
                    top.layer.close(index);//关闭对话框。

                },
                cancel: function(index){
                }
            });
        }
	</script>
	<style>
		body{
			background-color:transparent;
			filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#26FFFFFF, endColorstr=#26FFFFFF);
			color:#ffffff;
			background-color:rgba(255,255,255,0);
			height:100%;
		}
	</style>
</head>
<body>
<div class="wrapper wrapper-content">
	<sys:message content="${message}"/>
	<div class="layui-row">
		<div class="full-width fl">
			<div class="contentShadow layui-row" id="queryDiv">
				<form:form id="searchForm" modelAttribute="role" action="${ctx}/sys/role/list?look=true" method="post" class="form-inline">
					<form:hidden path="id"/>
                    <input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
					<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
					<table:sortColumn id="orderBy" name="orderBy" value="${page.orderBy}" callback="sortOrRefresh();"/><!-- 支持排序 -->
					<div class="commonQuery ">
						<div class="layui-item query athird">
							<label class="layui-form-label">姓名:</label>
							<div class="layui-input-block">
								<form:input path="workStaffBasicInfoName" htmlEscape="false" maxlength="20"  class=" form-control layui-input"/>
							</div>
						</div>
                        <div class="layui-item query athird">
                            <label class="layui-form-label">工号:</label>
                            <div class="layui-input-block">
                                <form:input path="no" htmlEscape="false" maxlength="20"  class=" form-control layui-input"/>
                            </div>
                        </div>
						<div class="layui-item athird">
							<div class="input-group">
								<a href="#" id="moresee"><i class="glyphicon glyphicon-menu-down"></i></a>
								<button id="searchReset" class="fixed-btn searchReset fr" onclick="resetSearch()">重置</button>
								<button id="searchQuery" class="fixed-btn searchQuery fr" onclick="search()">查询</button>
							</div>
						</div>
						<div style="    clear:both;"></div>
					</div>
					<div id="moresees" style="clear:both;display:none;">
						<div class="layui-item query athird">
							<label class="layui-form-label">性别:</label>
							<div class="layui-input-block">
								<form:select path="gender" class="form-control simple-select">
									<form:option value="" label=""/>
									<form:option value="1" label="男"/>
									<form:option value="2" label="女"/>
								</form:select>
							</div>
						</div>
                        <div class="layui-item query athird">
                            <label class="layui-form-label">部门:</label>
                            <div class="layui-input-block with-icon">
                                <sys:treeselect id="workStaffBasicInfoOfficeId" name="workStaffBasicInfoOffice.id" value="${role.workStaffBasicInfoOffice.id}" labelName="workStaffBasicInfoOffice.name" labelValue="${role.workStaffBasicInfoOffice.name}"
                                                title="部门" url="/sys/office/treeDataAll?type=2" cssClass="form-control layui-input" allowClear="true" notAllowSelectParent="true"/>
                            </div>
                        </div>
						<div class="layui-item query athird">
							<label class="layui-form-label">职级:</label>
							<div class="layui-input-block  with-icon">
								<sys:treeselectJob id="jobGrade" name="jobGradeId" value="${role.jobGradeId}" labelName="jobGradeName" labelValue="${role.jobGradeName}"
												   title="职级类型" url="/workjobgrade/workJobGrade/treeData"  cssClass="form-control layui-input required" allowClear="true" notAllowSelectParent="true"/>
							</div>
						</div>
					</div>
				</form:form>
			</div>
		</div>
		<div class="contentShadow shadowT full-width fl">
			<div class="layui-form contentDetails">
				<div class="nav-btns">
					<a href="javascript:void(0)" onclick="openDialogreUser('选择用户', '${ctx}/sys/office/gridSelectUser','90%','90%')" class="nav-btn nav-btn-add" ><i class="fa fa-plus"></i>&nbsp;选择</a>

					<button class="nav-btn nav-btn-refresh" data-toggle="tooltip" data-placement="left" onclick="sortOrRefresh()" title="刷新"><i class="glyphicon glyphicon-repeat"></i>&nbsp;刷新</button>
					<div style="clear: both;"></div>
				</div>
				<table class="oa-table layui-table" id="contentTable"></table>

				<!-- 分页代码 -->
				<table:page page="${page}"></table:page>
				<%--<div style="clear: both;"></div>

				<div class="form-group-label"><h2>关联岗位</h2></div>
				<table class="oa-table layui-table" id="contentTable2"></table>--%>
				<!-- 分页代码 -->
				<div style="clear: both;"></div>
			</div>
		</div>

	</div>
</div>
<script src="${ctxStatic}/layer-v2.3/layui/layui.all.js" charset="utf-8"></script>
<script>
    layui.use('table', function(){
        layui.table.render({
            limit:${ page.pageSize }
            ,elem: '#contentTable'
            ,page: false
            ,cols: [[
                // {checkbox: true, fixed: true},
                // {checkbox: true, fixed: true},
                {field:'index',align:'center',  width:40,title: '序号'}
                ,{field:'no',align:'center', title: '工号', minWidth:80,templet:function(d){
                        var xml = "<a class=\"attention-info\" href=\"javascript:void(0)\" onclick=\"openDialogView('关联岗位', '${ctx}/sys/role/form?userId=" + d.userId + "&view=user','95%','95%')\">" +
                            "<span title=" + d.no + ">" + d.no + "</span></a>";
                        return xml;
                    }}
                ,{field:'name',align:'center', title: '姓名', minWidth:120,templet:function(d){
                        return "<span title='"+ d.name +"'>" + d.name + "</span>";
                    }}
                ,{field:'office', align:'center',title: '部门', minWidth:120,templet:function(d){
                        return "<span title='"+ d.office +"'>" + d.office + "</span>";
                    }}
                ,{field:'jobGrade', align:'center',title: '职级', width:200,templet:function(d){
                        return "<span title='"+ d.jobGrade +"'>" + d.jobGrade + "</span>";
                    }}
                ,{field:'op',align:'center',title:"操作",minWidth:160,templet:function(d){
                        ////对操作进行初始化
                        var xml = "";
						if(d.candelete2 != undefined && d.candelete2 == "1")
                            xml +="<a href=\"${ctx}/sys/role/outrole?view=toUser&userId=" + d.userId + "&roleId=" + d.roleId + "&office=" + d.officeId + "\" onclick=\"return confirmx('确认要从该岗位删除该用户吗？', this.href)\"   class=\"op-btn op-btn-delete\"><i class=\"fa fa-trash\"></i> 删除</a>";
						return xml;
                    }}
            ]]
            ,data: [
                <c:if test="${ not empty page.list}">
                <c:forEach items="${page.list}" var="workStaffBasicInfo" varStatus="index">
                <c:if test="${index.index != 0}">,</c:if>
                {
                    "index":"${index.index+1}"
                    ,"id":"${workStaffBasicInfo.id}"
                    ,"roleId":"${role.id}"
                    ,"userId":"${workStaffBasicInfo.userId}"
                    ,"no":"${workStaffBasicInfo.no}"
                    ,"name":"${workStaffBasicInfo.name}"
                    ,"gender":"<c:if test="${workStaffBasicInfo.gender==1}">男</c:if><c:if test="${workStaffBasicInfo.gender==2}">女</c:if>"
                    ,"office":"${workStaffBasicInfo.office.topCompany}"
                    ,"officeId":"${workStaffBasicInfo.office.id}"
                    ,"jobGrade":"${workStaffBasicInfo.jobGrade.name}"
                    <shiro:hasPermission name="sys:user:edit">
                    ,"candelete1":"1"
                    </shiro:hasPermission>
                    <shiro:hasPermission name="sys:user:del">
					<c:if test="${fns:getUser().comId ne '1'}">
                    ,"candelete2":"1"
                    </c:if>
                    </shiro:hasPermission>
                }
                </c:forEach>
                </c:if>
            ]
            // ,even: true
            // ,height: 315
        });
    })

    /*layui.use('table', function(){
        layui.table.render({
            limit: '0'
            ,elem: '#contentTable2'
            ,page: false
            ,cols: [[
                // {checkbox: true, fixed: true},
                {field:'index',align:'center',  width:40,title: '序号'}
                ,{field:'name2',align:'center', title: '岗位编码', width:80,templet:function(d){
                        var xml = "<a class=\"attention-info\" href=\"javascript:void(0)\" onclick=\"openDialogView('查看岗位', '${ctx}/sys/role/form?id=" + d.id + "&office.id=" + d.officeId + "&office.name=" + encodeURI(d.office) + "&view=view','95%','95%')\">" +
                            "<span title=" + d.name2 + ">" + d.name2 + "</span></a>";
                        return xml;
                    }}
                ,{field:'name',align:'center', title: '岗位名称', minWidth:100,templet:function(d){
                        return "<span title='"+ d.name +"'>" + d.name + "</span>";
                    }}
                ,{field:'company', align:'center',title: '归属公司', minWidth :80,templet:function(d){
                        return "<span title='"+ d.company +"'>" + d.company + "</span>";
                    }}
                ,{field:'office', align:'center',title: '归属部门', minWidth:80,templet:function(d){
                        return "<span title='"+ d.office +"'>" + d.office + "</span>";
                    }}
                ,{field:'dataScope', align:'center',title: '数据范围',width:160}
                ,{field:'op',align:'center',title:"操作",width:200,templet:function(d){
                        ////对操作进行初始化
                        var xml = "";
                        if(d.candelete2 != undefined && d.candelete2 == "1")
                            xml +="<a href=\"${ctx}/sys/role/deleteAll?ids=" + d.id + "\" onclick=\"return confirmx('确认要删除该岗位吗？', this.href)\"   class=\"op-btn op-btn-delete\"><i class=\"fa fa-trash\"></i> 删除</a>";
                        return xml;
                    }}
            ]]
            ,data: [
                <c:if test="${ not empty page2.list}">
                <c:forEach items="${page2.list}" var="role" varStatus="index">
                <c:if test="${index.index != 0}">,</c:if>
                {
                    "index":"${index.index+1}"
                    ,"id":"${role.id}"
                    ,"name2":"${role.name}"
                    ,"name":"${role.name}"
                    ,"company":"${role.company.name}"
                    ,"office":"${role.office.name}"
                    ,"officeId":"${role.office.id}"
                    ,"dataScope":"${fns:getDictLabel(role.dataScope, 'sys_data_scope', '无')}"
                    <shiro:hasPermission name="sys:role:del">
                    ,"candelete2":"1"
                    </shiro:hasPermission>
                }
                </c:forEach>
                </c:if>
            ]
            // ,even: true
            // ,height: 315
        });
    })*/
    resizeListTable(175);
</script>
<script>
    $("a").on("click",addLinkVisied);

    resizeListWindow1();
    $(window).resize(function(){
        resizeListWindow1();
    });
</script>
</body>
</html>