cal.php 6.13 KB
<?php $this->load->view('common/header'); ?>

<body>
<div class="cl pd-5 bg-1">
        <span class="l">
            <button class="btn btn-primary radius" onclick="layer_load('', '<?= site_url('/tool/cal'); ?>');">
                <i class="Hui-iconfont">&#xe636;</i> 利息计算器
            </button>
            <button class="btn btn-primary radius" onclick="layer_load('', '<?= site_url('/tool/web'); ?>');">
                <i class="Hui-iconfont">&#xe60d;</i> 网查网址
            </button>
        </span>
</div>

<form id="form">
    <div class="panel panel-default">
        <div class="panel-body">
            <div class="row cl">
                <div class="form-group col-sm-3 col-md-2">
                    <label>产品名称</label>
                    <span class="form-control select-box">
                        <select id="product" class="select" size="1" v-model="product">
                            <option v-for="(v, index) in products" :value="v">{{v.productName}}</option>
                        </select>
                    </span>
                </div>
                <div class="form-group col-sm-3 col-md-2">
                    <label>借款金额</label>
                    <input name="borrowAmount" type="text" class="form-control input-text" v-model="borrowAmount">
                    <span class="glyphicon form-control-feedback"></span>
                </div>
                <div class="form-group col-sm-3 col-md-2">
                    <label>借款期数</label>
                    <span class="form-control select-box">
                        <select class="select" size="1" v-model="loanDeadline">
                            <option v-for="v in loanDeadlines" :value="v * 6">{{v * 6}} 期</option>
                        </select>
                    </span>
                </div>
                <div class="form-group col-sm-3 col-md-2">
                    <label>还款方式</label>
                    <input type="text" class="form-control input-text" readonly id="repaymentMode" :value="product.repaymentMode">
                </div>
            </div>
        </div>
    </div>

    <div class="panel panel-default mb-20">
        <div class="panel-header">计算结果</div>
        <div class="panel-body">
            <div class="row cl">
                <div class="form-group col-sm-3 col-md-2">
                    <label>&nbsp;</label>
                    <input type="text" class="form-control input-text" :value="periods" disabled>
                    <span class="glyphicon form-control-feedback"></span>
                </div>
                <div class="form-group col-sm-3 col-md-2">
                    <label>总共应还</label>
                    <input type="text" class="form-control input-text" :value="totalRepay" disabled>
                    <span class="glyphicon form-control-feedback"></span>
                </div>
                <div class="form-group col-sm-3 col-md-2">
                    <label>总共应还利息</label>
                    <input type="text" class="form-control input-text" :value="totalInterest" disabled>
                    <span class="glyphicon form-control-feedback"></span>
                </div>
            </div>
            <table class="table table-border table-bordered table-bg mt-20">
                <thead class="text-c">
                    <tr>
                        <th>期数</th>
                        <th>本期应还(元)</th>
                        <th>应还本金(元)</th>
                        <th>应还利息(元)</th>
                    </tr>
                </thead>
                <tbody class="text-c">
                    <tr v-for="repayPlan in repayPlans">
                        <td>{{repayPlan.period}}</td>
                        <td>{{repayPlan.totalAmount}}</td>
                        <td>{{repayPlan.principal}}</td>
                        <td>{{repayPlan.interest}}</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>

    <div class="row cl pb-20 col-sm-12">
        <div class="col-sm-offset-4 col-sm-2">
            <button class="btn btn-primary btn-block" type="button" @click="cal()">计算</button>
        </div>
        <div class="col-sm-2">
            <input class="btn btn-warning btn-block" value="重置" type="reset">
        </div>
    </div>
</form>

<?php $this->load->view('common/footer'); ?>

<script>
    var vm = new Vue({
        el: '#form',
        data: {
            products: [],
            product: {},

            borrowAmount: '',
            loanDeadline: 6,

            periods: '',
            totalInterest: '',
            totalRepay: '',
            repayPlans: [],
        },
        mounted () {
            let _this = this;
            instance.get('/config/products').then( ( {data} ) => {
                this.products = data.data
            });
        },
        methods: {
            cal () {
                let str = 'borrowAmount=' + this.borrowAmount + '&productId=' + this.product.id + '&loanDeadline=' + this.loanDeadline;
                instance.get('application/tool/interest?' + str).then( ( {data} ) => {
                    this.totalRepay = data.data.totalRepay;
                    this.periods = data.data.periods;
                    this.totalInterest = data.data.totalInterest;
                    this.repayPlans = data.data.repayPlans;
                });
            },
        },
        computed: {
            loanDeadlines () {
                return this.product.loanDeadline / 6 ? this.product.loanDeadline / 6 : 0;
            }
        },
        watch: {
            borrowAmount () {
                if(this.borrowAmount > this.product.loanLimit) {
                    layer.alert('不能超过最大值' + this.product.loanLimit);
                    this.borrowAmount = this.product.loanLimit;
                }
            },
            product () {
                if(this.borrowAmount > this.product.loanLimit) {
                    layer.alert('不能超过最大值' + this.product.loanLimit);
                    this.borrowAmount = this.product.loanLimit;
                }
            },
        }
    });
</script>
</body>
<html>