Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

256 lines
5.3KB

  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. showAll:false,
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad: function (options) {
  21. var state = wx.getStorageSync('state');
  22. if (state==1){//已注册
  23. wx.switchTab({
  24. url: '/pages/index/index'
  25. })
  26. } else if (state == 0){//未注册
  27. this.setData({
  28. showAll:true
  29. })
  30. } else if (state == -1){
  31. app.globalData.userInfoBackFn = res=>{//等待结果
  32. console.log(res)
  33. if (res){
  34. wx.switchTab({
  35. url: '/pages/index/index'
  36. })
  37. }else{
  38. this.setData({
  39. showAll: true
  40. })
  41. }
  42. }
  43. }
  44. },
  45. /**
  46. * 生命周期函数--监听页面初次渲染完成
  47. */
  48. onReady: function () {
  49. },
  50. /**
  51. * 生命周期函数--监听页面显示
  52. */
  53. onShow: function () {
  54. if (wx.canIUse('hideHomeButton')) {
  55. wx.hideHomeButton()
  56. }
  57. },
  58. /**
  59. * 生命周期函数--监听页面隐藏
  60. */
  61. onHide: function () {
  62. },
  63. /**
  64. * 生命周期函数--监听页面卸载
  65. */
  66. onUnload: function () {
  67. },
  68. /**
  69. * 页面相关事件处理函数--监听用户下拉动作
  70. */
  71. onPullDownRefresh: function () {
  72. },
  73. /**
  74. * 页面上拉触底事件的处理函数
  75. */
  76. onReachBottom: function () {
  77. },
  78. /**
  79. * 用户点击右上角分享
  80. */
  81. onShareAppMessage: function () {
  82. },
  83. yesCodeFn:function(){//验证码接口
  84. app.wxRequest(app.globalData.httpUrl + 'smscode', { user_phone: this.data.phone }, e => {
  85. console.log(e)
  86. if (e.code == 200) {
  87. wx.showToast({
  88. title: e.message,
  89. icon: 'success',
  90. duration: 500
  91. })
  92. }else{
  93. wx.showToast({
  94. title: e.message,
  95. icon: 'none',
  96. duration: 500
  97. })
  98. }
  99. }, this)
  100. },
  101. sendTouch:function(){//发送验证码
  102. if (this.data.phone){
  103. if (!(/^1[3456789]\d{9}$/.test(this.data.phone))) {
  104. wx.showToast({
  105. title: '手机号错误',
  106. icon: 'none',
  107. duration: 500
  108. })
  109. return;
  110. }
  111. }else{
  112. wx.showToast({
  113. title: '请先输入手机号',
  114. icon: 'none',
  115. duration: 500
  116. })
  117. return;
  118. }
  119. this.setData({
  120. yesSend: true,
  121. })
  122. if (this.data.yesSend) {
  123. time = setInterval(this.setIntervalFn,1000)
  124. }
  125. if (app.globalData.openId) {
  126. this.yesCodeFn();
  127. } else {
  128. app.globalData.openidSuccessFuc = this.yesCodeFn;
  129. }
  130. },
  131. setIntervalFn:function(){//定时器
  132. if (this.data.num > 0) {
  133. this.data.num--;
  134. if (this.data.num == 0) {
  135. this.setData({
  136. yesSend: false,
  137. })
  138. if (!this.data.yesSend){
  139. this.setData({
  140. num: 60,
  141. minter: 60,
  142. })
  143. }
  144. clearInterval(time);
  145. }
  146. }
  147. this.setData({
  148. minter: this.data.num
  149. })
  150. console.log(this.data.minter)
  151. },
  152. registerBtn:function(){//点击按钮注册
  153. if (app.globalData.openId) {
  154. this.registerFn();
  155. } else {
  156. app.globalData.openidSuccessFuc = this.registerFn;
  157. }
  158. },
  159. registerFn:function(){//注册接口
  160. if (this.data.yesRegister){
  161. return;
  162. }
  163. if(this.data.phone){
  164. if (!(/^1[3456789]\d{9}$/.test(this.data.phone))) {
  165. wx.showToast({
  166. title: '手机号错误',
  167. icon: 'none',
  168. duration: 500
  169. })
  170. return;
  171. }
  172. }else{
  173. wx.showToast({
  174. title: '请先输入手机号',
  175. icon: 'none',
  176. duration: 500
  177. })
  178. return;
  179. }
  180. if (!this.data.phoneCode){
  181. wx.showToast({
  182. title: '请先输入验证码',
  183. icon: 'none',
  184. duration: 500
  185. })
  186. return;
  187. }
  188. app.wxRequest(app.globalData.httpUrl + 'register', { user_phone: this.data.phone, code_num: this.data.phoneCode }, e => {
  189. console.log(e)
  190. this.data.yesRegister = true;
  191. if (e.code == 200) {
  192. clearInterval(time);
  193. app.globalData.user_phone = e.data.user_phone
  194. this.setData({
  195. minter: 60,
  196. num: 60
  197. })
  198. wx.showToast({
  199. title: '注册成功',
  200. icon: 'success',
  201. duration: 500
  202. })
  203. setTimeout(function () {
  204. if (app.globalData.present_id){
  205. wx.reLaunch({
  206. url: '/pages/receiveTicket/receiveTicket?shareId=' + app.globalData.present_id + "&number=" + app.globalData.number
  207. })
  208. } else {
  209. wx.switchTab({
  210. url: '../index/index'
  211. })
  212. }
  213. }, 1000)
  214. } else {
  215. this.data.yesRegister = false;
  216. wx.showToast({
  217. title: e.message,
  218. icon:"none",
  219. duration:500
  220. })
  221. }
  222. }, this,"POST")
  223. },
  224. getPhone: function (e) {//获取手机号
  225. console.log(e.detail.value);
  226. this.setData({
  227. phone: e.detail.value
  228. })
  229. },
  230. getCode: function (e) {//获取验证码
  231. console.log(e.detail.value);
  232. this.setData({
  233. phoneCode: e.detail.value
  234. })
  235. },
  236. })