123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571 |
- // 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:'【免费】视频号分析平台,盘点不同分类下互动最好的视频号',
- }
- }
- }
- })
|