cuiqian2004
8 天以前 f57571f987f3d25730123f488fccdfa3158ec5b1
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
<template>
    <view class="container items-center">
        <view class="reset-content">
            <form @submit="submitForm" class="reset-form">
                <view class="reset-form-item password-clz">
                    <view class="input">
                        <text class="reset-form-title">旧密码:</text>
                        <input class="reset-input" :focus="formData.passwordFocus" name="password" comfirm-type="done"
                            type="password" v-model="form.password" placeholder="请输入旧密码" />
                    </view>
                </view>
                <view class="reset-form-item password-clz">
                    <view class="input">
                        <text class="reset-form-title">新密码:</text>
                        <input class="reset-input" :focus="formData.newpasswordFocus" name="newpassword"
                            comfirm-type="done" type="password" v-model="form.newpassword" placeholder="请输入新密码" />
                    </view>
                </view>
                <view class="reset-form-item password-clz">
                    <view class="input">
                        <text class="reset-form-title">确认密码:</text>
                        <input class="reset-input" :focus="formData.confirmpasswordFocus" name="confirmpassword"
                            comfirm-type="done" type="password" v-model="form.confirmpassword" placeholder="请输入确认密码" />
                    </view>
                </view>
                <view class="button-clz">
                    <button form-type="submit" class="blue-button button-button-clz">确认修改</button>
                </view>
            </form>
        </view>
    </view>
</template>
 
<script>
    import Session from "@/common/utils.js"
    import {
        showModal,
        showToast
    } from "@/common/Page.js"
    import {
        resetPassword
    } from "@/api/org.js"
    import Validate from '@/common/Validate.js'
 
    export default {
        data() {
            return {
                form: {
                    password: '',
                    newpassword: '',
                    confirmpassword: ''
                },
                formData: {
                    passwordFocus: true,
                    newpasswordFocus: false,
                    confirmpasswordFocus: false,
                }
            }
        },
        methods: {
 
            submitForm(e) {
                var _this = this
                _this.validateForm = new Validate({
                    password: {
                        required: {
                            message: '旧密码不能为空'
                        }
                    },
                    newpassword: {
                        required: {
                            message: '新密码不能为空'
                        }
                    },
                    confirmpassword: {
                        required: {
                            message: '确认密码不能为空'
                        }
                    }
                });
                if (!_this.validateForm.checkForm(e)) {
 
                    let data = _this.validateForm.errorList[0];
                    console.log("submitForm failed ", data);
                    showToast(data.msg, "none");
                    return false;
                } else {
                    //保存数据
                    let param = e.detail.value;
                    let loginInfo = Session.getValue('logininfo')
                    if (param.password != loginInfo.password) {
                        showToast("原密码输入错误!", "none");
                        _this.form.confirmpassword = ""
                        _this.form.password = ""
                        _this.form.newpassword = ""
                        return false;
                    }
                    if (param.newpassword != param.confirmpassword) {
                        showToast("两次输入的密码不相同!", "none");
                        _this.form.confirmpassword = ""
                        _this.form.password = ""
                        _this.form.newpassword = ""
                        return false;
                    }
                    var _this = this
                    resetPassword(param.userlogin, param.password, param.newpassword).then((res) => {
                        const app = getApp()
                        console.log("resetPassword", ret[0].code)
                        loginInfo.password = ""
                        Session.setValue('logininfo', loginInfo)
                        showToast('密码已修改,请重新登录', 'none')
                        app.globalData.userdata = {};
                        Session.clearValue('userdata');
                        uni.reLaunch({
                            url: '/pages/loading/loading'
                        })
 
                    }).catch((rej) => {
                        console.log("密码修改异常", rej);
                        this.showError(rej);
 
                    })
                }
            },
            showError(ex) {
                let tip = typeof ex == 'string' ? ex : typeof ex.err_msg == 'string' ? ex.err_msg : typeof ex.errMsg ==
                    'string' ? ex.errMsg : ""
                showModal(tip, "提示", false)
            },
        }
    }
</script>
 
<style lang="scss" scoped>
    @import "../../common/css/button.scss";
 
    .justify-center {
        justify-content: center;
    }
 
    .items-center {
        align-items: center
    }
 
    .reset-form {
        display: flex;
        width: 750rpx;
        padding: 20px !important;
        flex-direction: column;
    }
 
    .reset-form-item {
        width: 750rpx;
        padding: 0.3125rem 0.3125rem !important;
        display: flex;
        align-items: center;
        justify-content: space-between;
 
    }
 
    .reset-form-item .input {
        display: flex;
        width: 100%;
        padding: 8px 0px;
        background-color: transparent;
        flex-direction: row;
    }
 
    .reset-form-title {
        padding-top: 2px;
        width: 80px;
        text-align: right;
    }
 
    .reset-input {
        display: flex;
        margin-left: 5px;
    }
 
    .password-clz {
        margin-left: 10px;
        width: calc(100% - 80px) !important;
        font-size: 14px !important;
        margin-top: 8px;
        margin-bottom: 0px;
        border-bottom: 1px solid #f2e7e7;
        margin-right: 10px;
    }
 
    .blue-button {
        background-color: #00aaff !important;
        color: white !important;
    }
 
    .button-clz {
        display: flex;
        justify-content: center;
        width: calc(100% - 40px) !important;
        font-size: 17px !important;
        margin-top: 20px;
        margin-bottom: 10px;
        border-radius: 0px;
    }
 
    .button-button-clz {
        font-size: 17px !important;
        margin: 0px !important;
        width: 240px !important;
        height: 48px;
    }
 
    .container {
        display: flex;
        font-size: 12px;
        width: 750rpx;
        height: 100%;
    }
 
    .reset-content {
        width: 750rpx;
        height: 360px;
    }
</style>