房贷计算器小程序

最近使用uniapp开发了个房贷计算器小程序,感觉uniapp对于开发小程序来说还是非常不错的,目前适配了微信小程序、qq小程序和支付宝小程序,由于抖音小程序和百度小程序目前不支持个人开发,暂时还没调试。
首先上几个截图:

 其实这个小程序页面并不复杂,主要是各种计算公式,下面分享一下用到的公式:

1.等额本息公式:

    			// 等额本息计算方法
			computedBX(total, rate, mouths) {
				// 等额本息  每月还本付息金额=[贷款本金×月利率×(1+月利率)^还款月数]÷[(1+月利率)^还款月数-1]
				// 每月应还利息=贷款本金×月利率×〔(1+月利率)^还款月数-(1+月利率)^(还款月序号-1)〕÷〔(1+月利率)^还款月数-1〕
				// 每月应还本金=贷款本金×月利率×(1+月利率)^(还款月序号-1)÷〔(1+月利率)^还款月数-1〕
				// 总利息=还款月数×每月月供额-贷款本金
				let result = (total * rate * Math.pow(1 + rate, mouths)) / (Math.pow(1 + rate, mouths) - 1)

				// result = result.toFixed(2)
				let total_rate = result.toFixed(2) * mouths
				let list = []
				for (let i = 1; i <= mouths; i++) {
					//每月应还本金=贷款本金×月利率×(1+月利率)^(还款月序号-1)÷〔(1+月利率)^还款月数-1〕
					let mybj = (total * rate * Math.pow(1 + rate, i - 1) / (Math.pow(1 + rate, mouths) - 1)).toFixed(2)
					//每月应还利息=贷款本金×月利率×〔(1+月利率)^还款月数-(1+月利率)^(还款月序号-1)〕÷〔(1+月利率)^还款月数-1〕
					let mylx = (total * rate * (Math.pow(1 + rate, mouths) - Math.pow(1 + rate, i - 1)) / (Math.pow(1 + rate, mouths) - 1)).toFixed(2)
					list.push({
						res: Number( result.toFixed(2) ),
						yu: Number( (total_rate - result.toFixed(2) * i).toFixed(2) ),
						mybj:mybj,
						mylx:mylx
					})
				}
				// 总利息
				let total_lixi = Number( (mouths * result - total).toFixed(2) )
				// 总利息 + 贷款本金
				let total_er = Number( (Number(total_lixi) + Number(total)).toFixed(2) )
				
				return {
					result: Number( result.toFixed(2) ),
					total_lixi,
					total_er,
					list,
					total,
					dijian: 0
				}
			}

 2.等额本金计算公式:

			// 等额本金计算方法
			// 贷款本金  月利率 还款月数 
			computedBJ(total, rate, mouths) {
				// 等额本金的计算公式为: 每月还本付息金额=(本金/还款月数)+(本金-累计已还本金)×月利率
				//  每月应还本金=贷款本金÷还款月数
				// 每月应还利息=剩余本金×月利率=(贷款本金-已归还本金累计额)×月利率。
				// 每月月供递减额=每月应还本金×月利率=贷款本金÷还款月数×月利率
				// 总利息=(还款月数+1)×贷款总额×月利率÷2
				
				// 月供
				let res
				// 已还本金
				let yhbj = 0;
				// 已还的本息
				let yhbx = 0
				// 递减金额
				let dijian
				res = (total / mouths) + (total - yhbj) * rate
				res = res.toFixed(2)
				yhbx = res + yhbx
				let result = Number(res)
				let total_lixi = (mouths + 1) * total * rate / 2
				let total_er = total_lixi + total
				let list = []
				//每月本金 每月归还本金=贷款总额÷归还月数;
				let mybj = (total / mouths).toFixed(2)
				//每月利息 、每月还款利息=(贷款总额-累计已还本金)×月利率;
				let mylx = (total * rate).toFixed(2)
				list.push({
					res: res,
					yu: (total_er - yhbx).toFixed(2),
					mybj:mybj,
					mylx:mylx
					
				})
				dijian =  Number((total / mouths * rate).toFixed(2))
				for (let i = 1; i < mouths; i++) {
					yhbj = total / mouths * i
					res = (total / mouths) + (total - yhbj) * rate
					res = res.toFixed(2)
					
					yhbx = Number(res) + Number(yhbx)
					mylx = ((total - mybj * i) * rate).toFixed(2)
					list.push({
						res: res,
						yu: Number( (total_er - yhbx).toFixed(2) ),
						mybj:mybj,
						mylx:mylx
						
					})
				}
				return {
					result,
					total_lixi,
					total_er,
					list,
					total,
					dijian
				}
			}

 3.提前还贷所有逻辑代码:

            //一次性提前还款计算(等额本息)
			calculateEqualPrincipalAndInterest(){
				let principal = this.datas.ydkze * 10000
				let monthRate = this.datas.yfdlv / (100 * 12);//月利率
				let months = this.datas.ydkqx * 12
				let payTimes = this.monthsBetw(this.datas.schkrq,this.datas.tqhkrq)
				
				let preLoan = (principal * monthRate * Math.pow((1 + monthRate), months)) / (Math.pow((1 + monthRate), months) - 1);//每月还款金额
				let totalMoney = preLoan * months;//还款总额
				let interest = totalMoney - principal;//还款总利息
				let leftLoan = principal * Math.pow(1 + monthRate, payTimes) - preLoan * (Math.pow(1 + monthRate, payTimes) - 1) / monthRate;//n个月后欠银行的钱
				
				this.payLoan = principal - leftLoan;//已还本金
				this.payTotal = preLoan * payTimes;//已还总金额
				this.payInterest = this.payTotal - this.payLoan;//已还利息
				this.totalPayAhead = leftLoan * (1 + monthRate);//剩余一次还清
				this.saveInterest = totalMoney - this.payTotal - this.totalPayAhead;节省利息
				
				this.principal = principal
				this.interest = interest
				this.totalMoney = totalMoney
				
				this.payTimes = payTimes
				
				this.preLoan = preLoan
				this.leftMonth = 0
				this.leftLoan = leftLoan//剩余还款本金
			},
			//一次性提前还款计算(等额本金)
			calculateEqualPrincipal(){
				let principal = this.datas.ydkze * 10000
				let monthRate = this.datas.yfdlv / (100 * 12);//月利率
				let months = this.datas.ydkqx * 12
				let payTimes = this.monthsBetw(this.datas.schkrq,this.datas.tqhkrq)
				
				
				let prePrincipal = principal / months;//每月还款本金
				let firstMonth = prePrincipal + principal * monthRate;//第一个月还款金额
				let decreaseMonth = prePrincipal * monthRate;//每月利息递减
				let interest = (months + 1) * principal * monthRate / 2;//还款总利息
				let totalMoney = principal + interest;//还款总额
				
				this.payLoan = prePrincipal * payTimes;//已还本金
				this.leftLoan = principal - this.payLoan//剩余还款本金
				this.payInterest = (principal * payTimes - prePrincipal * (payTimes - 1) * payTimes / 2) * monthRate;//已还利息
				this.payTotal = this.payLoan + this.payInterest;//已还总额
				this.totalPayAhead = (principal - this.payLoan) * (1 + monthRate);//提前还款金额(剩余本金加上剩余本金当月利息)
				this.saveInterest = totalMoney - this.payTotal - this.totalPayAhead;//节省利息
				
				this.principal = principal
				this.interest = interest
				this.totalMoney = totalMoney
				
				this.payTimes = payTimes
				
				this.prePrincipal = prePrincipal
				this.firstMonth = firstMonth
				this.decreaseMonth = decreaseMonth
				this.leftMonth = 0
			},
			//部分提前还款计算(等额本息、月供不变)
			calculateEqualPrincipalAndInterestApart(){
				let principal = this.datas.ydkze * 10000
				let monthRate = this.datas.yfdlv / (100 * 12);//月利率
				let months = this.datas.ydkqx * 12
				let payTimes = this.monthsBetw(this.datas.schkrq,this.datas.tqhkrq)
				let aheadPrincipalTotal = this.datas.tqhkje * 10000
				
				let preLoan = (principal * monthRate * Math.pow((1 + monthRate), months)) / (Math.pow((1 + monthRate), months) - 1);//每月还款金额
				let totalMoney = preLoan * months;//还款总额
				let interest = totalMoney - principal;//还款总利息
				let leftLoanBefore = principal * Math.pow(1 + monthRate, payTimes) - preLoan * (Math.pow(1 + monthRate, payTimes) - 1) / monthRate;//提前还款前欠银行的钱
				
				
				//提前还房贷的利息计算公式为:剩余贷款本金×[(提前还款日-上次扣款日)的天数]×日利率(日利率=年利率÷360)
				let lx = leftLoanBefore * this.datas.yfdlv / (100 * 360) * this.dayCha(this.datas.schkrq,this.datas.tqhkrq)
				let aheadPrincipal = aheadPrincipalTotal - lx
				
				// let leftLoan = principal * Math.pow(1 + monthRate, payTimes + 1) - preLoan * (Math.pow(1 + monthRate, payTimes + 1) - 1) / monthRate - aheadPrincipal;//提前还款后欠银行的钱
				let leftLoan = leftLoanBefore - aheadPrincipal;
				
				let payLoan = principal - leftLoanBefore;//已还本金
				let payTotal = preLoan * payTimes;//已还总金额
				let payInterest = payTotal - payLoan;//已还利息
				// let aheadTotalMoney = aheadPrincipal + preLoan;//提前还款总额
				let aheadTotalMoney = aheadPrincipal
				//计算剩余还款期限
				let leftMonth =  Math.floor(Math.log(preLoan / (preLoan - leftLoan * monthRate)) / Math.log(1 + monthRate));
				let newPreLoan = (leftLoan * monthRate * Math.pow((1 + monthRate), leftMonth)) / (Math.pow((1 + monthRate), leftMonth) - 1);//剩余贷款每月还款金额
				let leftTotalMoney = newPreLoan * leftMonth;//剩余还款总额
				// let leftInterest = leftTotalMoney - (leftLoan - aheadPrincipal);//剩余还款总利息
				let leftInterest = leftTotalMoney - leftLoan
				this.saveInterest = totalMoney - aheadTotalMoney - leftTotalMoney - payTotal;//节省利息
				
				this.principal = principal
				this.interest = interest
				this.totalMoney = totalMoney
				this.payTotal = payTotal
				this.payLoan = payLoan
				this.payInterest = payInterest
				
				this.payTimes = payTimes
				
				this.leftTotalMoney = leftTotalMoney
				this.leftInterest = leftInterest
				this.aheadPrincipal = aheadPrincipal
				
				this.newPreLoan = newPreLoan
				this.preLoan = preLoan
				
				this.leftMonth = leftMonth
				this.leftTotalMoney = leftTotalMoney
				this.leftInterest = leftInterest
				this.leftLoan = leftLoan
				
				this.aheadPrincipalTotal = aheadPrincipalTotal
				this.lx = lx
				

			},
			//部分提前还款计算(等额本金、月供不变)
			calculateEqualPrincipalApart(){
				let principal = this.datas.ydkze * 10000
				let monthRate = this.datas.yfdlv / (100 * 12);//月利率
				let months = this.datas.ydkqx * 12
				let payTimes = this.monthsBetw(this.datas.schkrq,this.datas.tqhkrq)
				let aheadPrincipalTotal = this.datas.tqhkje * 10000
				
				
				let prePrincipal = principal / months;//每月还款本金
				let firstMonth = prePrincipal + principal * monthRate;//第一个月还款金额
				let decreaseMonth = prePrincipal * monthRate;//每月利息递减
				let interest = (months + 1) * principal * monthRate / 2;//还款总利息
				let totalMoney = principal + interest;//还款总额
				let payLoan = prePrincipal * payTimes;//已还本金
				let payInterest = (principal * payTimes - prePrincipal * (payTimes - 1) * payTimes / 2) * monthRate;//已还利息
				let payTotal = payLoan + payInterest;//已还总额
				
				//提前还房贷的利息计算公式为:剩余贷款本金×[(提前还款日-上次扣款日)的天数]×日利率(日利率=年利率÷360)
				let lx = (principal - payLoan) * this.datas.yfdlv / (100 * 360) * this.dayCha(this.datas.schkrq,this.datas.tqhkrq)
				let aheadPrincipal = aheadPrincipalTotal - lx
				
				// let aheadTotalMoney = (principal - payLoan) * monthRate + aheadPrincipal + prePrincipal;//提前还款金额
				let aheadTotalMoney = aheadPrincipal;
				// let leftLoan = principal - aheadPrincipal - payLoan - prePrincipal;//剩余金额
				let leftLoan = principal - aheadPrincipal - payLoan;
				let leftMonth = Math.floor(leftLoan / prePrincipal);剩余还款期限
				let newPrePrincipal = leftLoan / leftMonth;//新的每月还款本金
				let newFirstMonth = newPrePrincipal + leftLoan * monthRate;//新的第一个月还款金额
				let newDecreaseMonth = newPrePrincipal * monthRate;//新的每月利息递减
				let leftInterest = (leftMonth + 1) * leftLoan * monthRate / 2;//还款总利息
				let leftTotalMoney = leftLoan + leftInterest;//剩余还款总额
				this.saveInterest = totalMoney - payTotal - aheadTotalMoney - leftTotalMoney;//节省利息
				
				this.principal = principal
				this.interest = interest
				this.totalMoney = totalMoney
				
				this.payTotal = payTotal
				this.payLoan = payLoan
				this.payInterest = payInterest
				
				this.payTimes = payTimes
				
				this.leftTotalMoney = leftTotalMoney
				this.leftLoan = leftLoan
				this.leftInterest = leftInterest
				this.aheadPrincipal = aheadPrincipal
				
				this.newPrePrincipal = newPrePrincipal
				this.newFirstMonth = newFirstMonth
				this.newDecreaseMonth = newDecreaseMonth
				
				this.prePrincipal = prePrincipal
				this.firstMonth = firstMonth
				this.decreaseMonth = decreaseMonth
				
				this.leftMonth = leftMonth
				
				this.aheadPrincipalTotal = aheadPrincipalTotal
				this.lx = lx
			
			},
			//部分提前还款计算(等额本息、期限不变)
			calculateEqualPrincipalAndInterestApart2(){
				let principal = this.datas.ydkze * 10000
				let monthRate = this.datas.yfdlv / (100 * 12);//月利率
				let months = this.datas.ydkqx * 12
				let payTimes = this.monthsBetw(this.datas.schkrq,this.datas.tqhkrq)
				let aheadPrincipalTotal = this.datas.tqhkje * 10000
				
				let leftMonth = months - payTimes;//剩余还款期限
				
				let preLoan = (principal * monthRate * Math.pow((1 + monthRate), months)) / (Math.pow((1 + monthRate), months) - 1);//每月还款金额
				let totalMoney = preLoan * months;//还款总额
				let interest = totalMoney - principal;//还款总利息
				let leftLoanBefore = principal * Math.pow(1 + monthRate, payTimes) - preLoan * (Math.pow(1 + monthRate, payTimes) - 1) / monthRate;//提前还款前欠银行的钱
				// let leftLoan = principal * Math.pow(1 + monthRate, payTimes + 1) - preLoan * (Math.pow(1 + monthRate, payTimes + 1) - 1) / monthRate;//提前还款后银行的钱
				
				//提前还房贷的利息计算公式为:剩余贷款本金×[(提前还款日-上次扣款日)的天数]×日利率(日利率=年利率÷360)
				let lx = leftLoanBefore * this.datas.yfdlv / (100 * 360) * this.dayCha(this.datas.schkrq,this.datas.tqhkrq)
				let aheadPrincipal = aheadPrincipalTotal - lx
				
				let leftLoan = leftLoanBefore - aheadPrincipal
				let payLoan = principal - leftLoanBefore;//已还本金
				let payTotal = preLoan * payTimes;//已还总金额
				let payInterest = payTotal - payLoan;//已还利息
				// let aheadTotalMoney = preLoan + aheadPrincipal;//下个月还款金额
				let aheadTotalMoney = aheadPrincipal;
				let newPreLoan = ((leftLoan) * monthRate * Math.pow((1 + monthRate), months - payTimes - 1)) / (Math.pow((1 + monthRate), months - payTimes - 1) - 1);//下个月起每月还款金额
				let leftTotalMoney = newPreLoan * (months - payTimes);//剩余还款总额
				// let leftInterest = leftTotalMoney - (leftLoan - aheadPrincipal);//剩余还款总利息
				let leftInterest = leftTotalMoney - leftLoan 
				this.saveInterest = totalMoney - payTotal - aheadTotalMoney - leftTotalMoney;//节省利息
				
				this.principal = principal
				this.interest = interest
				this.totalMoney = totalMoney
				
				this.payTotal = payTotal
				this.payLoan = payLoan
				this.payInterest = payInterest
				
				this.payTimes = payTimes
				
				this.leftTotalMoney = leftTotalMoney
				this.leftLoan = leftLoan
				this.leftInterest = leftInterest
				this.aheadPrincipal = aheadPrincipal
				
				this.newPreLoan = newPreLoan
				this.preLoan = preLoan
				this.leftMonth = leftMonth
				
				this.aheadPrincipalTotal = aheadPrincipalTotal
				this.lx = lx
			
			},
			//部分提前还款计算(等额本金、期限不变)
			calculateEqualPrincipalApart2(){
				let principal = this.datas.ydkze * 10000
				let monthRate = this.datas.yfdlv / (100 * 12);//月利率
				let months = this.datas.ydkqx * 12
				let payTimes = this.monthsBetw(this.datas.schkrq,this.datas.tqhkrq)
				let aheadPrincipalTotal = this.datas.tqhkje * 10000
				
				let prePrincipal = principal / months;//每月还款本金
				let firstMonth = prePrincipal + principal * monthRate;//第一个月还款金额
				let decreaseMonth = prePrincipal * monthRate;//每月利息递减
				let interest = (months + 1) * principal * monthRate / 2;//还款总利息
				let totalMoney = principal + interest;//还款总额
				let payLoan = prePrincipal * payTimes;//已还本金
				let payInterest = (principal * payTimes - prePrincipal * (payTimes - 1) * payTimes / 2) * monthRate;//已还利息
				let payTotal = payLoan + payInterest;//已还总额
				
				//提前还房贷的利息计算公式为:剩余贷款本金×[(提前还款日-上次扣款日)的天数]×日利率(日利率=年利率÷360)
				let lx = (principal - payLoan) * this.datas.yfdlv / (100 * 360) * this.dayCha(this.datas.schkrq,this.datas.tqhkrq)
				let aheadPrincipal = aheadPrincipalTotal - lx
				
				
				// let aheadTotalMoney = (principal - payLoan) * monthRate + aheadPrincipal + prePrincipal;//提前还款金额
				let aheadTotalMoney = aheadPrincipal;
				let leftMonth = months - payTimes;//剩余还款期限
				// let leftLoan = principal - aheadPrincipal - payLoan - prePrincipal;
				let leftLoan = principal - aheadPrincipal - payLoan;
				let newPrePrincipal = leftLoan / leftMonth;//新的每月还款本金
				let newFirstMonth = newPrePrincipal + leftLoan * monthRate;//新的第一个月还款金额
				let newDecreaseMonth = newPrePrincipal * monthRate;//新的每月利息递减
				let leftInterest = (leftMonth + 1) * leftLoan * monthRate / 2;//还款总利息
				let leftTotalMoney = leftLoan + leftInterest;//剩余还款总额
				this.saveInterest = totalMoney - payTotal - aheadTotalMoney - leftTotalMoney;节省利息
				
				this.principal = principal
				this.interest = interest
				this.totalMoney = totalMoney
				
				this.payTotal = payTotal
				this.payLoan = payLoan
				this.payInterest = payInterest
				
				this.payTimes = payTimes
				
				this.leftTotalMoney = leftTotalMoney
				this.leftLoan = leftLoan
				this.leftInterest = leftInterest
				this.aheadPrincipal = aheadPrincipal
				
				this.newPrePrincipal = newPrePrincipal
				this.newFirstMonth = newFirstMonth
				this.newDecreaseMonth = newDecreaseMonth
				
				this.prePrincipal = prePrincipal
				this.firstMonth = firstMonth
				this.decreaseMonth = decreaseMonth
				this.leftMonth = leftMonth
				
				this.aheadPrincipalTotal = aheadPrincipalTotal
				this.lx = lx
			
			}

最后附上我的微信小程序,由于不能放二维码,大家可以去微信搜一下,名字叫做:房贷计算器工具

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值