share.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. var app = getApp();
  2. var util = require('../../utils/util.js');
  3. Page({
  4. mixins: [require('../../mixin/compoentCartMixin.js'), require('../../mixin/globalMixin.js')],
  5. data: {
  6. list: [],
  7. topImg: '',
  8. rules: '',
  9. getRules: '',
  10. showRulesPopup: false,
  11. token: '',
  12. can_collect_gift: 0,
  13. coupon_info: '',
  14. point: '',
  15. isCollect: 0,
  16. needAuth: false
  17. },
  18. onLoad: function (options) {
  19. let share_id = '';
  20. if (options.scene) {
  21. var value = decodeURIComponent(options.scene);
  22. if (typeof value === 'object') {
  23. //记录推广人uid
  24. if (value.share_id) share_id = value.share_id;
  25. } else {
  26. share_id = value;
  27. }
  28. }
  29. if (options.share_id) share_id = options.share_id;
  30. wx.setStorageSync('share_id', share_id);
  31. //登錄後返回
  32. let can_collect_gift = options.can_collect_gift;
  33. let token = wx.getStorageSync('token') || '';
  34. this.setData({
  35. token,
  36. can_collect_gift
  37. })
  38. if(can_collect_gift==1) this.collectInvitegift();
  39. setTimeout(() => { this.getData() }, 100);
  40. },
  41. getData() {
  42. let suid = wx.getStorageSync('share_id');
  43. let token = wx.getStorageSync('token') || '';
  44. app.util.ProReq('invitegift.invitegiftIndex', { suid, token })
  45. .then(res=>{
  46. let { invite_activity_open_topback_img, invite_activity_rules, invite_activity_use_rules, suid } = res.data;
  47. this.setData({
  48. topImg: invite_activity_open_topback_img,
  49. rules: invite_activity_rules,
  50. getRules: invite_activity_use_rules,
  51. })
  52. })
  53. .catch(err=>{
  54. app.util.message(err.msg, 'switchTo:/lionfish_comshop/pages/index/index', 'error');
  55. })
  56. },
  57. /**
  58. * 授权成功回调
  59. */
  60. authSuccess: function (res) {
  61. console.log(res)
  62. let can_collect_gift = res.detail.data.is_can_collect_gift;
  63. // if(can_collect_gift==1) this.collectInvitegift();
  64. this.setData({
  65. needAuth: false,
  66. can_collect_gift
  67. }, ()=>{
  68. this.collectInvitegift();
  69. })
  70. },
  71. authModal: function(){
  72. if(this.data.needAuth) {
  73. this.setData({ showAuthModal: !this.data.showAuthModal });
  74. return false;
  75. }
  76. return true;
  77. },
  78. /**
  79. * 领取礼包
  80. */
  81. collectInvitegift() {
  82. let token = wx.getStorageSync('token') || '';
  83. app.util.ProReq('invitegift.collectInvitegift', {token})
  84. .then(res=>{
  85. this.setData({
  86. coupon_info: res.data.coupon_info,
  87. point: res.data.point,
  88. isCollect: 1
  89. })
  90. })
  91. .catch(err=>{
  92. this.setData({ can_collect_gift: 0 })
  93. app.util.message(err.msg, 'switchTo:/lionfish_comshop/pages/index/index', 'error');
  94. })
  95. },
  96. goLink: function(event) {
  97. let link = event.currentTarget.dataset.link;
  98. var pages_all = getCurrentPages();
  99. if (pages_all.length > 3) {
  100. wx.redirectTo({
  101. url: link
  102. })
  103. } else {
  104. wx.navigateTo({
  105. url: link
  106. })
  107. }
  108. },
  109. goIndex: function(event) {
  110. wx.switchTab({
  111. url: '/lionfish_comshop/pages/index/index',
  112. })
  113. },
  114. handleRuleModal() {
  115. this.setData({
  116. showRulesPopup: !this.data.showRulesPopup
  117. })
  118. },
  119. /**
  120. * 立即领取按钮
  121. */
  122. getGift() {
  123. // 1.判断登录
  124. wx.showLoading();
  125. let that = this;
  126. util.check_login_new().then((res)=>{
  127. if (res) {
  128. let token = wx.getStorageSync('token') || '';
  129. this.setData({ token })
  130. wx.hideLoading();
  131. } else {
  132. that.setData({ needAuth: true, showAuthModal: true });
  133. wx.hideLoading();
  134. }
  135. })
  136. }
  137. })