<!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 src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
        <script src="http://code.highcharts.com/highcharts.js"></script>
    </head>
    <body onload="InitParams({{.Player_id}}, {{.Item_id}})">
    <div class="x-body layui-anim layui-anim-up">
        <blockquote class="layui-elem-quote">
          玩家ID:<input id="player_id" type="text" />

          资源ID:<input id="item_id" 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=查询>

          <input class="layui-btn" type="button" onclick="submitDownload()" value=下载>
        </blockquote>
    </div>
    <table border="1">
      <thead>
        <th style="width:256px;">时间</th>
        <th style="width:128px;">玩家ID</th>
        <th style="width:256px;">事件ID</th>
        <th style="width:100px;">物品ID</th>
        <th style="width:100px;">变化数量</th>
        <th style="width:128px;">变化后剩余数量</th>
      </thead>
      <tbody>
        {{range .Events}}
          <tr>
            <td style = "text-align:center;">{{.EventTime}}</td>
            <td style = "text-align:center;">{{.Uid}}</td>
            <td style = "text-align:center;">{{.Event}}</td>
            <td style = "text-align:center;">{{.ItemId}}</td>
            <td style = "text-align:center;">{{.DeltaCount}}</td>
            <td style = "text-align:center;">{{.RemainCount}}</td>
          </tr>
        {{end}}
      </tbody>
    </table>
    <script language="JavaScript">
      function InitParams(PlayerId, ItemId) {
        if (PlayerId == null || PlayerId.length == 0) {
          PlayerId = "1000000"
        }
        document.getElementById("player_id").value = PlayerId;
        if (ItemId > 0) {
            document.getElementById("item_id").value = ItemId;
        }
      }
    
      function submitUpdate () {
        var uid = document.getElementById("player_id").value;
        var item_id = document.getElementById("item_id").value;
        var start_time = document.getElementById("start_time").value;
        var end_time = document.getElementById("end_time").value;
        var text = "uid=" + encodeURI(uid) + "&item_id=" + encodeURI(item_id) + "&start_time=" + encodeURI(start_time) + "&end_time=" + encodeURI(end_time) + "&action=query";
        
        $.ajax({
          type:"get",
          url:"/resource?" + text,
          success:function (data) {
            // alert(data.status);
            if (data.status){
              window.location.href="/resource?"+text;
              if (data.info){
                layer.msg(data.info,{icon:1,time:1000});
              }
            }else{
              if (data.info){
                alert(data.info);
              }else{
                window.location.href="/resource?"+text;
              }
            }
          }
        });
      }
      function submitDownload () {
        var uid = document.getElementById("player_id").value;
        var item_id = document.getElementById("item_id").value;
        var start_time = document.getElementById("start_time").value;
        var end_time = document.getElementById("end_time").value;
        var text = "uid=" + encodeURI(uid) + "&item_id=" + encodeURI(item_id) + "&start_time=" + encodeURI(start_time) + "&end_time=" + encodeURI(end_time) + "&querydata=resource";
        
        $.ajax({
          type:"get",
          url:"/resource?" + text,
          success:function (data) {
            // alert(data.status);
            if (data.status){
              window.location.href="/resource?"+text;
              if (data.info){
                layer.msg(data.info,{icon:1,time:1000});
              }
            }else{
              if (data.info){
                alert(data.info);
              }else{
                window.location.href="/resource?"+text;
              }
            }
          }
        });
      }
    </script>
    </body>
</html>