<!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({{.uid}}, {{.account}})">
    <div class="x-body layui-anim layui-anim-up">
        <blockquote class="layui-elem-quote">
          玩家ID:
          <input id="uid" type="text">
          <input class="layui-btn" type="button" onclick="submitQuery()" value=查询>
          <br>
          玩家账号:
          <input id="account" type="text">
          <input class="layui-btn" type="button" onclick="submitQuery()" value=查询>
          <br>
          <br>
          <span id ="account_status" style="font-size:20px;"> 账号状态 : 正常 </span>
          <br>
          <input class="layui-btn" type="button" onclick="submitBan()" value=封禁>
              
          <input class="layui-btn" type="button" onclick="submitUnban()" value=解禁>
        </blockquote>
    </div>
    <table border="1">
      <thead>
        <th style="width:128px;">角色ID</th>
        <th style="width:128px;">角色昵称</th>
        <th style="width:256px;">账号</th>
        <th style="width:256px;">服务器名</th>
        <th style="width:150px;">服务器id</th>
        <th style="width:150px;">角色状态</th>
        <th style="width:150px;">是否在线</th>
        <th style="width:150px;">角色等级</th>
        <th style="width:200px;">角色战力</th>
        <th style="width:256px;">创角时间</th>
        <th style="width:256px;">最近登入时间</th>
        <th style="width:256px;">最近登出时间</th>
      </thead>
      <tbody>
        {{range .role_map}}
          <tr>
            <td style = "text-align:center;">{{.pid}}</td>
            <td style = "text-align:center;">{{.name}}</td>
            <td style = "text-align:center;">{{.account}}</td>
            <td style = "text-align:center;">{{.server_name}}</td>
            <td style = "text-align:center;">{{.server_id}}</td>
            <td style = "text-align:center;">{{.status}}</td>
            <td style = "text-align:center;">{{.is_online}}</td>
            <td style = "text-align:center;">{{.grade}}</td>
            <td style = "text-align:center;">{{.power}}</td>
            <td style = "text-align:center;">{{.create_time}}</td>
            <td style = "text-align:center;">{{.login_time}}</td>
            <td style = "text-align:center;">{{.logout_time}}</td>
          </tr>
        {{end}}
      </tbody>
    </table>
    
    <script language="JavaScript">
      var status =  {{.account_status}};
      updateStatus(status)
      
      function InitParams(uid, account) {
        if (uid > 0) {
            document.getElementById("uid").value = uid;
        }
        if (account.length > 0) {
            document.getElementById("account").value = account;
        }
      }

      function submitQuery () {
        var uid = document.getElementById("uid").value;
        var account = document.getElementById("account").value;
        var text = "uid=" + encodeURI(uid) + "&account=" + encodeURI(account) + "&action=query";
        $.ajax({
          type:"get",
          url:"/accountquery?" + text,
          success:function (data) {
            // alert(data.status);
            if (data.status){
              window.location.href="/accountquery?"+text;
            }else{
              if (data.info){
                alert(data.info);
              }else{
                window.location.href="/accountquery?"+text;
              }
            }
          }
        });
      }
      function submitBan () {
        var uid = document.getElementById("uid").value;
        var account = document.getElementById("account").value;
        var text = "uid=" + encodeURI(uid) + "&account=" + encodeURI(account) + "&isban=" + encodeURI(1) + "&action=update";
        
        $.ajax({
          type:"put",
          url:"/accountquery?" + text,
          success:function (data) {
            if (data.info){
              alert(data.info);
            }
            window.location.href="/accountquery?"+"uid=" + encodeURI(uid) + "&account=" + encodeURI(account) + "&action=query";
          }
        });
      }
      function submitUnban () {
        var uid = document.getElementById("uid").value;
        var account = document.getElementById("account").value;
        var text = "uid=" + encodeURI(uid) + "&account=" + encodeURI(account) + "&isban=" + encodeURI(0) + "&action=update";
        
        $.ajax({
          type:"put",
          url:"/accountquery?" + text,
          success:function (data) {
          if (data.info){
              alert(data.info);
            }
            window.location.href="/accountquery?"+"uid=" + encodeURI(uid) + "&account=" + encodeURI(account) + "&action=query";
          }
        });
      }
      function updateStatus (status) {
        document.getElementById('account_status').innerText="账号状态 : "+status;
      }
    </script>
    </body>
</html>