mdfpassword.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. // pages/ucenter/accountsecurity/mdfpassword/mdfpassword.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. phone: null,
  8. password: '',
  9. rePassword: '',
  10. checkPass: false,
  11. errorMsg: '',
  12. showMsg: false
  13. },
  14. resetPassword(e) {
  15. let that = this;
  16. this.checkAll();
  17. this.setData({
  18. showMsg:true
  19. })
  20. if(!this.data.checkPass){
  21. return;
  22. }
  23. let{
  24. phone : phonenumber,
  25. password
  26. } = this.data;
  27. wx.request({
  28. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/resetPassword',
  29. data: {
  30. phonenumber,
  31. password
  32. },
  33. method: 'POST',
  34. success(res) {
  35. if (res.data.code == 1) {
  36. if(res.data.msg!=null && res.data.msg.startsWith("503")){
  37. getApp().showNetworkError();
  38. return;
  39. }
  40. wx.showModal({
  41. title: '提示',
  42. content: res.data.msg,
  43. showCancel: false,
  44. confirmColor:'#00AADD',
  45. });
  46. }else if (res.data.code == 2) {
  47. wx.showModal({
  48. title: '提示',
  49. content: '您未绑定手机号,请重新登录后自动刷新绑定信息',
  50. confirmText: '去登录',
  51. showCancel:false,
  52. confirmColor:'#00AADD',
  53. success: function (res1) {
  54. if (res1.confirm) {
  55. wx.removeStorageSync('userInfo');
  56. wx.removeStorageSync('isLogin');
  57. let url = '/pages/login/phone_login/phone_login';
  58. wx.redirectTo({
  59. url
  60. })
  61. }
  62. }
  63. });
  64. } else {
  65. let url = `/pages/ucenter/index/index`;
  66. wx.redirectTo({
  67. url
  68. });
  69. }
  70. }
  71. });
  72. },
  73. inputPassword(e) {
  74. this.setData({
  75. password: e.detail.value,
  76. showMsg: false
  77. });
  78. this.checkAll();
  79. },
  80. inputRepassword(e) {
  81. this.setData({
  82. rePassword: e.detail.value,
  83. showMsg: false
  84. });
  85. this.checkAll();
  86. },
  87. checkPassword() {
  88. if (!this.data.password || !this.data.rePassword || this.data.password != this.data.rePassword) {
  89. return false;
  90. }
  91. return true;
  92. },
  93. checkAll() {
  94. if ((this.data.password.length < 5 || this.data.password.length > 20)) {
  95. this.setData({
  96. errorMsg: '密码长度应为5-20',
  97. showMsg: false
  98. });
  99. this.setData({
  100. checkPass: false
  101. });
  102. return;
  103. }
  104. if (!this.checkPassword()) {
  105. this.setData({
  106. errorMsg: '两次密码输入不一致,请重新输入',
  107. showMsg: false
  108. });
  109. this.setData({
  110. checkPass: false
  111. });
  112. return;
  113. } else {
  114. this.setData({
  115. errorMsg: ''
  116. });
  117. }
  118. this.setData({
  119. checkPass: true
  120. });
  121. },
  122. /**
  123. * 生命周期函数--监听页面加载
  124. */
  125. onLoad(options) {
  126. let userInfo = wx.getStorageSync('userInfo');
  127. let isLogin = wx.getStorageSync('isLogin');
  128. // 页面显示
  129. if (userInfo && isLogin) {
  130. this.setData({
  131. phone: userInfo.phonenumber,
  132. });
  133. } else {
  134. //未登录信息
  135. this.setData({
  136. userInfo: {}
  137. });
  138. let url = `/pages/login/phone_login/phone_login`;
  139. wx.navigateTo({
  140. url
  141. });
  142. return;
  143. }
  144. },
  145. /**
  146. * 生命周期函数--监听页面初次渲染完成
  147. */
  148. onReady() {
  149. },
  150. /**
  151. * 生命周期函数--监听页面显示
  152. */
  153. onShow() {
  154. },
  155. /**
  156. * 生命周期函数--监听页面隐藏
  157. */
  158. onHide() {
  159. },
  160. /**
  161. * 生命周期函数--监听页面卸载
  162. */
  163. onUnload() {
  164. },
  165. /**
  166. * 页面相关事件处理函数--监听用户下拉动作
  167. */
  168. onPullDownRefresh() {
  169. },
  170. /**
  171. * 页面上拉触底事件的处理函数
  172. */
  173. onReachBottom() {
  174. },
  175. /**
  176. * 用户点击右上角分享
  177. */
  178. onShareAppMessage() {
  179. }
  180. })