Retrievepassword.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. const app = getApp();
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. user:'', //手机号码
  8. password: '', //新密码
  9. codeid: '', //验证码ID
  10. code: '', //验证码
  11. text: '获取验证码', //倒计时
  12. currentTime: 5, //倒计时
  13. phone: '', //获取到的手机栏中的值
  14. disabled: false, //按钮是否禁用
  15. color: '', //获取验证码的颜色
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad: function (options) {
  21. },
  22. //获取账号
  23. Telephone: function (e) {
  24. var user = e.detail.value;
  25. console.log(user);
  26. this.setData({
  27. user: user
  28. });
  29. },
  30. //获取密码
  31. password: function (e) {
  32. var password = e.detail.value;
  33. console.log(password);
  34. this.setData({
  35. password: password
  36. });
  37. },
  38. //获取验证码
  39. getCode: function (e) {
  40. var code = e.detail.value;
  41. console.log(code);
  42. this.setData({
  43. code: code
  44. });
  45. },
  46. // 获取验证码事件
  47. getVerificationCode(res) {
  48. var that = this
  49. that.setData({
  50. disabled: true,
  51. color: '#ccc',
  52. })
  53. var phone = that.data.user;
  54. var currentTime = that.data.currentTime //把手机号跟倒计时值变例成js值
  55. var warn = null; //warn为当手机号为空或格式不正确时提示用户的文字,默认为空
  56. if (phone == '') {
  57. warn = "号码不能为空";
  58. } else if (phone.trim().length != 11 || ! /^1[23456789]\d{9}$/.test(phone)) {
  59. warn = "手机号格式不正确";
  60. } else { //验证号码格式正确走下面
  61. // 获取验证码ajax
  62. let code_url = 'public/verificationcode';
  63. let code_data = {
  64. mobile:this.data.user,
  65. type:2,
  66. source:1,
  67. };
  68. app.postRequest(code_url, code_data, function (res) {
  69. if (res.code == 201) {
  70. // console.log(res.data.id);
  71. that.setData({
  72. codeid: res.data.id // 微信ID
  73. })
  74. //当手机号正确的时候提示用户短信验证码已经发送
  75. wx.showToast({
  76. title: '短信验证码已发送',
  77. icon: 'none',
  78. duration: 2000
  79. });
  80. return;
  81. }
  82. var _qrcode = res.msg
  83. getApp().Tips(_qrcode);
  84. })
  85. //设置一分钟的倒计时
  86. var interval = setInterval(function () {
  87. currentTime--; //每执行一次让倒计时秒数减一
  88. that.setData({
  89. text: "重新发送(" + currentTime + 's)', //按钮文字变成倒计时对应秒数
  90. })
  91. //如果当秒数小于等于0时 停止计时器 且按钮文字变成重新发送 且按钮变成可用状态 倒计时的秒数也要恢复成默认秒数 即让获取验证码的按钮恢复到初始化状态只改变按钮文字
  92. if (currentTime <= 0) {
  93. clearInterval(interval)
  94. that.setData({
  95. text: '重新发送',
  96. currentTime: 5,
  97. disabled: false,
  98. color: '#FF9BCA'
  99. })
  100. }
  101. }, 1000);
  102. };
  103. //判断 当提示错误信息文字不为空 即手机号输入有问题时提示用户错误信息 并且提示完之后一定要让按钮为可用状态 因为点击按钮时设置了只要点击了按钮就让按钮禁用的情况
  104. if (warn != null) {
  105. wx.showModal({
  106. title: '填写手机号码',
  107. content: warn,
  108. showCancel: false,
  109. })
  110. that.setData({
  111. disabled: false,
  112. color: '#FF9BCA'
  113. })
  114. return;
  115. };
  116. },
  117. //完成事件
  118. complete: function (e) {
  119. console.log(this)
  120. let user = this.data.user; //手机
  121. let password = this.data.password; //密码
  122. let code = this.data.code; //验证码
  123. var complete = null;
  124. if (user == '') {
  125. complete = '请输入手机号码';
  126. } else if (user.trim().length != 11 || ! /^1[23456789]\d{9}$/.test(user)) {
  127. complete = '手机号码格式不对';
  128. } else if (password == '') {
  129. complete = '请设置密码';
  130. }
  131. else if (code == '') {
  132. complete = '请输入验证码';
  133. } else if (code.trim().length != 4 || ! /^[0-9]\d{3}$/.test(code)) {
  134. complete = '验证码4位数';
  135. } else {
  136. var _this = this
  137. console.log(this.data.nickname)
  138. let income_url = 'public/getback';
  139. let income_data = {
  140. user: this.data.user, //手机
  141. password: this.data.password, //密码
  142. code: this.data.code, //验证码
  143. id: this.data.codeid, //验证码ID
  144. };
  145. app.postRequest(income_url, income_data, function (res) {
  146. // console.log(income_data.photo);
  147. if (res.code == 201) {
  148. console.log(res.msg);
  149. wx.showModal({
  150. title: '提示',
  151. content: res.msg,
  152. showCancel: false,
  153. })
  154. wx.navigateTo({ // 跳转登陆页面
  155. url: 'pages/Landpage/Land/Land'
  156. })
  157. } else if (res.code == 301){
  158. wx.showToast({
  159. title: res.msg,
  160. icon: 'none', // 不显示图标
  161. duration: 1500,
  162. })
  163. }
  164. })
  165. } //判断结束
  166. // 完成事件 用来提示用户输入手机、密码、验证码
  167. if (complete != null) {
  168. wx.showToast({
  169. title: complete,
  170. icon: 'none', // 不显示图标
  171. duration: 1500
  172. })
  173. return;
  174. };
  175. },
  176. })