retrievePassword.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. const _Http = getApp().globalData.http;
  2. import Toast from '@vant/weapp/toast/toast';
  3. const md5 = require('../../utils/md5');
  4. let passwordDowm = null;
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. from: {
  11. accountno: "", //账户名
  12. password: "", //验证码
  13. newPassword: "", //新密码
  14. verifyNewPassword: "", //确认密码
  15. },
  16. disabled: true, //修改按钮禁用
  17. loading: false,
  18. confirmPassword: "", //两次密码是否一致
  19. countDown: "", //倒计时
  20. },
  21. /**
  22. * 生命周期函数--监听页面加载
  23. */
  24. onLoad(options) {
  25. },
  26. /* 获取验证码 */
  27. getPassword() {
  28. let accountno = this.data.from.accountno;
  29. if (!accountno) return Toast({
  30. message: '您还未填写账户名称',
  31. position: 'bottom'
  32. });
  33. if (this.data.countDown != '') return Toast({
  34. message: '您已发送验证码,请勿重复获取',
  35. position: 'bottom'
  36. });
  37. _Http.base({
  38. "classname": "common.usercenter.usercenter",
  39. "method": "forgetPassword_getPassWord",
  40. "content": {
  41. accountno
  42. }
  43. }, false).then(res => {
  44. if (res.code != 1) return Toast({
  45. message: res.data,
  46. position: 'bottom'
  47. });
  48. this.setData({
  49. countDown: 30
  50. })
  51. passwordDowm = setInterval(() => {
  52. let countDown = (this.data.countDown == 0) ? '' : this.data.countDown - 1;
  53. this.setData({
  54. countDown
  55. })
  56. if (countDown == '') clearInterval(passwordDowm)
  57. }, 1000);
  58. Toast({
  59. message: res.msg,
  60. position: 'bottom'
  61. });
  62. })
  63. },
  64. /* 表单输入 */
  65. formInput(e) {
  66. let v = e.detail.value.trim(),
  67. name = e.currentTarget.dataset.name;
  68. this.setData({
  69. [`from.${name}`]: v
  70. });
  71. let disabled = false,
  72. from = this.data.from;
  73. for (let i in from) {
  74. if (from[i] == '') disabled = true;
  75. }
  76. this.setData({
  77. disabled
  78. })
  79. this.passwordBlur();
  80. },
  81. /* 验证确认密码 */
  82. passwordBlur() {
  83. let {
  84. from
  85. } = this.data,
  86. confirmPassword = from.newPassword == from.verifyNewPassword;
  87. if (from.newPassword == '' || from.verifyNewPassword == '') confirmPassword = ""
  88. this.setData({
  89. confirmPassword
  90. })
  91. },
  92. /* 清除确认密码 */
  93. clearNewPassword() {
  94. this.setData({
  95. ['from.verifyNewPassword']: '',
  96. confirmPassword: ""
  97. })
  98. },
  99. /* 修改密码 */
  100. changePassword() {
  101. if (this.data.disabled || this.data.loading) return;
  102. if (this.data.confirmPassword != true) return Toast({
  103. message: '请检查新密码与确认密码',
  104. position: 'bottom'
  105. });
  106. let from = this.data.from;
  107. this.setData({
  108. loading: true
  109. })
  110. _Http.base({
  111. "classname": "common.usercenter.usercenter",
  112. "method": "forgetPassword_changePassWord",
  113. "content": {
  114. "password": md5.hexMD5(from.password),
  115. "accountno": from.accountno,
  116. "newpassword": md5.hexMD5(from.newPassword)
  117. }
  118. }).then(res => {
  119. this.setData({
  120. loading: false
  121. })
  122. if (res.msg != '成功') return Toast({
  123. message: res.msg,
  124. position: 'bottom'
  125. });
  126. this.setData({
  127. disabled: true
  128. })
  129. wx.showToast({
  130. title: '修改成功!',
  131. })
  132. let pages = getCurrentPages(),
  133. prevPage = pages[pages.length - 2];
  134. prevPage.setData({
  135. password: "" // 需要传递的值
  136. })
  137. wx.setStorageSync('loginMsg', {
  138. "accountno": this.data.from.accountno,
  139. "password": this.data.from.newPassword
  140. })
  141. setTimeout(() => {
  142. wx.navigateBack({
  143. delta: 0
  144. })
  145. }, 300)
  146. })
  147. },
  148. onShareAppMessage() {}
  149. })