<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="decorator" content="base"/>
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/static/css/reset.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card layui-form">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">

                <button type="reset" class="layui-btn f-r mt-10 mr-15 pl-10 pr-10" type="reset" onclick="reset()">
                    <i class="layui-icon">&#xe666;</i>重置
                </button>
                <button class="layui-btn f-r mt-10 mr-15 pl-10 pr-10 " id="searchBtn" lay-submit
                        lay-filter="LAY-user-back-search">
                    <i class="layui-icon fs-12">&#xe615;</i>查询
                </button>
            </ul>
        </div>

        <div class="layui-card-body layuiadmin-card-header-auto">
            <form class="layui-form layui-card" action="" id="searchForm">
                <div class="layui-form-item">
                    <div class="layui-col-md2 layui-col-sm3">
                        <label class="layui-form-label">状态：</label>
                        <div class="layui-input-block">
                            <select name="status">
                                <option value="">请选择</option>
                                <option value="0">未读</option>
                                <option value="1">已读</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-lg4 layui-col-sm6">
                        <label class="layui-form-label">预警时间：</label>
                        <div class="layui-input-block">
                            <div class="layui-col-xs5">
                                <input type="text" name="createTimeMin" class="layui-input" id="createTimeMin"
                                       placeholder="开始日期" value="" autocomplete="off">
                            </div>
                            <div class="layui-col-xs2 text-c lh-30">
                                —
                            </div>
                            <div class="layui-col-xs5">
                                <input type="text" name="createTimeMax" class="layui-input" id="createTimeMax"
                                       placeholder="结束日期" value="" autocomplete="off">
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>

        <div class="layui-card-body">
            <table class="layui-hide " id="test" lay-filter="test"></table>
        </div>

    </div>
</div>
<div id="toolbarDemo" class="layui-form-item layui-hide">
    <button class="layui-btn layui-btn-sm" id="addBtn" lay-event="markAsRead"><i class="layui-icon layui-icon-add-1"></i>全部已读</button>
</div>

<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script type="text/javascript">

    //初始数据
    var form;
    var $;
    var table;
    var tableExt;
    var laydate;
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'tableExt', 'jquery', 'layer', 'laypage', 'laydate', 'form'], function () {
        $ = layui.$;
        form = layui.form;
        tableExt = layui.tableExt;
        table = layui.table;
        laydate = layui.laydate;


        //方案信息列表
        tableExt.render({
            elem: '#test'
            , height: 'full-130'
            , id: 'test'
            , defaultToolbar: false
            , url: '${ctx}/alarm/ajaxForAlarmData'
            , layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
            , page: true
            , toolbar: "#toolbarDemo"
            , method: "post"
            , limits: [20, 50, 100]
            , limit: 20
            , cols: [[
                {field: 'number', minWidth: 50, title: '序号', align: 'center', type: 'numbers', fixed: 'left'}
                , {field: 'content', title: '预警内容', minWidth: 180, align: 'center'}
                , {
                    field: 'status', title: '状态', minWidth: 120, align: 'center'
                    , templet: function (d) {
                        if (d.status === '1') {
                            return '已读';
                        } else if (d.status === '0') {
                            return '未读';
                        }
                    }
                }
                , {field: 'create_time', minWidth: 180, title: '预警时间', align: 'center',}
            ],
            ]
        });

        //开始日期
        var createTimeMin = laydate.render({
            elem: '#createTimeMin'
            , type: 'date'
            , done: function (value, date) {
                //更新结束日期的最小日期
                createTimeMax.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });
                //自动弹出结束日期的选择器
                createTimeMax.config.elem[0].focus();
            }
        });
        //结束日期
        var createTimeMax = laydate.render({
            elem: '#createTimeMax'
            , type: 'date'
            , done: function (value, date) {
                //更新开始日期的最大日期
                createTimeMin.config.max = lay.extend({}, date, {
                    month: date.month - 1
                });
            }
        });

        table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            if (obj.event === 'markAsRead') {
                layer.confirm('确定标记全部已读？', {icon: 3}, function(){
                    $.post('${ctx}/alarm/allMarkAsRead', function(result){
                        if (result.code === '200') {
                            layer.msg('操作成功', {time: 1000}, function () {
                                $(".layui-laypage-btn").click();
                            });
                        } else {
                            layer.msg('操作失败！' + result.errMsg);
                        }
                    });
                });

            }
        });



        function isBlank(val) {
            if (val == null || val == '' || val == undefined) {
                return true;
            }
            return false;
        }


        //监听搜索
        form.on('submit(LAY-user-back-search)', function (data) {
            var field = data.field;
            //执行重载
            table.reload('test', {
                where: field,
                page: {
                    curr: 1
                }
            });
        });

        //重置
        form.on('submit(resetButton)', function (data) {
            $("#searchForm")[0].reset();
            layui.form.render();

        });

    });


    function reset() {
        layui.form.render();
        $("#searchForm").find("select").val("");
        $("#searchForm").find("input").val("");
    }

</script>
</body>
</html>
