Skip to content

Commit e40a985

Browse files
committed
fix: step from value bind
1 parent c5de135 commit e40a985

File tree

2 files changed

+46
-15
lines changed

2 files changed

+46
-15
lines changed

src/views/form/stepForm/Step1.vue

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
<template>
22
<div>
3-
<a-form style="max-width: 500px; margin: 40px auto 0;">
3+
<a-form :form="form" style="max-width: 500px; margin: 40px auto 0;">
44
<a-form-item
55
label="付款账户"
66
:labelCol="labelCol"
77
:wrapperCol="wrapperCol"
88
>
9-
<a-select value="1" placeholder="[email protected]">
9+
<a-select
10+
placeholder="[email protected]"
11+
v-decorator="['paymentUser', { rules: [{required: true, message: '付款账户必须填写'}] }]">
1012
<a-select-option value="1">[email protected]</a-select-option>
1113
</a-select>
1214
</a-form-item>
@@ -15,27 +17,33 @@
1517
:labelCol="labelCol"
1618
:wrapperCol="wrapperCol"
1719
>
18-
<a-input-group :compact="true" style="display: inline-block; vertical-align: middle">
20+
<a-input-group
21+
style="display: inline-block; vertical-align: middle"
22+
:compact="true"
23+
>
1924
<a-select defaultValue="alipay" style="width: 100px">
2025
<a-select-option value="alipay">支付宝</a-select-option>
2126
<a-select-option value="wexinpay">微信</a-select-option>
2227
</a-select>
23-
<a-input :style="{width: 'calc(100% - 100px)'}" value="[email protected]"/>
28+
<a-input
29+
:style="{width: 'calc(100% - 100px)'}"
30+
v-decorator="['payType', { initialValue: '[email protected]', rules: [{required: true, message: '收款账户必须填写'}]}]"
31+
/>
2432
</a-input-group>
2533
</a-form-item>
2634
<a-form-item
2735
label="收款人姓名"
2836
:labelCol="labelCol"
2937
:wrapperCol="wrapperCol"
3038
>
31-
<a-input value="Alex" />
39+
<a-input v-decorator="['name', { initialValue: 'Alex', rules: [{required: true, message: '收款人名称必须核对'}] }]"/>
3240
</a-form-item>
3341
<a-form-item
3442
label="转账金额"
3543
:labelCol="labelCol"
3644
:wrapperCol="wrapperCol"
3745
>
38-
<a-input prefix="" value="5000" />
46+
<a-input prefix="" v-decorator="['momey', { initialValue: '5000', rules: [{required: true, message: '转账金额必须填写'}] }]"/>
3947
</a-form-item>
4048
<a-form-item :wrapperCol="{span: 19, offset: 5}">
4149
<a-button type="primary" @click="nextStep">下一步</a-button>
@@ -58,12 +66,19 @@ export default {
5866
data () {
5967
return {
6068
labelCol: { lg: { span: 5 }, sm: { span: 5 } },
61-
wrapperCol: { lg: { span: 19 }, sm: { span: 19 } }
69+
wrapperCol: { lg: { span: 19 }, sm: { span: 19 } },
70+
form: this.$form.createForm(this)
6271
}
6372
},
6473
methods: {
6574
nextStep () {
66-
this.$emit('nextStep')
75+
const { form: { validateFields } } = this
76+
// 先校验,通过表单校验后,才进入下一步
77+
validateFields((err, values) => {
78+
if (!err) {
79+
this.$emit('nextStep')
80+
}
81+
})
6782
}
6883
}
6984
}

src/views/form/stepForm/Step2.vue

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div>
3-
<a-form style="max-width: 500px; margin: 40px auto 0;">
3+
<a-form :form="form" style="max-width: 500px; margin: 40px auto 0;">
44
<a-alert
55
:closable="true"
66
message="确认转账后,资金将直接打入对方账户,无法退回。"
@@ -45,7 +45,10 @@
4545
:wrapperCol="wrapperCol"
4646
class="stepFormText"
4747
>
48-
<a-input type="password" style="width: 80%;" value="123456" />
48+
<a-input
49+
type="password"
50+
style="width: 80%;"
51+
v-decorator="['paymentPassword', { initialValue: '123456', rules: [{required: true, message: '请输入支付密码'}] }]" />
4952
</a-form-item>
5053
<a-form-item :wrapperCol="{span: 19, offset: 5}">
5154
<a-button :loading="loading" type="primary" @click="nextStep">提交</a-button>
@@ -62,21 +65,34 @@ export default {
6265
return {
6366
labelCol: { lg: { span: 5 }, sm: { span: 5 } },
6467
wrapperCol: { lg: { span: 19 }, sm: { span: 19 } },
65-
66-
loading: false
68+
form: this.$form.createForm(this),
69+
loading: false,
70+
timer: 0
6771
}
6872
},
6973
methods: {
7074
nextStep () {
7175
const that = this
76+
const { form: { validateFields } } = this
7277
that.loading = true
73-
setTimeout(function () {
74-
that.$emit('nextStep')
75-
}, 1500)
78+
validateFields((err, values) => {
79+
if (!err) {
80+
console.log('表单 values', values)
81+
that.timer = setTimeout(function () {
82+
that.loading = false
83+
that.$emit('nextStep')
84+
}, 1500)
85+
} else {
86+
that.loading = false
87+
}
88+
})
7689
},
7790
prevStep () {
7891
this.$emit('prevStep')
7992
}
93+
},
94+
beforeDestroy () {
95+
clearTimeout(this.timer)
8096
}
8197
}
8298
</script>

0 commit comments

Comments
 (0)