1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- //index.js
- import WxValidate from '../../utils/wxValidate';
- //获取应用实例
- const app = getApp();
- Page({
- data: {
- form: {}
- },
- initValidate() {
- const rules = {
- phone: {
- required: true,
- },
- oldPwd: {
- required: true,
- },
- password: {
- required: true,
- },
- isnewPwd: {
- required: false,
- },
- }
- // 验证字段的提示信息,若不传则调用默认的信息
- const messages = {
- phone: {
- required: '请输入手机号',
- },
- oldPwd: {
- required: '请输入原密码',
- },
- password: {
- required: '请输入新密码',
- },
- isnewPwd: {
- required: '请输入确认密码'
- }
- };
- this.WxValidate = new WxValidate(rules, messages)
- },
- //事件处理函数
- formSubmit: function (e) {
- const params = e.detail.value;
- if (!this.WxValidate.checkForm(params)) {
- const error = this.WxValidate.errorList[0];
- wx.showToast({
- title: error.msg,
- icon: 'none',
- duration: 2000
- })
- return false
- } else {
- // 判断新密码,确认新密码是否一致
- if (params.password === params.isnewPwd) {
- wx.request({
- url: app.globalData.publicUrl + '/api/htyd/card/passwd/' + this.data.form.id,
- method: "post",
- data: params,
- success: (res) => {
- if (res.data.errcode == '0') {
- wx.showToast({
- title: '修改密码成功',
- icon: 'success',
- duration: 2000
- })
- app.globalData.userInfo = {}
- wx.redirectTo({
- url: '/pages/login/login'
- })
- } else {
- wx.showToast({
- title: '修改失败',
- icon: 'error',
- duration: 2000
- })
- }
- }
- })
- } else {
- wx.showToast({
- title: '新密码与确认密码不一致,请重新输入',
- icon: 'none',
- duration: 2000
- })
- }
- }
- },
- onLoad: function (options) {
- this.initValidate()//验证规则函数
- let data = app.globalData.userInfo;
- if (data) {
- this.setData({ form: data })
- }
- },
- })
|