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.

264 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. success: res => {
  62. console.log(res, "转发成功")
  63. },
  64. }
  65. },
  66. yesCodeFn:function(){//验证码接口
  67. app.wxRequest(app.globalData.httpUrl + 'smscode', { user_phone: this.data.phone }, e => {
  68. console.log(e)
  69. if (e.code == 200) {
  70. wx.showToast({
  71. title: e.message,
  72. icon: 'success',
  73. duration: 500
  74. })
  75. }else{
  76. wx.showToast({
  77. title: e.message,
  78. icon: 'none',
  79. duration: 500
  80. })
  81. }
  82. }, this)
  83. },
  84. sendTouch:function(){//发送验证码
  85. if (this.data.phone){
  86. if (!(/^1[3456789]\d{9}$/.test(this.data.phone))) {
  87. wx.showToast({
  88. title: '手机号错误',
  89. icon: 'none',
  90. duration: 500
  91. })
  92. return;
  93. }
  94. }else{
  95. wx.showToast({
  96. title: '请先输入手机号',
  97. icon: 'none',
  98. duration: 500
  99. })
  100. return;
  101. }
  102. this.setData({
  103. yesSend: true,
  104. })
  105. if (this.data.yesSend) {
  106. time = setInterval(this.setIntervalFn,1000)
  107. }
  108. if (app.globalData.openId) {
  109. this.yesCodeFn();
  110. } else {
  111. app.globalData.openidSuccessFuc = this.yesCodeFn;
  112. }
  113. },
  114. setIntervalFn:function(){//定时器
  115. if (this.data.num > 0) {
  116. this.data.num--;
  117. if (this.data.num == 0) {
  118. this.setData({
  119. yesSend: false,
  120. })
  121. if (!this.data.yesSend){
  122. this.setData({
  123. num: 60,
  124. minter: 60,
  125. })
  126. }
  127. clearInterval(time);
  128. }
  129. }
  130. this.setData({
  131. minter: this.data.num
  132. })
  133. console.log(this.data.minter)
  134. },
  135. submitUser: function () {//提交用户信息
  136. if(this.data.userInfo){
  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. },
  152. getUserFn:function(e){//点击按钮注册
  153. console.log(e)
  154. if (e.detail.userInfo) {
  155. this.data.userInfo = e.detail.userInfo;
  156. wx.setStorageSync('noUser', 1);
  157. app.globalData.userInfo = e.detail.userInfo
  158. } else {
  159. wx.setStorageSync('noUser', 0);
  160. }
  161. this.registerFn();
  162. // if (app.globalData.openId) {
  163. // } else {
  164. // app.globalData.openidSuccessFuc = this.registerFn;
  165. // }
  166. },
  167. registerFn:function(){//注册接口
  168. if(this.data.phone){
  169. if (!(/^1[3456789]\d{9}$/.test(this.data.phone))) {
  170. wx.showToast({
  171. title: '手机号错误',
  172. icon: 'none',
  173. duration: 500
  174. })
  175. return;
  176. }
  177. }else{
  178. wx.showToast({
  179. title: '请先输入手机号',
  180. icon: 'none',
  181. duration: 500
  182. })
  183. return;
  184. }
  185. if (!this.data.phoneCode){
  186. wx.showToast({
  187. title: '请先输入验证码',
  188. icon: 'none',
  189. duration: 500
  190. })
  191. return;
  192. }
  193. if (this.data.yesRegister) {
  194. return;
  195. }
  196. this.data.yesRegister = true;
  197. app.wxRequest(app.globalData.httpUrl + 'register', { user_phone: this.data.phone, code_num: this.data.phoneCode }, e => {
  198. console.log(e)
  199. if (e.code == 200) {
  200. clearInterval(time);
  201. wx.setStorageSync('user_phone', e.data.user_phone);
  202. wx.setStorageSync("userInfo", this.data.userInfo)
  203. wx.setStorageSync('state', 1);
  204. // app.globalData.userInfo = e.data;
  205. this.submitUser();
  206. this.setData({
  207. minter: 60,
  208. num: 60
  209. })
  210. if (app.globalData.present_id){
  211. wx.reLaunch({
  212. url: '/pages/receiveTicket/receiveTicket?shareId=' + app.globalData.present_id + "&number=" + app.globalData.number
  213. })
  214. } else {
  215. console.log(5555)
  216. wx.navigateBack();
  217. }
  218. } else {
  219. this.data.yesRegister = false;
  220. wx.showToast({
  221. title: e.message,
  222. icon:"none",
  223. duration:500
  224. })
  225. }
  226. }, this,"POST")
  227. },
  228. getPhone: function (e) {//获取手机号
  229. console.log(e.detail.value);
  230. this.setData({
  231. phone: e.detail.value
  232. })
  233. },
  234. getCode: function (e) {//获取验证码
  235. console.log(e.detail.value);
  236. this.setData({
  237. phoneCode: e.detail.value
  238. })
  239. },
  240. })