// pages/sphRank/index.js const app = getApp() Page({ data: { isShow: true, notice: '公告:“-”代表该视频号预估粉丝增量数据获取异常,对您造成的不便尽请谅解.', field_type: 7, buttonTop: wx.getMenuButtonBoundingClientRect().top, infoList: [], isIpx: app.data.systemInfo.isIpx ? true : false, //底部按钮适配Iphone X rankType:1, statusNavBarHeight:app.data.statusNavBarHeight, safeAreaTop:0,//距离上面的安全距离 authorTypeList:[{ id:'', top_label:'全部' }], authorType:{ id:'', top_label:'全部' }, authorTypeFlag:false, start_time:'', end_time:'', pagesize:20, cycleList:[ {value:0,label:'日榜'}, {value:1,label:'周榜'}, {value:2,label:'月榜'}, ], cycle:0, dayList:[app.func.getDay(-1,false),app.func.getDay(-2,false),app.func.getDay(-3,false),app.func.getDay(-4,false),app.func.getDay(-5,false),app.func.getDay(-6,false),app.func.getDay(-7,false)], weekList: [ {end_time:app.func.getDay(-1,false),start_time:app.func.getDay(-7,false)}, {end_time:app.func.getDay(-8,false),start_time:app.func.getDay(-15,false)}, {end_time:app.func.getDay(-16,false),start_time:app.func.getDay(-23,false)}, ], monthList:[ { name: app.func.getDay(-30,false) + ' 至 ' + app.func.getDay(-1,false), end_time: app.func.getDay(-1,false), start_time: app.func.getDay(-30,false), } ], timeList:[], fanInfoListTree:[], fanInfoList:[], isScroll:true, timeFlag:false, choiceType:1, containerScrollTop:0, loading:true, page:1, total:0, isHaveMoreData:true, loading:true, scrollTop:0, }, onLoad: function (options) { this.setData({ rankType: options&&options.type?options.type:1, field_type: this.data.rankType==1?7:9, safeAreaTop:app.data.safeAreaTop, }) if(this.data.cycle == 0){ this.setData({ start_time:this.data.dayList[0], end_time:this.data.dayList[0] }) } this.setTime() this.getAuthorType() this.eventInit() }, /** * 生命周期函数--监听页面显示 */ onShow: function () { this.setData({ rankType: app.data.sph_type?app.data.sph_type:this.data.rankType, field_type: this.data.rankType==1?7:9, }) if((this.data.rankType==1&&this.data.fanInfoList.length==0)||(this.data.rankType==2&&this.data.infoList.length==0)) { this.getAuthorType() this.eventInit() } }, switchShow() { this.setData({ isShow: false }) }, goScrolltop:function(e){//返回顶部 if (wx.pageScrollTo) { wx.pageScrollTo({ scrollTop: 0 }) } else { wx.showModal({ title: '提示', content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。' }) } }, setTime() { var timeList = this.data.dayList,start_time = ''; if(app.func.getDay(0,true).now.split(" ")[1].split(":")[0]<=8) { timeList = timeList.slice(1,timeList.length) start_time = app.func.getDay(-2,false) this.setData({ end_time: app.func.getDay(-2,false) }) } this.setData({ timeList:timeList, start_time: start_time?start_time:app.func.getDay(-1,false) }) }, eventInit(){ if(this.data.rankType==1){ this.fansIncrIndex(1) } if(this.data.rankType == 2){ this.goodVideoNumberList(1) } }, // 互动榜 goodVideoNumberList(page){ wx.showLoading({ title: '加载中', }) this.setData({ page:page, loading:true }) app.func.req('/api/sphUserList/goodVideoNumberList', 'get', { page:page, label_id:this.data.authorType.id, sort: 'like_divided_by_fans', date:this.data.start_time, page_size:this.data.pagesize, type:this.data.cycle }, (res) => { wx.hideLoading() this.setData({ loading:false }) wx.stopPullDownRefresh(); if(res && res.errno == 0){ //成功 if(page==1){ this.setData({ containerScrollTop:0, infoList:[], fanInfoListTree:[], total:0, }) } this.setData({ infoList:this.data.infoList.length==0?res.rst.data:(this.data.infoList.concat(res.rst.data)), }) this.setData({ fanInfoListTree:page==1?res.rst.data:this.data.fanInfoListTree, total:res.rst.pageInfo.total }) if(this.data.page*this.data.pagesize>=this.data.total){ this.setData({ isHaveMoreData:false }) }else{ this.setData({ isHaveMoreData:true }) } }else{ wx.showToast({ title: res.err, icon: 'none', duration: 2000 }) } },()=>{ wx.stopPullDownRefresh(); this.setData({ loading:false }) wx.hideLoading() }) }, fansIncrIndex(page){ wx.showLoading({ title: '加载中', }) this.setData({ page:page, loading:true }) app.func.req('/api/sphUserList/fansIncrIndex', 'get', { page:page, label_id:this.data.authorType.id, sort: 'fans_incr', start_time:this.data.start_time, end_time:this.data.end_time, page_size:this.data.pagesize, type:this.data.cycle }, (res) => { wx.stopPullDownRefresh(); wx.hideLoading() this.setData({ loading:false }) if(res && res.errno == 0){ //成功 if(page==1){ this.setData({ containerScrollTop:0, fanInfoList:[], fanInfoListTree:[], total:0, }) } this.setData({ fanInfoList:this.data.fanInfoList.length==0?res.rst.data:(this.data.fanInfoList.concat(res.rst.data)), }) this.setData({ fanInfoListTree:page==1?res.rst.data:this.data.fanInfoListTree, total:res.rst.pageInfo.total }) if(this.data.page*this.data.pagesize>=this.data.total){ this.setData({ isHaveMoreData:false }) }else{ this.setData({ isHaveMoreData:true }) } }else{ wx.showToast({ title: res.err, icon: 'none', duration: 2000 }) } },()=>{ wx.stopPullDownRefresh(); this.setData({ loading:false }) wx.hideLoading() }) }, getAuthorType(){//获取作者类别 app.func.req('/api/sphUserList/labelList', 'get', { }, (res) => { if(res && res.errno == 0){ var arr = [{ id:'', top_label:'全部' }] this.setData({ authorTypeList:arr.concat(res.rst) }) }else{ wx.showToast({ title: res.err, icon: 'none', duration: 2000 }) } },()=>{ }) }, cycleEvent(e){//点击日期类别筛选 var data = e.currentTarget.dataset; if(this.data.cycle != data.info.value){ if(data.info.value == 0){ this.setData({ timeList:this.data.dayList, start_time:this.data.dayList[0], end_time:this.data.dayList[0] }) this.setTime() } if(data.info.value == 1){ this.setData({ timeList:this.data.weekList, start_time:this.data.weekList[0].start_time, end_time:this.data.weekList[0].end_time }) } if(data.info.value == 2){ this.setData({ timeList:this.data.monthList, start_time:this.data.monthList[0].start_time, end_time:this.data.monthList[0].end_time }) } this.setData({ cycle: data.info.value }) this.goScrolltop() this.eventInit() } }, cycle_0_click(e){ var data = e.currentTarget.dataset if(this.data.start_time != data.info || this.data.end_time != data.info){ this.setData({ start_time:e.currentTarget.dataset.info, end_time:e.currentTarget.dataset.info }) this.goScrolltop() this.eventInit() } this.closeToast() }, cycle_1_click(e){ var data = e.currentTarget.dataset if(this.data.start_time != data.info.start_time || this.data.end_time != data.info.end_time){ this.setData({ start_time:e.currentTarget.dataset.info.start_time, end_time:e.currentTarget.dataset.info.end_time }) this.goScrolltop() this.eventInit() } this.closeToast() }, timeChoiceClick(e){ var data = e.currentTarget.dataset; if((this.data.choiceType == 2 && data.type == 2)||(this.data.choiceType != data.type && data.type == 2)){ this.setData({ authorTypeFlag: !this.data.authorTypeFlag, timeFlag:false }) } if((this.data.choiceType != data.type && data.type == 1) || (this.data.choiceType == 1 && data.type == 1)){ this.setData({ timeFlag: !this.data.timeFlag, authorTypeFlag:false }) } this.setData({ choiceType:data.type }) if(!this.data.timeFlag && !this.data.authorTypeFlag){ this.setData({ isScroll:true }) } if(this.data.timeFlag || this.data.authorTypeFlag){ this.setData({ isScroll:false }) } }, authorTypeClick(e){ var data = e.currentTarget.dataset; if(data.info.id != this.data.authorType.id){ this.setData({ authorType:data.info }) this.goScrolltop() this.eventInit() } this.closeToast() }, closeToast(){ this.setData({ authorTypeFlag:false, timeFlag: false, isScroll:true }) }, rankTypeClick(e){//头部榜单type this.setTime(); var data = e.currentTarget.dataset if(this.data.rankType == data.type){ return; } if(data.type==2){ this.setData({ field_type: 9, cycle:0, timeList:this.data.dayList, start_time:this.data.dayList[0], end_time:this.data.dayList[0] }) }else if(data.type==1) { this.setData({ field_type: 7 }) } this.setData({ rankType: data.type, fanInfoList: [] }) app.data.sph_type = this.data.rankType this.goScrolltop() this.eventInit() }, bindscrolltolower(){//滚动到底部 if(this.data.loading){ return; } if(this.data.page * this.data.pagesize < this.data.total){ this.setData({ page:this.data.page+1, isHaveMoreData:true }) if(this.data.rankType==1){ this.fansIncrIndex(this.data.page) } if(this.data.rankType == 2){ this.goodVideoNumberList(this.data.page) } }else{ this.setData({ isHaveMoreData:false }) } }, goSearch() { wx.navigateTo({ url: '/pages/search/search', }) }, followEvent(e){ var data = e.currentTarget.dataset; var Interface = '/api/sphUserConsole/createFollow' if(data.is_follow==1){ Interface = '/api/sphUserConsole/cancelFollow' } this.setData({ loading:true }) wx.showLoading({ title: '加载中', }) app.func.req(Interface, 'post', { uid:data.user_id }, (res) => { wx.hideLoading() this.setData({ loading:false }) if(res && res.errno == 0){ var info = this.data.fanInfoListTree,msg=''; if(Interface == '/api/sphUserConsole/cancelFollow'){ info[data.id].is_follow = 0; msg = '取消收藏成功!' }else{ msg = '收藏成功' info[data.id].is_follow = 1; } wx.showToast({ title:msg, icon: 'none', duration: 2000 }) this.setData({ fanInfoListTree:info }) }else{ wx.showToast({ title: res.err, icon: 'none', duration: 2000 }) } },()=>{ this.setData({ loading:false }) wx.hideLoading() }) }, toUserDetail(e){ wx.navigateTo({ url: '/pages/userDrtail/index?user_id='+e.currentTarget.dataset.user_id, }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { this.eventInit() }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { if(this.data.loading){ return; } if(this.data.page * this.data.pagesize < this.data.total){ this.setData({ page:this.data.page+1, isHaveMoreData:true }) if(this.data.rankType==1){ this.fansIncrIndex(this.data.page) } if(this.data.rankType == 2){ this.goodVideoNumberList(this.data.page) } }else{ this.setData({ isHaveMoreData:false }) } }, onPageScroll: function(res) {//获取滑动的距离 this.setData({ scrollTop:res.scrollTop }) }, goScrolltop:function(e){//返回顶部 if (wx.pageScrollTo) { wx.pageScrollTo({ scrollTop: 0 }) } else { wx.showModal({ title: '提示', content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。' }) } }, /** * 用户点击右上角分享 */ onShareAppMessage: function (res) { if(this.data.rankType==1) { return { title:'【免费】视频号分析平台,盘点不同分类下涨粉最快的视频号', } }else { return { title:'【免费】视频号分析平台,盘点不同分类下互动最好的视频号', } } } })