<#include "/common/defaultEngine.html"/>
<@pageTheme mark="${config.optimize()?string('true', 'false')}">
<@header title="新增机构" bodyClass="white-bg" libs=["bootstrapSelect"]/>
<div class="wrapper wrapper-content ibox-content">
<@f.form id="form-dept-add" class="form-horizontal">
    <div class="form-group">
        <label class="col-sm-3 control-label"><span style="color: red; ">*</span>机构类型：</label>
        <div class="col-sm-8">
            <@f.select name="type" dictType="sys_comp_type"/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label "><span style="color: red; ">*</span>上级机构：</label>
        <div class="col-sm-8">
            <@f.treeselect id="parentId" name="parentId" boxTitle="请选择上级机构" url="sys/comp/treeData"
            expandLevel=true isParentIds=true value="${(dept.id)!''}" labelValue="${(dept.name)!''}"
            parenIdsValue="${(dept.id)!''},${(dept.parentIds)!''}"
            placeholder="请选择上级机构" required=true/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label"><span style="color: red; ">*</span>机构名称：</label>
        <div class="col-sm-8">
            <@f.input name="name" required=true/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label"><span style="color: red; ">*</span>机构全称：</label>
        <div class="col-sm-8">
            <@f.input name="fullName" required=true/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label"><span style="color: red; ">*</span>显示排序：</label>
        <div class="col-sm-8">
            <@f.input name="orderNum" required=true/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label"><span style="color: red; ">*</span>状态：</label>
        <div class="col-sm-8">
            <@f.radio name="status" dictType="sys_normal_disable"/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label">备注：</label>
        <div class="col-sm-8">
            <@f.textarea name="remark"/>
        </div>
    </div>
</@f.form>
</div>
<@footer>
<script type="text/javascript">
    var prefix = baseURL + "sys/dept";

    $("#form-dept-add").validate({
        onkeyup: false,
        rules:{
            name:{
                remote: {
                    url: prefix + "/checkCompNameUnique",
                    type: "POST",
                    dataType: "html",
                    data: {
                        "parentId": function() {
                            return $("input[name='parentId']").val();
                        },
                        "name" : function() {
                            return opt.common.trim($("#name").val());
                        }
                    },
                    dataFilter: function(data, type) {
                        return opt.validate.unique(data);
                    }
                }
            },
            orderNum:{
                digits:true
            }
        },
        messages: {
            "name": {
                remote: "已经存在"
            }
        },
        focusCleanup: true
    });


    function submitHandler() {
        if (opt.validate.form()) {
            opt.operate.save(prefix + "/add", $('#form-dept-add').serialize());
        }
    }
</script>
</@footer>
</@pageTheme>
