repayment-list.page.js 3.27 KB
/**
 * 分期还款
 * @author: wsl<shuiling.wang@yoho.cn>
 * @date: 2016/08/04
 */

var $ = require('yoho-jquery'),
    Repayment = require('./repayment'),
    tip = require('../plugin/tip'),
    bp = require('./burying-point');

var CHECKBOX_SELECTOR = '.repay-list input';
var repayment = new Repayment({
    onGetSelection: function() {
        var ret = [];

        $(CHECKBOX_SELECTOR + ':checked').each(function(key, item) {
            var li = $(item).parents('li');
            var data = {
                index: li.index(),
                orderCode: li.data('billNo'),
                termNo: li.data('currterm'),
                amount: parseFloat(li.data('curramt')),
                fee: parseFloat(li.data('currfee')) + 0
            };

            ret.push(data);
        });

        return ret;
    },
    onGetSelectableCount: function() {
        return $(CHECKBOX_SELECTOR).length;
    },
    onDeselectAll: function() {
        $(CHECKBOX_SELECTOR + ':checked').prop('checked', false);
        return [];
    },
    onSelectAll: function() {
        $(CHECKBOX_SELECTOR + ':not(:checked)').prop('checked', true);
        return this.getSelection();
    }
});

require('./overdue-notice');

$(CHECKBOX_SELECTOR + ':checkbox').click(function() {
    var isSkipped = false,
        self = this,
        billNo = $(self).parent().data('billNo'),
        li = $('li[data-bill-no=' + billNo + ']'),
        selection = li.find('input:checked'),
        lastIndex = li.eq(0).data('currterm');

    selection.parent().each(function(index, sel) {
        var key = $(sel).data('currterm');

        if ((key + 1) - lastIndex > 1) {
            isSkipped = true;
        } else {
            lastIndex = key + 1;
        }
    });

    if (isSkipped) {
        setTimeout(function() {
            tip.show('同一个分期订单不能跨期还款,请按时间顺序还款');
        }, 0);
        return false;
    }

    repayment.update();
});

repayment.update();

setTimeout(function() {
    // 统计:各模块的落地页进入时
    bp.setContYas({
        POS_ID: $('.repayment-list-page').data('posId')
    }, true);
}, 3000);


// 统计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;
            opt.termNoAll += $(item).parent().data('terms');
        }
    });
    return opt;
}

// 统计:立即还款按钮点击时
$('.repayment-btn').on('click', function() {
    var opt = countYasParams();

    bp.setContYas({
        POS_ID: $('.repayment-list-page').data('posId'),
        ORDER_CODE: opt.billNoAll,
        INST_STYLE: opt.termNoAll
    }, false);
});


// 统计:列表项点击右边箭头时
$('.list-right a').on('click', function() {
    var li = $(this).parents('li');

    bp.setContYas({
        POS_ID: $('.repayment-list-page').data('posId'),
        ORDER_CODE: li.data('billNo'),
        INST_STYLE: li.data('terms'),
        PERIODS: li.data('currterm')
    }, false);
});