receiveCard.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. var util = require('../../../../utils/util.js');
  2. var api = require('../../../../config/api');
  3. var user = require('../../../../utils/user.js');
  4. var app = getApp();
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. rId: 0,
  11. userName: '',
  12. avatarUrl: '/static/images/member/get.png',
  13. loginCode: '',
  14. },
  15. getPhoneNumber(e) {
  16. let that = this
  17. util.request(api.RefereeMemberCardReceive, {
  18. code: this.data.loginCode,
  19. encryptedData: e.detail.encryptedData,
  20. iv: e.detail.iv,
  21. rId: that.data.rId
  22. }, "POST")
  23. .then((res) => {
  24. if (res.errno == 0) {
  25. app.globalData.hasLogin = true;
  26. app.globalData.userInfo = res.data.userInfo;
  27. wx.setStorageSync('userInfo', res.data.userInfo);
  28. wx.setStorageSync('token', res.data.token);
  29. wx.navigateTo({
  30. url: '/pages/member/card/received/receivedCard?rId=' + that.data.rId,
  31. })
  32. } else {
  33. util.showErrorToast(res.errmsg);
  34. that.getLoginCode();
  35. }
  36. });
  37. },
  38. getLoginCode() {
  39. let that = this;
  40. user.login().then(res => {
  41. that.setData({
  42. loginCode: res.code
  43. })
  44. })
  45. },
  46. /**
  47. * 生命周期函数--监听页面加载
  48. */
  49. onLoad: function (options) {
  50. if (options.scene || options.rId) {
  51. var rid = 0;
  52. if (options.scene) {
  53. var referee = decodeURIComponent(options.scene)
  54. rid = referee.replace("rId=", "");
  55. } else {
  56. rid = options.rId;
  57. }
  58. this.setData({
  59. rId: rid
  60. });
  61. this.getReferee();
  62. } else {
  63. util.showErrorToast("无效分享");
  64. }
  65. },
  66. getReferee() {
  67. util.request(api.ReferrerRidInfo, {
  68. rId: this.data.rId,
  69. }, "GET")
  70. .then((res) => {
  71. if (res.errno == 0) {
  72. this.setData({
  73. userName: res.data.applyName,
  74. avatarUrl: res.data.avatar
  75. })
  76. app.globalData.recommend = {
  77. userName: res.data.applyName,
  78. avatarUrl: res.data.avatar
  79. };
  80. } else {
  81. util.showErrorToast(res.errmsg);
  82. }
  83. });
  84. },
  85. /**
  86. * 生命周期函数--监听页面初次渲染完成
  87. */
  88. onReady: function () {
  89. },
  90. /**
  91. * 生命周期函数--监听页面显示
  92. */
  93. onShow: function () {
  94. this.getLoginCode();
  95. },
  96. /**
  97. * 生命周期函数--监听页面隐藏
  98. */
  99. onHide: function () {
  100. },
  101. /**
  102. * 生命周期函数--监听页面卸载
  103. */
  104. onUnload: function () {
  105. },
  106. /**
  107. * 页面相关事件处理函数--监听用户下拉动作
  108. */
  109. onPullDownRefresh: function () {
  110. },
  111. /**
  112. * 页面上拉触底事件的处理函数
  113. */
  114. onReachBottom: function () {
  115. },
  116. /**
  117. * 用户点击右上角分享
  118. */
  119. onShareAppMessage: function () {
  120. },
  121. })