reset.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. var api = require('../../../config/api.js');
  2. var check = require('../../../utils/check.js');
  3. var app = getApp();
  4. Page({
  5. data: {
  6. mobile: '',
  7. code: '',
  8. password: '',
  9. confirmPassword: ''
  10. },
  11. onLoad: function(options) {
  12. // 页面初始化 options为页面跳转所带来的参数
  13. // 页面渲染完成
  14. },
  15. onReady: function() {
  16. },
  17. onShow: function() {
  18. // 页面显示
  19. },
  20. onHide: function() {
  21. // 页面隐藏
  22. },
  23. onUnload: function() {
  24. // 页面关闭
  25. },
  26. sendCode: function() {
  27. let that = this;
  28. wx.request({
  29. url: api.AuthRegisterCaptcha,
  30. data: {
  31. mobile: that.data.mobile
  32. },
  33. method: 'POST',
  34. header: {
  35. 'content-type': 'application/json'
  36. },
  37. success: function(res) {
  38. if (res.data.errno == 0) {
  39. wx.showModal({
  40. title: '发送成功',
  41. content: '验证码已发送',
  42. showCancel: false
  43. });
  44. } else {
  45. wx.showModal({
  46. title: '错误信息',
  47. content: res.data.errmsg,
  48. showCancel: false
  49. });
  50. }
  51. }
  52. });
  53. },
  54. startReset: function() {
  55. var that = this;
  56. if (this.data.mobile.length == 0 || this.data.code.length == 0) {
  57. wx.showModal({
  58. title: '错误信息',
  59. content: '手机号和验证码不能为空',
  60. showCancel: false
  61. });
  62. return false;
  63. }
  64. if (!check.isValidPhone(this.data.mobile)) {
  65. wx.showModal({
  66. title: '错误信息',
  67. content: '手机号输入不正确',
  68. showCancel: false
  69. });
  70. return false;
  71. }
  72. if (this.data.password.length < 3) {
  73. wx.showModal({
  74. title: '错误信息',
  75. content: '用户名和密码不得少于3位',
  76. showCancel: false
  77. });
  78. return false;
  79. }
  80. if (this.data.password != this.data.confirmPassword) {
  81. wx.showModal({
  82. title: '错误信息',
  83. content: '确认密码不一致',
  84. showCancel: false
  85. });
  86. return false;
  87. }
  88. wx.request({
  89. url: api.AuthReset,
  90. data: {
  91. mobile: that.data.mobile,
  92. code: that.data.code,
  93. password: that.data.password
  94. },
  95. method: 'POST',
  96. header: {
  97. 'content-type': 'application/json'
  98. },
  99. success: function(res) {
  100. if (res.data.errno == 0) {
  101. wx.navigateBack();
  102. } else {
  103. wx.showModal({
  104. title: '密码重置失败',
  105. content: res.data.errmsg,
  106. showCancel: false
  107. });
  108. }
  109. }
  110. });
  111. },
  112. bindPasswordInput: function(e) {
  113. this.setData({
  114. password: e.detail.value
  115. });
  116. },
  117. bindConfirmPasswordInput: function(e) {
  118. this.setData({
  119. confirmPassword: e.detail.value
  120. });
  121. },
  122. bindMobileInput: function(e) {
  123. this.setData({
  124. mobile: e.detail.value
  125. });
  126. },
  127. bindCodeInput: function(e) {
  128. this.setData({
  129. code: e.detail.value
  130. });
  131. },
  132. clearInput: function(e) {
  133. switch (e.currentTarget.id) {
  134. case 'clear-password':
  135. this.setData({
  136. password: ''
  137. });
  138. break;
  139. case 'clear-confirm-password':
  140. this.setData({
  141. confirmPassword: ''
  142. });
  143. break;
  144. case 'clear-mobile':
  145. this.setData({
  146. mobile: ''
  147. });
  148. break;
  149. case 'clear-code':
  150. this.setData({
  151. code: ''
  152. });
  153. break;
  154. }
  155. }
  156. })