// index.js // 获取应用实例 const app = getApp() const $api = require('../../utils/api.js').API; Page({ data: { notices:[], tabs:['关注','热门股票','胜率榜','防守榜','冠军心得'], cur:0, date:'2021-11-09', followList:[], page:1, total: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.getHot() $api.getNotoice().then(res=>{ this.setData({ notices:res.data.data }) }) }, //关注分页 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 $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 }) }) .catch(err=>{ this.setData({ error:1 }) // console.log(err) }) }, getData(){ //胜率 $api.getRinrate().then(res=>{ this.setData({ winList:res.data.data.list }) }) //防守 $api.getDefend().then(res => { this.setData({ defendList: res.data.data.list }) }) //心得 $api.getChampionlList().then(res => { this.setData({ championList: res.data.data.list }) }) }, getHot(){ //热门 let stock_date = this.data.date $api.getHotbuyList({ stock_date: stock_date }).then(res => { this.setData({ hotbuyList: res.data.data.list }) }) $api.getHotsellList({ stock_date: stock_date }).then(res => { this.setData({ hotsellList: res.data.data.list }) }) }, 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 }) this.getHot() }, onShow: function () { if (this.data.error) { this.onLoad() } }, })