createIOU.vue
15.1 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
<template>
<v-layout id="CreateIOU" column justify-center align-center>
<v-flex>
<v-card id="IOUInfoBlock" class="IOUList" flat height="15.5rem">
<div class="NameBlock FormLine">
<div class="labelBlock">
<span>借款金额</span>
</div>
<v-text-field
v-model.number="form.amount"
suffix="元"
color="light-gold"
class="BindCardInput "
name="PhoneInput"
placeholder="请输入借款金额"
:error-messages="amountErrMsg"
@input='amountCheck'
id='AmountInput'
single-line
></v-text-field>
</div>
<div class="BankBlock FormLine" @click="startPickerDislpay = true">
<div class="labelBlock">
<span>借款日期</span>
</div>
<div class="pickerValueBlock" v-if="!form.start" >{{'请选择'}}
<v-icon class="addCardIcon">keyboard_arrow_right</v-icon>
</div>
<div class="pickerValueBlockValue" v-if="!!form.start" >
<span>{{form.start}}</span>
</div>
<DatePicker title="请选择借款日期"
@pickerClose="startPickerDislpay = false"
v-model="form.start"
:display="startPickerDislpay"/>
</div>
<div class="BankBlock FormLine" @click="endPickerDislpay = true">
<div class="labelBlock">
<span>还款日期</span>
</div>
<div class="pickerValueBlock" v-if="!form.end" >{{'请选择'}}
<v-icon class="addCardIcon">keyboard_arrow_right</v-icon>
</div>
<div class="pickerValueBlockValue" v-if="!!form.end" >
<span>{{form.end}}</span>
</div>
<DatePicker title="请选择还款日期"
@pickerClose="endPickerDislpay = false"
v-model="form.end"
:display="endPickerDislpay"/>
</div>
<div class="BankBlock FormLine" @click="ratePickerDislpay = true">
<div class="labelBlock">
<span>年化利率</span>
</div>
<div class="pickerValueBlock" v-if="!form.rate" >{{'请选择'}}
<v-icon class="addCardIcon">keyboard_arrow_right</v-icon>
</div>
<div class="pickerValueBlockValue" v-if="!!form.rate" >
<span>{{form.rate}}</span><span class="rateInterest">{{interest}}元</span>
</div>
<Picker
:data="rates"
title="请选择年化利率"
@pickerClose="ratePickerDislpay = false"
@select="rateChange"
:display="ratePickerDislpay"/>
</div>
<div class="HintLine">
本金{{displayAmount}}+利息{{interest}}=到期本息<span>{{displayAmount + interest}}</span>元
</div>
</v-card>
<v-card id="IOUUsageBlock" class="IOUList" flat height="3.1rem">
<div class="NameBlock FormLine" @click="usageDislogDisplay = true">
<div class="labelBlock">
<span>借款用途</span>
</div>
<div class="pickerValueBlock" v-if="!form.usage" >{{'请选择'}}
<v-icon class="addCardIcon">keyboard_arrow_right</v-icon>
</div>
<div class="pickerValueBlockValue" v-if="!!form.usage" >
{{form.usage}}
</div>
<BorrowUsage :display="usageDislogDisplay" @change="usageChange" @close="usageDislogDisplay = false"/>
</div>
</v-card>
<v-card id="IOUTargetBlock" class="IOUList" flat height="4.2rem">
<div class="NameBlock FormLine" >
<div class="labelBlock">
<span>{{role === 'borrower' ? '出借人' : '借款人'}}姓名</span>
</div>
<v-text-field
v-model="form.target"
color="light-gold"
class="BindCardInput "
name="NameInput"
placeholder="正确才能生效哦"
:error-messages="targetErrMsg"
@input='targetChcek'
id='NameInput'
single-line
></v-text-field>
</div>
</v-card>
<div class="Agreement">
<div
@click="agreement = !agreement"
class="AgreementCheckBox"
:class="agreement ? 'AgreementChecked' : ''">
<v-icon id="CheckBoxCheck" v-if="agreement">check</v-icon>
</div>
已阅读并同意<span class="gold--text">《借款协议》</span><span class="gold--text">《居间服务协议》</span>
</div>
<div class="ConfirmButtonBlock">
<v-btn depressed id="ConfirmButton" :loading="isLoading" @click.native="formCheck">确 定</v-btn>
</div>
<v-dialog v-model="dialogDisplay" persistent max-width="290">
<v-card class="hintDialog">
<v-card-title class="headline">提示</v-card-title>
<v-card-text class='dialogContent'>{{dialogInfo}}</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn color="black" flat @click.native="dialogDisplay = false">知道了</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
<v-dialog v-model="comfirmDialogDisplay" persistent max-width="290">
<v-card class="hintDialog">
<v-card-title class="headline">提示</v-card-title>
<v-card-text class='dialogContent'>
<v-icon x-large class="warningIcon">warning</v-icon>
<p class='red--text bold'>借条是为已完成的借贷行为补一张借条,作为电子凭证,请确保你们线下交易完成</p>
<p>双方确认后借条即刻生效,要发起该借条吗?</p>
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn color="black" flat @click.native="comfirmDialogDisplay = false">不发起</v-btn>
<v-btn color="black" flat @click.native="submitIOU">发起</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</v-flex>
</v-layout>
</template>
<script>
import Picker from '@/components/Picker'
import DatePicker from '@/components/DatePicker'
import BorrowUsage from '@/components/BorrowUsage'
import {wechatShareSetting} from '@/helper'
export default {
layout: 'lightGold',
data:() => ({
agreement: false,
form: {
amount: null,
role: '',
target: '',
start: '',
end: '',
rate: '',
rateValue: '',
usage: '',
explanation: '',
imgs: [],
},
rates: [[
{ text: '0%', value:0 }, { text: '1%', value:0.01 },{ text: '2%', value:0.02 },{ text: '3%', value:0.03 },{ text: '4%', value:0.04 },{ text: '5%', value:0.05 },{ text: '6%', value:0.06 },
{ text: '7%', value:0.07 },{ text: '8%', value:0.08 },{ text: '9%', value:0.09 },{ text: '10%', value:0.1 },{ text: '11%', value:0.11 },{ text: '12%', value:0.12 }
,{ text: '13%', value:0.13 },{ text: '14%', value:0.14 },{ text: '15%', value:0.15 },{ text: '16%', value:0.16 },{ text: '17%', value:0.17 },{ text: '18%', value:0.18 },
{ text: '19%', value:0.19},{ text: '20%', value:0.2 },{ text: '21%', value:0.21 },{ text: '22%', value:0.22 },{ text: '23%', value:0.23 },{ text: '24%', value:0.24 }
]],
ratePickerDislpay: false,
startPickerDislpay: false,
endPickerDislpay: false,
usageDislogDisplay: false,
amountErrMsg: [],
targetErrMsg: [],
dialogDisplay: false,
dialogInfo: '',
comfirmDialogDisplay: false,
isLoading: false
}),
head:() => ({
title: '创建借条'
}),
computed: {
role () {
return this.$route.query.role || 'creditor'
},
displayAmount() {
return parseFloat(this.form.amount) || 0
},
interest () {
const rate = this.form.rateValue || 0
return Math.round(this.displayAmount * rate / 365 * this.days * 100) / 100
},
gap () {
if (!this.form.start || !this.form.end) return 0
let start = new Date(this.form.start).getTime()
let end = new Date(this.form.end).getTime()
return ((end - start) / (1000 * 60 * 60 * 24))
},
days () {
return this.gap > 0 ? this.gap : 0
}
},
components: {
Picker,
DatePicker,
BorrowUsage
},
mounted() {
wechatShareSetting(this.$axios, this.$store)
},
methods: {
showDialog(info) {
this.dialogInfo = info
this.dialogDisplay = true
},
rateChange(val, index, text) {
this.form.rate = text[0]
this.form.rateValue = val[0]
},
amountCheck() {
this.amountErrMsg = []
if (typeof this.form.amount !== 'number' || this.form.amount <= 0) {
this.amountErrMsg = ['请输入有效的借款金额']
return false
}
if (this.form.amount < 100) {
this.amountErrMsg = ['借款金额最低为100元']
return false
}
return true
},
targetChcek() {
this.targetErrMsg = []
if (typeof this.form.target !== 'string' || this.form.target.length === 0) {
this.targetErrMsg = ['请输入有效的姓名']
return false
}
return true
},
usageChange(e) {
this.form.usage = e.type
this.form.explanation = e.explanation
this.form.imgs = e.imgs
},
formCheck() {
if (this.form.amount < 100) {
this.showDialog('借款金额最低为100元')
return false
}
if (!this.amountCheck()) {
this.showDialog('请输入有效的借款金额!')
return false
}
if (!this.form.start) {
this.showDialog('请选择借款日期!')
return false
}
if (new Date(this.form.start).getTime() > new Date().getTime()) {
this.showDialog('借款日期不能晚于今天!')
return false
}
if (!this.form.end) {
this.showDialog('请选择还款日期!')
return false
}
if (new Date(this.form.end).getTime() < new Date().getTime() - 86400000) {
this.showDialog('还款日期不能早于今天!')
return false
}
if (this.gap < 0) {
this.showDialog('还款日期最早为借款日期当日')
return false
}
if (!this.form.rate || typeof this.form.rateValue !== 'number') {
this.showDialog('请选择年化利率!')
return false
}
if (!this.form.usage) {
this.showDialog('请选择借款用途!')
return false
}
if (!this.targetChcek()) {
this.showDialog('请输入有效的姓名!')
return false
}
if (!this.agreement) {
this.showDialog('请阅读并同意《借款协议》及《居间服务协议》!')
return false
}
// return true
this.comfirmDialogDisplay = true
},
async submitIOU() {
this.isLoading = true
const could = this.formCheck()
// if (!could) {
// this.isLoading = false
// return
// }
const form = new FormData()
form.append('userId', this.$store.state.user.id)
form.append('amount', this.form.amount)
form.append('role', this.role)
form.append('target', this.form.target)
form.append('start', this.form.start)
form.append('end', this.form.end)
form.append('rate', this.form.rate)
form.append('rateValue', this.form.rateValue)
form.append('usage', this.form.usage)
form.append('explanation', this.form.explanation)
for (let i = 0; i < this.form.imgs.length; i++) {
const img = this.form.imgs[i]
form.append(`img${i + 1}`, img)
}
let {data} = await this.$axios.post('/iou', form)
this.isLoading = false
if (data.success) {
this.$router.push(`borrowContent?id=${data.id}`)
} else {
this.$store.dispatch('displayMessage', data.msg)
}
}
}
}
</script>
<style lang="scss" scoped>
#CreateIOU {
.IOUList {
width: 90vw;
margin-top: 1.5rem;
background: #FFFFFF;
border-radius: 2px;
padding: 0 1.3rem;
.FormLine {
height: 3.3rem;
position: relative;
.labelBlock {
line-height: 3.3rem;
height: 3.3rem;
position: absolute;
font-size: 1rem;
font-weight: bold;
}
.BindCardInput {
padding-top: 0.75rem;
}
.pickerValueBlock {
padding-top: 0.75rem;
text-align: right;
font-size: 1rem;
.addCardIcon {
color: $light-gold;
}
}
.pickerValueBlockValue {
padding-top: 0.75rem;
padding-left: 6.7rem;
text-align: right;
font-size: 1rem;
.rateInterest {
margin-left: 0.5rem;
color: $light-gold;
}
}
}
/deep/ #AmountInput {
margin-left: 6.7rem;
text-align: right;
}
/deep/ #NameInput {
margin-left: 6.7rem;
text-align: right;
}
.BankBlock {
border-bottom: 1px solid rgba(0, 0, 0, .87);
}
.HintLine {
font-size: 0.9rem;
line-height: 2rem;
text-align: right;
color: #9D9D9D;
span {
color: $light-gold;
}
}
::-moz-placeholder { color: #9D9D9D; }
::-webkit-input-placeholder { color:#9D9D9D; }
:-ms-input-placeholder { color:#9D9D9D; }
}
#IOUUsageBlock {
margin-top: 1rem;
}
#IOUTargetBlock {
margin-top: 1rem;
}
.Agreement {
text-align: center;
font-size: 12px;
color: #666;
font-weight: bold;
height: 1.5rem;
line-height: 1.5rem;
margin-top: 1rem;
.AgreementCheckBox {
border: 2px solid #666;
color: #fff;
width: 1.2rem;
height: 1.2rem;
border-radius: 1.2rem;
transition: all 0.3s ease-in-out;
display: inline-block;
margin-right: 0.8rem;
position: relative;
top: 3px;
&.AgreementChecked {
background-image: linear-gradient(-229deg, #DAB269 37%, #E7C78C 87%);
border-color: #E7C78C;
}
#CheckBoxCheck {
position: absolute;
left: 0;
font-size: 15px;
font-weight: bold;
}
}
}
.ConfirmButtonBlock {
width: 90vw;
margin: 2.5rem auto;
#ConfirmButton {
color: #484646;
background-image: linear-gradient(-213deg, #DAB269 0%, #E7C78C 92%);
border-radius: 2px;
width: 100%;
height: 2.8rem;
font-size: 18px;
margin: auto;
transition: 0.2s all ease-in-out;
&:disabled {
background-image: none;
}
}
}
}
.hintDialog {
background-color: #fff;
color: #000;
.headline {
justify-content: center;
font-weight: bold;
padding-bottom: 0;
}
.dialogContent {
justify-content: center;
text-align: center;
.warningIcon {
margin-bottom: 0.5rem;
color: red;
font-size: 5rem;
}
.bold {
font-weight: bold;
}
p {
margin-bottom: 0;
}
}
.btn {
width: 100%;
}
}
</style>