bind-info.js 3.57 KB
/**
 * 第三方绑定完善个人信息
 * @author: wq
 * @date: 2016/1/27
 */
var $ = require('yoho-jquery');
var dovalidate = false; // 校验验证码的标识
var isvalidatecode = false; // 是否验证成功的标识
var isvalidatepwd = false; // 密码验证是否通过的标识
var second = ''; // 倒计时时间
var nopermissionoption = ''; // 倒计时的dom
var sendmessagehtml = ''; // 发送短信的dom
var $pwd,
    $pwdParent,
    $pwdTip1,
    $pwdIntensity;

require('../../simple-header');

nopermissionoption = $('#nopermissionmessage').html();
sendmessagehtml = $('.validatewrapper').html();
second = +$('.second').text();


function gettype(str, i) {
    if (str.charCodeAt(i) >= 48 && str.charCodeAt(i) <= 57) {
        return 1;
    } else if (str.charCodeAt(i) >= 97 && str.charCodeAt(i) <= 122) {
        return 2;
    } else if (str.charCodeAt(i) >= 65 && str.charCodeAt(i) <= 90) {
        return 3;
    }

    return 4;
}

function isregular(cur, pre, type) {
    var curCode = cur.charCodeAt(0);
    var preCode = pre.charCodeAt(0);

    if (curCode - preCode === 0) {
        return true;
    }

    if (type !== 4 && (curCode - preCode === 1 || curCode - preCode === -1)) {
        return true;
    }

    return false;
}


function getcomplex(curType, preType) {
    if (preType === 0 || curType === preType) {
        return 0;
    } else if (curType === 4 || preType === 4) {
        return 2;
    } else {
        return 1;
    }
}

function changeSecond() {
    second -= 1;
    if (second < 0) {
        second = 60;
        $('.validatewrapper').html(sendmessagehtml);
        return;
    } else {
        $('.second').text(second);
        window.setTimeout(changeSecond, 1000);
    }

}

/**
 * 启动倒计时
 * @return {[type]} [description]
 */
function circleTime() {
    $('.validatewrapper').html(nopermissionoption);
    window.setTimeout(changeSecond, 1000);
}

function sendMessageValidate() {
    var mobile = '';
    var area = '';

    $(document).on('click', '#sendmessage', function() {
        circleTime();
        mobile = $('#mobile').val();
        area = $('#area').val();
        $.ajax({
            type: 'POST',
            url: '/passport/cert/sendCertMsg',
            data: {
                mobile: mobile,
                area: area
            }
        }).then(function(data) {
            if (data.code !== 200) {
                alert(data.message);
            }
        });

    });
}

/**
 * 最终提交表单
 */
function actionSubmit() {
    var mobile = '';
    var area = '';
    var code = '';

    area = $('#area').val();
    mobile = $('#mobile').val();
    code = $('#validatenum').val();
    $.ajax({
        type: 'POST',
        url: '/passport/cert/certMobile',
        data: {
            area: area,
            mobile: mobile,
            code: code
        }
    }).then(function(data) {
        if (data.code === 200) {
            window.location.href = data.data.nextUrl;
        } else {
            alert(data.message);
        }
    });
}

/**
 * 确定完善信息
 * @return {[type]} [description]
 */
function actionConfirm() {
    var validatenum = '';

    $('#confirmsubmit').on('click', function() {
        validatenum = $('#validatenum').val();
        if (validatenum === '') {
            alert('短信验证码不能为空');
            return;
        }

        if (isvalidatecode === false) {
            alert('请输入正确的验证码');
            return;
        }
        actionSubmit();
    });
}



function init() {
    circleTime(); // 倒计时
    sendMessageValidate();
    codeValidate();
    actionConfirm();
}

init();