<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>后台管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="shortcut icon" th:href="@{/images/logo.jpg}"/>
    <link rel="stylesheet" th:href="@{/js/layui/css/layui.css}">
    <link rel="stylesheet" th:href="@{/js/layui/css/admin.css}">
    <script type="text/javascript" th:src="@{/js/jquery-3.3.1.min.js}"></script>
    <script th:src="@{/js/layui/layui.js}" charset="utf-8"></script>
</head>
<body>
<div class="layui-form" style="padding: 20px 0 0 0;">
    <form id="formId" onsubmit="return false;">

        <input type="hidden" class="layui-input"  th:value="${obj.id}" name="id">


        <div class="layui-form-item">
            <label class="layui-form-label">名称标题</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" id="stitle" th:value="${obj.stitle}"  name="stitle" style="width: 600px">
            </div>
        </div>
        

        <div class="layui-form-item">
            <label class="layui-form-label">通知内容</label>
            <div class="layui-input-inline">
                <textarea class="layui-input" style="width: 600px;height: 150px;" id="scontent" th:utext="${obj.scontent}"
                          placeholder="请输入通知内容"></textarea>
            </div>

        </div>


        <button class="layui-btn" style="display: none;" id="saveBtn" onclick="save()">保存</button>
    </form>
</div>
<script>

    layui.use('form', function () {
        var form = layui.form;
        form.render();
    });

    function save() {

        var id = '[[${obj.id}]]';



        var stitle = $("#stitle").val().trim();
        if (stitle == '') {
            layer.msg("名称标题不能为空!");
            return false;
        }

        
        var scontent = $("#scontent").val().trim();
        if (scontent == '') {
            layer.msg("内容不能为空!");
            return false;
        }

        var param = {};
        param.id = id;
        param.stitle = stitle;
        param.scontent = scontent;
        $.ajax({
            url: "add",
            data: JSON.stringify(param),
            type: "POST",
            dataType: "json",
            contentType: "application/json;charset=utf-8",
            success: function (result) {
                if (result.code == 0) {

                    layer.msg("恭喜您,提交成功", {icon: 6, time: 1000}, function () {
                        closeLayer();
                        parent.layui.table.reload('tableId');
                    });

                } else {
                    layer.msg(result.msg, {icon: 5});
                }
            }
        });
    }

    function closeLayer() {
        var index = parent.layer.getFrameIndex(window.name);
        //关闭当前frame
        parent.layer.close(index);
    }

</script>
</body>

</html>