<?php
/* @var $this \yii\web\View */
use yii\helpers\Url;

$this->title = '模拟账户申请';
?>
<?php $this->beginBlock('header_script'); ?>
<style>
    .cover {
        width: 100%;
        height: 190px;
    }

    .fileinput-button {
        position: relative;
        display: inline-block;
        overflow: hidden;
        width: 100%;
        height: 190px;
        text-align: center;
        border: 1px solid #DDD;
    }

    .fileinput-button .s {
        margin-top: 60px;
        font-size: 40px;
    }

    .fileinput-button input {
        position: absolute;
        right: 0px;
        top: 0px;
        opacity: 0;
        -ms-filter: 'alpha(opacity=0)';
        font-size: 100em;
    }

    .success {
        display: none;
        margin: 100px 0px;
        text-align: center;
    }

    .success h1 {
        color: #1ab394;
    }

    .wx {
        margin: 50px;
        text-align: center;
    }

    .icheckbox_square-green label.error {
        position: absolute;
        white-space: nowrap;
        top: 0;
        left: 190px;
    }

    .icheckbox_square-green input.error {
        background-color: #FBE3E4;
    }
</style>
<?php $this->endBlock(); ?>
<div class="ibox">
    <div class="ibox-title">
        <h2>模拟账户申请</h2>
    </div>
    <div class="ibox-content">
        <form id="form">
            <input type='hidden' name='token' value='1950354260442222285'/>
            <div class="row">
                <div class="col-sm-7 b-r">
                    <div id="result" class="success">
                        <h1><i class="fa fa-check"></i>恭喜，账户申请成功！</h1>
                        <p id="loginMsg"></p>
                    </div>
                    <div id="req">
                        <div class="form-group"><label>姓名 *</label>
                            <input name="name" type="text" placeholder="您的姓名" class="form-control">
                        </div>
                        <div class="form-group">
                            <label>电子邮箱 *</label>
                            <input id="email" name="email" type="text" placeholder="您的电子邮箱" class="form-control">
                        </div>
                        <div class="form-group">
                            <label>手机号码 *</label>
                            <input id="mobile" name="mobile" type="text" placeholder="您的手机号码" class="form-control">
                        </div>
                        <div class="form-group">
                            <label>金额</label>
                            <input type="text" class="form-control" value="100000" readonly>
                        </div>
                        <div class="form-group">
                            <label>杠杆</label>
                            <select name="level" class="form-control select22">
                                <option value="100">1:100</option>
                                <option value="200">1:200</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <label>
                                <input name="agree" type="checkbox" class="i-checks">
                                我已阅读和同意<a href="<?= Url::to(['agreement']) ?>" target="_blank">《用户协议》</a>
                            </label>
                        </div>
                        <div class="form-group">
                            <button id="submit" class="btn btn-lg btn-primary" type="button">
                                <strong>提交申请</strong>
                            </button>
                        </div>
                    </div>
                </div>
                <!--<div class="col-sm-5">
                    <div class="wx">
                        <div class="qrcode" id="qrcode"></div>
                        <h3>扫一扫，使用微信开户</h3>
                    </div>
                </div>-->
            </div>
        </form>
    </div>
</div>
<?php $this->beginBlock('footer_script'); ?>
<script src="<?= STATIC_URL ?>/ui/js/jquery-qrcode-0.14.0.min.js"></script>
<script>
    jQuery('#qrcode').qrcode({
        render: 'image',
        correctLevel: 0,
        text: '<?= Url::current([], true) ?>',
        size: 200,
        background: '#FFF'
    });
    function readFile0(obj) {
        var file = obj.files[0];
        if (!/image\/\w+/.test(file.type)) {
            return false
        }
        var reader = new FileReader();
        reader.readAsDataURL(file);
        reader.onload = function (e) {
            $('#cover0').attr('src', this.result)
        }
    }
    function readFile1(obj) {
        var file = obj.files[0];
        if (!/image\/\w+/.test(file.type)) {
            return false
        }
        var reader = new FileReader();
        reader.readAsDataURL(file);
        reader.onload = function (e) {
            $('#cover1').attr('src', this.result)
        }
    }
    var wait = 120;
    function time() {
        if (wait == 0) {
            $('#sendSms').html('获取验证码');
            wait = 120
        } else {
            $('#sendSms').html(wait + '秒后重试');
            wait--;
            setTimeout(function () {
                time()
            }, 1000)
        }
    }
    function sendSms() {
        if ($('#mobile').val().length == 11) {
            $.ajax({
                type: 'POST',
                url: '<?= Url::to(['sendsms']) ?>',
                data: {
                    mobile: $('#mobile').val()
                },
                dataType: 'json',
                beforeSend: function () {
                },
                success: function (data) {
                    if (data.isSuccess) {
                        time()
                    } else {
                        toastr.error(data.msg, '提示')
                    }
                },
                complete: function (XMLHttpRequest, textStatus) {
                },
                error: function () {
                }
            })
        } else {
            return;
        }
    }
    $(document).ready(function () {
        $('#form').validate({
            rules: {
                'name': {
                    required: true
                },
                'email': {
                    required: true,
                    email: true
                },
                'mobile': {
                    required: true
                },
                'level': {
                    required: true
                },
                'agree': {
                    required: true
                }
            }
        })
    });
    $('#submit').on('click', function () {
        if ($('#form').valid()) {
            $.ajax({
                type: 'POST',
                url: '<?= Url::to(['opendemosave']) ?>',
                data: $('#form').serialize(),
                dataType: 'json',
                beforeSend: function () {
                },
                success: function (data) {
                    if (data.isSuccess) {
                        $('#req').hide();
                        $('#loginMsg').html(data.msg);
                        $('#result').show();
                        //toastr.success(data.msg, "提示");
                    } else {
                        toastr.error(data.msg, '提示')
                    }
                },
                complete: function (XMLHttpRequest, textStatus) {
                },
                error: function () {
                }
            })
        }
    })
</script>
<?php $this->endBlock(); ?>
