third-pwd.js 2.61 KB
/**
 * 第三方绑定重设密码
 * @author: TaoHuang
 * @date: 2016/7/12
 */
var $ = require('yoho-jquery');

var pwdRegx = require('../common/mail-phone-regx').pwdValidateRegx;

var $passwordInput = $('#pwd'),
    $repasswordInput = $('#repwd');

var $sourceType = $('#sourceType');
var $openId = $('#openId');
var $mobile = $('#mobile');
var $area = $('#area');
var $next = $('#next');

require('yoho-jquery-placeholder');

function errTip(ele, msg) {
    var $errTip = ele.next('.tips');
    var $errMsg = $errTip.find('.content');

    $errMsg.text(msg);
    return $errTip.removeClass('hide');
}

function hideTip(ele) {
    return ele.next('.tips').addClass('hide');
}

$passwordInput.on('blur', function() {
    var length = $passwordInput.val().length;

    $passwordInput.removeClass('focus');

    if (length === 0) {
        errTip($passwordInput, '请输入密码');
        return;
    }

    if (length < 6 || length > 20) {
        errTip($passwordInput, '密码只支持 6-20 位字符,建议字母+数字的组合');
        return;
    }

    if (!pwdRegx.test($passwordInput.val())) {
        errTip($passwordInput, '密码只支持 6-20 位字符,建议字母+数字的组合');
        return;
    }

}).on('focus', function() {
    hideTip($passwordInput);
    $passwordInput.addClass('focus');
});

$repasswordInput.on('blur', function() {
    var length = $repasswordInput.val().length;

    $repasswordInput.removeClass('focus');

    if (length === 0) {
        errTip($repasswordInput, '请再次输入密码');
        return;
    }

    if ($passwordInput.val() !== $repasswordInput.val()) {
        errTip($repasswordInput, '两次输入的密码不一致,请重新输入');
        return;
    }

}).on('focus', function() {
    hideTip($repasswordInput);
    $repasswordInput.addClass('focus');
});

// 下一步
function nextPage() {
    $.ajax({
        type: 'POST',
        url: '/passport/autouserinfo/bindmobile',
        data: {
            openId: $openId.val(),
            sourceType: $sourceType.val(),
            mobile: $mobile.val(),
            area: $area.val(),
            password: $passwordInput.val()
        }
    }).then(function(result) {
        if (result.code === 200) {
            window.location.href = result.data.refer;
        } else {
            errTip($next, result.message);
        }
    });
}

$('[placeholder]').placeholder();

$next.on('click', function() {
    if (($.trim($passwordInput.val()) === '') || ($passwordInput.val() !== $repasswordInput.val())) {
        errTip($repasswordInput, '两次输入的密码不一致,请重新输入');
        return;
    }
    nextPage();
});