email.js 1.15 KB
/**
 * 找回密码-邮箱找回
 * @author: xuqi<qi.xu@yoho.cn>
 * @date: 2015/10/8
 */
let $ = require('yoho-jquery');

let $email = $('#email'),
    $btnSure = $('#btn-sure');

let api = require('../api');
let tip = require('plugin/tip');

let trim = $.trim;
let showErrTip = tip.show;

api.bindClearEvt();

$email.bind('input', function() {
    if (trim($email.val()) === '') {
        $btnSure.addClass('disable');
    } else {
        $btnSure.removeClass('disable');
    }
});

$btnSure.on('touchstart', function() {
    let email = trim($email.val());

    if ($btnSure.hasClass('disable')) {
        return;
    }

    if (api.emailRegx.test(email)) {
        $.ajax({
            url: '/passport/back/sendemail',
            type: 'POST',
            data: {
                email: email
            },
            success: function(data) {
                console.log(data);
                if (data.code === 200) {
                    location.href = data.data;
                } else {
                    showErrTip(data.message);
                }
            }
        });
    } else {
        showErrTip('邮箱格式不正确,请重新输入');
    }
});