|
@@ -1,20 +1,91 @@
|
|
|
const app = getApp()
|
|
|
+import WxValidate from '../../utils/wxValidate'
|
|
|
+const moment = require("../../utils/moment.min");
|
|
|
Page({
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 页面的初始数据
|
|
|
+ */
|
|
|
data: {
|
|
|
- info: {}
|
|
|
+ form: {},
|
|
|
+ },
|
|
|
+ initValidate() {
|
|
|
+ const rules = { password: { required: true }, is_password: { required: true } }
|
|
|
+ const messages = { password: { required: '请输入新密码' }, is_password: { required: '请确认新密码' } };
|
|
|
+ this.WxValidate = new WxValidate(rules, messages)
|
|
|
},
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
- onLoad(options) {
|
|
|
+ async onLoad(options) {
|
|
|
const that = this;
|
|
|
wx.showLoading({ title: '加载中', mask: true })
|
|
|
+ //验证规则函数
|
|
|
+ that.initValidate();
|
|
|
that.search()
|
|
|
wx.hideLoading()
|
|
|
},
|
|
|
- // 查询通知
|
|
|
- async search() {
|
|
|
+ search() {
|
|
|
+ const that = this;
|
|
|
+ wx.getStorage({
|
|
|
+ key: 'token',
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 提交保存
|
|
|
+ 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: 'token',
|
|
|
+ success(res) {
|
|
|
+ wx.showToast({ title: `修改密码成功`, icon: 'success' });
|
|
|
+ wx.redirectTo({ url: '/pagesHome/home/index' })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ wx.showToast({ title: `${res.errmsg}`, icon: 'none' });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 查询其他信息
|
|
|
+ async searchOther() {
|
|
|
const that = this;
|
|
|
+ let res;
|
|
|
+ // 性别
|
|
|
+ res = await app.$api('dictData', 'GET', { type: 'gender', is_use: '0' })
|
|
|
+ if (res.errcode == '0') that.setData({ genderList: res.data })
|
|
|
+ // 类别
|
|
|
+ res = await app.$api('dictData', 'GET', { type: 'type', is_use: '0' })
|
|
|
+ if (res.errcode == '0') that.setData({ typeList: res.data })
|
|
|
},
|
|
|
|
|
|
/**
|