MrShi
5 天以前 47d56a8b0f22fb15a46b69dfd46fac23560ad2cd
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
<template>
    <view class="change-password">
        <view class="form">
            <view class="form-item">
                <view class="form-item-left">
                    <image src="/static/icon/login_ic_password@2x.png" mode="widthFix"></image>
                </view>
                <input type="password" v-model="form.oldPassword" placeholder="请输入原密码" />
            </view>
            <view class="form-item">
                <view class="form-item-left">
                    <image src="/static/icon/login_ic_password@2x.png" mode="widthFix"></image>
                </view>
                <input type="password" v-model="form.newPassword" placeholder="请输入新密码(至少8位)" />
            </view>
            <view class="form-item">
                <view class="form-item-left">
                    <image src="/static/icon/login_ic_password@2x.png" mode="widthFix"></image>
                </view>
                <input type="password" v-model="form.confirmPassword" placeholder="请再次输入新密码" />
            </view>
        </view>
        <view class="btn" @click="submit">确认修改</view>
    </view>
</template>
 
<script>
    import { mapState } from 'vuex'
    export default {
        computed: {
            ...mapState(['userInfo'])
        },
        data() {
            return {
                form: {
                    oldPassword: '',
                    newPassword: '',
                    confirmPassword: ''
                }
            };
        },
        methods: {
            async submit() {
                if (!this.form.oldPassword) {
                    uni.showToast({
                        title: '请输入原密码',
                        icon: 'none'
                    })
                    return
                }
                if (!this.form.newPassword) {
                    uni.showToast({
                        title: '请输入新密码',
                        icon: 'none'
                    })
                    return
                }
                if (this.form.newPassword.length < 8) {
                    uni.showToast({
                        title: '新密码至少8位',
                        icon: 'none'
                    })
                    return
                }
                if (!this.form.confirmPassword) {
                    uni.showToast({
                        title: '请再次输入新密码',
                        icon: 'none'
                    })
                    return
                }
                if (this.form.newPassword !== this.form.confirmPassword) {
                    uni.showToast({
                        title: '两次密码输入不一致',
                        icon: 'none'
                    })
                    return
                }
                let res = await this.$u.api.updatePwd({
                    oldPassword: this.form.oldPassword,
                    newPassword: this.form.newPassword
                })
                if (res.code === 200) {
                    uni.showToast({
                        title: '修改成功',
                        icon: 'success'
                    })
                    setTimeout(() => {
                        uni.navigateBack()
                    }, 1500)
                } else {
                    uni.showToast({
                        title: res.msg || '修改失败',
                        icon: 'none'
                    })
                }
            }
        }
    }
</script>
 
<style lang="scss" scoped>
    .change-password {
        width: 100%;
        min-height: 100vh;
        background-color: #F9F9FB;
        padding: 30rpx;
        box-sizing: border-box;
    }
    .form {
        width: 100%;
        background-color: #fff;
        border-radius: 16rpx;
        padding: 0 30rpx;
        .form-item {
            width: 100%;
            height: 100rpx;
            display: flex;
            align-items: center;
            border-bottom: 1rpx solid #E5E5E5;
            &:last-child {
                border-bottom: none;
            }
            .form-item-left {
                width: 40rpx;
                height: 40rpx;
                flex-shrink: 0;
                margin-right: 20rpx;
                image {
                    width: 100%;
                    height: 100%;
                }
            }
            input {
                flex: 1;
                height: 100%;
                font-size: 28rpx;
                color: #333;
            }
        }
    }
    .btn {
        width: 100%;
        height: 88rpx;
        background-color: #004096;
        border-radius: 44rpx;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 32rpx;
        color: #fff;
        margin-top: 60rpx;
    }
</style>