<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>字典管理</title>
	<meta name="decorator" content="default"/>
	<style>
		#remarks-error{
			left:0;
			top:80px;
		}
	</style>
	<script type="text/javascript">
		var validateForm;
		function doSubmit(){//回调函数，在编辑和保存动作时，供openDialog调用提交表单。
		  if(validateForm.form()){
			  $("#inputForm").submit();
			  return true;
		  }
	
		  return false;
		}
		$(document).ready(function() {
			validateForm = $("#inputForm").validate({
				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);
					}
				}
			});
            jQuery.validator.addMethod("typeName", function(value, element) {
                var flag = true;
                $.ajax({
                    url:"${ctx}/sys/mainDict/typeName",
                    data:{
                        "typeName":value,
                        "id":'${mainDict.id}'
                    },
                    async:false,
                    type:"post",
                    success:function (result) {
                        console.info(result);
                        if(result.success && !result.body.isUsed){
                            flag=true;
                        }else {
                            flag=false;
                        }
                    },
                    error:function (result) {
                        top.layer.msg('异步类型异常！请稍后重试', {icon: 0});
                        flag=false;
                    }
                })
                return flag;
            }, "类型已存在");
		});
	</script>
</head>
<body>
<div class="single-form">
	<div class="container">
		<form:form id="inputForm" modelAttribute="mainDict" action="${ctx}/sys/mainDict/save" 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-sm12">
					<label class="layui-form-label"><span class="require-item">*</span>类型：</label>
					<div class="layui-input-block">
						<input id="oldTypeName" name="oldTypeName" type="hidden" value="${mainDict.typeName}"/>
						<form:input path="typeName" htmlEscape="false"    class="form-control typeName 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">
						<form:input path="name" htmlEscape="false"    class="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="typeSort" htmlEscape="false"    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">
						<form:select path="dictType"  class="form-control required simple-select">
							<form:option value="" label=""/>
							<form:options items="${fns:getDictList('main_type')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
						</form:select>
					</div>
				</div>
				<div class="layui-item layui-col-sm12 with-textarea">
					<label class="layui-form-label"><span class="require-item">*</span>类型描述：</label>
					<div class="layui-input-block">
						<form:textarea path="remarks" htmlEscape="false" rows="4" class="form-control required"/>
					</div>
				</div>
			</div>
		</form:form>
	</div>
</div>
</body>
</html>