(function ($) { Calculator = function (opts) { var obj = this; this.rate = new Array(); //本息本金还贷 this.loanResult = function (property, model) { var data = {}; var month = property.year * 12; data.month = month; if (property.type == "3") { // 组合型贷款(组合型贷款的计算,只和商业贷款额、和公积金贷款额有关,和按贷款总额计算无关) data.total = "略"; //房款总额 data.firstPay = 0; //首次还款 data.totalLoan = parseFloat(property.biz) + parseFloat(property.acc); //总贷款 var bizRate = getRate(2, property.year, property.rate); //商贷利率 var accRate = getRate(1, property.year, property.rate); //公积金利率 if (model == 1) { //本金还款 var all_total = 0, items = new Array(), pay = 0; for (j = 0; j < month; j++) { pay = getMonthPayForInterest(bizRate, property.biz, month, j) + getMonthPayForInterest(accRate, property.acc, month, j); all_total += pay; pay = Math.round(pay * 100) / 100; items.push({ month: j + 1, pay: pay }); } data.perMonthPay = items; //每月还款数组 data.totalPay = Math.round(all_total * 100) / 100; //还款总额 data.interestPay = Math.round((all_total - data.totalLoan) * 100) / 100; //支付利息款 } else { //本息还款 data.perMonthPay = getMonthPayForPrincipal(bizRate, property.biz, month) + getMonthPayForPrincipal(accRate, property.acc, month); data.totalPay = Math.round(data.perMonthPay * month * 100) / 100; data.interestPay = Math.round((data.totalPay - data.totalLoan) * 100) / 100; } } else { var _rate = getRate(property.type, property.year, property.rate); //利率 if (property.calType == 2) { data.totalLoan = property.biz; } else { data.totalLoan = property.acc; } if (model == 1) { //本金还款 var all_total = 0, items = new Array(), pay = 0; for (j = 0; j < month; j++) { pay = getMonthPayForInterest(_rate, data.totalLoan, month, j); all_total += pay; pay = Math.round(pay * 100) / 100; items.push({ month: j + 1, pay: pay }); } data.perMonthPay = items; //每月还款数组 data.totalPay = Math.round(all_total * 100) / 100; //还款总额 data.interestPay = Math.round((all_total - data.totalLoan) * 100) / 100; //支付利息款 } else { //本息还款 data.perMonthPay = getMonthPayForPrincipal(_rate, data.totalLoan, month); data.totalPay = Math.round(data.perMonthPay * month * 100) / 100; data.interestPay = Math.round((data.totalPay - data.totalLoan) * 100) / 100; data.perMonthPay = Math.round(data.perMonthPay * 100) / 100; } } return data; }; this.getRate = function (type, year, rateIndex) { var currRate = obj.rate[rateIndex], item, rate = 0; for (var i = 0; i < currRate.items.length; i++) { item = currRate.items[i]; if (year > item.min && year <= item.max) { rate = type == 1 ? item.accuFund : item.bizLoan; break; } } return rate; }; //获取月利率 类型(1公积金 2商贷)、期数、选中的利率标准 var getRate = function (type, year, rateIndex) { return obj.getRate(type, year, rateIndex) / 12; }; //本金还款的月还款额(参数: 年利率 / 贷款总额 / 贷款总月份 / 贷款当前月0~length-1) var getMonthPayForInterest = function (lilv, total, month, cur_month) { // var lilv_month = lilv / 12; //月利率 //return total * lilv_month * Math.pow(1 + lilv_month, month) / ( Math.pow(1 + lilv_month, month) -1 ); var benjin_money = total / month; return (total - benjin_money * cur_month) * lilv + benjin_money; } //本息还款的月还款额(参数: 年利率/贷款总额/贷款总月份) var getMonthPayForPrincipal = function (lilv, total, month) { //var lilv_month = lilv / 12;//月利率 return total * lilv * Math.pow(1 + lilv, month) / (Math.pow(1 + lilv, month) - 1); } //装载利率 var rateLoad = function (title, start, end, items) { var temps = new Array(); for (var i = 0; i < items.length; i++) { temps.push({ min: items[i][0], max: items[i][1], bizLoan: items[i][2], accuFund: items[i][3] }); } obj.rate.push({ title: title, start: start, end: end, items: temps }); }; //初始化 var init = function () { rateLoad('2015.08.26基准利率', 20150826, 0, [[0, 1, 0.046, 0.0275], [1, 5, 0.05, 0.0275], [5, 30, 0.0515, 0.0325]]); rateLoad('2015.06.28基准利率', 20150628, 0, [[0, 1, 0.0485, 0.03], [1, 5, 0.0525, 0.03], [5, 30, 0.054, 0.035]]); rateLoad('2015.05.11基准利率', 20150511, 0, [[0, 1, 0.051, 0.0325], [1, 5, 0.055, 0.0325], [5, 30, 0.0565, 0.0375]]); rateLoad('2015.03.01基准利率', 20150301, 0, [[0, 1, 0.0535, 0.035], [1, 5, 0.0575, 0.035], [5, 30, 0.059, 0.04]]); rateLoad('2015.08.26利率下限(7折)', 20150826, 0, [[0, 1, 0.0322, 0.0193], [1, 5, 0.035, 0.0193], [5, 30, 0.0361, 0.0228]]); rateLoad('2015.06.28利率下限(7折)', 20150628, 0, [[0, 1, 0.034, 0.021], [1, 5, 0.0368, 0.021], [5, 30, 0.0378, 0.0245]]); rateLoad('2015.05.11利率下限(7折)', 20150511, 0, [[0, 1, 0.0357, 0.0228], [1, 5, 0.0385, 0.0228], [5, 30, 0.0396, 0.0263]]); rateLoad('2015.03.01利率下限(7折)', 20150301, 0, [[0, 1, 0.0374, 0.0245], [1, 5, 0.0403, 0.0245], [5, 30, 0.0413, 0.028]]); rateLoad('2015.08.26利率下限(85折)', 20150826, 0, [[0, 1, 0.0391, 0.0234], [1, 5, 0.0425, 0.0234], [5, 30, 0.0438, 0.0376]]); rateLoad('2015.06.28利率下限(85折)', 20150628, 0, [[0, 1, 0.0412, 0.0225], [1, 5, 0.0446, 0.0225], [5, 30, 0.0459, 0.0297]]); rateLoad('2015.05.11利率下限(85折)', 20150511, 0, [[0, 1, 0.0434, 0.0276], [1, 5, 0.0468, 0.0276], [5, 30, 0.048, 0.0319]]); rateLoad('2015.03.01利率下限(85折)', 20150301, 0, [[0, 1, 0.0455, 0.0297], [1, 5, 0.0489, 0.0297], [5, 30, 0.0501, 0.034]]); rateLoad('2015.08.26利率上限(1.1倍)', 20150826, 0, [[0, 1, 0.0506, 0.0303], [1, 5, 0.055, 0.0303], [5, 30, 0.0567, 0.0358]]); rateLoad('2015.06.28利率上限(1.1倍)', 20150628, 0, [[0, 1, 0.0534, 0.033], [1, 5, 0.0578, 0.033], [5, 30, 0.0594, 0.0385]]); rateLoad('2015.05.11利率上限(1.1倍)', 20150511, 0, [[0, 1, 0.0561, 0.0358], [1, 5, 0.0605, 0.0358], [5, 30, 0.0622, 0.0413]]); rateLoad('2015.03.01利率上限(1.1倍)', 20150301, 0, [[0, 1, 0.0589, 0.0385], [1, 5, 0.0633, 0.0385], [5, 30, 0.0649, 0.044]]); rateLoad('2014.11.22首套房优惠(15%)利率', 20141122, 0, [[0, 1, 0.0476, 0.0375], [1, 5, 0.051, 0.0375], [5, 30, 0.052275, 0.0425]]); rateLoad('2014.11.22基准利率', 20141122, 0, [[0, 1, 0.056, 0.0375], [1, 5, 0.06, 0.0375], [5, 30, 0.0615, 0.0425]]); rateLoad('2014.11.22第二套房上浮(10%)利率', 20141122, 0, [[0, 1, 0.0616, 0.0375], [1, 5, 0.066, 0.0375], [5, 30, 0.06765, 0.0425]]); }; init(); }; })(jQuery);