phone_verif.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. var app = getApp()
  2. const util = require('../../utils/utils.js');
  3. let countTime = null//定时器
  4. Page({
  5. data: {
  6. currentTime: 60,//倒计时时间
  7. number: '',
  8. },
  9. onLoad: function (options) {
  10. console.log(options)
  11. let that = this
  12. that.setData({
  13. number: options.number
  14. })
  15. that.countDown()
  16. },
  17. //重新获取验证码
  18. getCodeno: util.throttle(function () {
  19. let that = this
  20. // 调用短信验证码接口
  21. let data = {
  22. mobile: that.data.number,
  23. type: 2
  24. }
  25. app.request('/verification-code', data, 'POST').then(res => {
  26. that.setData({
  27. currentTime:60
  28. })
  29. if (res.status == 200) {
  30. that.countDown()
  31. }
  32. })
  33. //60秒倒计时
  34. }, 1000),
  35. //倒计时
  36. countDown:function(){
  37. let that=this
  38. let currentTime = that.data.currentTime
  39. countTime = setInterval(function () {
  40. currentTime--
  41. that.setData({
  42. currentTime: currentTime
  43. })
  44. if (currentTime == 0) {
  45. clearInterval(countTime)
  46. }
  47. }, 1000)
  48. },
  49. onReady: function () {
  50. },
  51. onShow: function () {
  52. },
  53. onHide: function () {
  54. },
  55. onUnload: function () {
  56. },
  57. onPullDownRefresh: function () {
  58. },
  59. onReachBottom: function () {
  60. },
  61. onShareAppMessage: function () {
  62. }
  63. })