<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>机构管理</title>
	<meta name="decorator" content="default"/>
	<style>
		label.error{
			left:0;
			top:40px;
		}
	</style>
	<script type="text/javascript">
        var validateForm;
        function doSubmit(){//回调函数，在编辑和保存动作时，供openDialog调用提交表单。
            if(validateForm.form()){
                $("#inputForm").submit();
                return true;
            }

            return false;
        }
		$(document).ready(function() {
            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==0 || (length == 11 && mobile.test(value)));
            }, "请正确填写您的手机号码");
			$("#name").focus();
			validateForm = $("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
                /*rules: {
                    name:{remote: "${ctx}/sys/company/validateCompany?oldName=" + encodeURIComponent("${office.name}")}
                },
                messages: {
                    name:{remote: "此公司名称已经被注册!", required: "公司名称不能为空."}
                },*/
				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);
					}
				}
			});

            /*if('${sessionScope.state}' =='disabled'){
                $('select').attr('disabled','<%=session.getAttribute("state")%>');
            }else if('${sessionScope.state}' !='disabled'){
                $('select').removeAttr('disabled');
            }*/
            setCompInfo($("#officeId").val());
            dispSimpleName('${office.type}');
		});

        function setCompInfo(comId) {
            $.ajax({
                type:'post',
                url:'${ctx}/sys/office/compInfo',
                data:{
                    "id":comId
                },
                success:function(data){
                    if(data.type=="2"){
                        $("#type option[value='1']").hide();
                        $("#type option[value='2']").show();
                        $("#type option[value='3']").hide();
                    }else if(data.type=="3"){
                        $("#type option[value='1']").hide();
                        $("#type option[value='2']").show();
                        $("#type option[value='3']").show();
                    }else {
                        $("#type option[value='1']").hide();
                        $("#type option[value='2']").show();
                        $("#type option[value='3']").show();
                    }
                }
            })
        }
        function dispSimpleName(val) {
            /*if(val=='1'){
                $(".simpleName").show();
            }else {
                $(".simpleName").hide();
            }*/
        }
	</script>
</head>
<body>
<div class="single-form">
	<div class="container">
	<form:form id="inputForm" modelAttribute="office" action="${ctx}/sys/office/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>
		<input type="hidden" id = "sign"/>
		<c:set var="officedis" scope="session" value='<%=session.getAttribute("state")%>' />
		<c:set var="cnmae" scope="session" value='<%=session.getAttribute("cname")%>' />

		<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 with-icon">
					<c:choose>
						<c:when test="${not empty office.id}">
							<input htmlEscape="false"  readonly="true"  class="form-control layui-input" value="${office.parent.name}"/>
						</c:when>
						<c:otherwise>
							<sys:treeselectComp id="parentId" name="parent.id" value="${office.parent.id}" labelName="parent.name" labelValue="${office.parent.name}"
																			title="机构" url="/sys/office/treeData" extId="${office.id}"  cssClass="form-control layui-input required" allowClear="${office.currentUser.admin}"/>
						</c:otherwise>
					</c:choose>
				</div>
			</div>
			<%--<div class="layui-item layui-col-sm6">
				<label class="layui-form-label">归属区域：</label>
				<div class="layui-input-block with-icon">
					<sys:treeselectt id="area" name="area.id" value="${office.area.id}" labelName="area.name" labelValue="${office.area.name}"
									 title="区域" url="/sys/area/treeData" cssClass="form-control layui-input"/>
				</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">
					<c:choose>
						<c:when test="${cname == 'no'}">
							<td class="width-35">
								<input htmlEscape="false" readonly="true" class="form-control layui-input" value="${office.name}"/>
							</td>
						</c:when>
						<c:otherwise>
							<td class="width-35">
								<input id="oldName" name="oldName" type="hidden" value="${office.name}">
								<form:input path="name" htmlEscape="false" maxlength="50" class="form-control layui-input required"/>
						</c:otherwise>
					</c:choose>
				</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">
					<form:input path="topCompany" htmlEscape="false" maxlength="64"  cssClass="form-control layui-input required" />
				</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">
					<form:input path="code" htmlEscape="false" maxlength="50" class="form-control number layui-input required"/>
				</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">
					<c:choose>
						<c:when test="${not empty office.id}">
							<input htmlEscape="false" maxlength="50" readonly="ture" class="form-control layui-input" value="${fns:getDictLabel(office.type, 'sys_office_type', '')}"/>
						</c:when>
						<c:otherwise>
							<form:select path="type" class="form-control required simple-select" onchange="dispSimpleName(this.value);">
								<form:option value="" label=""/>
								<form:options items="${fns:getDictList('sys_office_type')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
							</form:select>
						</c:otherwise>
					</c:choose>
				</div>
			</div>
				<%--

                <div class="layui-item layui-col-sm6">
                    <label class="layui-form-label">邮箱：</label>
                    <div class="layui-input-block">
                        <form:input path="email" htmlEscape="false" maxlength="50" cssClass="form-control layui-input email" />
                    </div>
                </div>
                <div class="layui-item layui-col-sm6">
                    <label class="layui-form-label">联系地址：</label>
                    <div class="layui-input-block">
                        <form:input path="address" htmlEscape="false" maxlength="50" cssClass="form-control layui-input" />
                    </div>
                </div>
                <div class="layui-item layui-col-sm6">
                    <label class="layui-form-label">邮政编码：</label>
                    <div class="layui-input-block">
                        <form:input path="zipCode" htmlEscape="false" minlength="6" maxlength="6" cssClass="form-control number layui-input digits" />
                    </div>
                </div>
                <div class="layui-item layui-col-sm6">
                    <label class="layui-form-label">传真：</label>
                    <div class="layui-input-block">
                        <form:input path="fax" htmlEscape="false" maxlength="50" cssClass="form-control isTel layui-input" />
                    </div>
                </div>
                <div class="layui-item layui-col-sm6">
                    <label class="layui-form-label">电话：</label>
                    <div class="layui-input-block">
                        <form:input path="phone" htmlEscape="false" maxlength="50" cssClass="form-control text-muted number isMobile layui-input" />
                    </div>
                </div>
                <div class="layui-item layui-col-sm6 simpleName">
                    <label class="layui-form-label">公司简称：</label>
                    <div class="layui-input-block">
                        <form:input path="simpleName" htmlEscape="false" maxlength="10" cssClass="form-control layui-input" />
                    </div>
                </div>
                <div class="layui-item layui-col-sm6 simpleName">
                    <label class="layui-form-label">分公司简称：</label>
                    <div class="layui-input-block">
                        <form:input path="branchSimpleName" htmlEscape="false" maxlength="10" cssClass="form-control layui-input" />
                    </div>
                </div>
                <div class="layui-item layui-col-sm6 simpleName">
                    <label class="layui-form-label"><span class="require-item">*</span>分公司编号：</label>
                    <div class="layui-input-block">
                        <form:input path="branchNo" htmlEscape="false" maxlength="3" minlength="3" cssClass="form-control layui-input digits required" />
                    </div>
                </div>--%>
			<div class="layui-item layui-col-sm6">
				<label class="layui-form-label">机构状态：</label>
				<div class="layui-input-block with-icon">
					<c:choose>
						<c:when test="${not empty office.id}">
							<input htmlEscape="false" readonly="true" class="form-control layui-input" value="${fns:getDictLabel(office.useable, 'office_useable', '')}"/>
						</c:when>
						<c:otherwise>
							<form:select path="useable" class="form-control required simple-select" onchange="dispSimpleName(this.value);">
								<form:option value="" label=""/>
								<form:options items="${fns:getDictList('office_useable')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
							</form:select>
						</c:otherwise>
					</c:choose>
				</div>
			</div>
			<%--<div class="layui-item layui-col-sm6 simpleName">
				<label class="layui-form-label"><span class="require-item">*</span>负责人：</label>
				<div class="layui-input-block with-icon">
					<sys:treeselectt id="master" name="master" value="${office.master}" labelName="office.masterName" labelValue="${office.masterName}"
									 title="用户" url="/sys/office/treeDataAll?type=3" cssClass="form-control required layui-input" allowClear="true" notAllowSelectParent="true"/>
				</div>
			</div>--%>
			<div class="layui-item layui-col-sm12 with-textarea">
				<label class="layui-form-label">备注：</label>
				<div class="layui-input-block">
					<form:textarea path="remarks" htmlEscape="false" rows="3" maxlength="200" class="form-control"/>
				</div>
			</div>
		</div>

		</form:form>
	</div>
</div>
</body>
<%
	session.removeAttribute("state");
	session.removeAttribute("cname");
%>
</html>