123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- // parents//pages/ranking/ranking.js
- import { routers, viewImage, sharePage, isFn, getGlobalVal, formatDate, formatNumber} from '../../../utils/util.js'
- import { UserRankingLib, LibRankingHis } from '../../../utils/api.js'
- const { navigateTo, redirectTo, navigateBack } = routers()
- const { globalData, hasLibraryService, hasVipService } = getApp()
- const { baseImgUrl, qrcodeInvalidToastText } = globalData
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- baseImgUrl,
- isMonth:true,
- isLoaded: 1,
- content: '',
- hiddenModel:false,
- navIndex: 0,
- pageNo: 1,
- pageSize: 10,
- isAll: false,
- type:1,
- nodataArray: {
- text: '本月无排行榜数据',
- image: '../../../assets/nodata_1.png'
-
- }
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- options.vipId = getGlobalVal('vipId', `vipId_${getGlobalVal('userId')}`) || ''
- // options.vipId = 'ea4e93ee-8b22-41bd-bb09-ec36e88eab78'
- options.libId = getGlobalVal('library').id || ''
- this.setData({ options })
- this.getData(res => {
- this.setData({ isLoaded: 1 })
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- const obj = { navigateTo, redirectTo, navigateBack, viewImage }
- for (const i in obj) {
- this[i] = obj[i]
- }
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- this.setData({ pageNo: 1 })
- this.getData(res => {
- wx.stopPullDownRefresh()
- })
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- const { isAll } = this.data
- if (isAll) {
- return
- }
- this.getData()
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- if (isFn(sharePage)) return sharePage()
- },
- /**
- * 提示框隐藏
- */
- allShowModel: function () {
- this.setData({ hiddenModel: false })
- },
- /**
- * 提示框打开
- */
- showModel: function () {
- this.setData({ hiddenModel: true })
- },
- /**
- * 选择月度年度排行榜
- */
- selectMonth: function (e) {
- const {num}=e.currentTarget.dataset;
- this.setData({ type:num })
- this.getData()
- },
-
- /**
- * 获取馆内数据
- */
- getData: function (cb) {
- const continuousFn = { fn: this.getDataTwo, param: { ...arguments } }
- const { pageNo, pageSize, list, options,type } = this.data
- const { vipId, libId } = options
- wx.showLoading({
- title: '加载中',
- })
- UserRankingLib({ data: { vipId, libId, pageNo, pageSize,type }, continuousFn }).then(res => {
- const { rankingList, rankingVO,pages } = res.data.rankingInfo;
- wx.hideLoading()
- let arr = []
- if (pageNo == 1) {
- arr = [...rankingList]
- } else {
- arr = [...list, ...rankingList]
- }
- // console.log(rankingVO.childImg)
- this.setData({
- rankingVO,
- pages,
- list: arr,
- pageNo: rankingList.length == pageSize ? pageNo + 1 : pageNo,
- isAll: rankingList.length < pageSize,
- isLoaded: true
- })
- cb && cb()
- }).catch(res => {
- cb && cb()
- })
- },
- /**
- * 获取历史数据
- */
- getDataHistory: function (cb) {
- const continuousFn = { fn: this.getDataHistory, param: { ...arguments } }
- const { pageNo, pageSize, options,date} = this.data
- const { vipId, libId } = options
- LibRankingHis({ data: { vipId, libId, pageNo, pageSize, searchDate:date }, continuousFn }).then(res => {
- const listTemp = res.data.rankingList;
- const pages = res.data.pages
- let arr = []
- if (pageNo == 1) {
- arr = [...listTemp]
- } else {
- arr = [...list, ...listTemp]
- }
- this.setData({
- pages,
- list: arr,
- pageNo: listTemp.length == pageSize ? pageNo + 1 : pageNo,
- isAll: listTemp.length < pageSize,
- isLoaded: true
- })
- cb && cb()
- }).catch(res => {
- cb && cb()
- })
- },
- /**
- * 查看历史记录
- */
- selectHistory: function () {
- const { isMonth } = this.data
- const year = new Date().getFullYear()
- const month = new Date().getMonth()
- this.setData({ isMonth: !isMonth, pageNo: 1, list: [], date: year + '-' + formatNumber(month) })
- this.getDataHistory()
- },
- /**
- * 选择日期
- */
- changeDate:function(e){
- const {value}=e.detail;
- this.setData({ date:value})
- this.getDataHistory()
- }
- })
|