美文网首页
房贷计算器

房贷计算器

作者: ONEDAYLOG | 来源:发表于2020-05-22 22:43 被阅读0次

    最近房产版升级,需要重新制作房贷计算器的功能,主要参考了 房天下房贷计算器安居客房贷计算器,两大平台的计算器。

    1.界面展示

    个人认为:界面还是相当漂亮的,主要就是房贷计算器,提前还款计算器,购房能力评估,税费计算器


    image.png image.png image.png image.png

    2.界面代码

     <div class="calcontent" style="height:540px;">
                    <div class="calleft" id="calleft1">
                        <i class="icon-arrow"><span></span></i>
                        <div class="item-mod item-top hide">
                            <label class="item-label"><span>还款方式</span></label>
                            <span>
                                <input type="radio" name="repaytype" class="int-radio" value="0" checked="true">等额本息
                            </span>
                            <span>
                                <input type="radio" name="repaytype" class="int-radio" value="1">等额本金
                            </span>
                        </div>
    
                        <div class="item-mod">
                            <label class="item-label"><span>贷款类别</span></label>
                            <span><input type="radio" name="typeCal" class="int-radio" value="0" checked="true">商业贷款</span>
                            <span><input type="radio" name="typeCal" class="int-radio" value="1">公积金贷</span>
                            <span><input type="radio" name="typeCal" class="int-radio" value="2">组合贷</span>
                        </div>
    
                        <div id="houseCalInput">
                            <div class="item-mod">
                                <label class="item-label"><span>房款总价</span></label>
                                <div class="textbox">
                                    <input type="text" id="totalMoney" value="180" maxlength="9"><em>万元</em>
                                </div>
                                <span class="warn" style="display: none;"></span>
                            </div>
    
                            <div class="item-mod">
                                <label class="item-label"><span>贷款总额</span></label>
                                <div class="textbox">
                                    <input type="text" id="dkTotalMoney" value="100" maxlength="9"><em>万元</em>
                                </div>
                                <span class="warn" style="display: none;"></span>
                            </div>
    
                            <div class="item-mod">
                                <label class="item-label"><span>利       率</span></label>
                                <div class="textbox">
                                    <input type="text" value="4.9" maxlength="9" id="initrate"><em>%</em>
                                </div>
                                <span class="warn" style="display: none;"></span>
                            </div>
    
                            <div class="item-mod">
                                <label class="item-label"><span>按揭年数</span></label>
                                <div class="textbox">
                                    <select name="jQuery2" class="beautify_input" id="ajYear" style="display: none;">
                                        @for ($i = 1; $i < 31; $i++)
                                            @if($i != 20)
                                                <option value="{{$i}}"> {{$i}}年 ({{$i*12}}期)</option>
                                            @else
                                                <option value="{{$i}}" selected> {{$i}}年 ({{$i*12}}期)</option>
                                            @endif
                                        @endfor
                                    </select>
                                </div>
                                <span class="warn" style="display: none;"></span>
                            </div>
    
                        </div>
    
                        <div id="houseZHCalInput" class="hide">
                            <div class="item-mod">
                                <label class="item-label"><span>商业贷款总</span></label>
                                <div class="textbox">
                                    <input type="text" id="dkMoney" value="80" maxlength="9"><em>万元</em>
                                </div>
                                <span class="warn" style="display: none;"></span>
                            </div>
    
                            <div class="item-mod">
                                <label class="item-label"><span>商业利率</span></label>
                                <div class="textbox">
                                    <input type="text" value="4.9" maxlength="9" id="initrate1"><em>%</em>
                                </div>
                                <span class="warn" style="display: none;"></span>
                            </div>
    
                            <div class="item-mod">
                                <label class="item-label"><span>公积金贷款</span></label>
                                <div class="textbox">
                                    <input type="text" id="gjjMoney" value="40" maxlength="9"><em>万元</em>
                                </div>
                                <span class="warn" style="display: none;"></span>
                            </div>
    
                            <div class="item-mod">
                                <label class="item-label"><span>公积金利率</span></label>
                                <div class="textbox">
                                    <input type="text" value="3.2" maxlength="9" id="initrate2"><em>%</em>
                                </div>
                                <span class="warn" style="display: none;"></span>
                            </div>
    
                            <div class="item-mod">
                                <label class="item-label"><span>按揭年数</span></label>
                                <div class="textbox">
                                    <select name="jQuery2" class="beautify_input" id="ajyeardk" style="display: none;">
                                        @for ($i = 1; $i < 31; $i++)
                                            @if($i != 20)
                                                <option value="{{$i}}"> {{$i}}年 ({{$i*12}}期)</option>
                                            @else
                                                <option value="{{$i}}" selected> {{$i}}年 ({{$i*12}}期)</option>
                                            @endif
                                        @endfor
                                    </select>
                                </div>
                                <span class="warn" style="display: none;"></span>
                            </div>
                        </div>
    
                        <div class="item-bot">
                            <a class="cal-button" href="javascript:" id="startCal">开始计算</a>
                            <a class="cal-reset" href="javascript:" id="resetCal">清空重填</a>
                        </div>
                    </div>
    
                    <div class="calright">
                        <div id="caldefault1" class="default">
                            <i></i>
                            <p>要贷款买房?赶紧算算吧!</p>
                        </div>
    
                        <!--图形-->
                        <div class="news_items_module hide houseCal" id="houseCal">
    
                            <section class="jsresults" style="display: block;">
                                <div style="display: block;">
                                    <section>
                                        <div class="methodboxa">
                                            <div class="mTab">
                                                <div class="flexbox" id="payMethod">
                                                    <a href="javascript:;" class="active">等额本息
                                                    </a>
                                                    <a href="javascript:;" class="">等额本金
                                                    </a>
                                                </div>
                                            </div>
                                            <p class="f14" style="display: block;">每月还款额固定,所还总利息较多,适合收入稳定者。
                                            </p>
    
                                            <p class="f14" style="display: none;">每月还款额递减,所还总利息较低,前期还款额较大。
                                            </p>
                                        </div>
                                    </section>
                                    <div class="jsresults01 mt20">
                                        <a href="javascript:;" id="detailLink">
                                            <div class="quan">
                                                <div class="info">月供
                                                    <em id="monthPay">
                                                    </em>
                                                </div>
                                                <div style="overflow: visible; transform: translateZ(0px);">
                                                    <canvas id="pieConChar" width="100%" height="100%"/>
                                                </div>
                                            </div>
                                        </a>
                                    </div>
    
                                    <div class="jsresults02" id="danduCal">
                                        <dl>
                                            <dt>房款总价:</dt>
                                            <dd id="ddZj"></dd>
                                        </dl>
                                        <dl>
                                            <dt class="bj01">首付金额:</dt>
                                            <dd id="ddSf"></dd>
                                        </dl>
                                        <dl>
                                            <dt class="bj02">贷款总额:</dt>
                                            <dd id="ddDk"></dd>
                                        </dl>
                                        <dl>
                                            <dt class="bj03">支付利息:</dt>
                                            <dd id="ddLx"></dd>
                                        </dl>
                                        <dl>
                                            <dt>利<span style="margin:0 1em;"></span>率:</dt>
                                            <dd id="ddLr"></dd>
                                        </dl>
                                        <dl>
                                            <dt>首月月供:</dt>
                                            <dd id="ddYg"></dd>
                                        </dl>
                                    </div>
    
                                    <div class="jsresults02 hide" id="zhuheCal">
                                        <dl>
                                            <dt>还款总价:</dt>
                                            <dd id="HkZj"></dd>
                                        </dl>
                                        <dl>
                                            <dt class="bj01">贷款总价:</dt>
                                            <dd id="DkZj"></dd>
                                        </dl>
                                        <dl>
                                            <dt class="bj02">支付利息:</dt>
                                            <dd id="LxZj"></dd>
                                        </dl>
                                        <dl>
                                            <dt>首月月供:</dt>
                                            <dd id="ddYg2"></dd>
                                        </dl>
                                    </div>
                                    <p class="f14 f999 center mt10" id="cankao" style="display: block;">以上结果仅供参考</p>
                                </div>
                            </section>
                        </div>
    
                        <!--月供表-->
                        <div id="detailPage" class="hide detailPage">
                            <div class="mlist" id="listInfo">
                                <dl style="display: table;">
                                    <dt>还款总额
                                    </dt>
                                    <dd id="lIAllMoney">
                                    </dd>
                                </dl>
                                <dl style="display: table;">
                                    <dt>贷款总额
                                    </dt>
                                    <dd id="lIDkMoney">
                                    </dd>
                                </dl>
                                <dl style="display: table;">
                                    <dt>支付利息</dt>
                                    <dd id="lILxMoney"></dd>
                                </dl>
                                <dl style="display: table;">
                                    <dt>贷款月数
                                    </dt>
                                    <dd id="lIDkYear">
                                    </dd>
                                </dl>
                                <dl style="display: none;">
                                    <dt>商业贷款月数
                                    </dt>
                                    <dd id="lISyDkYear">
                                    </dd>
                                </dl>
                                <dl style="display: none;">
                                    <dt>公积金贷款月数
                                    </dt>
                                    <dd id="lIGjjDkYear">
                                    </dd>
                                </dl>
                                <dl style="display: table;">
                                    <dt>月均还款
                                    </dt>
                                    <dd id="lIHkMoney">
                                    </dd>
                                </dl>
                                <dl style="display: none;">
                                    <dt>月均利息
                                    </dt>
                                    <dd id="lIYjMoney">
                                    </dd>
                                </dl>
                            </div>
                            <div class="mlisttab" id="listHtml">
                            </div>
                        </div>
                    </div>
                </div>
    

    3.核心计算

            $(function () {
                jQuery("#housediv").slide({
                    titCell: ".calculatorhead div",
                    mainCell: "#housecaldiv",
                    delayTime: 0,
                });
                $(function () {
                    $('.beautify_input').cssSelect();
                });
                /*
     综合计算
     */
                /*
                 yearPeriad:总期数(月)[商业贷款]
                 money:本金[商业贷款 单位元]
                 monthInterest:月利息[商业贷款 格式:x.xxxxxx 小数点后六位]
                 money1:本金[公积金 单位元]
                 monthInterest1:月利息[公积金 格式x.xxxxxx 小数点后六位]
                 typeInterest:还息类型[1等额本金/0等额本息]
                 typeCal:计算类型[0商业贷款/1公积金贷款/2组合贷款]
                 */
                function CalLoan(yearPeriad, money, monthInterest, money1, monthInterest1, typeInterest, typeCal) {
                    var HouseLoanObject = {};
                    if (typeInterest == 1) {
                        switch (typeCal) {
                            case 0:
                                HouseLoanObject = CalAverageCapitalComm(yearPeriad, money, monthInterest);
                                break;
                            case 1:
                                HouseLoanObject = CalAverageCapitalComm(yearPeriad, money1, monthInterest1);
                                break;
                            case 2:
                                var HouseLoanObject1 = CalAverageCapitalComm(yearPeriad, money, monthInterest);
                                var HouseLoanObject2 = CalAverageCapitalComm(yearPeriad, money1, monthInterest1);
                                HouseLoanObject.BusInterest = HouseLoanObject1.Result;
                                HouseLoanObject.AccuInterest = HouseLoanObject2.Result;
                                HouseLoanObject.Result = HouseLoanObject1.Result + HouseLoanObject2.Result;
                                HouseLoanObject.ResultCount = HouseLoanObject1.ResultCount + HouseLoanObject2.ResultCount;
                                HouseLoanObject.MaxPayment = HouseLoanObject1.MaxPayment + HouseLoanObject2.MaxPayment;
                                HouseLoanObject.MaxInterest = HouseLoanObject1.MaxInterest + HouseLoanObject2.MaxInterest;
                                var houseLoan = {};
                                var houseLoanArray = new Array();
                                for (var i = 1; i <= yearPeriad; i++) {
                                    houseLoan =
                                        {
                                            ReplyPrincipalIntreest: (HouseLoanObject1.HouseLoan[i - 1].ReplyPrincipalIntreest + HouseLoanObject2.HouseLoan[i - 1].ReplyPrincipalIntreest),
                                            ReplyInterest: (HouseLoanObject1.HouseLoan[i - 1].ReplyInterest + HouseLoanObject2.HouseLoan[i - 1].ReplyInterest),
                                            ReplyPrincipal: (HouseLoanObject1.HouseLoan[i - 1].ReplyPrincipal + HouseLoanObject2.HouseLoan[i - 1].ReplyPrincipal),
                                            SurplusPrincipal: (HouseLoanObject1.HouseLoan[i - 1].SurplusPrincipal + HouseLoanObject2.HouseLoan[i - 1].SurplusPrincipal)
                                        };
                                    houseLoanArray.push(houseLoan);
                                }
                                HouseLoanObject.HouseLoan = houseLoanArray;
                                break;
                        }
                    } else {
                        switch (typeCal) {
                            case 0:
                                HouseLoanObject = CalAverageCapitalPlusInterestComm(yearPeriad, money, monthInterest);
                                break;
                            case 1:
                                HouseLoanObject = CalAverageCapitalPlusInterestComm(yearPeriad, money1, monthInterest1);
                                break;
                            case 2:
                                var HouseLoanObject1 = CalAverageCapitalPlusInterestComm(yearPeriad, money, monthInterest);
                                var HouseLoanObject2 = CalAverageCapitalPlusInterestComm(yearPeriad, money1, monthInterest1);
                                HouseLoanObject.BusInterest = HouseLoanObject1.Result;
                                HouseLoanObject.AccuInterest = HouseLoanObject2.Result;
                                HouseLoanObject.Result = HouseLoanObject1.Result + HouseLoanObject2.Result;
                                HouseLoanObject.ResultCount = HouseLoanObject1.ResultCount + HouseLoanObject2.ResultCount;
                                HouseLoanObject.MonthPayment = HouseLoanObject1.MonthPayment + HouseLoanObject2.MonthPayment;
                                HouseLoanObject.MaxPayment = HouseLoanObject1.MaxPayment + HouseLoanObject2.MaxPayment;
                                HouseLoanObject.MaxInterest = HouseLoanObject1.MaxInterest + HouseLoanObject2.MaxInterest;
                                var houseLoan = {};
                                var houseLoanArray = new Array();
                                for (var i = 1; i <= yearPeriad; i++) {
                                    houseLoan =
                                        {
                                            ReplyPrincipalIntreest: (HouseLoanObject1.HouseLoan[i - 1].ReplyPrincipalIntreest + HouseLoanObject2.HouseLoan[i - 1].ReplyPrincipalIntreest),
                                            ReplyInterest: (HouseLoanObject1.HouseLoan[i - 1].ReplyInterest + HouseLoanObject2.HouseLoan[i - 1].ReplyInterest),
                                            ReplyPrincipal: (HouseLoanObject1.HouseLoan[i - 1].ReplyPrincipal + HouseLoanObject2.HouseLoan[i - 1].ReplyPrincipal),
                                            SurplusPrincipal: (HouseLoanObject1.HouseLoan[i - 1].SurplusPrincipal + HouseLoanObject2.HouseLoan[i - 1].SurplusPrincipal)
                                        };
                                    houseLoanArray.push(houseLoan);
                                }
                                HouseLoanObject.HouseLoan = houseLoanArray;
                                break;
                        }
                    }
                    /*
                     BusInterest:组合计算商业贷款利息总额
                     AccuInterest:组合计算公积金贷款利息总额
                     Result:利息总额
                     ResultCount:累计还款总额
                     MonthPayment:每月月供
                     MaxPayment:最高月供
                     MaxInterest:最高利息
                     HouseLoan:累计偿还利息集合
                     */
                    return HouseLoanObject;
                }
                /*计算公式=(总期数(月)+1)* 本金 *(月利率)/2
                 月利率=年利率/12
                 */
                /*
                 通用等额本金计算规则
                 利息总额=(总期数+1)*本金*月利率/2
                 累计还款总额=本金+利息总额
                 最高月供=(本金/总期数)+(本金-0)*月利息
                 最高月付利息=本金*月利息^1
                 */
                /*
                 yearPeriad:总期数(月)
                 money:本金[元]
                 monthInterest:月利率
                 */
                function CalAverageCapitalComm(yearPeriad, money, monthInterest) {
                    /*商贷利息总额=(总期数(月)+1)* 本金 *(月利率)/2 */
                    var result = (yearPeriad + 1) * money * monthInterest / 2;
                    result = Math.abs(result.toFixed(2));
                    /*累计还款总额=利息+本金*/
                    var resultCount = parseFloat(result.toFixed(2)) + parseFloat(money);
                    resultCount = Math.abs(resultCount);
                    /*最高月供=(本金/总期数(月))+(本金-0)*月利息*/
                    var maxPayment = (money / yearPeriad) + (money - 0) * monthInterest;
                    maxPayment = Math.abs(maxPayment.toFixed(2));
                    /*最高利息=本金*(年利率/12)^1*/
                    var maxInterest = money * Math.pow(monthInterest, 1);
                    maxInterest = Math.abs(maxInterest.toFixed(2));
                    var houseLoan = {};
                    var houseLoanArray = new Array();
                    for (var i = 1; i <= yearPeriad; i++) {
                        var replyPrincipalIntreest = (i != 1 ? ((money - (money / yearPeriad) * (i - 1)) * monthInterest) + (money / yearPeriad) : maxPayment); //偿还本息
                        var replyInterest = (i != 1 ? ((money - (money / yearPeriad) * (i - 1)) * monthInterest) : maxInterest); //偿还利息
                        var replyPrincipal = money / yearPeriad; //偿还本金
                        var surplusPrincipal = money - (money / yearPeriad) * i; //剩余本金
                        houseLoan = {
                            ReplyPrincipalIntreest: replyPrincipalIntreest,
                            ReplyInterest: replyInterest,
                            ReplyPrincipal: replyPrincipal,
                            SurplusPrincipal: surplusPrincipal
                        };
                        houseLoanArray.push(houseLoan);
                    }
                    var HouseLoanObject = {};
                    HouseLoanObject.Result = result;
                    HouseLoanObject.ResultCount = resultCount;
                    HouseLoanObject.MaxPayment = maxPayment;
                    HouseLoanObject.MaxInterest = maxInterest;
                    HouseLoanObject.HouseLoan = houseLoanArray;
                    return HouseLoanObject;
                }
                /*
                 商业贷款等额本息计算通用方法
                 偿还本息 = (本金*月利息)*(1+月利息)^贷款期限)/((1+月利息)^贷款期限-1)
                 利息总额 = 偿还本息*总期数-本金
                 累计还款总额 = 偿还本息 * 总期数
                 每月月供=偿还本息
                 最高月付利息=本金*月利息^1
                 */
                /*
                 yearPeriad:总期数(月)
                 money:本金
                 monthInterest:月利率
                 */
                function CalAverageCapitalPlusInterestComm(yearPeriad, money, monthInterest) {
                    /*偿还本息=((本金*月利息)*(1+月利息)^贷款期限)/((1+月利息)^贷款期限-1)*/
                    var repleyInterest = (money * monthInterest * Math.pow(1 + monthInterest, yearPeriad)) / (Math.pow(1 + monthInterest, yearPeriad) - 1);
                    /*利息总额=偿还本息*总期数 - 本金*/
                    var result = repleyInterest * yearPeriad - money;
                    result = Math.abs(result.toFixed(2));
                    /*累计还款总额=偿还本息* 总期数*/
                    var resultCount = repleyInterest * yearPeriad;
                    resultCount = Math.abs(resultCount.toFixed(2));
                    /*每月月供=偿还本息*/
                    var monthPayment = Math.abs(repleyInterest.toFixed(2));
                    /*最高付款利息= 本金 * 月息^期次*/
                    var maxPayment = money * Math.pow(monthInterest, 1);
                    maxPayment = Math.abs(maxPayment.toFixed(2));
                    var houseLoan = {};
                    var houseLoanArray = new Array();
                    for (var i = 1; i <= yearPeriad; i++) {
                        var surplusPrincipal1 = money * Math.pow(1 + monthInterest, i) - repleyInterest * (Math.pow(1 + monthInterest, i) - 1) / monthInterest; /*剩余本金*/
                        var surplusPrincipal2 = money * Math.pow(1 + monthInterest, i - 1) - repleyInterest * (Math.pow(1 + monthInterest, i - 1) - 1) / monthInterest; /*取上一次的本金计算每月偿还利息*/
                        var repeyInt = surplusPrincipal2 * monthInterest; /*每月偿还利息*/
                        var repeyPrincipal1 = Math.abs((repleyInterest - repeyInt).toFixed(2)); /*每月偿还本金*/
                        var replyPrincipalIntreest = monthPayment; //偿还本息
                        var replyInterest = (i != 1 ? repeyInt : maxPayment); //偿还利息
                        var replyPrincipal = (i != 1 ? repeyPrincipal1 : (repleyInterest - maxPayment)); //偿还本金
                        var surplusPrincipal = (i != 1 ? surplusPrincipal1 : (money - repleyInterest + maxPayment)); //剩余本金
                        houseLoan = {
                            ReplyPrincipalIntreest: replyPrincipalIntreest,
                            ReplyInterest: replyInterest,
                            ReplyPrincipal: replyPrincipal,
                            SurplusPrincipal: surplusPrincipal
                        };
                        houseLoanArray.push(houseLoan);
                    }
                    var HouseLoanObject = {};
                    HouseLoanObject.Result = result;
                    HouseLoanObject.ResultCount = resultCount;
                    HouseLoanObject.MonthPayment = monthPayment;
                    HouseLoanObject.MaxPayment = maxPayment;
                    HouseLoanObject.HouseLoan = houseLoanArray;
                    return HouseLoanObject;
                }
                var HouseLoanObject;
                var txtTotalMoney = $('#totalMoney');
                // var selSfRate     = $('#sfRate');
                var txtdkTotalMoney = $('#dkTotalMoney');
                var selajYear = $("#ajYear");
                var txtinitrate = $("#initrate");
                //组合贷款
                var txtGjMoney = $('#gjjMoney');
                var txtDkMoney = $('#dkMoney');
                var selAjyeardk = $('#ajyeardk');
                var txtInitrate1 = $('#initrate1');
                var txtInitrate2 = $('#initrate2');
                var m_sfMoney, m_dkMoney, m_typeCal = 0;
                var selTypeCal = 0;
                $('input[type=radio][name=typeCal]').change(function () {
                    if (this.value == 0) {
                        $("#initrate").val(4.9);
                        $("#houseCalInput").show();
                        $("#houseZHCalInput").hide();
                    }
                    if (this.value == 1) {
                        $("#initrate").val(3.2);
                        $("#houseCalInput").show();
                        $("#houseZHCalInput").hide();
                    }
                    if (this.value == 2) {
                        $("#houseCalInput").hide();
                        $("#houseZHCalInput").show();
                    }
                });
                $('#payMethod a').click(function () {
                    m_typeCal = $(this).index();
                    $('#payMethod a').removeClass('active');
                    $(this).addClass('active');
                    $("#detailPage").hide();
                    calFun();
                });
                $("#startCal").on("click", function () {
                    selTypeCal = Number($("input[name='typeCal']:checked").val());
                    m_typeCal = Number($("input[name='repaytype']:checked").val());
                    // m_dkMoney = txtdkTotalMoney.val();
                    // m_sfMoney = txtTotalMoney.val() - txtdkTotalMoney.val();
                    m_dkMoney = Math.round(txtdkTotalMoney.val());
                    m_sfMoney = Math.round(txtTotalMoney.val() - m_dkMoney);
                    $("#houseCal").show();
                    $("#danduCal").show();
                    $("#caldefault1").hide();
                    $("#detailPage").hide();
                    if (selTypeCal != 2) {
                        $("#danduCal").show();
                        $("#zhuheCal").hide();
                    } else {
                        $("#danduCal").hide();
                        $("#zhuheCal").show();
                    }
                    calFun();
                });
                //重填
                $("#resetCal").on("click", function () {
                    $("#caldefault1").show();
                    $("#houseCal").hide();
                    $("#detailPage").hide();
                });
                $("#detailLink").on("click", function () {
                    $("#detailPage").show();
                    $("#houseCal").hide();
                    //if(selTypeCal!=2){
                    $("#lIAllMoney").html(Math.round(HouseLoanObject.ResultCount) + "元");
                    $("#lIDkMoney").html(Math.round(HouseLoanObject.ResultCount - HouseLoanObject.Result) + "元");
                    $("#lILxMoney").html(Math.round(HouseLoanObject.Result) + "元");
                    $("#lIDkYear").html("(" + Math.round(HouseLoanObject.HouseLoan.length) + "月)(" + Math.round(HouseLoanObject.HouseLoan.length) / 12 + "年)");
                    $("#lIHkMoney").html(Math.round(HouseLoanObject.ResultCount / HouseLoanObject.HouseLoan.length) + "元/月");
                    var htmlArr = [];
                    htmlArr.push('<table border="0" cellpadding="0" cellspacing="0"><tbody><tr><th>月份</th><th>月供</th><th>月供本金</th><th>月供利息</th><th>剩余贷款</th></tr></tbody></table>');
                    for (var i = 0; i < HouseLoanObject.HouseLoan.length / 12; i++) {
                        htmlArr.push('<table style="width:100% ;border:0 ;cellpadding:0;cellspacing:0"><tbody><tr><td colspan="5" class="lf4">第' + (i + 1) + '年</td></tr>');
                        for (var j = 0; j < 12; j++) {
                            htmlArr.push('<tr><td>' + (j + 1) + '月</td><td>¥' + Math.round(HouseLoanObject.HouseLoan[(i * 12 + j)].ReplyPrincipalIntreest) + '</td><td>¥' + Math.round(HouseLoanObject.HouseLoan[(i * 12 + j)].ReplyPrincipal) + '</td><td>¥' + Math.round(HouseLoanObject.HouseLoan[(i * 12 + j)].ReplyInterest) + '</td><td>¥' + Math.round(HouseLoanObject.HouseLoan[(i * 12 + j)].SurplusPrincipal) + '</td></tr>')
                        }
                        htmlArr.push('</tbody></table>');
                    }
                    $("#listHtml").html(htmlArr.join(""));
                });
                var calFun = function () {
                    if (selTypeCal != 2) {
                        //贷款钱
                        var dke = txtdkTotalMoney.val() * 10000;
                        //年份
                        var ns = selajYear.val();
                        //利率
                        var nll = txtinitrate.val();
                        if (selTypeCal == 0) {
                            HouseLoanObject = CalLoan(ns * 12, dke, nll / 12 / 100, 0, 0, m_typeCal, selTypeCal);
                        } else if (selTypeCal == 1) {
                            HouseLoanObject = CalLoan(ns * 12, 0, 0, dke, nll / 12 / 100, m_typeCal, selTypeCal);
                        }
                        var doughnutData = [
                            {
                                value: m_sfMoney.toFixed(1),
                                color: "#6dbdff",
                                highlight: "#3bbdff"
                            },
                            {
                                value: Math.round(HouseLoanObject.Result / 10000),
                                color: "#ff6ea0",
                                highlight: "#ff3ca0"
                            },
                            {
                                value: m_dkMoney.toFixed(1),
                                color: "#ffd87b",
                                highlight: "#ffd83f"
                            }
                        ];
                        var ctx = document.getElementById("pieConChar").getContext("2d");
                        window.myDoughnut = new Chart(ctx).Doughnut(doughnutData, {
                            responsive: true,
                            scaleShowLabels: false
                        });
                        $("#monthPay").html("¥" + HouseLoanObject.HouseLoan[0].ReplyPrincipalIntreest.toFixed(1));
                        $("#ddZj").html(Math.round(txtTotalMoney.val()) + "万元");
                        $("#ddSf").html(Math.round(m_sfMoney) + "万元");
                        $("#ddDk").html(Math.round(m_dkMoney) + "万元");
                        $("#ddLx").html(Math.round(HouseLoanObject.Result) + "元");
                        $("#ddLr").html(txtinitrate.val() + "%");
                        $("#ddYg").html(Math.round(HouseLoanObject.HouseLoan[0].ReplyPrincipalIntreest) + "元/月");
                    } else {
                        HouseLoanObject = CalLoan(selAjyeardk.val() * 12, txtDkMoney.val() * 10000, txtInitrate1.val() / 12 / 100, txtGjMoney.val() * 10000, txtInitrate2.val() / 12 / 100, m_typeCal, selTypeCal);
                        var doughnutData = [
                            {
                                value: Math.round(HouseLoanObject.ResultCount - HouseLoanObject.Result),
                                color: "#6dbdff",
                                highlight: "#3bbdff"
                            },
                            {
                                value: Math.round(HouseLoanObject.Result),
                                color: "#ffd87b",
                                highlight: "#ffd83f"
                            }
                        ];
                        var ctx = document.getElementById("pieConChar").getContext("2d");
                        window.myDoughnut = new Chart(ctx).Doughnut(doughnutData, {
                            responsive: true,
                            scaleShowLabels: false
                        });
                        $("#monthPay").html("¥" + Math.round(HouseLoanObject.HouseLoan[0].ReplyPrincipalIntreest));
                        $("#HkZj").html(Math.round(HouseLoanObject.ResultCount) + "元");
                        $("#DkZj").html(Math.round(HouseLoanObject.ResultCount - HouseLoanObject.Result) + "元");
                        $("#LxZj").html(Math.round(HouseLoanObject.Result) + "元");
                        $("#ddYg2").html(Math.round(HouseLoanObject.HouseLoan[0].ReplyPrincipalIntreest) + "元/月");
                    }
                }
            });
    

    4.代码开放

    Githttps://github.com/gityuh/house_calculator

    相关文章

      网友评论

          本文标题:房贷计算器

          本文链接:https://www.haomeiwen.com/subject/yxhhahtx.html