thirdlogin.js 3.29 KB
/**
 * 登录
 * @author: wq
 * @date: 2016/1/21
 */
var $ = require('yoho.jquery');

function chooseProtocol() {
    $('.choosetag').on('change', function() {
        if ($(this).attr('checked')) {
            $('.choosewrapper').css({
                'background-image': 'url("http://webstatic.dev.yohobuy.com/img/passport/choosed.png")'
            });
        } else {
            $('.choosewrapper').css({
                'background-image': 'none'
            });
        }

    });
}

function chooseAreaToogle() {
    $('.optionshow').on('click', function() {
        $('.optionslist').toggleClass('hide');
    });
}

function cancelChooseArea() {
    $(document).on('click', 'body', function(e) {
        var $target = $(e.target);

        if ($target.hasClass('yohoselectarea') ||
            $target.hasClass('yohoselectarea') ||
            $target.hasClass('areaname') ||
            $target.hasClass('righttag') ||
            $target.hasClass('optionslist') ||
            $target.hasClass('optionitem')) {
            return;
        } else {
            $('.optionslist').addClass('hide');
        }
    });
}

function chooseArea() {
    $('.optionitem').on('click', function() {
        var $option = $(this);
        var areanum = $option.attr('areanum');
        var areaname = $option.text();

        $('#areaname').text(areaname);
        $('#areanum').text(areanum);
        $('#areacode').val(areanum);
        $('.optionslist').addClass('hide');
    });
}

function isagree() {
    return $('.choosetag').attr('checked');
}

function closeMask() {
    var $target;

    $(document).on('click', '#alreayregist', function(e) {
        $target = $(e.target);
        if ($target.hasClass('mask') || $target.hasClass('backdrop')) {
            $('#alreayregist').hide();
        }
    })
}

function nextStep() {
    var openId = '';
    var sourceType = '';
    var mobile = '';
    var areaCode = '';

    $('#bindfirststep').on('click', function(e) {
        e.preventDefault();
        mobile = $('.phonenum').val();
        areaCode = $('.areanum').text();
        if (mobile === '') {
            alert('手机号码不能为空');
            return;
        }
        if (!isagree()) {
            alert('请先同意我们的协议');
            return;
        }
        openId = $('#openId').val() || '29803EC6D4AAC3AAB8ABDB6AE829D579';
        sourceType = $('#sourceType').val() || 'qq';
        $.ajax({
            type: 'post',
            url: '/passport/autouserinfo/bindCheck',
            data: {
                mobile: mobile,
                area: areaCode,
                openId: openId,
                sourceType: sourceType
            },
            dataType: 'json',
            success: function(data) {
                if (data.code === 200) {
                    if (data.data.isReg === 0) {
                        $('#bindmobileform').attr('action', '/passport/thirdlogin/noregist');
                        $('#bindmobileform').submit();
                    } else {
                        $('#alreayregist').show();
                    }
                } else {
                    alert(data.message);
                }
            }
        });
    });
}

function init() {
    chooseProtocol();
    chooseArea();
    chooseAreaToogle();
    cancelChooseArea();
    nextStep();
    closeMask();
}
init();