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.

191 lines
3.9KB

  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. yesRegister:false,//防止重复点击注册
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad: function (options) {
  20. },
  21. /**
  22. * 生命周期函数--监听页面初次渲染完成
  23. */
  24. onReady: function () {
  25. },
  26. /**
  27. * 生命周期函数--监听页面显示
  28. */
  29. onShow: function () {
  30. if (wx.canIUse('hideHomeButton')) {
  31. wx.hideHomeButton()
  32. }
  33. },
  34. /**
  35. * 生命周期函数--监听页面隐藏
  36. */
  37. onHide: function () {
  38. },
  39. /**
  40. * 生命周期函数--监听页面卸载
  41. */
  42. onUnload: function () {
  43. },
  44. /**
  45. * 页面相关事件处理函数--监听用户下拉动作
  46. */
  47. onPullDownRefresh: function () {
  48. },
  49. /**
  50. * 页面上拉触底事件的处理函数
  51. */
  52. onReachBottom: function () {
  53. },
  54. /**
  55. * 用户点击右上角分享
  56. */
  57. onShareAppMessage: function () {
  58. },
  59. yesCodeFn:function(){//验证码接口
  60. app.wxRequest(app.globalData.httpUrl + 'smscode', { user_phone: this.data.phone }, e => {
  61. console.log(e)
  62. if (e.code == 200) {
  63. wx.showToast({
  64. title: e.message,
  65. icon: 'success',
  66. duration: 500
  67. })
  68. }
  69. }, this)
  70. },
  71. sendTouch:function(){//发送验证码
  72. if (!(/^1[3456789]\d{9}$/.test(this.data.phone))) {
  73. wx.showToast({
  74. title: '手机号错误',
  75. icon: 'none',
  76. duration: 500
  77. })
  78. return;
  79. }
  80. this.setData({
  81. yesSend: true,
  82. })
  83. if (this.data.yesSend) {
  84. time = setInterval(this.setIntervalFn,1000)
  85. }
  86. if (app.globalData.openId) {
  87. this.yesCodeFn();
  88. } else {
  89. app.globalData.openidSuccessFuc = this.yesCodeFn;
  90. }
  91. },
  92. setIntervalFn:function(){//定时器
  93. if (this.data.num > 0) {
  94. this.data.num--;
  95. if (this.data.num == 0) {
  96. this.setData({
  97. yesSend: false,
  98. })
  99. if (!this.data.yesSend){
  100. this.setData({
  101. num: 60,
  102. minter: 60,
  103. })
  104. }
  105. clearInterval(time);
  106. }
  107. }
  108. this.setData({
  109. minter: this.data.num
  110. })
  111. console.log(this.data.minter)
  112. },
  113. registerBtn:function(){//点击按钮注册
  114. if (app.globalData.openId) {
  115. this.registerFn();
  116. } else {
  117. app.globalData.openidSuccessFuc = this.registerFn;
  118. }
  119. },
  120. registerFn:function(){//注册接口
  121. if (this.data.yesRegister){
  122. return;
  123. }
  124. this.data.yesRegister = true;
  125. app.wxRequest(app.globalData.httpUrl + 'register', { user_phone: this.data.phone, code_num: this.data.phoneCode }, e => {
  126. console.log(e)
  127. if (e.code == 200) {
  128. clearInterval(time);
  129. app.globalData.userInfo = e.data.user_phone
  130. this.data.yesRegister = false;
  131. this.setData({
  132. minter: 60,
  133. num: 60
  134. })
  135. wx.showToast({
  136. title: '注册成功',
  137. icon: 'success',
  138. duration: 500
  139. })
  140. setTimeout(function () {
  141. if (app.globalData.present_id){
  142. wx.reLaunch({
  143. url: '/pages/receiveTicket/receiveTicket?shareId=' + app.globalData.present_id + "&number=" + app.globalData.number
  144. })
  145. } else {
  146. wx.switchTab({
  147. url: '../index/index'
  148. })
  149. }
  150. }, 1000)
  151. }else{
  152. wx.showToast({
  153. title: e.message,
  154. duration:500
  155. })
  156. }
  157. }, this,"POST")
  158. },
  159. getPhone: function (e) {//获取手机号
  160. console.log(e.detail.value);
  161. this.setData({
  162. phone: e.detail.value
  163. })
  164. },
  165. getCode: function (e) {//获取验证码
  166. console.log(e.detail.value);
  167. this.setData({
  168. phoneCode: e.detail.value
  169. })
  170. },
  171. })