// index.js // 获取应用实例 const app = getApp() const $api = require('../../utils/api.js').API; Page({ data: { loading:0, notices:[], tabs:['关注','热门股票','胜率榜','防守榜','冠军心得'], cur:0, date:'2021-11-09', followList:[], defendList:[], winList:[], page:1, total:0, page1: 1, total1: 0, page2: 1, total2: 0, error:0 }, onLoad() { var y = new Date().getFullYear(), m = (new Date().getMonth() + 1), d = new Date().getDate(); m = m > 9 ? m : '0' + m; d = d > 9 ? d : '0' + d; this.setData({ date: y + '-' + m + '-' + d }) this.getFollow() this.getData() this.getWin() this.getDefen() $api.getNotoice().then(res=>{ this.setData({ notices:res.data.data }) }) }, fresh: function () { console.log(233) this.setData({ page:1, total:0, loading:1 }) this.getFollow() }, //关注分页 next: function () { if (this.data.followList.length < this.data.total) { const page = this.data.page + 1 this.setData({ page: page }) this.getFollow() } }, getFollow(){ var followList = this.data.followList if(this.data.loading){ followList=[] } $api.getMyFollow({ page: this.data.page, page_size: 20 }).then(res => { res.data.data.list.forEach(item=>{ followList.push(item) }) this.setData({ followList: followList, total:res.data.data.total, error:0, loading: 0 }) }) .catch(err=>{ this.setData({ error:1 }) // console.log(err) }) }, //胜率分页 next1: function () { if (this.data.winList.length < this.data.total1) { const page = this.data.page1 + 1 this.setData({ page1: page }) this.getWin() } }, getWin() { var winList = this.data.winList $api.getRinrate({ page: this.data.page1, page_size: 20 }).then(res => { res.data.data.list.forEach(item => { winList.push(item) }) this.setData({ winList: winList, total1: res.data.data.total }) }) }, //防守分页 next2: function () { if (this.data.defendList.length < this.data.total2) { const page = this.data.page2 + 1 this.setData({ page2: page }) this.getDefen() } }, getDefen() { var defendList = this.data.defendList $api.getDefend({ page: this.data.page1, page_size: 20 }).then(res => { res.data.data.list.forEach(item => { defendList.push(item) }) this.setData({ defendList: defendList, total2: res.data.data.total }) }) }, getData(){ //心得 $api.getChampionlList().then(res => { this.setData({ championList: res.data.data.list }) }) $api.getDate().then(res=>{ this.setData({ date:res.data.data }) this.getHot() }) }, getHot(){ //热门 let stock_date = this.data.date $api.getHotbuyList({ stock_date: stock_date }).then(res => { wx.hideNavigationBarLoading() this.setData({ hotbuyList: res.data.data.list }) }) $api.getHotsellList({ stock_date: stock_date }).then(res => { this.setData({ hotsellList: res.data.data.list }) wx.hideNavigationBarLoading() }) }, tabChange(e){ this.setData({ cur:e.target.dataset.id }) }, //预览 preview(e){ console.log(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 }) } }, //热门股票 bindDateChange(e){ this.setData({ date:e.detail.value }) wx.showNavigationBarLoading() this.getHot() }, onShow: function () { if (this.data.error) { this.onLoad() } }, })