index.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import {
  2. getRankingData,
  3. getRankedDay
  4. } from '~/api/global'
  5. import event from '~/mixins/event'
  6. Page({
  7. behaviors: [event],
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. userList: [],
  13. ranking:'',
  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 {
  45. userList,
  46. ranking
  47. } = await getRankingData({
  48. type: options.type,
  49. day: this.data.day
  50. })
  51. this.setData({
  52. userList,
  53. ranking
  54. })
  55. },
  56. switchType({
  57. target
  58. }) {
  59. let rankingType = target.dataset.type
  60. if (rankingType && rankingType != this.data.rankingType) {
  61. this.getRankInfo({
  62. type: rankingType
  63. })
  64. }
  65. },
  66. bindDateChange(e) {
  67. this.setData({
  68. day: e.detail.value
  69. })
  70. this.getRankInfo({
  71. type: this.data.rankingType
  72. })
  73. },
  74. jumpIndex() {
  75. wx.switchTab({
  76. url: '/pages/index/index',
  77. })
  78. },
  79. jumpUserInfo({
  80. currentTarget
  81. }) {
  82. if (!currentTarget.dataset.uid) {
  83. return
  84. }
  85. wx.navigateTo({
  86. url: `/pages/personal/index?uid=${currentTarget.dataset.uid}&type=${this.data.rankingType==4?'pk':'user'}`,
  87. })
  88. },
  89. onShareAppMessage() {
  90. return {
  91. title: this.data.rankingType == 3 ? '我要上热门,就差你的一个赞,快来帮帮我吧!' : '这个小程序太赞了!孩子朗读能力蹭蹭上涨,推荐你试试!',
  92. path: `/pages/index/index?uid=${wx.getStorageSync('uid')}`,
  93. 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'
  94. }
  95. }
  96. })