recommend.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. import Dialog from '@vant/weapp/dialog/dialog';
  2. const util = require('../../../../utils/util.js');
  3. const api = require('../../../../config/api.js');
  4. const user = require('../../../../utils/user.js');
  5. const app = getApp();
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. rId: 0,
  12. checked: false,
  13. userName: '',
  14. loginCode: '',
  15. avatarUrl: '',
  16. bCode: '',
  17. userName: '',
  18. avatarUrl: ''
  19. },
  20. /**
  21. * 生命周期函数--监听页面加载
  22. */
  23. onLoad: function (options) {
  24. if (options.rId) {
  25. this.setData({
  26. rId: options.rId
  27. });
  28. app.globalData.rId = options.rId;
  29. this.getReferrerRidInfo();
  30. }
  31. },
  32. getReferrerRidInfo() {
  33. util.request(api.ReferrerRidInfo, {
  34. rId: this.data.rId,
  35. }, "GET")
  36. .then((res) => {
  37. console.info(res)
  38. if (res.errno == 0) {
  39. this.setData({
  40. userName: res.data.applyName,
  41. avatarUrl: res.data.avatar,
  42. userName: res.data.applyName,
  43. avatarUrl: res.data.avatar,
  44. bCode: res.data.bCode
  45. })
  46. } else {
  47. util.showErrorToast(res.errmsg);
  48. }
  49. });
  50. },
  51. getPhoneNumber(e) {
  52. console.info(e)
  53. this.setData({
  54. detail: e.detail
  55. })
  56. this.getDenPhone();
  57. },
  58. getDenPhone() {
  59. let that=this;
  60. util.request(api.GetDenPhone, {
  61. code: that.data.loginCode,
  62. encryptedData: that.data.detail.encryptedData,
  63. errMsg: that.data.detail.errMsg,
  64. iv: that.data.detail.iv
  65. }, "POST")
  66. .then((res) => {
  67. if (res.errno == 0) {
  68. let isNew = res.data.isNew;
  69. if (isNew) {
  70. app.globalData.recommend.phone = res.data.phone;
  71. app.globalData.recommend.unionId = res.data.unionId;
  72. app.globalData.recommend.openId = res.data.openId;
  73. app.globalData.recommend.sessionKey = res.data.sessionKey;
  74. wx.navigateTo({
  75. url: '../register/register',
  76. })
  77. } else {
  78. // 不是新人,则跳转到首页
  79. Dialog.alert({
  80. title: '引荐失败',
  81. message: '您已是鲸致商城用户,当前引荐人计划只面向新用户,敬请期待',
  82. }).then(() => {
  83. // on close
  84. wx.switchTab({
  85. url: '/pages/index/index',
  86. });
  87. });
  88. }
  89. } else {
  90. util.showErrorToast(res.errmsg);
  91. this.getLoginCode();
  92. }
  93. });
  94. },
  95. /**
  96. * 生命周期函数--监听页面初次渲染完成
  97. */
  98. onReady: function () {
  99. },
  100. getLoginCode() {
  101. let that = this;
  102. user.login().then(res => {
  103. that.setData({
  104. loginCode: res.code
  105. })
  106. })
  107. },
  108. /**
  109. * 生命周期函数--监听页面显示
  110. */
  111. onShow: function () {
  112. this.getLoginCode();
  113. },
  114. onChange(e) {
  115. console.log(e);
  116. this.setData({
  117. checked: e.detail,
  118. });
  119. },
  120. confirmJoin() {
  121. if (!this.data.checked) {
  122. Dialog.alert({
  123. title: '提示',
  124. message: '请阅读《用户条款》并勾选',
  125. }).then(() => {
  126. // on close
  127. });
  128. } else {
  129. wx.navigateTo({
  130. url: '../confirm/confirm'
  131. });
  132. }
  133. },
  134. userProtocol() {
  135. wx.navigateTo({
  136. url: '../protocol/protocol'
  137. });
  138. },
  139. /**
  140. * 生命周期函数--监听页面隐藏
  141. */
  142. onHide: function () {
  143. },
  144. /**
  145. * 生命周期函数--监听页面卸载
  146. */
  147. onUnload: function () {
  148. },
  149. /**
  150. * 页面相关事件处理函数--监听用户下拉动作
  151. */
  152. onPullDownRefresh: function () {
  153. },
  154. /**
  155. * 页面上拉触底事件的处理函数
  156. */
  157. onReachBottom: function () {
  158. },
  159. /**
  160. * 用户点击右上角分享
  161. */
  162. onShareAppMessage: function () {
  163. }
  164. })