cal.php
6.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?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"></i> 利息计算器
</button>
<button class="btn btn-primary radius" onclick="layer_load('', '<?= site_url('/tool/web'); ?>');">
<i class="Hui-iconfont"></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> </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>