小小儁爺
2025-11-18 aab92bb255f1cbd758cb9d96a89bfc73133bfb4a
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
<template>
    <view class="">
        <page-nav title="密码设置"></page-nav>
 
 
        <view class="flex_column head titleFont" style="min-height: 1400rpx;">
            <view class="flex_center marginTop20 marginLeft20">
                <view style="margin-left: 36rpx;">原密码:</view>
                <view class='inputClass'>
                    <u--input placeholder="请输入" border="surround" v-model="oldPassword"></u--input>
                </view>
            </view>
            <view class="flex_center marginTop20 marginLeft20">
                <view style="margin-left: 36rpx;">新密码:</view>
                <view class='inputClass'>
                    <u--input placeholder="请输入" border="surround" v-model="newPassword"></u--input>
                </view>
            </view>
            <view class="flex_center marginTop20 marginLeft20">
                <view>确认密码:</view>
                <view class='inputClass'>
                    <u--input placeholder="请输入" border="surround" v-model="newPasswordConfirm"></u--input>
                </view>
            </view>
        </view>
 
 
        <view class="footer" style="display: flex;flex-direction: row;">
            <u-button :loading="isDisabledSubmitButtonReset" loadingText="重置中..."
                style='width: 49%;border-radius: 10rpx 0 0 10rpx;' type="success" @click="resetPassword" text="重置密码"
                size="large">
            </u-button>
            <u-button :loading="isDisabledSubmitButtonEdit" loadingText="修改中..."
                style='width: 49%;border-radius:0 10rpx 10rpx 0' @click="editPassword" type="primary" text="修改密码"
                size="large"></u-button>
        </view>
 
    </view>
</template>
 
 
<script>
    import {
        UpdateUserPassword,
        ResettUserPassword
    } from '../../config/api.js';
 
    export default {
        onLoad(option) {
 
        },
 
        onPullDownRefresh() {
            setTimeout(() => {
                this.init(() => {
                    uni.stopPullDownRefresh();
                })
            }, 1000);
        },
 
        data() {
            return {
                topRightMessageCount: '',
 
                isDisabledSubmitButtonReset: false,
 
                isDisabledSubmitButtonEdit: false,
 
                oldPassword: '', //原密码
                newPassword: '', //新密码
                newPasswordConfirm: '', //确认密码
 
 
            }
        },
        created() {
 
        },
        mounted() {
            this.init()
 
        },
        methods: {
            init() {
                uni.stopPullDownRefresh();
            },
 
            // 重置密码
            async resetPassword() {
                const data = {
                    usercode: uni.getStorageSync("usercode"),
                    username: uni.getStorageSync("username"),
                    usertype: 'APP'
                }
                this.isDisabledSubmitButtonReset = true
                const res = await ResettUserPassword(this.global.formatData(data))
 
                if (res.code === '200') {
                    this.isDisabledSubmitButtonReset = false
                    this.$u.toast('密码重置成功!')
 
                    uni.setStorageSync("Token", '')
                    uni.setStorageSync("usercode", '')
                    uni.setStorageSync("username", '')
                    uni.setStorageSync("storg_code", '')
                    uni.setStorageSync("storg_name", '')
 
                    setTimeout(() => {
                        uni.redirectTo({
                            url: '../login/index'
                        });
                    }, 2000)
 
                } else {
                    this.isDisabledSubmitButtonReset = false
                    this.$u.toast('密码重置失败!')
                }
 
            },
            // 修改密码
            async editPassword() {
                if (!this.oldPassword) {
                    return this.$u.toast('请输入原密码!')
                }
                if (!this.newPassword) {
                    return this.$u.toast('请输入新密码!')
                }
                if (!this.newPasswordConfirm) {
                    return this.$u.toast('请输入确认密码!')
                }
 
                if (this.newPassword.trim() !== this.newPasswordConfirm.trim()) {
                    return this.$u.toast('新密码与确认密码不一致!')
                }
 
                const data = {
                    // usercode: uni.getStorageSync("usercode"),
                    // username: uni.getStorageSync("username"),
                    password: this.oldPassword.trim(),
                    newpassword: this.newPassword.trim()
                }
 
                this.isDisabledSubmitButtonEdit = true
                const res = await UpdateUserPassword(this.global.formatData(data))
 
                if (res.code === '200') {
                    this.isDisabledSubmitButtonEdit = false
                    this.$u.toast('密码修改成功!')
                    uni.setStorageSync("Token", '')
                    uni.setStorageSync("usercode", '')
                    uni.setStorageSync("username", '')
                    uni.setStorageSync("storg_code", '')
                    uni.setStorageSync("storg_name", '')
 
                    setTimeout(() => {
                        uni.redirectTo({
                            url: '../login/index'
                        });
                    }, 2000)
 
                } else {
                    this.isDisabledSubmitButtonEdit = false
                    this.$u.toast('密码修改失败!')
                }
 
            }
 
        }
    }
</script>
 
<style lang="scss" scoped>
    @import url('@/style/global.css');
 
    ::v-deep .uicon-arrow-left>span {
        display: block;
    }
</style>