123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- const app = getApp()
- import WxValidate from '../../utils/wxValidate'
- const moment = require("../../utils/moment.min");
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- form: {},
- },
- // 提交保存
- async toSave(e) {
- const that = this;
- const params = e.detail.value;
- if (!this.WxValidate.checkForm(params)) {
- const error = that.WxValidate.errorList[0];
- wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
- return false
- } else {
- if (params.password !== params.is_password) {
- wx.showToast({ title: '密码输入不一致', duration: 2000, icon: 'error', })
- } else {
- // 判断id使用
- let form = that.data.form;
- let data = { _id: form._id, password: params.password }
- let res;
- if (form._id) res = await app.$api(`user/rp`, 'POST', data);
- else wx.showToast({ title: `未登录无法修改密码`, icon: 'none' });
- if (res.errcode == '0') {
- wx.removeStorage({
- key: 'user',
- success(res) {
- wx.showToast({ title: `修改密码成功`, icon: 'success' });
- wx.redirectTo({ url: '/pagesHome/home/index' })
- }
- })
- } else {
- wx.showToast({ title: `${res.errmsg}`, icon: 'none' });
- }
- }
- }
- },
- /**
- * 生命周期函数--监听页面加载
- */
- async onLoad(options) {
- const that = this;
- wx.showLoading({ title: '加载中', mask: true })
- //验证规则函数
- that.initValidate();
- that.search()
- wx.hideLoading()
- },
- initValidate() {
- const rules = { password: { required: true }, is_password: { required: true } }
- const messages = { password: { required: '请输入新密码' }, is_password: { required: '请确认新密码' } };
- this.WxValidate = new WxValidate(rules, messages)
- },
- search() {
- const that = this;
- wx.getStorage({
- key: 'user',
- async success(res) {
- let form = {}
- let aee = await app.$api(`user/${res.data._id}`, 'GET', {})
- if (aee.errcode == '0') {
- form = aee.data;
- } else {
- wx.showToast({ title: `${aee.errmsg}`, icon: 'error' });
- }
- that.setData({ form })
- },
- fail(err) {
- // console.log(err);
- }
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- }
- })
|