<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <title>欢迎页面-X-admin2.0</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
        <link rel="stylesheet" href="./static/css/font.css">
        <link rel="stylesheet" href="./static/css/xadmin.css">
        
        <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
        <script src="./static/lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="./static/js/xadmin.js"></script>
    </head>
    <body onload="InitParams({{.Scene}}, {{.EventId}})">
    <input type="text" id="token" value={{.token}} hidden=true>
    <div class="x-body layui-anim layui-anim-up">
        <blockquote class="layui-elem-quote">
          场景:<input id="scene" type="text" />

          事件ID:<input id="eventid" type="text" />
          <br>
          开始时间:
          <input type="date" id="start_time" name="trip-start" value={{.Start_time}} min="2018-01-01 00:00:00" max="2018-12-31 00:00:00" />

          结束时间:
          <input type="date" id="end_time" name="trip-start" value={{.End_time}} min="2018-01-01 23:59:59" max="2018-12-31 23:59:59" />
          <br>
          <br>
          <input class="layui-btn" type="button" onclick="submitUpdate()" value=查询>
        </blockquote>
    </div>
    <table border="1">
      <thead>
        <th style="width:200px;">时间</th>
        <th style="width:128px;">服务器ID</th>
        <th style="width:128px;">场景</th>
        <th style="width:128px;">事件ID</th>
        <th style="width:400px;">内容</th>
      </thead>
      <tbody>
        {{range .Events}}
          <tr>
            <td style = "text-align:center;">{{TimeToStr .EventTime}}</td>
            <td style = "text-align:center;">{{.ServerId}}</td>
            <td style = "text-align:center;">{{.Scene}}</td>
            <td style = "text-align:center;">{{.EventId}}</td>
            <td style = "text-align:center;">{{.Label}}</td>
          </tr>
        {{end}}
      </tbody>
    </table>
    
    <script language="JavaScript">
      function InitParams(Scene, EventId) {
        if (Scene.length > 0) {
            document.getElementById("scene").value = Scene;
        }
        if (EventId != null && EventId.length > 0) {
            document.getElementById("eventid").value = EventId;
        }
      }
    
      function submitUpdate () {
        var scene = document.getElementById("scene").value;
        var eventid = document.getElementById("eventid").value;
        var start_time = document.getElementById("start_time").value;
        var end_time = document.getElementById("end_time").value;
        
        var text = "token=" + encodeURI(token);
        text += "&scene=" + encodeURI(scene);
        text += "&eventid=" + encodeURI(eventid);
        text += "&start_time=" + encodeURI(start_time);
        text += "&end_time=" + encodeURI(end_time);
        
        $.ajax({
          type:"get",
          url:"/client?" + text,
          success:function (data) {
            // alert(data.status);
            if (data.status){
              window.location.href="/client?"+text;
              if (data.info){
                layer.msg(data.info,{icon:1,time:1000});
              }
            }else{
              if (data.info){
                alert(data.info);
              }else{
                window.location.href="/client?"+text;
              }
            }
          }
        });
      }
    </script>
    </body>
</html>