register.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. let that=this;
  69. if (that.data.cityValue == '请选择城市') {
  70. util.showErrorToast('请选择城市');
  71. } else if (that.data.username == '') {
  72. util.showErrorToast('请输入姓名');
  73. } else {
  74. wx.getUserProfile({
  75. desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  76. success: (res) => {
  77. console.log(res);
  78. if (res.userInfo == null) {
  79. wx.showToast({
  80. title: '未授权,无法完善信息',
  81. icon: 'success',
  82. duration: 3000
  83. });
  84. return;
  85. } else {
  86. that.setData({
  87. userInfo: res.userInfo,
  88. });
  89. that.registerReferrer();
  90. }
  91. },
  92. fail:(res)=>{
  93. wx.showToast({
  94. title: '未授权,无法完善信息',
  95. icon: 'success',
  96. duration: 3000
  97. });
  98. }
  99. })
  100. }
  101. },
  102. registerReferrer() {
  103. util.request(api.RegisterReferrer, {
  104. "applyCode": this.data.bCode,
  105. "avatar": this.data.userInfo.avatarUrl,
  106. "cityId": this.data.cityId,
  107. "customerName": this.data.username,
  108. "gender": this.data.userInfo.gender,
  109. "nickname": this.data.userInfo.nickName,
  110. "openId": app.globalData.recommend.openId,
  111. "phone": this.data.phone,
  112. "ruserid": app.globalData.rId,
  113. "sessionKey": app.globalData.recommend.sessionKey,
  114. "unionId": app.globalData.recommend.unionId
  115. }, "POST")
  116. .then((res) => {
  117. if (res.errno == 0) {
  118. //存储用户信息
  119. app.globalData.hasLogin = true;
  120. wx.setStorageSync('userInfo', res.data.userInfo);
  121. wx.setStorageSync('token', res.data.token);
  122. app.globalData.shareImage = res.data.sharImage;
  123. // wx.navigateTo({
  124. // url: '../steward/steward',
  125. // })
  126. wx.showToast({
  127. title: '注册成功',
  128. duration: 2000,
  129. success: function () {
  130. setTimeout(function(){
  131. wx.switchTab({
  132. url: '/pages/index/index',
  133. })
  134. },2000);
  135. }
  136. })
  137. } else {
  138. util.showErrorToast(res.errmsg);
  139. }
  140. });
  141. },
  142. /**
  143. * 生命周期函数--监听页面初次渲染完成
  144. */
  145. onReady: function () {
  146. },
  147. /**
  148. * 生命周期函数--监听页面显示
  149. */
  150. onShow: function () {
  151. },
  152. /**
  153. * 生命周期函数--监听页面隐藏
  154. */
  155. onHide: function () {
  156. },
  157. /**
  158. * 生命周期函数--监听页面卸载
  159. */
  160. onUnload: function () {
  161. },
  162. /**
  163. * 页面相关事件处理函数--监听用户下拉动作
  164. */
  165. onPullDownRefresh: function () {
  166. },
  167. /**
  168. * 页面上拉触底事件的处理函数
  169. */
  170. onReachBottom: function () {
  171. },
  172. /**
  173. * 用户点击右上角分享
  174. */
  175. onShareAppMessage: function () {
  176. }
  177. })