inviteFriends.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. // pages/activity/inviteFriends.js
  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. showModalStatus: false,
  12. userInfo: {},
  13. invationData: {}, //当前邀请的信息
  14. namestr: "", //名字加*
  15. invitees: [], //加入活动的人
  16. datedifference: "", //活动到期时间
  17. isfirst: false, //是否首次
  18. },
  19. preventTouchMove: function () {
  20. },
  21. tank: function (e) {
  22. console.log("点击了");
  23. this.setData({
  24. showModalStatus: !this.data.showModalStatus
  25. })
  26. },
  27. toActivityHistory: function () {
  28. wx.navigateTo({
  29. url: '/pages/activity/activityhistory/activityHistory',
  30. })
  31. },
  32. getActivityOngoing() {
  33. let that = this;
  34. wx.showLoading({
  35. title: '加载中',
  36. });
  37. util.request(api.ActivityOngoing, {
  38. userId: that.data.userInfo.id
  39. }).then(function (res) {
  40. console.info(res.data);
  41. if (res.errno === 0) {
  42. that.setData({
  43. invationData: res.data.assistance,
  44. invitees: res.data.invitees,
  45. })
  46. if (Object.keys(res.data.assistance).length != 0) {
  47. that.setData({
  48. datedifference: util.dateDifference( res.data.assistance.endTime)
  49. })
  50. that.setData({
  51. isfirst: false
  52. })
  53. } else {
  54. that.setData({
  55. isfirst: true
  56. })
  57. }
  58. }
  59. wx.hideLoading();
  60. }).catch(function (err) {
  61. console.log(err);
  62. wx.hideLoading();
  63. });
  64. },
  65. /**
  66. * 生命周期函数--监听页面加载
  67. */
  68. onLoad: function (options) {
  69. // if (!app.globalData.hasLogin) {
  70. // wx.navigateTo({
  71. // url: "/pages/auth/login/login"
  72. // });
  73. // };
  74. let userInfo = wx.getStorageSync('userInfo');
  75. //console.info(userInfo);
  76. this.setData({
  77. userInfo: userInfo,
  78. });
  79. },
  80. /**
  81. * 生命周期函数--监听页面初次渲染完成
  82. */
  83. onReady: function () {
  84. },
  85. /**
  86. * 生命周期函数--监听页面显示
  87. */
  88. onShow: function () {
  89. this.getActivityOngoing();
  90. let str = wx.getStorageSync('userInfo').nickName;
  91. if (null != str) {
  92. this.setData({
  93. namestr:str
  94. })
  95. // if (str.length > 2) {
  96. // this.setData({
  97. // namestr: str.split("")[0] + "**" + str.split("")[str.split.length + 1]
  98. // })
  99. // } else {
  100. // this.setData({
  101. // namestr: str.split("")[0] + "**"
  102. // })
  103. // }
  104. }
  105. },
  106. /**
  107. * 生命周期函数--监听页面隐藏
  108. */
  109. onHide: function () {
  110. },
  111. /**
  112. * 生命周期函数--监听页面卸载
  113. */
  114. onUnload: function () {
  115. },
  116. /**
  117. * 页面相关事件处理函数--监听用户下拉动作
  118. */
  119. onPullDownRefresh: function () {
  120. },
  121. /**
  122. * 页面上拉触底事件的处理函数
  123. */
  124. onReachBottom: function () {
  125. },
  126. lingqu() {
  127. //领取60元大洋
  128. //实际系统后台自动发送
  129. if (this.data.invationData.isSendCoupon == 1) {
  130. this.myshowtost("你已领取本次活动现金券");
  131. } else {
  132. this.myshowtost("领取成功,10分钟后发放到你的账户");
  133. }
  134. },
  135. myshowtost: function (v) {
  136. wx.showToast({
  137. title: v,
  138. icon: 'none',
  139. duration: 3000
  140. })
  141. },
  142. async requestActivityCreate() {
  143. let tt = await util.request(api.ActivityCreate, {
  144. userId: this.data.userInfo.id
  145. }).then(function (res) {
  146. console.log(res.data);
  147. }).catch(function (err) {
  148. console.log(err);
  149. });
  150. },
  151. /**
  152. * 用户点分享
  153. */
  154. onShareAppMessage: function (e) {
  155. let state = e.target.dataset.state;
  156. console.log(state);
  157. let that = this;
  158. that.requestActivityCreate();
  159. console.log("that.data.userInfo.id" + that.data.userInfo.id);
  160. return {
  161. title: "邀请好友领60元现金券",
  162. path: '/pages/index/index?rId=' + that.data.userInfo.id,
  163. // path: '/pages/index/index?rId=1',
  164. success: function (res) {
  165. // 转发成功
  166. that.getActivityOngoing();
  167. console.log("转发成功:" + JSON.stringify(res));
  168. },
  169. fail: function (res) {
  170. that.getActivityOngoing();
  171. // 转发失败
  172. console.log("转发失败:" + JSON.stringify(res));
  173. }
  174. };
  175. },
  176. })