<%@ 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">

		function doSubmit(){//回调函数，在编辑和保存动作时，供openDialog调用提交表单。
		   var detailName=$("#detailName").val();
		   if(detailName==null||detailName==""){
               top.layer.msg('名称不能为空！', {icon: 0});
               return false;
		   }
            var detailKey=$("#detailKey").val();
            if(detailKey==null||detailKey==""){
                top.layer.msg('键值不能为空！', {icon: 0});
                return false;
            }
            var state=false;
            var branchOffice=$("#branchOffice").val();
            $.ajax({
                url:"${ctx}/sys/mainDictDetail/detailKey",
                data:{
                    "detailKey":detailKey,
                    "typeId":'${mainDict.id}',
                    "id":"${mainDictDetail.id}",
					"branchOffice":branchOffice
                },
                async:false,
                type:"post",
                success:function (result) {
                    if(result.success && !result.body.isUsed){
                        state=true;
                    }else {
                        state=false;

                    }
                }
            });
            if(state){

			}else{
                top.layer.msg('该键值已存在，键值不能重复！', {icon: 0});
                return false;
			}
            var sort=$("#sort").val();
            if(sort==null||sort==""){
                top.layer.msg('排序不能为空！', {icon: 0});
                return false;
            }
            if(isNaN(sort)){
                top.layer.msg('请输入有效数字！', {icon: 0});
                return false;
			}
		  return true;
		}
        var validateForm;
		$(document).ready(function() {
		    if( $("#id").val()!=null&& $("#id").val()!=''){
                $("#detailKey").attr("readonly",true);
			}
			validateForm = $("#inputFormAdd").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("detailKey", function(value, element) {
                var flag = true;
                $.ajax({
                    url:"${ctx}/sys/mainDictDetail/detailKey",
                    data:{
                        "detailKey":value,
                        "typeId":'${mainDict.id}',
						"id":"${mainDictDetail.id}"
                    },
                    async:false,
                    type:"post",
                    success:function (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 view-form">
		<form:form id="inputFormAdd" modelAttribute="mainDictDetail" action="${ctx}/sys/mainDictDetail/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<form:hidden path="branchOffice"/>
		<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">
						<form:input path="detailName" htmlEscape="false" id="detailName"   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="detailKey" htmlEscape="false" id="detailKey"   class="form-control detailKey layui-input required"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label">父节点：</label>
					<div class="layui-input-block with-icon">
						<sys:treeselecdict id="parentId" name="parentId" value="${mainDictDetail.parentId}" labelName="parentName" labelValue="${mainDictDetail.parentName}"
										   title="字典明细" url="/sys/mainDictDetail/treeData?typeId=1&company=${mainDictDetail.branchOffice}" isAll="true" typeName="${mainDict.typeName}" cssClass="form-control layui-input" notAllowSelectParent="false"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label">类型名称：</label>
					<div class="layui-input-block">
						<input type="hidden" name="typeId" value="${mainDict.id}">
						<input htmlEscape="false" readonly="true"   class="form-control layui-input required" value="${mainDict.name}"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label">所属类型：</label>
					<div class="layui-input-block">
						<input htmlEscape="false" readonly="true"   class="form-control layui-input required" value="${mainDict.typeName}"/>
					</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="sort" htmlEscape="false"  id="sort"  class="form-control number layui-input required"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label">末级标记：</label>
					<div class="layui-input-block">
						<input htmlEscape="false" readonly="true" class="form-control layui-input required" value="<c:choose><c:when test="${mainDictDetail.endFlag == '0'}">否</c:when><c:otherwise>是</c:otherwise></c:choose>"/>
					</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="4" class="form-control "/>
					</div>
				</div>
			</div>
		</form:form>
	</div>
</div>
</body>
</html>