<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="admin/common/html/head :: head_Normal(~{::title},~{::link},~{::style})">

<title th:text=${title}></title>

<link rel="stylesheet" th:href="@{/static/admin/assets/js/button/ladda/ladda.min.css}">
<link th:href="@{/static/admin/assets/js/bootstrap/css/bootstrap-table/bootstrap-table.min.css}" rel="stylesheet"/>

<style type="text/css">
.select-list ul li{
	list-style-type: none;
	float: left;
}
.timeBut{
    float: left;
    padding-top: 15px
}
.timeBut2{
    float: left;
    padding-top: 10px
}
</style>

</head>

<body id="listbody">

<!-- 右边内容 -->
<div class="wrap-fluid">
    <div class="container-fluid bevel tlbr"
         style="min-height: 600px;position: relative;overflow: hidden;">
        <div class="body-nest" id="Blank_Page_Content">
            <form role="form" class="form-inline" id="maxHotForm">
                <div class="form-group">
                    <label class="control-label timeBut" >日期：</label>
                    <span class='input-group date datetimepicker' style="width: 43%;float: left" id='datetimepicker1' data-date-format="yyyy-mm-dd hh:ii:ss">
                        <input type='text' class="form-control" name="startTime" id="startTime"/>
                        <span class="input-group-addon">
                           <span class="glyphicon glyphicon-calendar"></span>
                        </span>
                    </span>
                    <label class="control-label timeBut" >~</label>
                    <span class='input-group date datetimepicker'  style="width: 43%"  id='datetimepicker2' data-date-format="yyyy-mm-dd hh:ii:ss">
                        <input type='text' class="form-control"  name="endTime" id="endTime"/>
                        <span class="input-group-addon">
                           <span class="glyphicon glyphicon-calendar"></span>
                        </span>
                    </span>
                </div>
                <div class="form-group" >
                    <label class="control-label timeBut2">热点：</label>
                    <input type="text" name="key" placeholder="key"class="form-control" style="width: 34%;float: left;margin-left: 1%">

                    <label class="control-label timeBut2" style="margin-left: 9%">所属APP：</label>
                    <select name="app" id="apps" class="form-control" style="width: 32%">
                    </select>
                </div>
                <button onclick="$.table.search(this)" class="btn btn-success" type="button"  style="margin-left: 64%"><i class="fa fa-search"></i>&nbsp;搜索</button>
                <button onclick="exportHot()" class="btn btn-success"type="button"  style="margin-left: 3%"><i class="fa fa-arrow-circle-o-down"></i>&nbsp;导出</button>
            </form>

            <table id="dataTable" class="table-striped footable-res footable metro-blue" data-page-size="6">
            </table>
        </div>
    </div>
</div>
<!-- 结束右边内容 -->

<!-- 通用js -->
<div th:include="admin/common/html/js :: onload_js">
   
</div>
<!-- bootstarp 表格 -->
<script th:src="@{/static/admin/assets/js/bootstrap/js/bootstrap-table/bootstrap-table.min.js}" type="text/javascript"></script>
<script th:src="@{/static/admin/assets/js/bootstrap/js/bootstrap-table/locale/bootstrap-table-zh-CN.min.js}" type="text/javascript"></script>
<script th:src="@{/static/admin/assets/js/bootstrap/js/base_list.js}" type="text/javascript"></script>
<script th:src="@{/static/admin/assets/js/layer/layer.js}" type="text/javascript"></script>

<script type="text/javascript">
var dataUrl="/key/listMaxHot";
var removeUrl="/key/remove";
var createUrl="/key/add";
var options = {
    dataUrl: dataUrl,
    createUrl: createUrl,
    removeUrl: removeUrl,
    sortName: "count",
    modalName: "KEY",
    search: false,      //是否显示表格搜索
    showRefresh: false,//刷新按钮
    showColumns: false,//显示列按钮
    dataColumns: [
        { field: 'keyName', title: 'key名称'},
        { field: 'count', title: '次数'},
        { field: 'app', title: '所属APP'},]
};

$(function(){
    $.ajax({
        cache : true,
        type : "POST",
        url : "/user/info",
        headers: {
            "Authorization":getCookie("token")
        },
        async : false,
        error : function(XMLHttpRequest){
            $.modal.alertError(XMLHttpRequest.responseJSON.msg);
        },
        success : function(data) {
            console.log(data)
            var role = data.role;
            if(role === "ADMIN"){
                $("#apps").append("<option></option>");
            }
            var apps = data.appNames;
            var appName = data.appName;
            for (var i = 0; i < apps.length; i++) {
                var app = apps[i];
                if(app === appName){
                    $("#apps").append("<option selected = selected>" + apps[i] + "</option>");
                }else{
                    $("#apps").append("<option>" + apps[i] + "</option>");
                }
            }
        }
    });


    var oTab=$.table.oTableInit(options);
    oTab.Init();

    $('.datetimepicker').datetimepicker({
        language: 'zh-CN',
        CustomFormat: 'yyyy-mm-dd HH:ii:ss',
        weekStart: 1,
        todayBtn: 1,            //显示当天按钮，点击则选择当天当天时间
        autoclose: 1,           //选完时间自动关闭
        todayHighlight: 1,      //当天时间高亮
        startView: 2,           //从月视图开始，选天
        minView: 0,             //提供选择分钟的视图
        forceParse: 0,
        minuteStep: 1           //用于构建小时视图。就是最小的视图是每1分钟可选一次。是以分钟为单位的
    });

    var now = new Date();
    $("#datetimepicker2").datetimepicker("setDate", now);
    var pre5hours = now.setHours(now.getHours() - 5);
    $("#datetimepicker1").datetimepicker("setDate", new Date(pre5hours));
})

function exportHot() {
    $("#maxHotForm").attr("action","/key/export");//改变表单的提交地址为下载的地址
    $("#maxHotForm").submit();//提交表单
}
</script>

</body>

</html>
