<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
    <title>登录</title>
    <link rel="stylesheet" href="/canyin2/Public/static/css/animate.css">
    <link rel="stylesheet" href="/canyin2/Public/static/css/base.css">
    <link rel="stylesheet" href="/canyin2/Public/static/css/login.css">
</head>

<body>
    <div id="wrapper">
        <div class="main_box">
            <div class="title">Login</div>
            <form>
            <div class="input_wrapper">
                <div class="row account">
                    <input type="text" required="true" id="username"  placeholder="Insert Account Number">
                </div>
                <div class="row password">
                    <input type="password" required="true" id="password" placeholder="Insert Password">
                </div>
            </div>
            <div class="tips"><a> </a></div>
            <div class="button-wrapper command">
                <button class="sign-button submit" id="submit" type="button">login</button>
            </div>
            </form>
        </div>
    </div>
    </div>
    <!--<div class="logo" id="logo">
        <a href="http://mpwechat.net"><img alt="mpwechat.net" title="mpwechat.net" src="/canyin2/Public/static/images/canyin.png" ></a>
    </div>-->
    <script type='text/javascript' src='/canyin2/Public/static/js/jquery-1.11.1.min.js'></script>
    <script src="/canyin2/Public/layer/layer.js"></script>
    <!-- <script src="/canyin2/Public/js/jquery.min.js"></script> -->
    <script type='text/javascript' src='/canyin2/Public/static/js/jquery.particleground.min.js'></script>
    <script type='text/javascript' src='/canyin2/Public/static/js/demo.js'></script>
    <script type="text/javascript" src="/canyin2/Public/static/js/login.js"></script>
</body>
<script type="text/javascript">
    $(function(){
       function layert(content){
        layer.open({
          title:'',
          content:content,
          shade:0.2,
          success: function(layero, index){
            $(document).on('keypress', function(event){
              if(event.keyCode == "13"){
                layer.close(index);
              }
            });
          }
        });
      }
      $("#username")[0].focus();
      $('input').bind('keypress',function(event){
        if(event.keyCode == "13"){
          $(this).blur();
          $("#submit").click();
        }
      });
      var force = 0;
      var flag = 0;
      $("#submit").on('click',function(){
        console.log("click")
        $(this).blur();
        if(flag) return false;
        var username = $('#username').val();
        var password = $('#password').val();
        if(!username){layert('Please enter the account number');return false;}
        if(!password){layert('Please enter password');return false;}
        flag = 1;
        $.ajax({
          url: "<?php echo U('doLogin');?>",
          data:{
            "username":username,
            "password":password,
            "force":force
          },
          type: "POST",
          header: {
            Accept:{
              'Content-Type':'application/json;charset=UTF-8'
            }
          },
          dataType:"json",
          success:function(result){
            // console.log(1)
            
            if(result == 1){
              // layer.msg(result.info);
              // var link = "<?= session('toy_admin_after_login')?:U('Admin/index'); ?>";
              var link = "<?php echo U('Index/index');?>";
              window.location.href = link;
            }
            if(result == 1000){
              layer.msg('Please enter password');
            }
            if(result == 2000){
              layer.msg('The account has been disabled');
            }
            if(result == 3000){
              layer.msg('Password mistake');
            }
            if(result == 4000){
              layer.msg('Login failed');
            }
            if(result == 5000){
              layer.msg('This account has been logged in other devices, please log out in this device first');
            }
          },
          error :function(res){
            console.log(1)
          },
          complete: function(res){
            flag = 0;
          }
        });
      });
    });
</script>
</html>