lyfO_o
2022-05-06 4b4622c9f74150ca60eb7c4f038e55fb98be02d7
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
<template>
    <div class="register_main">
        <div class="register_main_body">
            <span class="register_main_body_span">密码重置</span>
        </div>
        <div class="register_main_form">
            <el-form :model="pwdForm" :rules="rules" ref="ruleForm" label-width="150px">
                <el-row>
                    <el-col :span="20">
                        <el-form-item label="姓名" prop="username">
                            <el-input v-model="pwdForm.username"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="20">
                        <el-form-item label="手机号(账户)" prop="phone">
                            <el-input v-model="pwdForm.phone" ref="tel"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="20">
                        <el-form-item label="密码" prop="password">
                            <el-input v-model="pwdForm.password"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
 
                <el-row>
                    <el-col :span="20">
                        <el-form-item label="确认密码" prop="repassword">
                            <el-input v-model="pwdForm.repassword"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                </el-row>
            </el-form>
            <div  align="center" style="padding-bottom: 30px">
                <el-button type="primary" :disabled="submitting" @click="submit()">修改密码</el-button>
            </div>
        </div>
    </div>
</template>
 
<script>
import {pwdChange} from "../../api/user";
import {parseError} from "../../utils/messageDialog";
 
export default {
    name: "register",
    data(){
        return{
            submitting: false,
            pwdForm:{
                username:'',
                password:'',
                repassword:'',
                phone:'',
            },
            rules:{
                username:[
                    { required: true, message: '请填写姓名', trigger: 'blur' },
                ],
                phone:[
                    { required: true, message: '请填写手机号', trigger: 'blur' },
                ],
                password:[
                    { required: true, message: '请填写密码', trigger: 'blur' },
                ],
                repassword:[
                    { required: true, message: '请填写确认密码', trigger: 'blur' },
                ],
 
 
            },
        }
    },
    watch:{
    },
    created(){
 
    },
    methods:{
        async submit(){
            if (this.pwdForm.password !==  this.pwdForm.repassword) {
                this.$message({
                    type:'warning',
                    message:'两次密码输入不一致'
                })
                return
            }
            if (this.pwdForm.phone.length !== 11) {
                this.$message({
                    type:'warning',
                    message:'手机号长度不为11'
                })
                return
            }
            this.$refs["ruleForm"].validate((valid) =>{
                if(valid){
                    this.register()
                }else{
                    this.$message({
                        type:'warning',
                        message:'请填写基本信息'
                    })
                }
            });
 
        },
 
        register(){
            this.submitting = true
            pwdChange(this.pwdForm)
                .then(res=>{
                    if (res.data.code === '200') {
                        this.$message({
                            type:'success',
                            message:'修改成功'
                        })
                        setTimeout(()=>{
                            this.$router.push({path:'/login'})
                        },1000)
                    }else{
                        this.$message({
                            type:'warning',
                            message:res.data.message
                        })
                    }
                })
                .catch(err=>{
                    console.log(err)
                    this.$message({
                        type:'warning',
                        message:'请求超时'
                    })
                })
                .finally(()=>{
                    this.submitting = false
                });
        }
    }
}
</script>
 
<style rel="stylesheet/scss" lang="scss">
$dark_gray:#889aa4;
.register_main{
    display: block;
    width: 100%;
    max-width: 1200px;
    padding: 0 20px;
    margin: 30px auto
}
.register_main_body{
    font-size: 24px;
}
.register_main_form{
    padding-top: 70px;
    margin: 30px auto;
    max-width: 800px;
    display: block;
    width: 100%;
}
.register_main_body_span{
    padding: 6px 5px 6px 15px;
    color: $dark_gray;
    vertical-align: middle;
    width: 30px;
    display: inline-block;
}
</style>