Blame view

public/js/passport/bind/password.js 1.96 KB
姜枫 authored
1 2 3 4 5
/**
 * 注册-密码
 * @author: xuqi<qi.xu@yoho.cn>
 * @date: 2015/10/8
 */
王水玲 authored
6
var $ = require('yoho-jquery');
姜枫 authored
7 8

var $pwd = $('#pwd'),
9 10
    $pwdLint = $('.pwd-lint'),
    $pwdLintTxt = $pwdLint.find('.pwd-lint-txt'),
姜枫 authored
11 12 13
    $btnSure = $('#btn-sure');

var api = require('../api');
郝肖肖 authored
14
var tip = require('plugin/tip');
15
var validatePWD = require('../password-check');
姜枫 authored
16 17 18 19

var trim = $.trim;
var showErrTip = tip.show;
王水玲 authored
20
var sourceType = $('#sourceType').val(),
姜枫 authored
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
    openId = $('#openId').val(),
    phoneNum = $('#phone-num').val(),
    areaCode = $('#area-code').val().replace('+', ''),
    code = $('#code').val();

function startBind(password) {
    $.ajax({
        url: '/passport/bind/bindMobile',
        type: 'post',
        data: {
            areaCode: areaCode.replace('+', ''),
            phoneNum: phoneNum,
            openId: openId,
            sourceType: sourceType,
            password: password,
            code: code
        },
姜枫 authored
38
        success: function(res) {
姜枫 authored
39 40
            if (res.code === 200) {
                tip.show('登录成功');
姜枫 authored
41
                setTimeout(function() {
姜枫 authored
42 43 44 45 46 47
                    location.href = res.data.refer;
                }, 2000);
            } else {
                tip.show(res.message);
            }
        },
姜枫 authored
48
        error: function() {
姜枫 authored
49 50 51 52 53 54
            tip.show('登录失败,请重试!');
        }
    });
}

api.bindEyesEvt({
姜枫 authored
55
    status: 'open' // 默认眼睛打开
姜枫 authored
56 57
});
姜枫 authored
58
$pwd.bind('input', function() {
59 60 61 62 63 64 65 66 67 68
    var val = $.trim(this.value);
    var bool = validatePWD(val, function(res) {
        $pwdLint.css({visibility: res.valid ? 'hidden' : 'visible'});

        if (!res.valid) {
            $pwdLintTxt.text(res.msg);
        }
    });

    $btnSure.toggleClass('disable', !bool);
姜枫 authored
69 70
});
姜枫 authored
71
$btnSure.on('touchstart', function() {
姜枫 authored
72 73 74 75 76 77
    var pwd = trim($pwd.val());

    if ($btnSure.hasClass('disable')) {
        return;
    }
78
    if (validatePWD(pwd) === false) {
姜枫 authored
79 80 81 82 83
        showErrTip('密码6-20位,请重新输入');
    } else {
        startBind(pwd);
    }
});