cert.js 2.51 KB
/**
 * 第三方绑定完善个人信息
 * @author: wq
 * @date: 2016/1/27
 */
var $ = require('yoho-jquery');
var second = ''; // 倒计时时间
var nopermissionoption = ''; // 倒计时的dom
var sendmessagehtml = ''; // 发送短信的dom

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

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

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 = '';
    var refer = '';

    area = $('#area').val();
    mobile = $('#mobile').val();
    code = $('#validatenum').val();
    refer = $('#refer').val();

    $.ajax({
        type: 'POST',
        url: '/passport/cert/certMobile',
        data: {
            area: area,
            mobile: mobile,
            code: code,
            refer: refer
        }
    }).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;
        }

        actionSubmit();
    });
}



function init() {
    sendMessageValidate();
    actionConfirm();

    $('#sendmessage').click();
    circleTime(); // 倒计时
}

init();