<?php

use yii\helpers\Html;
use yii\bootstrap\ActiveForm;

/* @var $this yii\web\View */
/* @var $form yii\bootstrap\ActiveForm */
/* @var $model \common\models\LoginForm */

$this->title = '微信登录';
$cssString = "html{
    background: url('" . Yii::$app->config->get('site_login_bg') . "');
    background-size: cover !important;
    background-attachment: fixed !important;
}
.login-page, .register-page{background: transparent;}
";
$this->registerCss($cssString);

?>

    <div class="login-box">
        <div class="login-logo">
            <a href="#"><b style="color: #fff;"><?= Yii::$app->config->get('name') ?></b></a>
        </div>
        <!-- /.login-logo -->
        <div class="login-box-body">
            <a href="login">
                <img src="/assets/images/password.png"
                     style="height: 40px; margin-left: 250px; cursor: pointer; position: absolute;" title="密码登录">
            </a>
            <h4 class="login-box-msg" style="padding-bottom: 30px">微信登录</h4>
            <?php if ($errcode == 0): ?>
                <div class="row">
                    <div class="col-xs-12" style="text-align: center">
                        <img style="width: 150px" src="<?= $media['url'] ?>">
                    </div>
                </div>
                <div class="row" style="padding-top: 10px">
                    <div class="col-xs-12 js-footer" style="text-align: center">
                        <i class="fa fa-fw fa-wechat"></i>
                        <span class="js-tips">打开微信扫一扫登录</span>
                    </div>
                </div>
            <?php else: ?>
                <div class="row" style="padding-top: 10px">
                    <div class="col-xs-12" style="text-align: center">
                        <i class="fa fa-fw fa-wechat"></i>
                        <span class=""><?= $errmsg ?></span>
                    </div>
                </div>
            <?php endif; ?>

        </div>
        <!-- /.login-box-body -->
    </div><!-- /.login-box -->


<?php
$js = <<<JS

$(document).ready(function() {
    setInterval( () => {
        $.post(location.href, {
            access_token:"{$access_token}",
            qrcode_hash:"{$media['name']}",
        }, (res) => {
            if (res.status == 1) {
                location.href = res.returnUrl;
            } else {
                 $('.js-tips').text(res.message);
                 if (res.errors.qrcode_hash) {
                     $('.js-footer').css('color', '#19be6b');
                 } else {
                     $('.js-footer').css('color', '#ed3f14');
                 }
            }
        });
    }, 1000);
});
JS;
$this->registerJs($js);
?>