// index.js // 获取应用实例 const app = getApp() const $api = require('../../utils/api.js').API; const $push = require('../../utils/api.js').PUSH; Page({ data: { loading:0, notices:[], tabs:['今日留言','我的关注'], tabs1:['收益榜','盈利榜','亏损榜'], cur:0, cur1:0, date:'2022-04-27', explist:[], //留言 total1:0, page1:1, followList:[], //关注 total2:-1, page2:1, banners:[], winLost:{}, baikeList:[], articleList1:[], articleList2:[], articleList3:[], articleList4:[], groups:{}, role:0, match_day:0, }, onLoad() { wx.showNavigationBarLoading() wx.getStorage({ key: 'user', complete: res => { this.setData({ role: res.data.role, }) } }) $api.getDate().then(res=>{ this.setData({ date:res.data.data }) $api.getNotoice().then(res=>{ this.setData({ notices:res.data.data }) }) }) this.getFollow() this.getIndexData() this.getExp() }, fresh: function () { }, // 获取首页数据 getIndexData:function(){ $api.getChampionlList({isbanner:1}).then(res=>{ console.log(res) this.setData({ banners:res.data.data.list }) }) $api.getWinList({new:1}).then(res=>{ let day = res.data.data[0].valid_dates.indexOf(res.data.data[0].date) this.setData({ winLost:res.data.data[0], match_day:day, }) $api.getAvg({match_id:res.data.data[0].match_id}).then(res=>{ var week=['一','二','三','四','五','六','七','八','九','十','十一','十二','十三','十四','十五'] var days=res.data.data.list,weeks=[[]] days=days.reverse() week.forEach((item,index)=>{ weeks[index]={ name:'第'+item+'周', data:[], total:0 } }) var i=0 days.forEach(item=>{ var w=new Date(item.stock_date).getDay() item.day=w if(w==1){ i++ } weeks[i].data.push(item) }) weeks.forEach(item=>{ if(item.data.length>0){ var total=0 item.data.forEach(i=>{ var incom=Number(i.today_income.replace('%','')) total+=incom i.date=(new Date(i.stock_date).getMonth()+1)+'/'+(new Date(i.stock_date).getDate()) }) item.total=total.toFixed(2) } }) console.log(2333,days) this.setData({ days:weeks.reverse() }) }) $api.getWinLose({match_id:res.data.data[0].match_id}).then(res1=>{ this.setData({ groups:res1.data.data }) }) }) $api.getBaikeRandom().then(res=>{ this.setData({ baikeList:res.data.data }) }) $api.getChampionlList({category:'游资专场',page:1}).then(res=>{ this.setData({ articleList1:res.data.data.list }) }) $api.getChampionlList({category:'冠军交割',page:1}).then(res=>{ this.setData({ articleList2:res.data.data.list }) }) $api.getChampionlList({category:'牛人专场',page:1}).then(res=>{ this.setData({ articleList3:res.data.data.list }) }) $api.getChampionlList({category:'妖股列传',page:1}).then(res=>{ this.setData({ articleList4:res.data.data.list }) }) }, //获取今日留言 getExp:function(){ var list = this.data.explist $api.getExperience({page:this.data.page1,page_size:20}).then(res=>{ res.data.data.list.forEach(item => { list.push(item) }) this.setData({ explist: list, total1: res.data.data.total }) }) }, //留言分页 next1: function () { if (this.data.explist.length < this.data.total1) { const page = this.data.page1 + 1 this.setData({ page1: page }) this.getExp() } }, //我的关注 getFollow(){ var followList = this.data.followList if(this.data.loading){ followList=[] } $api.getMyFollowV3({ page: this.data.page2, page_size: 20 }).then(res => { wx.hideNavigationBarLoading() res.data.data.list.forEach(item => { followList.push(item) }) this.setData({ followList: followList, total2:res.data.data.total, error:0, loading: 0 }) app.globalData.follow = 0 }) .catch(err=>{ this.setData({ error:1 }) }) }, //关注分页 next2: function () { if (this.data.followList.length < this.data.total2) { const page = this.data.page2 + 1 this.setData({ page2: page }) this.getFollow() } }, tabChange(e){ this.setData({ cur:e.target.dataset.id }) this.renew() }, tabChange1(e){ this.setData({ cur1:e.target.dataset.id }) }, tapGroup(e){ wx.navigateTo({ url: '../avg/avg?index='+e.currentTarget.dataset.index + '&list=' + encodeURIComponent(JSON.stringify(this.data.groups.group_win_lose_list)), }) }, tapAvg(e){ wx.navigateTo({ url: '../avg/avg?index=0' + '&list=' + encodeURIComponent(JSON.stringify(this.data.groups.group_win_lose_list)), }) }, //预览 preview(e){ wx.previewImage({ urls: e.target.dataset.urls, current: e.target.dataset.src }) }, curChange(e){ if (e.detail.source == "touch"){ this.setData({ cur: e.detail.current }) this.renew() } }, curChange1(e){ if (e.detail.source == "touch"){ this.setData({ cur1: e.detail.current }) } }, renew(){ this.setData({ followList:[], explist:[], page1: 1, total1: 0, page2: 1, total2: -1 }) switch(this.data.cur){ case 0: this.data.page1 = 1 this.getExp() break; case 1: this.data.page2 = 1 this.getFollow() break; } }, pushToday(e){ $push.pushToday(e.currentTarget.dataset) }, onShow: function (e) { $api.initUser() $api.getsignup().then(res => { this.setData({ info: res.data.data }) }) if(this.data.cur == 0 && app.globalData.follow == 1){ this.data.loading = 1 this.data.page2 = 1 this.data.total2 = -1, this.getFollow() } }, })