reset_password.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. // pages/reset_password/reset_password.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 {
  47. wx.navigateBack();
  48. }
  49. }
  50. });
  51. },
  52. inputPassword(e) {
  53. this.setData({
  54. password: e.detail.value,
  55. showMsg: false,
  56. });
  57. this.checkAll();
  58. },
  59. inputRepassword(e) {
  60. this.setData({
  61. rePassword: e.detail.value,
  62. showMsg: false,
  63. });
  64. this.checkAll();
  65. },
  66. checkPassword() {
  67. if (!this.data.password || !this.data.rePassword || this.data.password != this.data.rePassword) {
  68. return false;
  69. }
  70. return true;
  71. },
  72. checkAll() {
  73. if ( (this.data.password.length < 5 || this.data.password.length > 20)) {
  74. this.setData({
  75. errorMsg: '密码长度应为5-20',
  76. showMsg: false,
  77. });
  78. this.setData({
  79. checkPass: false
  80. });
  81. return;
  82. }
  83. if (!this.checkPassword()) {
  84. this.setData({
  85. errorMsg: '两次密码输入不一致,请重新输入',
  86. showMsg: false,
  87. });
  88. this.setData({
  89. checkPass: false
  90. });
  91. return;
  92. } else {
  93. this.setData({
  94. errorMsg: ''
  95. });
  96. }
  97. this.setData({
  98. checkPass: true
  99. });
  100. },
  101. /**
  102. * 生命周期函数--监听页面加载
  103. */
  104. onLoad: function(options) {
  105. let {
  106. phone
  107. } = options;
  108. this.setData({
  109. phone: phone
  110. });
  111. //resetPassword
  112. },
  113. /**
  114. * 生命周期函数--监听页面初次渲染完成
  115. */
  116. onReady: function() {
  117. },
  118. /**
  119. * 生命周期函数--监听页面显示
  120. */
  121. onShow: function() {
  122. },
  123. /**
  124. * 生命周期函数--监听页面隐藏
  125. */
  126. onHide: function() {
  127. },
  128. /**
  129. * 生命周期函数--监听页面卸载
  130. */
  131. onUnload: function() {
  132. },
  133. /**
  134. * 页面相关事件处理函数--监听用户下拉动作
  135. */
  136. onPullDownRefresh: function() {
  137. },
  138. /**
  139. * 页面上拉触底事件的处理函数
  140. */
  141. onReachBottom: function() {
  142. },
  143. /**
  144. * 用户点击右上角分享
  145. */
  146. onShareAppMessage: function() {
  147. }
  148. })