index.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import {
  2. getRankingData,
  3. getSelfRanking,
  4. getRankedDay
  5. } from '~/api/global'
  6. import event from '~/mixins/event'
  7. Page({
  8. behaviors: [event],
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. userList: [],
  14. //2:邀新榜,3:热播榜,4:挑战pk榜
  15. rankingType: '',
  16. icon: '',
  17. podiumBoxBg: '',
  18. historyList: [],
  19. day: '',
  20. },
  21. /**
  22. * 生命周期函数--监听页面加载
  23. */
  24. async onLoad(options) {
  25. let historyList = await getRankedDay()
  26. console.log(historyList);
  27. this.setData({
  28. historyList,
  29. day: historyList[historyList.length - 1]
  30. }, () => {
  31. this.getRankInfo(options)
  32. })
  33. },
  34. async getRankInfo(options) {
  35. this.setData({
  36. rankingType: options.type,
  37. icon: options.type == '2' ? '/static/yx.png' : options.type == '3' ? '/static/play.png' : '/static/win.png',
  38. podiumBoxBg: options.type == '2' ? 'invitation' : options.type == '3' ? 'hot' : 'pk',
  39. })
  40. wx.setNavigationBarColor({
  41. frontColor: '#ffffff',
  42. backgroundColor: options.type == '2' ? '#50AE75' : options.type == '3' ? '#FF7E6C' : '#8468FA',
  43. })
  44. let userList = await getRankingData({
  45. type: options.type,
  46. day: this.data.day
  47. })
  48. let self = await getSelfRanking({
  49. type: options.type,
  50. day: this.data.day
  51. })
  52. console.log(self);
  53. this.setData({
  54. userList,
  55. })
  56. },
  57. switchType({
  58. target
  59. }) {
  60. let rankingType = target.dataset.type
  61. if (rankingType && rankingType != this.data.rankingType) {
  62. this.getRankInfo({
  63. type: rankingType
  64. })
  65. }
  66. },
  67. bindDateChange(e) {
  68. this.setData({
  69. day: e.detail.value
  70. })
  71. this.getRankInfo({
  72. type: this.data.rankingType
  73. })
  74. },
  75. jumpIndex() {
  76. wx.switchTab({
  77. url: '/pages/index/index',
  78. })
  79. },
  80. jumpUserInfo({
  81. currentTarget
  82. }) {
  83. if (!currentTarget.dataset.uid) {
  84. return
  85. }
  86. wx.navigateTo({
  87. url: `/pages/personal/index?uid=${currentTarget.dataset.uid}&type=${this.data.rankingType==4?'pk':'user'}`,
  88. })
  89. },
  90. onShareAppMessage() {
  91. return {
  92. title: this.data.rankingType == 3 ? '我要上热门,就差你的一个赞,快来帮帮我吧!' : '这个小程序太赞了!孩子朗读能力蹭蹭上涨,推荐你试试!',
  93. path: `/pages/index/index?uid=${wx.getStorageSync('uid')}`,
  94. imageUrl: this.data.rankingType == 3 ? 'http://reader-wx.ai160.com/images/reader/v3/375-300-3.jpg' : 'http://reader-wx.ai160.com/images/reader/v3/375-300-2.jpg'
  95. }
  96. }
  97. })