
﻿
lebi.chaxun.fangdai={title:"房贷计算器",bindEvents:function(){$("#btnSubmit").click(function(){do_q();});$("#in-debt").recoverableInputText();$("input.txt").keyup(function(e){e=e||window.event;if(e.keyCode==13){$("#btnSubmit").click();}});},init:function(){this.bindEvents();lebi.chaxun.showTitle(this.title,false);}};lebi.chaxun.fangdai.init();var comms=['备注：等额本息还款方式是在还款期内，每月偿还同等数额的贷款(包括本金和利息)，这样由于每月的还款额固定，可以有计划地控制家庭收入的支出，也便于每个家庭根据自己的收入情况，确定还贷能力。','备注：等额本金还款方式是将本金每月等额偿还，然后根据剩余本金计算利息，所以初期由于本金较多，将支付较多的利息，从而使还款额在初期较多，而在随后的时间每月递减，这种方式的好处是，由于在初期偿还较大款项而减少利息的支出，比较适合还款能力较强的家庭。'];var interests=[[0.06579,0.06656,0.0477,0.0522],[0.0851,0.0861,0.0477,0.0522],[0.0851,0.0861,0.0477,0.0522],[0.06426,0.06579,0.0459,0.0513],[0.0832,0.0851,0.0459,0.0513],[0.0832,0.0851,0.0459,0.0513],[0.062,0.0635,0.0432,0.0486],[0.0802,0.0822,0.0432,0.0486],[0.0802,0.0822,0.0432,0.0486],[0.051,0.0523,0.0405,0.0459],[0.0802,0.0822,0.0405,0.0459],[0.0729,0.0747,0.0405,0.0459],[0.0802,0.0822,0.0405,0.0459],[0.0491,0.0504,0.0405,0.0459],[0.0772,0.0792,0.0405,0.0459],[0.0702,0.0720,0.0405,0.0459],[0.0772,0.0792,0.0405,0.0459],[0.0594,0.0612,0.0351,0.0405],[0.0576,0.0594,0.0333,0.0387]];function getMonthlyMoney(total,inter,month){var in_m=inter/12;return total*in_m*Math.pow(1+in_m,month)/(Math.pow(1+in_m,month)-1);}
function getMonthMoney2(total,inter,month,seq){var in_m=inter/12,ave=total/month;return(total-ave*seq)*in_m+ave;}
function do_q(){var inp=$('#in-debt').val();$("#auswer .answer:eq(0)").html(inp+' 元');$("#auswer .answer:eq(1)").html('');$("#auswer .answer:eq(2)").html('');$("#auswer .answer:eq(3)").html('');if(isNaN(parseFloat(inp))||inp<0){$("#auswer .answer:eq(0)").html(lebi.chaxun.errorText("请输入有效的贷款总额数字"));return false;}
var interest=parseFloat($('#in-int').val());if(isNaN(interest)||interest<=0||interest>=1){inte_changed();interest=parseFloat($('#in-int').val());}
var month=($('#years')[0].selectedIndex+1)*12;if($('#recharge-type')[0].selectedIndex){var t=0,display='<ul>';for(var i=0;i<month;i++){var mm=getMonthMoney2(inp,interest,month,i);t+=mm;display+="<li>"+Math.round(mm*100)/100+" 元(第"+(i+1).toString()+"个月)</li>";}
display+="</ul>";$("#auswer .answer:eq(1)").html(Math.round(t*100)/100+' 元');$("#auswer .answer:eq(2)").html(Math.round((t-inp)*100)/100+' 元');$("#auswer .answer:eq(3)").html(display);}
else{var money=getMonthlyMoney(inp,interest,month);$("#auswer .answer:eq(1)").html(Math.round(money*month*100)/100+' 元');$("#auswer .answer:eq(2)").html(Math.round((money*month-inp)*100)/100+' 元');$("#auswer .answer:eq(3)").html(Math.round(money*100)/100+' 元');}}
function show_comm(){$('#comm').html(comms[$('#recharge-type')[0].selectedIndex]);}
function inte_changed(){var idx=$('#debt-type')[0].selectedIndex*2+($('#years')[0].selectedIndex<5?0:1),interest=interests[interests.length-$('#inte')[0].selectedIndex-1][idx];$('#in-int').val(Math.round(interest*1000000)/1000000);}
show_comm();inte_changed();
