@using GBLab.Common.Expand;
@{
    Layout = "~/Views/Shared/_Layout_User.cshtml";
    var config = ViewData["SystemConfig"] as GBLab.Entities.Config.SystemConfig;
}
<div class="middle-box text-center loginscreen   animated fadeInDown">
    <div>
        <div>
            <h1 class="logo-name"></h1>
        </div>
        <h3>欢迎登录 互联网集市</h3>
        <div class="m-t" role="form">
            <div class="form-group">
                <input id="userName" name="userName" type="text" class="form-control" placeholder="请输入用户名" required="">
            </div>
            <div class="form-group">
                <input id="userPasswrod" name="userPasswrod" type="password" class="form-control" placeholder="请输入密码" required="">
            </div>
            <div class="form-group">
                <input id="code" name="code" type="text" class="form-control" placeholder="请输入验证码" required="">
            </div>
            <div class="form-group" style="text-align:left">
                <img src="/Code.aspx" alt="" width="76" height="35" style="vertical-align: middle;" />
            </div>
            <button type="submit" id="subapply" class="btn btn-primary block full-width m-b">登 录</button>
            <p class="text-muted text-center">
                <small>忘记密码了？</small><a href="/user/reg">注册一个新账户</a>
            </p>
        </div>
    </div>
</div>
@section JavaScript{
    <script type="text/javascript">
        $(function () {
            // 如果已经注册，直接跳转到会员中心页面
            if ($.cookie('@(GBLab.Common.Utils.ConfigHelper.ZYUserAuthName)') != null && $.cookie('@(GBLab.Common.Utils.ConfigHelper.ZYUserAuthName)') != undefined) {
                tousercenter();
            } else {
                $("#subapply").click(function () {
                    sub();
                });
            }
        });
        function tousercenter() {
            window.location = '/default.html';
        }
        function sub() {
            var userName = $('input[name="userName"]').val();
            var userPasswrod = $('input[name="userPasswrod"]').val();
            var code = $('input[name="code"]').val();
            // 获取分类信息
            $.ajax({
                type: "POST",
                url: "/user/loginaction",
                data: "userName=" + userName
                    + "&userPasswrod=" + userPasswrod
                    + "&code=" + code,
                success: function (data) {
                    console.log(data);
                    var result = $.parseJSON(data);
                    if (result != null && result != undefined) {
                        if (result.statusCode === 200) {
                            alert("[成功]账户登录成功。" + result.message);
                            setTimeout("window.location.href='/default.html';", 2000)
                        }
                        if (result.statusCode === 300) {
                            alert("[失败]" + result.message)
                        }
                    }
                },
                error: function (data) {
                    alert('数据提交失败，请联系管理员。')
                }
            });
        }
    </script>
}