forget.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. // pages/forget/forget.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. userName: null,
  8. phone: null,
  9. email: null,
  10. checkPass: false,
  11. errorMsg: ''
  12. },
  13. goNext(e){
  14. let that = this;
  15. let {
  16. userName: loginName,
  17. phone,
  18. email
  19. } = this.data;
  20. wx.request({
  21. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/forget',
  22. data: {
  23. loginName,
  24. phonenumber: phone,
  25. email
  26. },
  27. method: 'POST',
  28. success(res) {
  29. //console.log(res);
  30. //console.log(res.data.code == 1);
  31. if (res.data.code == 1) {
  32. that.setData({
  33. errorMsg: res.data.msg
  34. });
  35. } else {
  36. //跳转到下一步
  37. let url = `/pages/reset_password/reset_password?loginName=${loginName}`;
  38. wx.redirectTo({
  39. url
  40. });
  41. }
  42. }
  43. });
  44. },
  45. inputAccount(e) {
  46. this.setData({
  47. userName: e.detail.value
  48. });
  49. this.checkAll();
  50. },
  51. inputPhone(e) {
  52. this.setData({
  53. phone: e.detail.value
  54. });
  55. this.checkAll();
  56. },
  57. inputEmail(e) {
  58. this.setData({
  59. email: e.detail.value
  60. });
  61. this.checkAll();
  62. },
  63. checkPhone() {
  64. if (!(/^1[3456789]\d{9}$/.test(this.data.phone))) {
  65. return false;
  66. }
  67. return true;
  68. },
  69. checkMail() {
  70. if (!(/^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/.test(this.data.email))) {
  71. return false;
  72. }
  73. return true;
  74. },
  75. checkAll() {
  76. if (!this.data.userName || !this.data.userName.replace(/(^\s*)|(\s*$)/g, "")) {
  77. this.setData({
  78. errorMsg: '账号不能为空'
  79. });
  80. this.setData({
  81. checkPass: false
  82. });
  83. return;
  84. } else {
  85. this.setData({
  86. errorMsg: ''
  87. });
  88. }
  89. if (!this.checkPhone()) {
  90. this.setData({
  91. errorMsg: '手机号输入有误,请重新输入'
  92. });
  93. this.setData({
  94. checkPass: false
  95. });
  96. return;
  97. } else {
  98. this.setData({
  99. errorMsg: ''
  100. });
  101. }
  102. if (!this.checkMail()) {
  103. this.setData({
  104. errorMsg: '邮箱输入有误,请重新输入'
  105. });
  106. this.setData({
  107. checkPass: false
  108. });
  109. return;
  110. } else {
  111. this.setData({
  112. errorMsg: ''
  113. });
  114. }
  115. this.setData({
  116. checkPass: true
  117. });
  118. },
  119. /**
  120. * 生命周期函数--监听页面加载
  121. */
  122. onLoad: function(options) {
  123. },
  124. /**
  125. * 生命周期函数--监听页面初次渲染完成
  126. */
  127. onReady: function() {
  128. },
  129. /**
  130. * 生命周期函数--监听页面显示
  131. */
  132. onShow: function() {
  133. },
  134. /**
  135. * 生命周期函数--监听页面隐藏
  136. */
  137. onHide: function() {
  138. },
  139. /**
  140. * 生命周期函数--监听页面卸载
  141. */
  142. onUnload: function() {
  143. },
  144. /**
  145. * 页面相关事件处理函数--监听用户下拉动作
  146. */
  147. onPullDownRefresh: function() {
  148. },
  149. /**
  150. * 页面上拉触底事件的处理函数
  151. */
  152. onReachBottom: function() {
  153. },
  154. /**
  155. * 用户点击右上角分享
  156. */
  157. onShareAppMessage: function() {
  158. }
  159. })