<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <title>欢迎页面-X-admin2.0</title>
        <meta name="renderer" content="webkit">
        <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({{.SelectUserName}}, {{.Days}}, {{.Promoter}})">
    <input type="text" id="token" value={{.token}} hidden=true>
    <div class="x-body layui-anim layui-anim-up">
        <blockquote class="layui-elem-quote">
          <label for="select_username" id="label_username">主播列表:</label>
          <select name="" id="select_username" style="width:256px;">
            <option value="">全部</option>
            {{range .users}}
              <option value={{.Username}}>{{.Username}}</option>
            {{end}}
          </select>
          {{"       "}}
          过往天数:<input id="days" type="text" name="天数" />
          <br>
          <br>
          <input class="layui-btn" type="button" onclick="submitUpdate()" value=刷新>
              
          <input class="layui-btn" type="button" onclick="submitDownload()" value=下载>
        </blockquote>
    </div>
    <div id="container" style="width: 1600px; height: 800px; margin: 0 auto"></div>
    <script language="JavaScript">
      $(document).ready(function() {
        var chart = {
          type: 'spline'
        };
        var title = {
            text: '注册'   
        };
        var subtitle = {
            text: '来源:游戏服'
        };
        var xAxis = {
            title: {
              text: '时间(每5分钟)'
            },
            tickPixelInterval: 1,
            categories: {{.Categories}}
        };
        var yAxis = {
            title: {
              text: '人数'
            },
            plotLines: [{
              value: 0,
              width: 1,
              color: '#808080'
            }]
        };   

        var tooltip = {
          valueSuffix: '人'
        }

        var legend = {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'middle',
            borderWidth: 0
        };

        var series =  [
        ];
        var list = {{.Series}}
        for ( var i= 0; i < list.length; i++){
          series.push({"name":list[i].Name, "data":eval(list[i].Data)})
        }

        var json = {};

        json.title = title;
        json.subtitle = subtitle;
        json.xAxis = xAxis;
        json.yAxis = yAxis;
        json.tooltip = tooltip;
        json.legend = legend;
        json.series = series;
        json.chart = chart;

        $('#container').highcharts(json);
      });
    
      var promoter = 0
      function InitParams(SelectUserName, Days, Promoter) {
        promoter = Promoter
        if (SelectUserName.length > 0) {
            var obj = document.getElementById("select_username");
            if (obj.options.length > 0){
              for (var i = 0; i < obj.options.length; i ++){
                if (obj.options[i].value == SelectUserName) {
                  obj.options[i].selected = true;
                  break
                }
              }
            }
        }
        if (Days != null && Days > 0) {
            document.getElementById("days").value = Days;
        }
        if (promoter == 1){
          document.getElementById("label_username").hidden = true
          document.getElementById("select_username").hidden = true
        }
      }

      function submitUpdate () {
        var sid = document.getElementById("select_username").value;
        var days = document.getElementById("days").value;
        var text = "select_username=" + encodeURI(sid) + "&days=" + encodeURI(days);
        
        $.ajax({
          type:"get",
          url:"/register?" + text,
          success:function (data) {
            // alert(data.status);
            if (data.status){
              window.location.href="/register?"+text;
              if (data.info){
                layer.msg(data.info,{icon:1,time:1000});
              }
            }else{
              if (data.info){
                alert(data.info);
              }else{
                window.location.href="/register?"+text;
              }
            }
          }
        });
      }
      function submitDownload () {
        var sid = document.getElementById("select_username").value;
        var days = document.getElementById("days").value;
        var text = "select_username=" + encodeURI(sid) + "&days=" + encodeURI(days) + "&querydata=register";
        
        $.ajax({
          type:"get",
          url:"/register?" + text,
          success:function (data) {
            // alert(data.status);
            if (data.status){
              window.location.href="/register?"+text;
              if (data.info){
                layer.msg(data.info,{icon:1,time:1000});
              }
            }else{
              if (data.info){
                alert(data.info);
              }else{
                window.location.href="/register?"+text;
              }
            }
          }
        });
      }
    </script>
    </body>
</html>