index.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. import {
  2. getSelfRead
  3. } from '~/api/user'
  4. import {
  5. isActivityWork
  6. } from '~/api/works'
  7. import {
  8. getModelTexts,
  9. getReadRanking,
  10. getActivityInfo,
  11. getSelfReadRanking
  12. } from '~/api/global'
  13. import {
  14. store
  15. } from '~/store/index'
  16. import {
  17. createStoreBindings
  18. } from 'mobx-miniprogram-bindings'
  19. import event from '~/mixins/share'
  20. import share from '~/mixins/share'
  21. Page({
  22. behaviors: [share,event],
  23. /**
  24. * 页面的初始数据
  25. */
  26. data: {
  27. list: [],
  28. // true是人气榜,false是参赛作品
  29. currentType: true,
  30. activityUserList: [],
  31. modelList: [],
  32. myActivityUser: {},
  33. activityId: '',
  34. bannerList: [],
  35. //1是收费0是免费
  36. free: 1
  37. },
  38. /**
  39. * 生命周期函数--监听页面加载
  40. */
  41. onLoad(options) {
  42. this.setData({
  43. activityId: options.activityId
  44. })
  45. getActivityInfo(options.activityId).then(res => {
  46. let {
  47. free
  48. } = res
  49. this.setData({
  50. free
  51. })
  52. })
  53. this.getLocUserInfo()
  54. if (Object.keys(this.data.userInfo).length > 0) {
  55. this.reload()
  56. } else {
  57. getApp().callBack = (res) => {
  58. this.getLocUserInfo()
  59. this.reload()
  60. }
  61. }
  62. },
  63. getLocUserInfo() {
  64. this.storeBindings = createStoreBindings(this, {
  65. store,
  66. fields: {
  67. userInfo: 'userInfo'
  68. },
  69. actions: {
  70. setUser: 'setUser'
  71. }
  72. })
  73. this.storeBindings.updateStoreBindings()
  74. },
  75. reload() {
  76. this.getModelTexts()
  77. this.getReadRanking()
  78. },
  79. // 获取范文
  80. async getModelTexts() {
  81. let modelList = await getModelTexts({
  82. grade: this.data.userInfo.grade,
  83. activityId: this.data.activityId
  84. })
  85. this.setData({
  86. modelList
  87. })
  88. },
  89. async getReadRanking() {
  90. let {
  91. activityUserList,
  92. myActivityUser,
  93. activity
  94. } = await getReadRanking({
  95. activityId: this.data.activityId
  96. })
  97. console.log(activity);
  98. this.setData({
  99. activityUserList,
  100. myActivityUser,
  101. bannerList: activity.bannerList
  102. })
  103. },
  104. async getSelfReadRanking() {
  105. let list = await getSelfReadRanking({
  106. activityId: this.data.activityId
  107. })
  108. this.setData({
  109. list
  110. })
  111. },
  112. bannelEvent({
  113. target
  114. }) {
  115. wx.navigateTo({
  116. url: `/pages/reading/index?videoId=${target.dataset.id}&activityId=${this.data.activityId}&readingType=readMatch&autoPlay=true&free=${this.data.free}`
  117. })
  118. },
  119. jumpUserInfo({
  120. currentTarget
  121. }) {
  122. wx.navigateTo({
  123. url: `/pages/personal/index?uid=${currentTarget.dataset.uid}`,
  124. })
  125. },
  126. selectType({
  127. target
  128. }) {
  129. if (target.dataset.type) {
  130. let currentType = JSON.parse(target.dataset.type)
  131. if (!currentType) {
  132. this.getSelfReadRanking()
  133. }
  134. this.setData({
  135. currentType
  136. })
  137. }
  138. },
  139. jumpIntro({
  140. currentTarget
  141. }) {
  142. let iconDetail = currentTarget.dataset.icondetail
  143. if (iconDetail) {
  144. wx.navigateTo({
  145. url: `/pages/rankIntro/index?img=${iconDetail}`,
  146. })
  147. }
  148. },
  149. })