check.page.js 1.34 KB
require('3party/check.page.css');
require('common');

let $ = require('yoho-jquery'),
    Validate = require('plugin/validata');

let $check = $('#js-img-check');

let baseInfo = {pid: window.queryString.pid};
let validateOptions = {
    useREM: {
        rootFontSize: 40,
        picWidth: 140
    }
};

if ($check.data('riskimg')) {
    validateOptions.imgSrc = '/passport/img-check-risk.jpg';
    baseInfo.apiRiskValidate = true;
}

let validate = new Validate($check, validateOptions);

validate.init();

$(function() {
    $('.submit').on('click', function() {
        validate.getResults().then((result) => {
            $.extend(result, baseInfo);

            $.ajax({
                method: 'POST',
                url: '/3party/check/submit',
                data: result,
                success: function(ret) {
                    validate.type === 2 && validate.refresh();
                    if (ret.code === 200) {
                        if (window.queryString.refer) {
                            window.location.href = decodeURIComponent(window.queryString.refer);
                        } else {
                            window.location.href = '//m.yohobuy.com';
                        }
                    } else {
                        validate.refresh();
                    }
                }
            });
        });
    });
});