<div class="layui-layout layui-layout-admin" style="padding-left: 40px;margin-top: 20px;">

    <form class="layui-form" action="" method="post">

        <div class="layui-form-item">
            <label class="layui-form-label mw200">模板名称</label>
            <div class="layui-input-inline mw400">
                <input type="text" name="tpl_name" id="tpl_name" lay-verify="required" autocomplete="off"
                       placeholder="模板名称" class="layui-input" value="">
            </div>
            <div class="layui-form-mid layui-word-aux"></div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label mw200">模板类型</label>
            <div class="layui-input-inline mw400">
                <input type="radio" name="tpl_type" lay-filter="tpl_type" lay-verify="type" value="0" title="邮箱" checked>
                <input type="radio" name="tpl_type" lay-filter="tpl_type" lay-verify="type" value="1" title="短信" >
                <input type="radio" name="tpl_type" lay-filter="tpl_type" lay-verify="type" value="2" title="钉钉" >
                <input type="radio" name="tpl_type" lay-filter="tpl_type" lay-verify="type" value="3" title="微信" >
            </div>
            <div class="layui-form-mid layui-word-aux"></div>
        </div>

        <div class="layui-form-item J_title">
            <label class="layui-form-label mw200">模板标题</label>
            <div class="layui-input-inline mw400">
                <input type="text" name="title" id="title" autocomplete="off"
                       placeholder="模板标题" class="layui-input" value="">
            </div>
            <div class="layui-form-mid layui-word-aux"></div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label mw200">模板内容</label>
            <div class="layui-input-inline mw400">
                <textarea rows="100" name="content" id="content" style="height: 300px" placeholder="请输入模板内容" class="layui-textarea"></textarea>
            </div>
            <div class="layui-form-mid layui-word-aux" style="padding: 0px 0px !important;">
                <pre class="layui-code" style="margin: 0;">

  {{"任务 ID {{TaskId}}"}}
  {{"资源 ID {{ServerId}}"}}
  {{"任务名称 {{TaskName}}"}}
  {{"执行命令 {{ExecuteCommand}}"}}
  {{"执行时间 {{ExecuteTime}}"}}
  {{"执行耗时 {{ProcessTime}}"}}
  {{"执行状态 {{ExecuteStatus}}"}}
  {{"任务输出 {{TaskOutput}}"}}
  {{"错误输出 {{ErrorOutput}}"}}

                </pre>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label mw200">状态</label>
            <div class="layui-input-inline mw400">
                <input type="radio" name="status" lay-verify="type" value="0" title="禁用" checked>
                <input type="radio" name="status" lay-verify="type" value="1" title="启用" >
            </div>
            <div class="layui-form-mid layui-word-aux"></div>
        </div>

        <input type="hidden" name="id" id="id" value="0">
        <div class="layui-form-item">
            <label class="layui-form-label mw200"></label>
            <div class="layui-input-inline mw400">
                <button class="layui-btn" lay-submit="" lay-filter="sub">立即提交</button>
            </div>
        </div>
    </form>
</div>
<script>
    var $;
    layui.use(['form', 'element', 'layer', 'jquery'], function () {
        var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
        var $ = layui.jquery;

        var error_info = "{{.flash.error}}";
        if (error_info) {
            layer.msg(error_info, {icon: 2, shade: 0.3}, function () {
                window.history.go(-1)
            })
            return;
        }

        form.on('submit(sub)', function (data) {
            var form_data = $("form").serialize();
            $.post('{{urlfor "NotifyTplController.AjaxSave"}}', form_data, function (out) {
                if (out.status == 0) {
                    layer.msg("操作成功", {icon: 1, shade: 0.3, time: 1000}, function () {
                        window.parent.deleteCurrentTab();
                    })
                } else {
                    layer.msg(out.message)
                }
            }, "json");
            return false;
        });

        form.on('radio(tpl_type)', function (data) {
            if (data.value == 0){
                $(".J_title").show()
            } else {
                $(".J_title").hide()
                $("#title").val("")
            }
        });

        //但是，如果你的HTML是动态生成的，自动渲染就会失效
        //因此你需要在相应的地方，执行下述方法来手动渲染，跟这类似的还有 element.init();
        form.render();
    });
</script>