Blame view

public/js/home/repayment-list.page.js 3.6 KB
王水玲 authored
1 2 3 4 5 6
/**
 * 分期还款
 * @author: wsl<shuiling.wang@yoho.cn>
 * @date: 2016/08/04
 */
王水玲 authored
7
var $ = require('yoho-jquery'),
王水玲 authored
8
    Repayment = require('./repayment'),
王水玲 authored
9 10
    tip = require('../plugin/tip'),
    bp = require('./burying-point');
王水玲 authored
11
王水玲 authored
12
var CHECKBOX_SELECTOR = '.repay-list input';
王水玲 authored
13 14 15 16 17 18 19
var curTermNo = {
    1: 1,
    3: 2,
    6: 3,
    9: 4,
    12: 5
};
王水玲 authored
20 21 22
var repayment = new Repayment({
    onGetSelection: function() {
        var ret = [];
王水玲 authored
23
王水玲 authored
24
        $(CHECKBOX_SELECTOR + ':checked').each(function(key, item) {
王水玲 authored
25 26 27
            var li = $(item).parents('li');
            var data = {
                index: li.index(),
王水玲 authored
28 29
                orderCode: li.data('billNo'),
                termNo: li.data('currterm'),
王水玲 authored
30
                amount: parseFloat(li.data('curramt')),
王水玲 authored
31
                fee: parseFloat(li.data('currfee')) + 0
王水玲 authored
32
            };
王水玲 authored
33
王水玲 authored
34 35
            ret.push(data);
        });
王水玲 authored
36
王水玲 authored
37 38
        return ret;
    },
王水玲 authored
39 40 41
    onGetSelectableCount: function() {
        return $(CHECKBOX_SELECTOR).length;
    },
王水玲 authored
42
    onDeselectAll: function() {
王水玲 authored
43
        $(CHECKBOX_SELECTOR + ':checked').prop('checked', false);
王水玲 authored
44 45 46
        return [];
    },
    onSelectAll: function() {
王水玲 authored
47
        $(CHECKBOX_SELECTOR + ':not(:checked)').prop('checked', true);
王水玲 authored
48
        return this.getSelection();
王水玲 authored
49
    }
王水玲 authored
50 51
});
王水玲 authored
52
require('./overdue-notice');
王水玲 authored
53
王水玲 authored
54
$(CHECKBOX_SELECTOR + ':checkbox').click(function() {
王水玲 authored
55 56 57 58 59
    var isSkipped = false,
        self = this,
        billNo = $(self).parent().data('billNo'),
        li = $('li[data-bill-no=' + billNo + ']'),
        selection = li.find('input:checked'),
王水玲 authored
60
        lastIndex = li.eq(0).data('currterm');
王水玲 authored
61
王水玲 authored
62
    selection.parent().each(function(index, sel) {
王水玲 authored
63
        var key = $(sel).data('currterm');
王水玲 authored
64 65

        if ((key + 1) - lastIndex > 1) {
王水玲 authored
66
            isSkipped = true;
王水玲 authored
67
        } else {
王水玲 authored
68
            lastIndex = key + 1;
王水玲 authored
69 70
        }
    });
王水玲 authored
71
王水玲 authored
72 73
    if (isSkipped) {
        setTimeout(function() {
王水玲 authored
74
            tip.show('同一个分期订单不能跨期还款,请按时间顺序还款');
王水玲 authored
75 76 77
        }, 0);
        return false;
    }
王水玲 authored
78
王水玲 authored
79 80
    repayment.update();
});
王水玲 authored
81
王水玲 authored
82
repayment.update();
王水玲 authored
83
王水玲 authored
84
$(window).load(function() {
王水玲 authored
85
    // 统计:各模块的落地页进入时
沈志敏 authored
86 87 88 89
    bp.setContYas({
        op: 'YB_INST_REPAYMENT',
        appop: 'YB_H5_INST_REPAYMENT_C'
    }, {
王水玲 authored
90
        POS_ID: $('.repayment-list-page').data('posId')
沈志敏 authored
91
    }, true);
王水玲 authored
92
});
王水玲 authored
93
王水玲 authored
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
// 统计yas 需要传的参数
function countYasParams() {
    var curBillNo = '';
    var opt = {
        billNoAll: '',
        termNoAll: ''
    };

    $(CHECKBOX_SELECTOR + ':checked').each(function(key, item) {
        curBillNo = $(item).parent().data('billNo');

        if (opt.billNoAll.indexOf(curBillNo) < 0) {
            opt.billNoAll += (key !== 0) ? ',' : '';
            opt.termNoAll += (key !== 0) ? ',' : '';
            opt.billNoAll += curBillNo;
王水玲 authored
109
            opt.termNoAll += curTermNo[$(item).parent().data('terms')];
王水玲 authored
110 111
        }
    });
王水玲 authored
112
王水玲 authored
113 114 115 116
    return opt;
}

// 统计:立即还款按钮点击时
王水玲 authored
117
$('.repayment-btn').on('click', function() {
王水玲 authored
118 119
    var opt = countYasParams();
沈志敏 authored
120 121 122 123
    bp.setContYas({
        op: 'YB_INST_TOPAY_CLICK',
        appop: 'YB_H5_INST_TOPAY_C'
    }, {
王水玲 authored
124 125 126
        POS_ID: $('.repayment-list-page').data('posId'),
        ORDER_CODE: opt.billNoAll,
        INST_STYLE: opt.termNoAll
沈志敏 authored
127
    }, true);
王水玲 authored
128
});
王水玲 authored
129 130 131 132 133 134


// 统计:列表项点击右边箭头时
$('.list-right a').on('click', function() {
    var li = $(this).parents('li');
沈志敏 authored
135 136 137 138
    bp.setContYas({
        op: 'YB_INST_TOPAY_INFO',
        appop: 'YB_H5_INST_TOPAY_INFO_C'
    }, {
王水玲 authored
139 140
        POS_ID: $('.repayment-list-page').data('posId'),
        ORDER_CODE: li.data('billNo'),
王水玲 authored
141
        INST_STYLE: curTermNo[li.data('terms')],
王水玲 authored
142
        PERIODS: li.data('currterm')
沈志敏 authored
143
    }, true);
王水玲 authored
144
});