您的位置:首页 > 其它

气球贷计算器

2016-03-31 12:02 260 查看
/**
* 气球货计算器
* author:luozihua
* data:2011-8-29 13:57:22 房贷计算器
*/
// 注册命名空间calculator.CALCULATE
Namespace.register("calculator.houseLoan");
//在calculator.GEA命名空间里面声明类Person
calculator.houseLoan.Person = function(name, age)
{
this.name = name;
this.age = age;
}
//给类Person添加一个公共方法loanCalc()
calculator.houseLoan.Person.prototype.loanCalc = function()
{
// 获取还款方式并计算
var loanMethod = parseInt($("#loanMethod").val()); // 还款方式
if (calculator.houseLoan.Person.prototype.validateCheck()) {
switch (loanMethod) {
case 1:
calculator.houseLoan.Person.prototype.loanCalc1();
break;
case 2:
calculator.houseLoan.Person.prototype.loanCalc2();
break;
}
}
}

//等额本息
calculator.houseLoan.Person.prototype.loanCalc1 = function()
{
var P = parseFloat($("#totalLoan").val()) * 10000; // 贷款金额(元)
var Y = parseFloat($("#loanYear").val()); // 贷款年限
var F = parseFloat($("#loanMethod").val()); // 还款方式
var G = parseFloat($("#loanRate").val()); // 还款方式 // 年贷款利率
var Z = parseFloat($("#periodMonthNum").val()); // 还款周期(月、季、半年、年)
var H = calculator.houseLoan.Person.prototype.getRate(); // 浮动比率
var T = parseFloat((Y * 12) / Z).toFixed(2); // 还款周期数(月)
var HY = Math.round(G * (1 + H / 100.0) * 10000) / 10000; // 利率年浮动比率
var I = HY * Z / 12 / 100.0; // 还款周期利率
var S = P; // 上期还款后剩余本金
var Q = parseFloat($("#forecastLoanYear").val()); // 预计还款日期
var Interest = 0; // 支付息款
var CLoan = 0; // 本期还款额
var CInterest = 0; // 本期应还利息
var CorpusPay = 0; // 本期还款本金

var html = "<table style=\"float:left;width:480px;\" height=\"\" class=\"DataList MarginTop0\" cellspacing=\"0\" cellpadding=\"0\">";
html1 = "<tr style=\"height:0\"><th style=\"width:60px;text-align:center\">还款期次</th><th style=\"width:80px;text-align:center\">偿还本金</th><th style=\"width:80px;text-align:center\">偿还利息</th><th style=\"width:80px;text-align:center\">偿还本息</th><th style=\"width:80px;text-align:center\">剩余本金</th></tr>";
// 第1---(T-1)期
for ( var i = 1; i < T; i++) {
var itemStyle;
var residueP = 0;
CInterest = parseFloat((S * I * 100) / 100).toFixed(2); // 本期应还利息,
// 小数点保留2位
CLoan = parseFloat((P * I * 100 / (1 - Math.pow(1 + I, -Q))) / 100.0)
.toFixed(2); // 本期还款额,(1+I)的-Q次幂运算,四舍五入,小数点保留2位
CorpusPay = parseFloat((CLoan - CInterest) * 100 / 100).toFixed(2); // 本期还款本金,四舍五入,小数点保留2位
S = parseFloat(((S - CorpusPay) * 100) / 100).toFixed(2); // 本期还款后剩余本金,四舍五入,小数点保留2位
if (i % 2 == 0) {
itemStyle = "Item";
} else {
itemStyle = "Item";
}
html1 = html1 + "<tr class=" + itemStyle + "><td align='center' width='60'>" + i + "</td><td align='center' width='80'>"
+ CorpusPay + "</td><td align='center' width='80'>" + CInterest + "</td><td align='center' width='80'>" + CLoan
+ "</td><td align='center' width='80'>" + S + "</td></tr>";
Interest = parseFloat(parseFloat(Interest) + parseFloat(CInterest))
.toFixed(2);
}

var totalPay = CLoan * (parseInt(T) - 1);
// 第T期
CInterest = parseFloat((S * I * 100) / 100).toFixed(2); // 本期应还利息, 小数点保留2位
CorpusPay = S; // 本期还款本金,四舍五入,小数点保留2位
CLoan = (parseFloat(CorpusPay) + parseFloat(CInterest)).toFixed(2); // 本期还款额
S = 0.00; // 本期还款后剩余本金,四舍五入,小数点保留2位
if (i % 2 == 0) {
itemStyle = "Item";
} else {
itemStyle = "Item";
}
html1 = html1 + "<tr class=" + itemStyle + "><td align='center' width='60'>" + parseInt(T)
+ "</td><td align='center' width='80'>" + CorpusPay + "</td><td align='center' width='80'>" + CInterest + "</td><td align='center' width='80'>"
+ CLoan + "</td><td align='center' width='80'>" + S + "</td></tr>";

html = html + html1 + "</table>";
$("#loanPlanDetail").html(html);
totalPay = (parseFloat(totalPay) + parseFloat(CLoan)).toFixed(2);
Interest = parseFloat(parseFloat(Interest) + parseFloat(CInterest))
.toFixed(2);
$("#totalPay").val(totalPay);
$("#totalInterest").val(Interest);
if (parseInt($("#floatRateFlag").val()) != 0) {
$("#floatedYearRateLabel").css("display", "");
$("#floatedYearRateData").css("display", "");
$("#floatedYearRate").val(HY);
} else {
$("#floatedYearRateLabel").css("display", "none");
$("#floatedYearRateData").css("display", "none");
$("#floatedYearRate").val("");
}
$("#interestLabel").css("display", "none");
$("#interestData").css("display", "none");
$("#interest").html("");
}

//给类Person添加一个公共方法loanCalc2() 等额本金
calculator.houseLoan.Person.prototype.loanCalc2 = function()
{
var P = parseFloat($("#totalLoan").val()) * 10000; // 贷款金额
var Y = parseFloat($("#loanYear").val()); // 贷款年限
var F = parseFloat($("#loanMethod").val()); // 还款方式
var G = parseFloat($("#loanRate").val()); // 年贷款利率
var Z = parseFloat($("#periodMonthNum").val()); // 还款周期(月、季、半年、年)
var H = calculator.houseLoan.Person.prototype.getRate(); // 浮动比率
var T = parseFloat((Y * 12) / Z).toFixed(2); // 还款周期数(月)
var HY = Math.round(G * (1 + H / 100.0) * 10000) / 10000; // 利率年浮动比率
var I = HY * Z / 12 / 100.0; // 还款周期利率
var S = P; // 上期还款后剩余本金
var Q = parseFloat($("#forecastLoanYear").val()); // 预计还款日期
var Interest = 0; // 支付息款
var CLoan = 0; // 本期还款额
var CInterest = 0; // 本期应还利息
var CorpusPay = 0; // 本期还款本金
var totalPay = 0; // 累计还款总额
var html = "<table style=\"float:left;width:480px;\" height=\"\" class=\"DataList MarginTop0\" cellspacing=\"0\" cellpadding=\"0\">";
html1 = "<tr style=\"height:0\"><th style=\"width:60px;text-align:center\">还款期次</th><th style=\"width:80px;text-align:center\">偿还本金</th><th style=\"width:80px;text-align:center\">偿还利息</th><th style=\"width:80px;text-align:center\">偿还本息</th><th style=\"width:80px;text-align:center\">剩余本金</th></tr>";

// 第1---(T-1)期
for ( var i = 1; i < T; i++) {
var itemStyle;
var residueP = 0;
CInterest = parseFloat((S * I * 100) / 100).toFixed(2); // 本期应还利息,
// 小数点保留2位
CorpusPay = parseFloat((P * 1.0 / Q * 100) / 100).toFixed(2); // 本期还款本金,四舍五入,小数点保留2位
CLoan = parseFloat(
(parseFloat(CorpusPay) + parseFloat(CInterest)) * 100 / 100)
.toFixed(2); // 本期还款额,四舍五入,小数点保留2位
S = parseFloat(((S - CorpusPay) * 100) / 100).toFixed(2); // 本期还款后剩余本金,四舍五入,小数点保留2位
if (i % 2 == 0) {
itemStyle = "Item";
} else {
itemStyle = "Item";
}
html1 = html1 + "<tr class=" + itemStyle + "><td align='center' width='60'>" + i + "</td><td align='center' width='80'>"
+ CorpusPay + "</td><td align='center' width='80'>" + CInterest + "</td><td align='center' width='80'>" + CLoan
+ "</td><td align='center' width='80'>" + S + "</td></tr>";
Interest = parseFloat(parseFloat(Interest) + parseFloat(CInterest))
.toFixed(2);
}

totalPay = CLoan * (parseInt(T) - 1);
// 第T期
CInterest = parseFloat((S * I * 100) / 100).toFixed(2); // 本期应还利息, 小数点保留2位

CorpusPay = S; // 本期还款本金,四舍五入,小数点保留2位
CLoan = (parseFloat(CorpusPay) + parseFloat(CInterest)).toFixed(2); // 本期还款额
S = 0.00; // 本期还款后剩余本金,四舍五入,小数点保留2位
if (i % 2 == 0) {
itemStyle = "Item";
} else {
itemStyle = "Item";
}
html1 = html1 + "<tr class=" + itemStyle + "><td align='center' width='60'>" + parseInt(T)
+ "</td><td align='center' width='80'>" + CorpusPay + "</td><td align='center' width='80'>" + CInterest + "</td><td align='center' width='80'>"
+ CLoan + "</td><td align='center' width='80'>" + S + "</td></tr>";

html = html + html1 + "</table>";
$("#loanPlanDetail").html(html);
totalPay = (parseFloat(totalPay) + parseFloat(CLoan)).toFixed(2);
Interest = parseFloat(parseFloat(Interest) + parseFloat(CInterest))
.toFixed(2);
$("#totalPay").val(totalPay);
$("#totalInterest").val(Interest);
if (parseInt($("#floatRateFlag").val()) != 0) {
$("#floatedYearRateLabel").css("display", "");
$("#floatedYearRateData").css("display", "");
$("#floatedYearRate").val(HY);
} else {
$("#floatedYearRateLabel").css("display", "none");
$("#floatedYearRateData").css("display", "none");
$("#floatedYearRate").val("");
}
$("#interestLabel").css("display", "none");
$("#interestData").css("display", "none");
$("#interest").html("");
}
//控制浮动
calculator.houseLoan.Person.prototype.selectChange = function(id)
{
var isShow = $("#" + id).val();
if (isShow == "0") {
$("#floatRateArea").css("display", "none");
} else {
$("#floatRateArea").css("display", "");
}
}
//验证浮动比率
calculator.houseLoan.Person.prototype.getRate = function()
{
var isShow = parseInt($("#floatRateFlag").val());
if (isShow == 0) {
return 0;
} else {
if (!$("#txtFloatRate").val()) {
alert("浮动比率不能为空!");
return;
}
return parseFloat($("#txtFloatRate").val()) * isShow;
}
}
calculator.houseLoan.Person.prototype.validateCheck = function()
{
if ($("#totalLoan").val() == "" || !$("#totalLoan").val()) {
alert("贷款金额不能为空!");
return false;
}
if ($("#loanYear").val() == "" || !$("#loanYear").val()) {
alert("贷款年限不能为空!");
return false;
}
if ($("#loanRate").val() == "" || !$("#loanRate").val()) {
alert("年贷款利率不能为空!");
return false;
}
if ($("#forecastLoanYear").val() == "" || !$("#forecastLoanYear").val()) {
alert("设定还款期限不能为空!");
return false;
} else {
if (parseFloat($("#forecastLoanYear").val()) < parseFloat($("#loanYear")
.val()) * 12) {
alert("设定还款期限不能小于贷款年限!");
return false;
}
if (parseFloat($("#forecastLoanYear").val()) > 360) {
alert("设定还款期限不能大于360!");
return false;
}
}
return true;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: