ranking.js 4.6 KB

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