前言界面
源码地址:核心代码
本帖转自:https://www.haorooms.com/post/js_housecal
纯js版本的房贷计算器,界面精美。
源码地址:
github地址:
https://github.com/confidence68/houseCal
预览地址:
https://www.haorooms.com/uploads/loancal/
[JavaScript]
纯文本查看
复制代码
001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047 048 049 050 051 052 053 054 055 056 057 058 059 060 061 062 063 064 065 066 067 068 069 070 071 072 073 074 075 076 077 078 079 080 081 082 083 084 085 086 087 088 089 090 091 092 093 094 095 096 097 098 099 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | //等额本息计算 benxi: function (type, num, year, lilv) { //每月月供额=〔贷款本金×月利率×(1+月利率)^还款月数〕÷〔(1+月利率)^还款月数-1〕 var mouth = parseInt(year) * 12, mouthlilv = parseFloat(lilv) / 12, dknum = parseFloat(num) * 10000; //每月月供 var yuegong = (dknum * mouthlilv * Math.pow((1 + mouthlilv), mouth)) / (Math.pow((1 + mouthlilv), mouth) - 1); //总利息=还款月数×每月月供额-贷款本金 var totalLixi = mouth * yuegong - dknum; //还款总额 总利息+贷款本金 var totalPrice = totalLixi + dknum, leftFund = totalLixi + dknum; //循环月份 var mouthdataArray = [], nowmouth = new Date().getMonth(), realmonth = 0; for (var i = 1; i <= mouth; i++) { realmonth = nowmouth + i; var yearlist = Math.floor(i / 12); realmonth = realmonth - 12 * yearlist; if (realmonth > 12) { realmonth = realmonth - 12 } //console.log(realmonth) //每月应还利息=贷款本金×月利率×〔(1+月利率)^还款月数-(1+月利率)^(还款月序号-1)〕÷〔(1+月利率)^还款月数-1〕 var yuelixi = dknum * mouthlilv * (Math.pow((1 + mouthlilv), mouth) - Math.pow((1 + mouthlilv), i - 1)) / (Math.pow((1 + mouthlilv), mouth) - 1); //每月应还本金=贷款本金×月利率×(1+月利率)^(还款月序号-1)÷〔(1+月利率)^还款月数-1〕 var yuebenjin = dknum * mouthlilv * Math.pow((1 + mouthlilv), i - 1) / (Math.pow((1 + mouthlilv), mouth) - 1); leftFund = leftFund - (yuelixi + yuebenjin); if (leftFund < 0) { leftFund = 0 } mouthdataArray[i - 1] = { monthName: realmonth + "月", yuelixi: yuelixi, yuebenjin: yuebenjin, //剩余还款 leftFund: leftFund } } return { yuegong: yuegong, totalLixi: totalLixi, totalPrice: totalPrice, mouthdataArray: mouthdataArray, totalDknum: num, year: year }; }, //等额本金计算 benjin: function (type, num, year, lilv) { var mouth = parseInt(year) * 12, mouthlilv = parseFloat(lilv) / 12, dknum = parseFloat(num) * 10000, yhbenjin = 0; //首月还款已还本金金额是0 //每月应还本金=贷款本金÷还款月数 var everymonthyh = dknum / mouth //每月月供额=(贷款本金÷还款月数)+(贷款本金-已归还本金累计额)×月利率 var yuegong = everymonthyh + (dknum - yhbenjin) * mouthlilv; //每月月供递减额=每月应还本金×月利率=贷款本金÷还款月数×月利率 var yuegongdijian = everymonthyh * mouthlilv; //总利息=〔(总贷款额÷还款月数+总贷款额×月利率)+总贷款额÷还款月数×(1+月利率)〕÷2×还款月数-总贷款额 var totalLixi = ((everymonthyh + dknum * mouthlilv) + dknum / mouth * (1 + mouthlilv)) / 2 * mouth - dknum; //还款总额 总利息+贷款本金 var totalPrice = totalLixi + dknum, leftFund = totalLixi + dknum; //循环月份 var mouthdataArray = [], nowmouth = new Date().getMonth(), realmonth = 0; for (var i = 1; i <= mouth; i++) { realmonth = nowmouth + i; var yearlist = Math.floor(i / 12); realmonth = realmonth - 12 * yearlist; if (realmonth > 12) { realmonth = realmonth - 12 } yhbenjin = everymonthyh * (i - 1); var yuebenjin = everymonthyh + (dknum - yhbenjin) * mouthlilv; //每月应还利息=剩余本金×月利率=(贷款本金-已归还本金累计额)×月利率 var yuelixi = (dknum - yhbenjin) * mouthlilv; leftFund = leftFund - yuebenjin; if (leftFund < 0) { leftFund = 0 } mouthdataArray[i - 1] = { monthName: realmonth + "月", yuelixi: yuelixi, //每月本金 yuebenjin: everymonthyh, //剩余还款 leftFund: leftFund } } return { yuegong: yuegong, totalLixi: totalLixi, totalPrice: totalPrice, yuegongdijian: yuegongdijian, mouthdataArray: mouthdataArray, totalDknum: num, year: year } } |
本帖转自:https://www.haorooms.com/post/js_housecal