register-new.js 1.39 KB
const $ = require('yoho-jquery');
const $captcha = $('#js-img-check');
const tip = require('plugin/tip');
const showErrTip = tip.show;
const Validate = require('plugin/validata');
const validate = new Validate($captcha, {
    useREM: {
        rootFontSize: 40,
        picWidth: 150
    }
});

class RegisterNew {
    constructor() {
        this.view = {
            getVerifyCodeBtn: $('#getVerifyCodeBtn'),
            regBtn: $('#regBtn'),
        };

        this.requested = false;

        this.getVerifyCodeBtn.on('click', this.getVerifyCode.bind(this));
    }

    /**
     * 获取验证码
     */
    getVerifyCode() {
        let params = {};

        $.ajax({
            url: '/passport/reg/verifymobile',
            type: 'POST',
            data: params,
            success: function(data) {
                validate.type === 2 && validate.refresh();
                if (data.code === 200) {
                    location.href = data.data;
                } else {
                    (data.changeCaptcha && validate.type !== 2) && validate.refresh();

                    showErrTip(data.message);
                    this.requested = false;
                }
            },
            error: function() {
                showErrTip('出错了,请重试');
                validate.refresh();
                this.requested = false;
            }
        });
    }
}

module.exports = RegisterNew;