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

var $ = require('yoho-jquery');

var $notice = $('.installment-overdue-notice'),
    $currAmt = $('.repayment-bottom').find('.curr-amt'),
    $currFee = $('.repayment-bottom').find('.curr-fee');

$('.repay-list .notice').on('click', function() {
    $notice.show();

    return false;
});

$('.think-ok, .mask-bg').on('click', function() {
    $notice.hide();
});

$('.repay-list .cont').on('click', function() {
    var $input = $(this).parent().prev(),
        currAmt = +$currAmt.html(),
        currFee = +$currFee.html(),
        amt = +$(this).parents('li').attr('data-curramt'),
        fee = +$(this).parents('li').attr('data-currfee'),
        count = 0;

    if ($input.is(':checked')) {
        $currAmt.html(currAmt - amt);
        $currFee.html(currFee - fee);
    } else {
        $currAmt.html(amt + currAmt);
        $currFee.html(fee + currFee);
    }
    setTimeout(function(){
        count = $('.repay-list input:checked').length;
        $('#repayment-total').prop('checked', count === $('.repay-list li').length);
    }, 0)

});

// 全选||全不选
$('.repayment-bottom label').on('click', function() {
    var totalAmt = 0;
    var totalFee = 0;

    if ($(this).prev().is(':checked')) {
        $('.repay-list input').prop('checked', false);
        $currAmt.html('0');
        $currFee.html('0');
    } else {
        $('.repay-list input').prop('checked', true);
        $('.repay-list li').each(function() {
            totalAmt += (+$(this).attr('data-curramt'));
            totalFee += (+$(this).attr('data-currfee'));
        });

        $currAmt.html(totalAmt);
        $currFee.html(totalFee);
    }
});

$('.repayment-btn').on('click', function() {
    var path = location.pathname;

    $(this).attr('href', path + '?openby:yohobuy={"action":"go.instalmentRepayment","params":{"amount":' + (+$currAmt.html()) + '}}');
});