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

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

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

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

api.bindClearEvt();

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

$btnSure.on('touchstart', function() {
    var 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('邮箱格式不正确,请重新输入');
    }
});