password.js 1.49 KB
/**
 * 注册-密码
 * @author: xuqi<qi.xu@yoho.cn>
 * @date: 2015/10/8
 */
var $ = require('yoho.jquery');

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

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

var trim = $.trim;
var showErrTip = api.showErrTip;

api.initErrTip();

api.bindEyesEvt();

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

$btnSure.on('touchstart', function() {
    var pwd = trim($pwd.val());

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

    if (api.pwdValidate(pwd) === false) {
        showErrTip('密码6-20位,请重新输入');
    } else {
        $.ajax({
            type: 'POST',
            url: '/passport/register/regmobile',
            data: {
                password: pwd
            }
        }).then(function(data) {
            if (data.code === 200) {
                showErrTip('注册成功');

                //1000ms后跳转页面
                setTimeout(function() {
                    location.href = data.data;
                }, 1000);
            } else {
                if (data.code === 401 || data.code === 404 || data.code === 505) {
                    showErrTip(data.message);
                } else {
                    showErrTip(data.message);
                    setTimeout(function() {
                        location.href = data.data;
                    }, 1000);
                }
            }
        });
    }
});