retrievePassword.js 4.5 KB

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