password.js 3.04 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 tip = require('../../plugin/tip');

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

var qs;

require('../../common');

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

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

qs = window.queryString;

if (qs.selected && qs.selected === 'N') {
    $('.pitch').removeClass('select').html('&#xe648;');
}

$('.pitch').on('click', function() {
    if ($('.pitch').hasClass('select')) {
        $(this).removeClass('select');
        $(this).html('&#xe648;');
    } else {
        $(this).addClass('select');
        $(this).html('&#xe60a;');
    }
});

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

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

    if (api.pwdValidate(pwd) === false) {
        showErrTip('密码6-20位,请重新输入');
    } else {

        if ($('.pitch').hasClass('secect')) {
            $.ajax({
                type: 'POST',
                url: '/passport/reg/setpassword',
                data: {
                    password: pwd,
                    phoneNum: $('#phone-num').val(),
                    areaCode: $('#area-code').val(),
                    token: $('#token').val()
                },
                success: function(data) {
                    var res = data.data;

                    if (data.code === 200) {
                        showErrTip('注册成功');

                        location.href = res.href;
                    } else {
                        showErrTip(data.message);
                    }
                }
            });
        } else {
            $('.prompt').show();

            $('.ensure').on('click', function() {
                $('.prompt').hide();

                $.ajax({
                    type: 'POST',
                    url: '/passport/reg/setpassword',
                    data: {
                        password: pwd,
                        phoneNum: $('#phone-num').val(),
                        areaCode: $('#area-code').val(),
                        token: $('#token').val()
                    },
                    success: function(data) {
                        var res = data.data;

                        if (data.code === 200) {
                            showErrTip('注册成功');

                            location.href = res.href;
                        } else {
                            showErrTip(data.message);
                        }
                    }
                });
            });

            $('.deny').on('click', function() {
                //console.log('//m.yohobuy.com/passport/agreement' + window.location.search)
                location.href = '//m.yohobuy.com/passport/agreement' + window.location.search;
            });
        }
    }
});