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

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

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

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

var nickname = $('#nickname').val(),
    sourceType = $('#sourceType').val(),
    openId = $('#openId').val(),
    phoneNum = $('#phone-num').val(),
    areaCode = $('#area-code').val().replace('+', '');

function startBind(password) {
    $.ajax({
        url: '/passport/bind/bindMobile',
        type: 'post',
        data: {
            areaCode: areaCode.replace('+', ''),
            phoneNum: phoneNum,
            openId: openId,
            sourceType: sourceType,
            nickname: nickname,
            password: password
        },
        success: function(res) {
            if (res.code === 200) {
                tip.show('登录成功');
                setTimeout(function() {
                    location.href = res.data.refer;
                }, 2000);
            } else {
                tip.show(res.message);
            }
        },
        error: function(err) {
            tip.show('登录失败,请重试!');
        }
    });
}

api.bindEyesEvt({
    status: 'open' //默认眼睛打开
});

$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 {
        startBind(pwd);
    }
});