陶杰
2024-08-22 4aa0bd47801606b4d0e0a6a2ed8fe92a7e5f2444
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
<template>
    <view class="wrap bg-app-white hidebar" style="min-height: calc(100vh - 150rpx);">
        <u-form :model="model" :rules="rules" ref="uForm">
            <!--         <u-form-item :label-position="labelPosition" label="原始密码" label-width="150" prop="oldpassword">
                <u-input :border="border" type="password" v-model="model.oldpassword" placeholder="请确认密码"></u-input>
            </u-form-item> -->
            <!--             <u-form-item :label-position="labelPosition" label="旧密码" prop="oldpassword" label-width="150">
                <u-input :password-icon="true" :border="border" type="password" v-model="model.oldpassword"
                    placeholder="请输入旧密码"></u-input>
            </u-form-item>
            <u-divider></u-divider> -->
            <u-form-item :label-position="labelPosition" label="新密码" prop="password" label-width="150">
                <u-input :password-icon="false" :border="border" :type="showPassword1?'text':'password'"
                    v-model="model.password" placeholder="请输入新密码">
                    <template slot="suffix">
                        <uni-icons color="#20613D" :type="showPassword1 ? 'eye-filled' : 'eye-slash-filled'" size="24"
                            @click="()=>{
                                showPassword1=!showPassword1;
                                $forceUpdate()
                            }"></uni-icons>
                    </template>
                </u-input>
            </u-form-item>
            <u-divider></u-divider>
            <u-form-item :label-position="labelPosition" label="确认密码" label-width="150" prop="rePassword">
                <u-input :password-icon="false" :border="border" :type="showPassword2?'text':'password'"
                    v-model="model.rePassword" placeholder="请确认密码">
                    <template slot="suffix">
                        <uni-icons color="#20613D" :type="showPassword2 ? 'eye-filled' : 'eye-slash-filled'" size="24"
                            @click="()=>{
                                showPassword2=!showPassword2;
                                $forceUpdate()
                            }"></uni-icons>
                    </template>
                </u-input>
            </u-form-item>
        </u-form>
        <!-- <u-button @click="submit">提交</u-button> -->
        <view class="button-green-1 m-t-20 button-fixed-bottom" @click="submit">
            保存
        </view>
    </view>
</template>
 
<script>
    export default {
        data() {
            let that = this;
            return {
                labelPosition: 'left',
                model: {
                    oldpassword: '',
                    password: '',
                    rePassword: ''
                },
                showPassword1: false,
                showPassword2: false,
                rules: {
                    // oldpassword: [
                    //     {
                    //         required: true,
                    //         message: '请输入密码',
                    //         trigger: ['change', 'blur']
                    //     },
                    //     // {
                    //     //     // 正则不能含有两边的引号
                    //     //     pattern: /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]+\S{5,12}$/,
                    //     //     message: '需同时含有字母和数字,长度在6-12之间',
                    //     //     trigger: ['change', 'blur']
                    //     // }
                    // ],
                    oldpassword: [{
                        required: true,
                        message: '请输入旧密码',
                        trigger: ['change', 'blur']
                    }],
                    password: [{
                        required: true,
                        message: '请输入密码',
                        trigger: ['change', 'blur']
                    }],
                    rePassword: [{
                            required: true,
                            message: '请重新输入密码',
                            trigger: ['change', 'blur']
                        },
                        {
                            validator: (rule, value, callback) => {
                                return value === this.model.password;
                            },
                            message: '两次输入的密码不相等',
                            trigger: ['change', 'blur']
                        }
                    ]
                },
                border: false,
                check: false,
                selectStatus: 'close',
 
                errorType: ['message']
            };
        },
        onLoad() {},
        computed: {
            borderCurrent() {
                return this.border ? 0 : 1;
            }
        },
        onReady() {
            this.$refs.uForm.setRules(this.rules);
        },
        methods: {
            back() {
                uni.navigateBack({
                    animationDuration: 500,
                })
            },
            submit() {
                if (!this.model.password) {
                    this.$message.showToast('密码未填写');
 
                    return
                }
                if (this.model.rePassword === this.model.password) {
                    this.updatePwd();
                } else {
                    this.$message.showToast('两次密码不一样');
 
                    return
                }
                // this.$refs.uForm.validate(valid => {
                //     if (valid) {
                //         // if(!this.model.agreement) return this.$u.toast('请勾选协议');
                //         // console.log('验证通过');
                //         this.updatePwd();
                //     } else {
                //         // console.log('验证失败');
                //     }
                // });
            },
            async updatePwd() {
                const resp = await this.$http.request('post', '/api/current/user/password/change', {
                    data: {
                        // password: this.model.oldpassword,
                        // newpassword: this.model.password
                        oldPassword: this.model.oldPassword,
                        password: this.model.password
                    }
                });
                if (resp && resp.code == 0) {
                    this.model.password = ''
                    this.model.rePassword = ''
                    this.model.oldPassword = ''
                    this.$message.showToast('修改成功');
                    let tmp = this
                    setTimeout(() => {
                        tmp.$store.commit('updateLogin', false)
                        uni.reLaunch({
                            url: '/pages/login/supplier-login'
                        })
                    }, 1500)
                }
            },
            // 点击actionSheet回调
            actionSheetCallback(index) {
                uni.hideKeyboard();
                this.model.sex = this.actionSheetList[index].text;
            },
            // checkbox选择发生变化
            checkboxGroupChange(e) {
                this.model.likeFruit = e;
            },
            // radio选择发生变化
            radioGroupChange(e) {
                this.model.payType = e;
            },
            // 勾选版权协议
            checkboxChange(e) {
                this.model.agreement = e.value;
            },
            // 选择地区回调
            regionConfirm(e) {
                this.model.region = e.province.label + '-' + e.city.label + '-' + e.area.label;
            },
            // 选择商品类型回调
            selectConfirm(e) {
                this.model.goodsType = '';
                e.map((val, index) => {
                    this.model.goodsType += this.model.goodsType == '' ? val.label : '-' + val.label;
                });
            },
            borderChange(index) {
                this.border = !index;
            },
            radioCheckboxChange(index) {
                if (index == 0) {
                    this.radioCheckWrap = false;
                    this.radioCheckWidth = 'auto';
                } else if (index == 1) {
                    this.radioCheckWrap = true;
                    this.radioCheckWidth = 'auto';
                } else if (index == 2) {
                    this.radioCheckWrap = false;
                    this.radioCheckWidth = '50%';
                }
            },
            labelPositionChange(index) {
                this.labelPosition = index == 0 ? 'left' : 'top';
            },
            codeChange(text) {
                this.codeTips = text;
            },
            // 获取验证码
            getCode() {
                if (this.$refs.uCode.canGetCode) {
                    // 模拟向后端请求验证码
                    uni.showLoading({
                        title: '正在获取验证码',
                        mask: true
                    });
                    setTimeout(() => {
                        uni.hideLoading();
                        // 这里此提示会被this.start()方法中的提示覆盖
                        this.$u.toast('验证码已发送');
                        // 通知验证码组件内部开始倒计时
                        this.$refs.uCode.start();
                    }, 2000);
                } else {
                    this.$u.toast('倒计时结束后再发送');
                }
            },
            errorChange(index) {
                if (index == 0) this.errorType = ['message'];
                if (index == 1) this.errorType = ['toast'];
                if (index == 2) this.errorType = ['border-bottom'];
                if (index == 3) this.errorType = ['border'];
            }
        }
    };
</script>
 
<style scoped lang="scss">
    .wrap {
        padding: 30rpx;
    }
 
    .agreement {
        display: flex;
        align-items: center;
        margin: 40rpx 0;
 
        .agreement-text {
            padding-left: 8rpx;
            color: $u-tips-color;
        }
    }
</style>