import debounce from "../../../utils/debounce"; import {setChangePassword} from "../../../api/index"; const app = getApp() Page({ data: { form: { password: '', newPassword: '', againNewPassword: '', }, rules: { "password": "请输入旧密码", "newPassword": "请输入新密码", "againNewPassword": "请再次输入新密码", } }, bindInput(event) { this.setData({ form: { ...this.data.form, [event.currentTarget.dataset.key]: event.detail, } }) }, submitPassword() { debounce(async () => { for (const rulesKey in this.data.rules) { if (!this.data.form[rulesKey]) { wx.showToast({ title: this.data.rules[rulesKey], icon: "none" }) return; } } if (this.data.form.newPassword !== this.data.form.againNewPassword) { wx.showToast({ title: '两次密码不一致', icon: "none" }) return } const resData = await setChangePassword({ USERNAME: app.globalData.userInfo.USERNAME, USER_ID: app.globalData.userInfo.USER_ID, PASSWORD: this.data.form.password, NOWPASSWORD: this.data.form.newPassword, }) if(resData.code != "0") { wx.showToast({ title: '旧密码有误', icon:'error' }) return } wx.showToast({ title: '修改成功', mask: true }) app.globalData.userInfo = {} setTimeout(() => { wx.reLaunch({ url: '/pages/login/login' }) }, 1500) }) } })