reset.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 (this.data.password.length < 3) {
  65. wx.showModal({
  66. title: '错误信息',
  67. content: '用户名和密码不得少于3位',
  68. showCancel: false
  69. });
  70. return false;
  71. }
  72. if (this.data.password != this.data.confirmPassword) {
  73. wx.showModal({
  74. title: '错误信息',
  75. content: '确认密码不一致',
  76. showCancel: false
  77. });
  78. return false;
  79. }
  80. wx.request({
  81. url: api.AuthReset,
  82. data: {
  83. mobile: that.data.mobile,
  84. code: that.data.code,
  85. password: that.data.password
  86. },
  87. method: 'POST',
  88. header: {
  89. 'content-type': 'application/json'
  90. },
  91. success: function(res) {
  92. if (res.data.errno == 0) {
  93. wx.navigateBack();
  94. } else {
  95. wx.showModal({
  96. title: '密码重置失败',
  97. content: res.data.errmsg,
  98. showCancel: false
  99. });
  100. }
  101. }
  102. });
  103. },
  104. bindPasswordInput: function(e) {
  105. this.setData({
  106. password: e.detail.value
  107. });
  108. },
  109. bindConfirmPasswordInput: function(e) {
  110. this.setData({
  111. confirmPassword: e.detail.value
  112. });
  113. },
  114. bindMobileInput: function(e) {
  115. this.setData({
  116. mobile: e.detail.value
  117. });
  118. },
  119. bindCodeInput: function(e) {
  120. this.setData({
  121. code: e.detail.value
  122. });
  123. },
  124. clearInput: function(e) {
  125. switch (e.currentTarget.id) {
  126. case 'clear-password':
  127. this.setData({
  128. password: ''
  129. });
  130. break;
  131. case 'clear-confirm-password':
  132. this.setData({
  133. confirmPassword: ''
  134. });
  135. break;
  136. case 'clear-mobile':
  137. this.setData({
  138. mobile: ''
  139. });
  140. break;
  141. case 'clear-code':
  142. this.setData({
  143. code: ''
  144. });
  145. break;
  146. }
  147. }
  148. })