<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增')"/>
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-guidance-add">
        <input id="treeId" name="parentId" type="hidden" th:value="${guidanceNode.yyqhGuidanceId}"/>
        <div class="form-group">
            <label class="col-sm-3 control-label ">上级目录：</label>
            <div class="col-sm-8">
                <div class="input-group">
                    <input class="form-control" type="text" onclick="selectGuidanceTree()" id="treeName" readonly="true"
                           th:value="${guidanceNode.guidanceName}">
                    <span class="input-group-addon"><i class="fa fa-search"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label" id="itemName">事项名称：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="guidanceName" id="guidanceName" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">事项类型：</label>
            <div class="col-sm-8">
                <div class="radio-box">
                    <input type="radio" name="guidanceType" value="1" checked>
                    <label text="">分类</label>
                </div>
                <div class="radio-box">
                    <input type="radio" name="guidanceType" value="2">
                    <label text="">事项</label>
                </div>
            </div>
        </div>
        <div class="form-group" id="sequenceIdDiv">
            <label class="col-sm-3 control-label">叫号机对接序列ID：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="sequenceId" id="sequenceId" required>
            </div>
        </div>
        <div class="form-group" id="remarkDiv">
            <label class="col-sm-3 control-label">详细事项：</label>
            <div class="col-sm-8">
                <textarea id="remark" name="remark" class="form-control"></textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">显示排序：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="orderNum" required>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: bootstrap-fileinput-js"/>
<script>
    var prefix = ctx + "system/yyqh/guidance";
    var treeid = $("#treeId").val();
    $(function () {
        var type = $('input[name="guidanceType"]:checked').val();
        show2Hide(type);
        $(":radio").on('ifChecked',
            function (event) {
                var guidanceType = $(event.target).val();
                show2Hide(guidanceType);
            });
    });

    function show2Hide(type) {
        if (type == "1") {
            $("#remarkDiv").hide();
            $("#itemName").html("分类名称：");
        } else {
            $("#remarkDiv").show();
            $("#itemName").html("事项名称：");
        }
    }

    $("#form-guidance-add").validate({
        onkeyup: false,
        rules: {
            guidanceName: {
                required: true
            },
            orderNum: {
                digits: true,
                required: true
            },
        },
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            var type = $('input[name="guidanceType"]:checked').val();
            var parentId = $('#treeId').val();
            if (parentId == 0 && type != "1") {
                alert("根目录不允许创建事项，请先创建分类");
            } else {
                var data = $("#form-guidance-add").serializeArray();
                $.operate.save(prefix + "/add", data);
            }
        }
    }

    /*菜单管理-新增-选择菜单树*/
    function selectGuidanceTree() {
        var treeId = $("#treeId").val();
        var guidanceId = treeId > 0 ? treeId : 0;
        var url = prefix + "/selectGuidanceTree/" + guidanceId;
        var options = {
            title: '目录选择',
            width: "380",
            url: url,
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero) {
        var body = layer.getChildFrame('body', index);
        $("#treeId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        if (body.find('#treeId').val() != 0) {
            $("#iconUrl").parents(".form-group").hide();
            $("#itemName").html("事项名称：");
        }
        layer.close(index);
    }
</script>
</body>
</html>
