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.

261 lines
5.7KB

  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. if(this.data.userInfo && this.data.userInfo.province){
  138. var params = {
  139. "province": this.data.userInfo.province,
  140. "language": this.data.userInfo.language,
  141. "city": this.data.userInfo.city,
  142. "gender": this.data.userInfo.gender,
  143. "nickname": this.data.userInfo.nickName,
  144. "headimgurl": this.data.userInfo.avatarUrl,
  145. }
  146. app.wxRequest(app.globalData.httpUrl + 'submit', params, e => {
  147. console.log(e)
  148. if (e.code == 200) {
  149. }
  150. }, this, "POST")
  151. }
  152. },
  153. getUserFn:function(e){//点击按钮注册
  154. console.log(e)
  155. this.data.userInfo = e.detail.userInfo;
  156. if(e.detail.userInfo){
  157. app.globalData.userInfo = e.detail.userInfo
  158. }
  159. this.registerFn();
  160. // if (app.globalData.openId) {
  161. // } else {
  162. // app.globalData.openidSuccessFuc = this.registerFn;
  163. // }
  164. },
  165. registerFn:function(){//注册接口
  166. if (this.data.yesRegister){
  167. return;
  168. }
  169. if(this.data.phone){
  170. if (!(/^1[3456789]\d{9}$/.test(this.data.phone))) {
  171. wx.showToast({
  172. title: '手机号错误',
  173. icon: 'none',
  174. duration: 500
  175. })
  176. return;
  177. }
  178. }else{
  179. wx.showToast({
  180. title: '请先输入手机号',
  181. icon: 'none',
  182. duration: 500
  183. })
  184. return;
  185. }
  186. if (!this.data.phoneCode){
  187. wx.showToast({
  188. title: '请先输入验证码',
  189. icon: 'none',
  190. duration: 500
  191. })
  192. return;
  193. }
  194. app.wxRequest(app.globalData.httpUrl + 'register', { user_phone: this.data.phone, code_num: this.data.phoneCode }, e => {
  195. console.log(e)
  196. this.data.yesRegister = true;
  197. if (e.code == 200) {
  198. clearInterval(time);
  199. wx.setStorageSync('user_phone', e.data.user_phone);
  200. wx.setStorageSync("userInfo", this.data.userInfo)
  201. wx.setStorageSync('state', 1);
  202. // app.globalData.userInfo = e.data;
  203. this.submitUser();
  204. this.setData({
  205. minter: 60,
  206. num: 60
  207. })
  208. if (app.globalData.present_id){
  209. wx.reLaunch({
  210. url: '/pages/receiveTicket/receiveTicket?shareId=' + app.globalData.present_id + "&number=" + app.globalData.number
  211. })
  212. } else {
  213. console.log(5555)
  214. wx.navigateBack();
  215. }
  216. } else {
  217. this.data.yesRegister = false;
  218. wx.showToast({
  219. title: e.message,
  220. icon:"none",
  221. duration:500
  222. })
  223. }
  224. }, this,"POST")
  225. },
  226. getPhone: function (e) {//获取手机号
  227. console.log(e.detail.value);
  228. this.setData({
  229. phone: e.detail.value
  230. })
  231. },
  232. getCode: function (e) {//获取验证码
  233. console.log(e.detail.value);
  234. this.setData({
  235. phoneCode: e.detail.value
  236. })
  237. },
  238. })