reset_password.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // pages/reset_password/reset_password.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. userName: null,
  8. password: null,
  9. rePassword: null,
  10. checkPass: false,
  11. errorMsg: ''
  12. },
  13. resetPassword(e) {
  14. let that = this;
  15. let{
  16. userName : loginName,
  17. password
  18. } = this.data;
  19. wx.request({
  20. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/resetPassword',
  21. data: {
  22. loginName,
  23. password
  24. },
  25. method: 'POST',
  26. success(res) {
  27. //console.log(res);
  28. //console.log(res.data.code == 1);
  29. if (res.data.code == 1) {
  30. that.setData({
  31. errorMsg: res.data.msg
  32. });
  33. } else {
  34. wx.navigateBack();
  35. }
  36. }
  37. });
  38. },
  39. inputPassword(e) {
  40. this.setData({
  41. password: e.detail.value
  42. });
  43. this.checkAll();
  44. },
  45. inputRepassword(e) {
  46. this.setData({
  47. rePassword: e.detail.value
  48. });
  49. this.checkAll();
  50. },
  51. checkPassword() {
  52. if (!this.data.password || !this.data.rePassword || this.data.password != this.data.rePassword) {
  53. return false;
  54. }
  55. return true;
  56. },
  57. checkAll() {
  58. if (this.data.password && (this.data.password.length < 5 || this.data.password.length > 20)) {
  59. this.setData({
  60. errorMsg: '密码长度应为5-20'
  61. });
  62. this.setData({
  63. checkPass: false
  64. });
  65. return;
  66. }
  67. if (!this.checkPassword()) {
  68. this.setData({
  69. errorMsg: '两次密码输入不一致,请重新输入'
  70. });
  71. this.setData({
  72. checkPass: false
  73. });
  74. return;
  75. } else {
  76. this.setData({
  77. errorMsg: ''
  78. });
  79. }
  80. this.setData({
  81. checkPass: true
  82. });
  83. },
  84. /**
  85. * 生命周期函数--监听页面加载
  86. */
  87. onLoad: function(options) {
  88. let {
  89. loginName
  90. } = options;
  91. this.setData({
  92. userName: loginName
  93. });
  94. //resetPassword
  95. },
  96. /**
  97. * 生命周期函数--监听页面初次渲染完成
  98. */
  99. onReady: function() {
  100. },
  101. /**
  102. * 生命周期函数--监听页面显示
  103. */
  104. onShow: function() {
  105. },
  106. /**
  107. * 生命周期函数--监听页面隐藏
  108. */
  109. onHide: function() {
  110. },
  111. /**
  112. * 生命周期函数--监听页面卸载
  113. */
  114. onUnload: function() {
  115. },
  116. /**
  117. * 页面相关事件处理函数--监听用户下拉动作
  118. */
  119. onPullDownRefresh: function() {
  120. },
  121. /**
  122. * 页面上拉触底事件的处理函数
  123. */
  124. onReachBottom: function() {
  125. },
  126. /**
  127. * 用户点击右上角分享
  128. */
  129. onShareAppMessage: function() {
  130. }
  131. })