register.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. const util = require('../../../../utils/util.js');
  2. const api = require('../../../../config/api.js');
  3. const app = getApp();
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. phone: '',
  10. bCode: '',
  11. showPicker: false,
  12. cityId: '',
  13. cityValue: '请选择城市',
  14. cityList: [],
  15. columns: [],
  16. username: '',
  17. userInfo: {},
  18. },
  19. onCancel: function () {
  20. this.setData({
  21. showPicker: false,
  22. });
  23. },
  24. onConfirm: function (event) {
  25. this.setData({
  26. cityId: this.data.cityList[event.detail.index].id,
  27. cityValue: event.detail.value,
  28. showPicker: false,
  29. });
  30. },
  31. showPicker() {
  32. this.setData({
  33. showPicker: true,
  34. });
  35. },
  36. nameInput(e) {
  37. this.setData({
  38. username: e.detail.value
  39. })
  40. },
  41. getAllCity() {
  42. util.request(api.GetAllCity, {}, 'get').then(res => {
  43. if (res.errno === 0) {
  44. let list = res.data;
  45. let columns = list.map(item => {
  46. return item.cityName
  47. });
  48. this.setData({
  49. cityList: list,
  50. columns: columns
  51. })
  52. } else {
  53. util.showErrorToast(res.errmsg);
  54. }
  55. })
  56. },
  57. /**
  58. * 生命周期函数--监听页面加载
  59. */
  60. onLoad: function (options) {
  61. this.getAllCity();
  62. this.setData({
  63. phone: app.globalData.recommend.phone,
  64. bCode: app.globalData.recommend.bCode
  65. })
  66. },
  67. confirmRegister() {
  68. if (this.data.cityValue == '请选择城市') {
  69. util.showErrorToast('请选择城市');
  70. } else if (this.data.username == '') {
  71. util.showErrorToast('请输入姓名');
  72. } else {
  73. wx.getUserProfile({
  74. desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  75. success: (res) => {
  76. console.log(res);
  77. if (res.userInfo == null) {
  78. wx.showToast({
  79. title: '未授权,无法完善信息',
  80. icon: 'success',
  81. duration: 3000
  82. });
  83. return;
  84. } else {
  85. this.setData({
  86. userInfo: res.userInfo,
  87. });
  88. this.registerReferrer();
  89. }
  90. }
  91. })
  92. }
  93. },
  94. registerReferrer() {
  95. util.request(api.RegisterReferrer, {
  96. "applyCode": this.data.bCode,
  97. "avatar": this.data.userInfo.avatarUrl,
  98. "cityId": this.data.cityId,
  99. "customerName": this.data.username,
  100. "gender": this.data.userInfo.gender,
  101. "nickname": this.data.userInfo.nickName,
  102. "openId": app.globalData.recommend.openId,
  103. "phone": this.data.phone,
  104. "ruserid": app.globalData.rId,
  105. "sessionKey": app.globalData.recommend.sessionKey,
  106. "unionId": app.globalData.recommend.unionId
  107. }, "POST")
  108. .then((res) => {
  109. if (res.errno == 0) {
  110. //存储用户信息
  111. app.globalData.hasLogin = true;
  112. wx.setStorageSync('userInfo', res.data.userInfo);
  113. wx.setStorageSync('token', res.data.token);
  114. app.globalData.shareImage = res.data.sharImage;
  115. // wx.navigateTo({
  116. // url: '../steward/steward',
  117. // })
  118. wx.showToast({
  119. title: '注册成功',
  120. duration: 2000,
  121. success: function () {
  122. setTimeout(function(){
  123. wx.switchTab({
  124. url: '/pages/index/index',
  125. })
  126. },2000);
  127. }
  128. })
  129. } else {
  130. util.showErrorToast(res.errmsg);
  131. }
  132. });
  133. },
  134. /**
  135. * 生命周期函数--监听页面初次渲染完成
  136. */
  137. onReady: function () {
  138. },
  139. /**
  140. * 生命周期函数--监听页面显示
  141. */
  142. onShow: function () {
  143. },
  144. /**
  145. * 生命周期函数--监听页面隐藏
  146. */
  147. onHide: function () {
  148. },
  149. /**
  150. * 生命周期函数--监听页面卸载
  151. */
  152. onUnload: function () {
  153. },
  154. /**
  155. * 页面相关事件处理函数--监听用户下拉动作
  156. */
  157. onPullDownRefresh: function () {
  158. },
  159. /**
  160. * 页面上拉触底事件的处理函数
  161. */
  162. onReachBottom: function () {
  163. },
  164. /**
  165. * 用户点击右上角分享
  166. */
  167. onShareAppMessage: function () {
  168. }
  169. })