選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

register.js 4.8KB

5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. }else{
  69. wx.showToast({
  70. title: e.message,
  71. icon: 'none',
  72. duration: 500
  73. })
  74. }
  75. }, this)
  76. },
  77. sendTouch:function(){//发送验证码
  78. if (this.data.phone){
  79. if (!(/^1[3456789]\d{9}$/.test(this.data.phone))) {
  80. wx.showToast({
  81. title: '手机号错误',
  82. icon: 'none',
  83. duration: 500
  84. })
  85. return;
  86. }
  87. }else{
  88. wx.showToast({
  89. title: '请先输入手机号',
  90. icon: 'none',
  91. duration: 500
  92. })
  93. return;
  94. }
  95. this.setData({
  96. yesSend: true,
  97. })
  98. if (this.data.yesSend) {
  99. time = setInterval(this.setIntervalFn,1000)
  100. }
  101. if (app.globalData.openId) {
  102. this.yesCodeFn();
  103. } else {
  104. app.globalData.openidSuccessFuc = this.yesCodeFn;
  105. }
  106. },
  107. setIntervalFn:function(){//定时器
  108. if (this.data.num > 0) {
  109. this.data.num--;
  110. if (this.data.num == 0) {
  111. this.setData({
  112. yesSend: false,
  113. })
  114. if (!this.data.yesSend){
  115. this.setData({
  116. num: 60,
  117. minter: 60,
  118. })
  119. }
  120. clearInterval(time);
  121. }
  122. }
  123. this.setData({
  124. minter: this.data.num
  125. })
  126. console.log(this.data.minter)
  127. },
  128. registerBtn:function(){//点击按钮注册
  129. if (app.globalData.openId) {
  130. this.registerFn();
  131. } else {
  132. app.globalData.openidSuccessFuc = this.registerFn;
  133. }
  134. },
  135. registerFn:function(){//注册接口
  136. if (this.data.yesRegister){
  137. return;
  138. }
  139. if(this.data.phone){
  140. if (!(/^1[3456789]\d{9}$/.test(this.data.phone))) {
  141. wx.showToast({
  142. title: '手机号错误',
  143. icon: 'none',
  144. duration: 500
  145. })
  146. return;
  147. }
  148. }else{
  149. wx.showToast({
  150. title: '请先输入手机号',
  151. icon: 'none',
  152. duration: 500
  153. })
  154. return;
  155. }
  156. if (!this.data.phoneCode){
  157. wx.showToast({
  158. title: '请先输入验证码',
  159. icon: 'none',
  160. duration: 500
  161. })
  162. return;
  163. }
  164. app.wxRequest(app.globalData.httpUrl + 'register', { user_phone: this.data.phone, code_num: this.data.phoneCode }, e => {
  165. console.log(e)
  166. this.data.yesRegister = true;
  167. if (e.code == 200) {
  168. clearInterval(time);
  169. app.globalData.userInfo = e.data.user_phone
  170. this.setData({
  171. minter: 60,
  172. num: 60
  173. })
  174. wx.showToast({
  175. title: '注册成功',
  176. icon: 'success',
  177. duration: 500
  178. })
  179. setTimeout(function () {
  180. if (app.globalData.present_id){
  181. wx.reLaunch({
  182. url: '/pages/receiveTicket/receiveTicket?shareId=' + app.globalData.present_id + "&number=" + app.globalData.number
  183. })
  184. } else {
  185. wx.switchTab({
  186. url: '../index/index'
  187. })
  188. }
  189. }, 1000)
  190. } else {
  191. this.data.yesRegister = false;
  192. wx.showToast({
  193. title: e.message,
  194. icon:"none",
  195. duration:500
  196. })
  197. }
  198. }, this,"POST")
  199. },
  200. getPhone: function (e) {//获取手机号
  201. console.log(e.detail.value);
  202. this.setData({
  203. phone: e.detail.value
  204. })
  205. },
  206. getCode: function (e) {//获取验证码
  207. console.log(e.detail.value);
  208. this.setData({
  209. phoneCode: e.detail.value
  210. })
  211. },
  212. })