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

register.js 5.5KB

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