<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>邀请加入公司</title>
	<meta name="decorator" content="default"/>
	<script src="${ctxStatic}/common/inspinia.js?v=3.2.0"></script>
	<script src="${ctxStatic}/common/contabs.js"></script>
	<script type="text/javascript">
        var validateForm;
        var msg;
        function doSubmit(){//回调函数，在编辑和保存动作时，供openDialog调用提交表单。
            if(validateForm.form()){
                if (msg!= null && msg != '' && msg!= undefined ){
                    parent.layer.msg(msg, {icon: 2});
                    return false;
				}
                $("#inputForm").submit();
                return true;
            }

            return false;
        }

        $(document).ready(function() {
            $("#name").focus();
            validateForm = $("#inputForm").validate({
                /*rules: {
                    no: {remote: "${ctx}/sys/user/checkNo?oldNo=" + encodeURIComponent($("#oldNo").val())},//设置了远程验证，在初始化时必须预先调用一次。
                },
                messages: {
                    no: {remote: "重复的工号"},
                },*/
                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);
                    }
                }
            });
        });
	</script>
</head>
<body>
<div class="single-form">
	<div class="container">
	<%--<div class="ibox-title" style="height: 70px;">
        <h5>邀请加入公司
        </h5>
        <div class="ibox-tools">
            <a class="collapse-link">
                <i class="fa fa-chevron-up"></i>
            </a>
            <a class="dropdown-toggle" data-toggle="dropdown" href="javascript:void(0)">
                <i class="fa fa-wrench"></i>
            </a>
            <ul class="dropdown-menu dropdown-user">
                <li><a href="javascript:void(0)">选项1</a>
                </li>
                <li><a href="javascript:void(0)">选项2</a>
                </li>
            </ul>
            <a class="close-link">
                <i class="fa fa-times"></i>
            </a>
        </div>
    </div>--%>
	<%--<div class="ibox-content">--%>
		<form:form id="inputForm" modelAttribute="user" action="${ctx}/sys/company/addUserToCompany" method="post" class="form-horizontal" autocomplete="off">
			<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">
					<label class="layui-form-label"><span class="require-item">*</span>手机：</label>
					<div class="layui-input-block">
						<input id="mobile" name="mobile" type="text" class="layui-input required form-control"/>
						<span class="help-inline"></span>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label"></label>
					<div class="layui-input-block">
						<span class="help-inline"></span>
					</div>
				</div>
				<%--<div class="layui-item layui-col-sm6">
					<label class="layui-form-label"><span class="require-item">*</span>工号：</label>
					<div class="layui-input-block">
						<div class="input-group">
							<input id="no" name="no" type="text" class="layui-input form-control required"/>
							<input id="oldNo" name="oldNo" type="hidden" value="${user.no}"/>
							<span class="help-inline"></span>
						</div>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label"><span class="require-item">*</span>号码隐藏：</label>
					<div class="layui-input-block">
						<div class="input-group">
							<form:select path="ishide"  class="form-control simple-select">
								<form:option value="1" label="是"/>
								<form:option value="0" label="否"/>
							</form:select>
						</div>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label"><span class="require-item">*</span>用户类型：</label>
					<div class="layui-input-block">
						<div class="input-group">
							<form:select path="userType"  class="form-control simple-select">
								<form:option value="" label="请选择"/>
								<form:options items="${fns:getDictList('sys_user_type')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
							</form:select>
						</div>
					</div>
				</div>--%>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label"><span class="require-item">*</span>归属部门：</label>
					<div class="layui-input-block">
						<div class="input-group with-icon">
							<sys:treeselect id="office" name="office.id" value="${user.office.id}" labelName="office.name" labelValue="${user.office.name}"
											title="部门" url="/sys/office/treeData?type=2" cssClass="form-control required layui-input" notAllowSelectParent="true"/>
						</div>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label"><span class="require-item">*</span>岗位：</label>
					<div class="layui-input-block">
						<div class="input-group with-icon">
							<sys:treeselectRole id="roleIds" name="roleIds" value="${user.roleIds}" labelName="roleNames" labelValue="${user.roleNames}"
												title="选择岗位" url="/sys/office/treeDataRole?type=2&isAll=false&userId=${user.id}" cssClass="form-control required layui-input" allowClear="true" notAllowSelectParent="true"/>
							<label id="roleIdList-error" class="error" for="roleIdList"></label>
						</div>
					</div>
				</div>
			</div>



			<%--Start 正则验证输入内容 -hfj --%>
			<script type="text/javascript">
                /**
                 * 判断手机号和工号正则验证
                 */
                $('#mobile').blur(function (){
                    $('#mobile').next("span").html("");
                    if($('#mobile').val()==null||$('#mobile').val()==""){
                        $('#mobile').next("span").hidden=true;
                        $(this).next("span").html("手机号不能为空");
                        msg = "手机号不能为空";
                        return;
                    }else{
                        $('#mobile').next("span").hidden=true;
                        var mobile = /^1[345789]\d{9}$/;
                        if(!mobile.test($('#mobile').val())){
                            $('#mobile').next("span").hidden=true;
                            $(this).next("span").html("手机号填写不正确");
                            msg = "手机号填写不正确";
                            return;
                        }else{
                            var mobileNo = $('#mobile').val();
                            var comId= '${fns:getUser().comId}';
                            $.ajax({
                                type: "post",
                                url: "${ctx}/sys/company/registerUser",
                                data: {mobile:mobileNo,comId:comId},
                                dataType:"text",
                                success: function(data) {
                                    $('#mobile').next("span").hidden=true;
                                    if(data=='2'){
                                        $('#mobile').next("span").hidden=true;
                                        $('#mobile').next("span").html("您邀请的用户不存在");
                                        msg = "您邀请的用户不存在";
                                        return;
                                    }else if(data=='3'){
                                        $('#mobile').next("span").hidden=true;
                                        $('#mobile').next("span").html("此用户已经存在，不能重复邀请");
                                        msg = "此用户已经存在，不能重复邀请";
                                        return;
                                    }else{
                                        $('#mobile').next("span").hidden=true;
                                        $('#mobile').next("span").html("用户已通过验证");
                                        msg = "";
                                    }
                                },
                                error: function(XMLHttpRequest, textStatus, errorThrown) {
                                }
                            });
                        }
                    }
                });
                /*$('#no').blur(function (){
                    if($('#no').val()==null||$('#no').val()=="") {
                        $('#no').next("span").html("工号不能为空");
                        return;
                    }else{
                        $('#no').next("span").html("");
                    }
                });*/
			</script>
			<%--正则验证输入内容 end--%>
		</form:form>
	</div>
</div>
</body>
</html>

