微信小店联盟带货小程序

index.js 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. Page({
  2. data: {
  3. inviteCode: '',
  4. inviteLink: '',
  5. inviteRewards: {
  6. directInvite: '50.00',
  7. teamInvite: '200.00'
  8. },
  9. invitedFriends: [],
  10. inviteStats: {
  11. totalInvited: 0,
  12. activeInvited: 0,
  13. totalReward: '0.00'
  14. }
  15. },
  16. onLoad() {
  17. this.generateInviteCode()
  18. this.getInviteStats()
  19. this.getInvitedFriendsList()
  20. },
  21. // 生成邀请码
  22. generateInviteCode() {
  23. // 生成一个唯一的邀请码
  24. const code = 'INV' + Math.random().toString(36).substr(2, 6).toUpperCase()
  25. const link = `https://yourapp.com/invite?code=${code}`
  26. this.setData({
  27. inviteCode: code,
  28. inviteLink: link
  29. })
  30. },
  31. // 获取邀请统计数据
  32. getInviteStats() {
  33. // TODO: 调用后端API获取邀请统计
  34. this.setData({
  35. inviteStats: {
  36. totalInvited: 15,
  37. activeInvited: 8,
  38. totalReward: '1280.50'
  39. }
  40. })
  41. },
  42. // 获取邀请好友列表
  43. getInvitedFriendsList() {
  44. // TODO: 调用后端API获取邀请好友列表
  45. this.setData({
  46. invitedFriends: [
  47. {
  48. id: '1',
  49. avatarUrl: '/static/images/avatar1.png',
  50. nickName: '小明',
  51. registerTime: '2023-09-15',
  52. status: '已激活',
  53. reward: '50.00'
  54. },
  55. {
  56. id: '2',
  57. avatarUrl: '/static/images/avatar2.png',
  58. nickName: '小红',
  59. registerTime: '2023-09-16',
  60. status: '未激活',
  61. reward: '0.00'
  62. }
  63. ]
  64. })
  65. },
  66. // 复制邀请码
  67. copyInviteCode() {
  68. wx.setClipboardData({
  69. data: this.data.inviteCode,
  70. success: () => {
  71. wx.showToast({
  72. title: '邀请码已复制',
  73. icon: 'success'
  74. })
  75. }
  76. })
  77. },
  78. // 复制邀请链接
  79. copyInviteLink() {
  80. wx.setClipboardData({
  81. data: this.data.inviteLink,
  82. success: () => {
  83. wx.showToast({
  84. title: '邀请链接已复制',
  85. icon: 'success'
  86. })
  87. }
  88. })
  89. },
  90. // 分享邀请
  91. onShareAppMessage() {
  92. return {
  93. title: '快来加入我的分销团队,一起赚钱!',
  94. path: `/pages/index/index?inviteCode=${this.data.inviteCode}`,
  95. imageUrl: '/static/images/share.jpg'
  96. }
  97. },
  98. // 查看邀请奖励规则
  99. viewInviteRules() {
  100. wx.navigateTo({
  101. url: '/pages/distribution/rules'
  102. })
  103. }
  104. })