retrievePassword.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. },
  80. /* 验证确认密码 */
  81. passwordBlur() {
  82. let {
  83. from
  84. } = this.data,
  85. confirmPassword = from.newPassword == from.verifyNewPassword;
  86. if (from.newPassword == '' || from.verifyNewPassword == '') confirmPassword = ""
  87. this.setData({
  88. confirmPassword
  89. })
  90. },
  91. /* 清除确认密码 */
  92. clearNewPassword() {
  93. this.setData({
  94. ['from.verifyNewPassword']: '',
  95. confirmPassword: ""
  96. })
  97. },
  98. /* 修改密码 */
  99. changePassword() {
  100. if (this.data.disabled || this.data.loading) return;
  101. if (this.data.confirmPassword != true) return Toast({
  102. message: '请检查新密码与确认密码',
  103. position: 'bottom'
  104. });
  105. let from = this.data.from;
  106. this.setData({
  107. loading: true
  108. })
  109. _Http.base({
  110. "classname": "common.usercenter.usercenter",
  111. "method": "forgetPassword_changePassWord",
  112. "content": {
  113. "password": md5.hexMD5(from.password),
  114. "accountno": from.accountno,
  115. "newpassword": md5.hexMD5(from.newPassword)
  116. }
  117. }).then(res => {
  118. this.setData({
  119. loading: false
  120. })
  121. if (res.msg != '成功') return Toast({
  122. message: res.msg,
  123. position: 'bottom'
  124. });
  125. this.setData({
  126. disabled: true
  127. })
  128. wx.showToast({
  129. title: '修改成功!',
  130. })
  131. let pages = getCurrentPages(),
  132. prevPage = pages[pages.length - 2];
  133. prevPage.setData({
  134. password: "" // 需要传递的值
  135. })
  136. wx.setStorageSync('loginMsg', {
  137. "accountno": this.data.from.accountno,
  138. "password": this.data.from.newPassword
  139. })
  140. setTimeout(() => {
  141. wx.navigateBack({
  142. delta: 0
  143. })
  144. }, 300)
  145. })
  146. },
  147. /**
  148. * 生命周期函数--监听页面初次渲染完成
  149. */
  150. onReady() {
  151. },
  152. /**
  153. * 生命周期函数--监听页面显示
  154. */
  155. onShow() {
  156. },
  157. /**
  158. * 生命周期函数--监听页面隐藏
  159. */
  160. onHide() {
  161. },
  162. /**
  163. * 生命周期函数--监听页面卸载
  164. */
  165. onUnload() {
  166. },
  167. /**
  168. * 页面相关事件处理函数--监听用户下拉动作
  169. */
  170. onPullDownRefresh() {
  171. },
  172. /**
  173. * 页面上拉触底事件的处理函数
  174. */
  175. onReachBottom() {
  176. },
  177. /**
  178. * 用户点击右上角分享
  179. */
  180. onShareAppMessage() {
  181. }
  182. })