<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('须知列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>标题：</label>
                            <input type="text" name="title"/>
                        </li>
                        <li>
                            <label>须知类型：</label>
                            <select name="noticeType">
                                <option value="">全部</option>
                                <option value="1">购票说明</option>
                                <option value="2">观演须知</option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="kylin:notices:create">
                <i class="fa fa-plus"></i> 添加
            </a>
<!--            <a class="btn btn-danger multiple disabled" onclick="removeAllNotices()" shiro:hasPermission="kylin:notices:delete">-->
<!--                删除-->
<!--            </a>-->
        </div>
        <div class="col-sm-12 select-table table-bordered">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var updateFlag = [[${@permission.hasPermi('kylin:notices:update')}]];
    var removeFlag = [[${@permission.hasPermi('kylin:notices:delete')}]];
    var detailFlag = [[${@permission.hasPermi('kylin:notices:detail')}]];

    var prefix = ctx + "kylin/notices";
    $(function () {
        var options = {
            url: prefix + "/list",
            updateUrl: prefix + "/update/{id}",
            createUrl: prefix + "/create",
            removeUrl: prefix + "/delete",
            detailUrl: prefix + "/detail/{id}",
            modalName: "须知",
            columns: [
            //     {
            //     checkbox: true
            // },
                // {
                //     field: 'buyNoticeId',
                //     title: 'ID'
                // },
                {
                    field: 'imgUrl',
                    title: '图标',
                    formatter: function(value, row, index) {
                        return $.table.imageView(value, "300", "600");
                    }
                },
                {
                    field: 'title',
                    title: '标题'
                },
                {
                    field: 'noticeTypeName',
                    title: '须知类型'
                },
                {
                    field: 'message',
                    title: '须知内容'
                },
                {
                    field: 'createdAt',
                    title: '创建时间',
                    formatter: function(value, row, index) {
                        if (value) {
                            // 将LocalDateTime格式转换为可读的日期格式
                            var date = new Date(value);
                            return date.getFullYear() + '-' + 
                                   String(date.getMonth() + 1).padStart(2, '0') + '-' + 
                                   String(date.getDate()).padStart(2, '0') + ' ' + 
                                   String(date.getHours()).padStart(2, '0') + ':' + 
                                   String(date.getMinutes()).padStart(2, '0') + ':' + 
                                   String(date.getSeconds()).padStart(2, '0');
                        }
                        return '';
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-info btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.buyNoticeId + '\')"><i class="fa fa-eye"></i>详情</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + updateFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.buyNoticeId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="removeNotice(\'' + row.buyNoticeId + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        return actions.join('');
                    }
                }]
        };

        $.table.init(options);
    });
    
    // 单条删除
    function removeNotice(id) {
        $.operate.remove(id, "删除后该信息将无法被引用，也无法找回，确认要将该条须知内容删除吗？");
    }
    
    // 批量删除
    function removeAllNotices() {
        $.operate.removeAll("删除后该信息将无法被引用，也无法找回，确认要将选中的须知内容删除吗？");
    }
</script>
</body>
</html>