{% load staticfiles %}
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>预警记录</title>
    <link rel="stylesheet" href="{% static '/lib/layui/css/layui.css' %}">
    <link rel="stylesheet" href="{% static '/lib/font/fontIcon/iconfont.css' %}">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.10/css/select2.min.css" rel="stylesheet" />
    <link rel="stylesheet" href="{% static '/lib/css/reset.css' %}">
    <style>
        /* 面包屑导航 */

        .breadcrumbs {
            /* line-height: 38px; */
            padding: 12px 0 12px 30px;
            border-bottom: 1px solid #dbdbdb;
        }

        .layui-breadcrumb>* {
            font-size: 16px;
        }

        /* 内容 */

        .mainContent {
            padding: 30px;
        }

        .widget-title {
            position: relative;
            padding-left: 10px;
            font-size: 16px;
            padding: 5px 0 5px 10px;
        }

        .widget-title::after {
            position: absolute;
            content: '';
            left: 0;
            top: 9px;
            height: 15px;
            border-left: 5px solid #23a3ee;
            padding-left: 10px;
            font-size: 16px;
            padding: 5px 0 5px 10px;
        }

        .widget-title h2 {
            font-weight: 700;
            line-height: 33px;
        }

        .widget-title h2 span {
            font-size: 13px;
            font-weight: 100;
            margin-left: 20px;
            color: #333;
        }

        .redClolr {
            color: red;
            ;
        }

        #datatable {
            text-align: center;
        }

        .listDiv {
            margin-top: 20px;
        }

        /* 筛选框 */

        .selectModel {
            display: none;
        }
        .selectModel >div{
            width: 90%;
            margin-top: 30px;
        }
        /* select2 */
        .currEquip{
            padding: 20px;
        }
    </style>
</head>

<body>
    <div class="content">
        <!-- 导航 -->
        <div class="breadcrumbs">
            <span class="layui-breadcrumb">
                <a href="info_pub" target="BoardRight">首页</a>
                <a>
                    <cite>预警记录</cite>
                </a>
            </span>
        </div>
        <!-- 内容 -->
        <div class="mainContent">
            <div class="widget-title">
                <!-- <button type="button" class="layui-btn  layui-btn-normal layui-btn-sm fr" onclick="selectModelFun()">筛选</button> -->
                <h2>预警记录</h2>
            </div>
            <!-- <div class="currEquip">
                当前设备： 
                {% if equip_list|length %}
                <select class="currEquipSelect" name="state" id="equipSelect">
                    {% for equip in equip_list %}
                    <option value="{{equip.equip_id}}">{{equip.equip_id}}</option>
                    {% endfor %}
                </select>
                {% else %} 当前暂无设备 {% endif %}
            </div> -->
            <div>
                <div class="listDiv">
                    <table id="datatable" class="table layui-table table-bordered table-hover">
                        <thead>
                            <tr>
                                <td>设备ID</td>
                                <td>通道</td>
                                <td>监测指标</td>
                                <td>时间</td>
                            </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                </div>
                <div class="fenpei-bottom">
                    <div id="page"></div>
                </div>
            </div>
        </div>

    </div>

    <script src="{% static '/lib/js/jquery-2.1.4.min.js'%}"></script>
    <script src="{% static '/js/backstageNet/common.js'%}"></script>
    <script src="{% static '/lib/layui/layui.js'%}"></script>
    <script>

        var element, laydate, laypage, form;
        layui.use(['element', 'layer', 'laydate', 'laypage', 'form'], function () {
            // layer = layui.layer;
            laydate = layui.laydate;
            laypage = layui.laypage;
            form = layui.form;           

        })
        getData(1)
        function getData(page,curr){
            $.ajax({
                url:'alarm_record',
                type:'post',
                data:{
                    page:page
                },
                dataType:'json',
                success:function(data){
                    console.log(data)
                    if(data.dat){
                        Fill_Table('datatable', data.dat, '');
                        $('.fenpei-bottom').show();
                        Fill_page(data.nums,curr);
                    }else{
                        Fill_null_Table('datatable', data.dat, '');
                        $('.fenpei-bottom').hide();
                    }
                }
            })
        }
        // 填充表格
        function Fill_Table(table_id, data, facId) {
            var table = document.getElementById(table_id).children[1]
            var html = "";
            for (var i = 0; i < data.length; i++) {
                html += "<tr>";
                html += "<td>" + data[i].equip_id + "</td><td>通道" + data[i].ekey.substring(1) + "</td><td><span class='redClolr'>" + data[i].logs + "</span></td><td>" + data[i].upl_time + "</td>";
                html += "</tr>";
                if (i == data.length - 1) {
                    $(table).html(html);
                    scrollBar()
                }
            }
        }
        function Fill_null_Table(table_id) {
            var html = "";
            html += "<thead><tr><th>采集时间</th><th>风速</th><th>温度</th></tr></thead>";
            html += "<tr><td colspan=3 style='line-height:100px'>暂无数据</td></tr>";
            $(document.getElementById(table_id)).html(html);
            scrollBar()
        }

        function Fill_page(data,curr) {
            layui.use(['laypage'], function () {
                laypage = layui.laypage;       
                laypage.render({
                    elem: 'page' //注意，这里的 test1 是 ID，不用加 # 号
                    // , count: 30
                    , count: data
                    , curr:curr
                    , theme: '#2ca9f9'
                    , layout: ['prev', 'page', 'next', 'skip']
                    , jump: function (obj, first) {
                        if(!first){
                            getData(obj.curr,obj.curr)
                        }
                    }
                });
            })
            
        }
    </script>
</body>

</html>