.uk-layui-form
    form.layui-form.uk-form(action='/admin/organ/update.html')
        input(type='hidden', name='id', value=organData.id)
        input#area(type='hidden', name='area', value=organData.area)
        input#parent(type='hidden', name='parent', value=(organData ? organData.parent : 0))
        .layui-form-item
            label.layui-form-label 部门：
            .layui-input-inline
                input.layui-input(type='text', name='name', lay-verify='requiredOrgiName', value=organData.name, placeholder='请输入部门名称', autocomplete='off')
        if isRootOrgan != true
            .layui-form-item
                .layui-inline
                    label.layui-form-label 上级机构：
                    .layui-input-inline(style='position: relative;')
                        input#parentname.layui-input(type="text", name="parentname", required="", value=(organData ? organData.name : '组织机构'), lay-verify="requiredTwo", autocomplete="off", readonly="readonly", onclick="showMenu();")
                        i.layui-icon(style="position: absolute;right: 3px;top: 6px;font-size: 25px;(#{systemConfig.color ? systemConfig.color : 'color:#0096C4;'})", onclick="showMenu()") 
                        #menuContent.ukefu-ztree(style="display:none; position: absolute;z-index:10000;width: 218px;")
                            ul#organTree.ztree(style="width:208px;")
        .layui-form-item
            label.layui-form-label 启用技能组：
            .layui-input-block
                input(type='checkbox', name='skill', lay-skin='switch', lay-filter='area', value='1', lay-text='开启|关闭' checked=(organData.skill ? 'checked' : false))
        .layui-form-button
            .layui-button-block
                button.layui-btn(lay-submit, lay-filter='formDemo') 立即提交
                button.layui-btn.layui-btn-original(type='reset') 重置
script.
    //Demo
    layui.use('form', function () {
        var form = layui.form();
        form.render(); //更新全部
        form.verify({
            requiredOrgiName: function (value) {
                if (value == $('#parentname').val()) {
                    return '部门和上级部门不能一致';
                }
                if (value.length > 50) {
                    return "部门名称不能超过50字";
                }

                if (!value) {
                    return "部门名称必填";
                }
            },

        })
        form.on("switch(area)", function (data) {
            if (data.elem.checked) {
                $('#area').show();
            } else {
                $('#area').hide();
            }
        });
    });

script(type='text/javascript').
    var setting = {
        data: {simpleData: {enable: true}},
        callback: {onClick: onClick, beforeClick: beforeClick}
    };
    function beforeClick(treeId, treeNode) {
        var zTree = $.fn.zTree.getZTreeObj("organTree")
        nodes = zTree.getSelectedNodes();
        var allow = true, lastnode;
        for (var i = 0, l = nodes.length; i < l; i++) {
            lastnode = nodes[i].type;
            if (nodes[i].organ && (nodes.length >= 1 && (event.ctrlKey || event.shiftKey))) {
                allow = false;
                break;
            }
        }
        if (lastnode != treeNode.type && (event.ctrlKey || event.shiftKey)) {
            allow = false;
        }
        if (allow == false) {
            top.layer.alert("组织机构不能点选多个上级机构，也不能同时选择地区和机构", {icon: 3});
            return false;
        } else {
            return true;
        }
    }
    function onClick(e, treeId, treeNode) {
        var zTree = $.fn.zTree.getZTreeObj("organTree"), nodes = zTree.getSelectedNodes(), v = "", value = "";
        nodes.sort(function compare(a, b) {
            return a.id - b.id;
        });
        for (var i = 0, l = nodes.length; i < l; i++) {
            v += nodes[i].name + ",";
            if (value != "") {
                value = value + ",";
            }
            value = nodes[i].id;
        }
        if (v.length > 0) v = v.substring(0, v.length - 1);
        if (treeNode.type == "area") {
            $("#parentname").attr("value", v);
            $("#parent").attr("value", "0");
            $("#area").attr("value", value);
        } else {
            $("#parentname").attr("value", v);
            $("#parent").attr("value", value);
            $("#area").attr("value", "");
        }
        if (!event.ctrlKey && !event.shiftKey) {
            hideMenu();
        }
    }
    var zNodes = !{pugHelper.toJSON(organList)}
    $.each(zNodes, function (i, o) {
        o.id = o.id;
        o.pId = o.parent ? o.parent : '0';
        o.name = o.name;
        o.open = true;
        o.organ = true;
        o.type = "organ";
        o.icon = '/images/dept.png'
    });
    $(document).ready(function () {
        var ztree = $.fn.zTree.init($("#organTree"), setting, zNodes);
        if ('#{organData}') {
            var node = ztree.getNodeByParam('id', '#{organData.parent}');//获取id为1的点
            ztree.selectNode(node);//选择点
            if (node) {
                $("#parentname").attr("value", node.name);
            }
            var areaList = '#{organData.area}'.split(",")
            areaList.forEach(function (area, index) {
                var areanode_#{index} = ztree.getNodeByParam('id', area);//获取id为1的点
                ztree.selectNode(areanode_#{index}, true);//选择点
            });
        }
    })
    function showMenu() {
        $("#menuContent").css({left: "0px", top: "38px"}).show();
        $("body").bind("mousedown", onBodyDown);
    }
    function hideMenu() {
        $("#menuContent").hide();
        $("body").unbind("mousedown", onBodyDown);
    }
    function onBodyDown(event) {
        if (!(event.target.id == "menuBtn" || event.target.id == "menuContent" || $(event.target).parents("#menuContent").length > 0)) {
            hideMenu();
        }
    }
            
