You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

161 lines
3.2KB

  1. // pages/register/register.js
  2. const app = getApp()
  3. let time;
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. yesSend:false,//是否发送验证码
  10. minter: 60,//发送验证码60秒后才可再次发送
  11. num:60,
  12. phone: "",//手机号
  13. phoneCode: "",//验证码
  14. },
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad: function (options) {
  19. },
  20. /**
  21. * 生命周期函数--监听页面初次渲染完成
  22. */
  23. onReady: function () {
  24. },
  25. /**
  26. * 生命周期函数--监听页面显示
  27. */
  28. onShow: function () {
  29. },
  30. /**
  31. * 生命周期函数--监听页面隐藏
  32. */
  33. onHide: function () {
  34. },
  35. /**
  36. * 生命周期函数--监听页面卸载
  37. */
  38. onUnload: function () {
  39. },
  40. /**
  41. * 页面相关事件处理函数--监听用户下拉动作
  42. */
  43. onPullDownRefresh: function () {
  44. },
  45. /**
  46. * 页面上拉触底事件的处理函数
  47. */
  48. onReachBottom: function () {
  49. },
  50. /**
  51. * 用户点击右上角分享
  52. */
  53. onShareAppMessage: function () {
  54. },
  55. sendTouch:function(){//发送验证码
  56. if (!(/^1[3456789]\d{9}$/.test(this.data.phone))) {
  57. wx.showToast({
  58. title: '手机号错误',
  59. icon: 'none',
  60. duration: 500
  61. })
  62. return;
  63. }
  64. this.setData({
  65. yesSend: true,
  66. })
  67. if (this.data.yesSend) {
  68. time = setInterval(this.setIntervalFn,1000)
  69. }
  70. app.wxRequest(app.globalData.httpUrl + 'smscode', { user_phone:this.data.phone}, e => {
  71. console.log(e)
  72. if(e.code==200){
  73. wx.showToast({
  74. title: e.message,
  75. icon: 'success',
  76. duration: 500
  77. })
  78. }
  79. }, this)
  80. },
  81. setIntervalFn:function(){//定时器
  82. if (this.data.num > 0) {
  83. this.data.num--;
  84. if (this.data.num == 0) {
  85. this.setData({
  86. yesSend: false,
  87. })
  88. if (!this.data.yesSend){
  89. this.setData({
  90. num: 60,
  91. minter: 60,
  92. })
  93. }
  94. clearInterval(time);
  95. }
  96. }
  97. this.setData({
  98. minter: this.data.num
  99. })
  100. console.log(this.data.minter)
  101. },
  102. registerFn:function(){//注册
  103. app.wxRequest(app.globalData.httpUrl + 'register', { user_phone: this.data.phone, code_num: this.data.phoneCode }, e => {
  104. console.log(e)
  105. if (e.code == 200) {
  106. clearInterval(time);
  107. this.setData({
  108. minter: 60,
  109. num: 60
  110. })
  111. wx.showToast({
  112. title: '注册成功',
  113. icon: 'success',
  114. duration: 500
  115. })
  116. setTimeout(function () {
  117. if (app.globalData.present_id){
  118. wx.switchTab({
  119. url: '/pages/receiveTicket/receiveTicket?shareId=' + app.globalData.present_id + "&number=" + app.globalData.number
  120. })
  121. } else {
  122. wx.switchTab({
  123. url: '../index/index'
  124. })
  125. }
  126. }, 1000)
  127. }
  128. }, this,"POST")
  129. },
  130. getPhone: function (e) {//获取手机号
  131. console.log(e.detail.value);
  132. this.setData({
  133. phone: e.detail.value
  134. })
  135. },
  136. getCode: function (e) {//获取验证码
  137. console.log(e.detail.value);
  138. this.setData({
  139. phoneCode: e.detail.value
  140. })
  141. },
  142. })