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

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

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

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

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
            },
            success: 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);
                    }
                }
            }
        });
    }
});