<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>用户管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
        var validateForm;
        function doSubmit(){//回调函数，在编辑和保存动作时，供openDialog调用提交表单。
            if(validateForm.form()){
                $("#inputForm").submit();
                return true;
            }
            return false;
        }
        $(document).ready(function() {
            //初始化加载
            /*var companyId = $("#companyId").val();
            queryRole(companyId)
            $("#no").focus();*/
            // 手机号码验证
           /* jQuery.validator.addMethod("isMobile", function(value, element) {
                var length = value.length;
                var mobile = /^(13[0-9]{9})|(18[0-9]{9})|(19[0-9]{9})|(14[0-9]{9})|(17[0-9]{9})|(15[0-9]{9})$/;
                return (length == 11 && mobile.test(value));
            }, "请正确填写您的手机号码");*/
            validateForm = $("#inputForm").validate({
                rules: {
                    loginName: {remote: "${ctx}/sys/user/checkLoginName?oldLoginName=" + encodeURIComponent('${user.loginName}')},//设置了远程验证，在初始化时必须预先调用一次。
                },
                messages: {
                    loginName: {remote: "用户登录名已存在"},
                    confirmNewPassword: {equalTo: "输入与上面相同的密码"},
                },
                submitHandler: function(form){
                    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);
                    }
                }
            });

            //在ready函数中预先调用一次远程校验函数，是一个无奈的回避案。(刘高峰）
            //否则打开修改对话框，不做任何更改直接submit,这时再触发远程校验，耗时较长，
            //submit函数在等待远程校验结果然后再提交，而layer对话框不会阻塞会直接关闭同时会销毁表单，因此submit没有提交就被销毁了导致提交表单失败。
            $("#inputForm").validate().element($("#loginName"));
        });

        /**
         * 查询岗位
         * @param obj
         */
        /*function queryRole(obj){
            $.ajax({
                type:'post',
                url:'${ctx}/sys/user/queryRole',
                data:{
                    "officeId":obj
                },
                success:function(data){
                    $("#rolest").empty();
                    var rId = $("#roleId").val();
                    $("#rolest").append("<option class='required' selected value=''>-- 请选择 --</option>");
                    $.each(data.list, function(index,item){
                        if(rId == item.id){
                            $("#rolest").append("<option class='required' selected value='"+item.id+"'>"+item.name+"</option>")
                        }else{
                            $("#rolest").append("<option class='required' value='"+item.id+"'>"+item.name+"</option>")
                        }
                    });
                }
            });
        }*/
        function getSelectUserIds() {
            return "";
        }

        function changeUser(roleIds,names) {
			var userId = '${userId}';
            $.ajax({
                type:'POST',
                dataType:'json',
                url:'${ctx}/sys/role/assignRoleUserIds',
                data:{"userId":userId,"roleIds":roleIds},
                cache:false,
                success: function(data) {
                    if (data.success){
                        parent.layer.msg(data.msg,{icon:1});
                    }else {
                        parent.layer.msg(data.msg,{icon:2});
                    }
                    location.reload();
                },
                error:function () {
                    parent.layer.msg("获取岗位信息失败！！！",{icon:2});
                    parent.layer.close(loadingMessage);
                }
            });
        }
	</script>
</head>
<body>
<div class="single-form">
	<div class="container view-form">
		<form:form id="inputForm" modelAttribute="user" action="${ctx}/sys/user/save" enctype="multipart/form-data" method="post" class="form-horizontal">
			<form:hidden path="id"/>
			<sys:message content="${message}"/>
			<div class="form-group layui-row first">
				<div class="form-group-label"><h2>用户信息</h2></div>
				<div class="layui-item layui-col-sm6 lw7" style="padding-right: 0;">
					<div class="layui-item layui-col-sm12">
						<label class="layui-form-label"><span class="require-item">*</span>登录名：</label>
						<div class="layui-input-block">
							<input id="oldLoginName" name="oldLoginName" type="hidden" value="${user.loginName}">
							<form:input path="loginName" htmlEscape="false" minlength="11" maxlength="11" class="form-control layui-input required number text-muted isMobile userName"/>
						</div>
					</div>
					<div class="layui-item layui-col-sm12">
						<label class="layui-form-label"><span class="require-item">*</span>手机：</label>
						<div class="layui-input-block">
							<form:input path="mobile" htmlEscape="false" maxlength="11" minlength="11" class="form-control layui-input text-muted number required isMobile"/>
						</div>
					</div>
					<div class="layui-item layui-col-sm12">
						<label class="layui-form-label">邮箱：</label>
						<div class="layui-input-block">
							<form:input path="email" readonly="true" htmlEscape="false" maxlength="100" class="form-control layui-input email"/>
						</div>
					</div>
				</div>
				<div class="layui-item layui-col-sm6 lw7">
					<div style="margin-right: 120px;">
						<div class="layui-item layui-col-sm12">
							<label class="layui-form-label"><span class="require-item">*</span>姓名：</label>
							<div class="layui-input-block">
								<form:input path="name" readonly="true" htmlEscape="false" maxlength="50" class="form-control layui-input required"/>
							</div>
						</div>

						<div class="layui-item layui-col-sm12">
							<label class="layui-form-label"><span class="require-item">*</span>归属公司：</label>
							<div class="layui-input-block">
								<input htmlEscape="false" readonly="true" class="form-control layui-input" value="${user.company.name}"/>
							</div>
						</div>
						<div class="layui-item layui-col-sm12">
							<label class="layui-form-label"><span class="require-item">*</span>归属部门：</label>
							<div class="layui-input-block with-icon">
								<input htmlEscape="false" readonly="true" class="form-control layui-input" value="${user.office.topCompany}"/>
							</div>
						</div>
					</div>
					<div class="profile_box_wrapper">
						<div class="profile_box">
							<div id="this_upload_image_div_1">
								<div id="this_upload_div_1" style="position:relative;">
									<c:choose>
										<c:when test="${not empty user.photo}">
											<img alt="_blank" id="this_upload_image_1" class="upload_ico" style="cursor:pointer;"  src="${user.photo}?x-oss-process=image/resize,w_150,limit_0"/>
										</c:when>
										<c:otherwise>
											<img alt="_blank" id="this_upload_image_1" class="upload_ico" style="cursor:pointer;"  src="${pageContext.request.contextPath}/static/common/img/pic_add.png"/>
										</c:otherwise>
									</c:choose>
								</div>
							</div>
						</div>
					</div>
				</div>
                <div class="layui-item layui-col-sm12 lw7">
                    <label class="layui-form-label">备注：</label>
                    <div class="layui-input-block">
                        <form:textarea path="remarks" readonly="true" htmlEscape="false" rows="2" maxlength="200" class="form-control"/>
                    </div>
                </div>
                <c:if test="${not empty user.id}">
                    <div class="layui-item layui-col-sm6 lw7">
                        <label class="layui-form-label">创建时间：</label>
                        <div class="layui-input-block">
                            <input htmlEscape="false" disabled="true" class="form-control layui-input" value="<fmt:formatDate value="${user.createDate}" type="both" dateStyle="full"/>"/>
                        </div>
                    </div>
                    <div class="layui-item layui-col-sm6 lw7">
                        <label class="layui-form-label">最后登陆：</label>
                        <div class="layui-input-block">
                            <input htmlEscape="false" disabled="true" class="form-control layui-input" value="IP: ${user.loginIp}&nbsp;&nbsp;&nbsp;&nbsp;时间：<fmt:formatDate value="${user.loginDate}" type="both" dateStyle="full"/>"/>
                        </div>
                    </div>
                </c:if>
			</div>
			<div class="form-group layui-row ">
				<div class="form-group-label"><h2>档案信息</h2></div>
                <div class="layui-item layui-col-sm6 lw7">
                    <label class="layui-form-label">工号：</label>
                    <div class="layui-input-block">
                        <input htmlEscape="false" disabled="true" class="form-control layui-input" value="${workStaffBasicInfo.no}" type="both" dateStyle="full"/>
                    </div>
                </div>
                <div class="layui-item layui-col-sm6 lw7">
                    <label class="layui-form-label">姓名：</label>
                    <div class="layui-input-block">
                        <input htmlEscape="false" disabled="true" class="form-control layui-input" value="${workStaffBasicInfo.name}" type="both" dateStyle="full"/>
                    </div>
                </div>
                <div class="layui-item layui-col-sm6 lw7">
                    <label class="layui-form-label">性别：</label>
                    <div class="layui-input-block">
                        <input htmlEscape="false" disabled="true" class="form-control layui-input" value="${fns:getDictLabel(workStaffBasicInfo.gender,'sex' ,'' )}" type="both" dateStyle="full"/>
                    </div>
                </div>
                <div class="layui-item layui-col-sm6 lw7">
                    <label class="layui-form-label">职级：</label>
                    <div class="layui-input-block">
                        <input htmlEscape="false" disabled="true" class="form-control layui-input" value="${workStaffBasicInfo.jobGrade.name}" type="both" dateStyle="full"/>
                    </div>
                </div>

                <!-- 分页代码 -->
					<%--<table:page page="${page}"></table:page>--%>
				<div style="clear: both;"></div>
			</div>
			<div class="form-group layui-row ">
				<div class="form-group-label"><h2>关联岗位</h2></div>
				<c:choose>
					<c:when test="${not empty roleStatus && roleStatus}">
						<div class="layui-item nav-btns">
							<sys:treeselectusers id="role" name="role" value="${role.id}" labelName="role.name" labelValue="${role.name}"
												 title="岗位" url="/sys/office/treeDataRole?type=2&isAll=false&userId=${userId}" checked="true" cssClass="form-control required" allowClear="true" notAllowSelectParent="true"/>
								<%--<a class="nav-btn nav-btn-add" onclick="addRow('#workAccountList', workAccountListRowIdx, workAccountListTpl);workAccountListRowIdx = workAccountListRowIdx + 1;" title="新增"><i class="fa fa-plus"></i>&nbsp;新增</a>--%>
						</div>
					</c:when>
					<c:otherwise>
						<div class="layui-item nav-btns" style="display: none">
							<sys:treeselectusers id="role" name="role" value="${role.id}" labelName="role.name" labelValue="${role.name}"
												 title="岗位" url="/sys/office/treeDataRole?type=2&isAll=false&userId=${userId}" checked="true" cssClass="form-control required" allowClear="true" notAllowSelectParent="true"/>
								<%--<a class="nav-btn nav-btn-add" onclick="addRow('#workAccountList', workAccountListRowIdx, workAccountListTpl);workAccountListRowIdx = workAccountListRowIdx + 1;" title="新增"><i class="fa fa-plus"></i>&nbsp;新增</a>--%>
						</div>
					</c:otherwise>
				</c:choose>
				<table class="oa-table layui-table" id="contentTable"></table>

				<!-- 分页代码 -->
				<%--<table:page page="${page}"></table:page>--%>
				<div style="clear: both;"></div>
			</div>
		</form:form>
	</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:${fn:length(list)}
            ,elem: '#contentTable'
            ,page: false
            ,cols: [[
                // {checkbox: true, fixed: true},
                {field:'index',align:'center',  width:40,title: '序号'}
                /*,{field:'number',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.roleId + "&office.id=" + d.officeId + "&office.name=" + encodeURI(d.office) + "&view=view','95%','95%')\">" +
                            "<span title=" + d.number + ">" + d.number + "</span></a>";
                        return xml;
                    }}*/
                ,{field:'number',align:'center', title: '岗位编码', minWidth:100,templet:function(d){
                        return "<span title='"+ d.number +"'>" + d.number + "</span>";
                    }}
                ,{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/outrole?roleId=" + d.roleId + "&userId=" + d.userId + "&office=" + d.officeId+"&view=user\" 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 list}">
                <c:forEach items="${list}" var="role" varStatus="index">
                <c:if test="${index.index != 0}">,</c:if>
                {
                    "index":"${index.index+1}"
                    ,"roleId":"${role.id}"
                    ,"userId":"${userId}"
                    ,"number":"${role.number}"
                    ,"name":"${role.name}"
                    ,"company":"${role.company.name}"
                    ,"office":"${role.office.topCompany}"
                    ,"officeId":"${role.office.id}"
                    ,"dataScope":"${fns:getDictLabel(role.dataScope, 'sys_data_scope', '无')}"
                    <shiro:hasPermission name="sys:role:del">
                    <c:if test="${not empty roleStatus && roleStatus}">
                    ,"candelete2":"1"
					</c:if>
                    </shiro:hasPermission>
                }
                </c:forEach>
                </c:if>
            ]
            // ,even: true
            // ,height: 315
        });
    })
    resizeListTable();
</script>
<script>
    $("a").on("click",addLinkVisied);
    resizeListWindow3();
    $(window).resize(function(){
        resizeListWindow3();
    });
</script>
</body>
</html>