ranking.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. // parents//pages/ranking/ranking.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal, formatDate, formatNumber} from '../../../utils/util.js'
  3. import { UserRankingLib, LibRankingHis } from '../../../utils/api.js'
  4. const { navigateTo, redirectTo, navigateBack } = routers()
  5. const { globalData, hasLibraryService, hasVipService } = getApp()
  6. const { baseImgUrl, qrcodeInvalidToastText } = globalData
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. baseImgUrl,
  13. isMonth:true,
  14. isLoaded: 1,
  15. content: '',
  16. hiddenModel:false,
  17. navIndex: 0,
  18. pageNo: 1,
  19. pageSize: 10,
  20. isAll: false,
  21. type:1,
  22. nodataArray: {
  23. text: '本月无排行榜数据',
  24. image: '../../../assets/nodata_1.png'
  25. }
  26. },
  27. /**
  28. * 生命周期函数--监听页面加载
  29. */
  30. onLoad: function (options) {
  31. options.vipId = getGlobalVal('vipId', `vipId_${getGlobalVal('userId')}`) || ''
  32. // options.vipId = 'ea4e93ee-8b22-41bd-bb09-ec36e88eab78'
  33. options.libId = getGlobalVal('library').id || ''
  34. this.setData({ options })
  35. this.getData(res => {
  36. this.setData({ isLoaded: 1 })
  37. })
  38. },
  39. /**
  40. * 生命周期函数--监听页面初次渲染完成
  41. */
  42. onReady: function () {
  43. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  44. for (const i in obj) {
  45. this[i] = obj[i]
  46. }
  47. },
  48. /**
  49. * 生命周期函数--监听页面显示
  50. */
  51. onShow: function () {
  52. },
  53. /**
  54. * 生命周期函数--监听页面隐藏
  55. */
  56. onHide: function () {
  57. },
  58. /**
  59. * 生命周期函数--监听页面卸载
  60. */
  61. onUnload: function () {
  62. },
  63. /**
  64. * 页面相关事件处理函数--监听用户下拉动作
  65. */
  66. onPullDownRefresh: function () {
  67. this.setData({ pageNo: 1 })
  68. this.getData(res => {
  69. wx.stopPullDownRefresh()
  70. })
  71. },
  72. /**
  73. * 页面上拉触底事件的处理函数
  74. */
  75. onReachBottom: function () {
  76. const { isAll } = this.data
  77. if (isAll) {
  78. return
  79. }
  80. this.getData()
  81. },
  82. /**
  83. * 用户点击右上角分享
  84. */
  85. onShareAppMessage: function () {
  86. if (isFn(sharePage)) return sharePage()
  87. },
  88. /**
  89. * 提示框隐藏
  90. */
  91. allShowModel: function () {
  92. this.setData({ hiddenModel: false })
  93. },
  94. /**
  95. * 提示框打开
  96. */
  97. showModel: function () {
  98. this.setData({ hiddenModel: true })
  99. },
  100. /**
  101. * 选择月度年度排行榜
  102. */
  103. selectMonth: function (e) {
  104. const {num}=e.currentTarget.dataset;
  105. this.setData({ type:num })
  106. this.getData()
  107. },
  108. /**
  109. * 获取馆内数据
  110. */
  111. getData: function (cb) {
  112. const continuousFn = { fn: this.getDataTwo, param: { ...arguments } }
  113. const { pageNo, pageSize, list, options,type } = this.data
  114. const { vipId, libId } = options
  115. wx.showLoading({
  116. title: '加载中',
  117. })
  118. UserRankingLib({ data: { vipId, libId, pageNo, pageSize,type }, continuousFn }).then(res => {
  119. const { rankingList, rankingVO,pages } = res.data.rankingInfo;
  120. wx.hideLoading()
  121. let arr = []
  122. if (pageNo == 1) {
  123. arr = [...rankingList]
  124. } else {
  125. arr = [...list, ...rankingList]
  126. }
  127. // console.log(rankingVO.childImg)
  128. this.setData({
  129. rankingVO,
  130. pages,
  131. list: arr,
  132. pageNo: rankingList.length == pageSize ? pageNo + 1 : pageNo,
  133. isAll: rankingList.length < pageSize,
  134. isLoaded: true
  135. })
  136. cb && cb()
  137. }).catch(res => {
  138. cb && cb()
  139. })
  140. },
  141. /**
  142. * 获取历史数据
  143. */
  144. getDataHistory: function (cb) {
  145. const continuousFn = { fn: this.getDataHistory, param: { ...arguments } }
  146. const { pageNo, pageSize, options,date} = this.data
  147. const { vipId, libId } = options
  148. LibRankingHis({ data: { vipId, libId, pageNo, pageSize, searchDate:date }, continuousFn }).then(res => {
  149. const listTemp = res.data.rankingList;
  150. const pages = res.data.pages
  151. let arr = []
  152. if (pageNo == 1) {
  153. arr = [...listTemp]
  154. } else {
  155. arr = [...list, ...listTemp]
  156. }
  157. this.setData({
  158. pages,
  159. list: arr,
  160. pageNo: listTemp.length == pageSize ? pageNo + 1 : pageNo,
  161. isAll: listTemp.length < pageSize,
  162. isLoaded: true
  163. })
  164. cb && cb()
  165. }).catch(res => {
  166. cb && cb()
  167. })
  168. },
  169. /**
  170. * 查看历史记录
  171. */
  172. selectHistory: function () {
  173. const { isMonth } = this.data
  174. const year = new Date().getFullYear()
  175. const month = new Date().getMonth()
  176. this.setData({ isMonth: !isMonth, pageNo: 1, list: [], date: year + '-' + formatNumber(month) })
  177. this.getDataHistory()
  178. },
  179. /**
  180. * 选择日期
  181. */
  182. changeDate:function(e){
  183. const {value}=e.detail;
  184. this.setData({ date:value})
  185. this.getDataHistory()
  186. }
  187. })