Blame view

public/js/home/bind-card.page.js 2.76 KB
徐炜 authored
1 2 3 4 5 6
/**
 * 新增银行卡
 * @author: wsl<shuiling.wang@yoho.cn>
 * @date: 2016/08/25
 */
lijing authored
7 8 9 10 11 12 13
let $ = require('yoho-jquery');
let tip = require('plugin/tip');
let checkCard = require('./bind-card-check');
let loading = require('plugin/loading');
let applyButton = $('.open-btn');
let flag = true;
let formData = {
徐炜 authored
14 15 16 17 18 19
    cardNo: '',
    mobile: '',
    bankName: '',
    bankCode: ''
};
lijing authored
20 21
let validateForm = function() {
    let ret = false;
徐炜 authored
22 23

    if (formData.cardNo &&
王水玲 authored
24
        formData.mobile.length === 11 &&
徐炜 authored
25 26 27 28 29 30 31 32 33 34 35 36
        formData.bankName &&
        formData.bankCode) {
        applyButton.removeClass('disabled');
        ret = true;
    } else {
        applyButton.addClass('disabled');
        ret = false;
    }

    return ret;
};
37
require('common');
王水玲 authored
38
require('./overdue-notice');
王水玲 authored
39
徐炜 authored
40 41
checkCard(formData);
42 43 44
// 定时更新模型,解决各种浏览器奇葩问题终极办法
setInterval(function() {
    $('input').each(function() {
lijing authored
45
        let name = $(this).attr('name');
徐炜 authored
46
47 48
        formData[name] = $(this).val();
    });
徐炜 authored
49
    validateForm();
50
}, 500);
徐炜 authored
51 52 53 54 55 56 57 58 59 60 61

applyButton.on('click', function() {
    if (!flag || $(this).hasClass('disabled') || !validateForm()) {
        return false;
    }

    if (!/^1[3|4|5|8|7][0-9]{9}$/.test(formData.mobile)) {
        tip.show('手机号输入不正确!');
        return false;
    }
王水玲 authored
62 63
    loading.showLoadingMask();
徐炜 authored
64 65 66 67 68 69 70
    flag = false;

    $.ajax({
        type: 'GET',
        url: '/home/installment/post-account',
        data: formData,
        success: function(data) {
lijing authored
71
            let params = {
徐炜 authored
72 73
                action: 'go.bindCardResult',
                params: {
王水玲 authored
74
                    status: 0
徐炜 authored
75 76
                }
            };
王水玲 authored
77
lijing authored
78
            let url = location.href + '&openby:yohobuy=';
徐炜 authored
79
王水玲 authored
80 81 82 83
            if (window.queryString.title) {
                params.params.name = $('.username').html();
            }
徐炜 authored
84 85
            if (data.code === 200) {
                params.params.status = 1;
王水玲 authored
86 87 88
            } else if (data.code === 500) {
                tip.show('连接超时');
                flag = true;
王水玲 authored
89
                params.params.message = '网络连接超时!';
王水玲 authored
90 91
            } else {
                params.params.message = data.message;
徐炜 authored
92 93 94 95
            }

            url += encodeURIComponent(JSON.stringify(params));
王水玲 authored
96 97
            loading.hideLoadingMask();
王水玲 authored
98
            $('body').append('<a href=' + url + ' style="display: none;"><span class="jump">&npsb;</span></a>');
王水玲 authored
99 100

            $('.jump').click();
徐炜 authored
101 102
        },
        error: function() {
王水玲 authored
103
            loading.hideLoadingMask();
徐炜 authored
104 105 106 107 108
            tip.show('网络断开连接了~');
            flag = true;
        }
    });
});
王水玲 authored
109 110 111 112


// 使用H5标签后 maxlength 标签失效
$('input[maxlength]').keyup(function() {
lijing authored
113
    let value = $(this).val(),
王水玲 authored
114 115 116 117
        length = $(this).attr('maxlength') || 20;

    $(this).val(value.slice(0, length));
});