<scroll-view scroll-y="true" scroll-top="{{curScrollTop}}" class="nav_scroll" style="height: {{scrollHeight}}px" bindscrolltolower="loadMore" bindscroll="scroll">
<block wx:for="{{raiTabs}}" wx:key="raiTab.id" wx:for-item="raiTab" wx:for-index="index"></block> </scroll-view>
var app = getApp()
var api = require( '../../utils/api.js' )
var action = require( './../../utils/action.js' )
Page({
data: {
curNavId: 1,
articles: [],
raiTabs: [],
indexs: 0,
type: "" ,
alias: "" ,
anShow: true ,
scrollTop: [],
scrollHeight:0,
loading: [],
noMore: false ,
pageNum: 0,
page: 0,
params: {},
curScrollTop: 0
},
onLoad: function (){
wx.showToast({
title: '加载中' ,
icon: 'loading' ,
duration: 10000
})
let tabsUrl = 'store/strategy/tabs?cityId=310100&addr=1' ;
api.fetchGet(tabsUrl, { 'r' : 'article' }).then(res => {
var that = this
that.setData({
raiTabs : res.data.items,
alias : res.data.items.alias,
type : res.data.items.type
})
that.data.type = res.data.items[0].type
that.data.alias = res.data.items[0].alias
let scrollTop = []
let loading = []
for (let i = 0; i < this .data.raiTabs.length; i++) {
scrollTop.push(0)
loading.push( false )
wx.removeStorage({
key: 'strategyData' + i,
success: function (res) {
}
})
wx.removeStorage({
key: 'strategyPage' + i,
success: function (resp) {
}
})
}
this .setData({
scrollTop: scrollTop
})
this .getData()
})
},
onShow () {
wx.getSystemInfo( {
success: ( res ) => {
let top = 84 * res.windowWidth / 750
this .setData({
scrollHeight: res.windowHeight - top
})
}
})
},
getData: function () {
var that = this
var num = this .data.indexs
if (that.data.type == 'collection' ){
let collectionUrl = 'store/strategy/collection?limit=20&addr=1'
api.fetchGet(collectionUrl,{
page: that.data.pageNum,
alias: that.data.alias,
type: that.data.type,
r: 'article'
}).then(res => {
wx.hideToast()
if (res.data.items.length === 0) {
this .setData({
noMore: true
})
wx.showToast({
title: '已加载全部' ,
icon: 'loading'
})
}
that.data.pageNum++
that.data.articles = that.data.articles.concat(res.data.items)
let lArr = this .data.loading
lArr[num] = false
this .setData({
loading: lArr,
page: that.data.pageNum,
articles : that.data.articles
})
wx.setStorage({
key: 'strategyData' + that.data.indexs,
data:that.data.articles
})
wx.setStorage({
key: 'strategyPage' + that.data.indexs,
data:that.data.pageNum
})
})
}
},
switchTab (e) {
if ( this .data.indexs == e.currentTarget.dataset.index){ return }
for (let key in this .data.loading) {
this .data.loading[key] = false
}
var n = e.currentTarget.dataset.index;
let id = e.currentTarget.dataset.id;
var rName = e.currentTarget.dataset.alias;
var rType = e.currentTarget.dataset.type;
this .setData({
pageNum: 0,
articles: [],
alias: rName,
type: rType,
indexs: n
})
let lArr = this .data.loading
lArr[n] = true
this .setData({
loading: lArr,
noMore: false
})
var pageValue = wx.getStorageSync( 'strategyPage' + this .data.indexs)
var dataValue = wx.getStorageSync( 'strategyData' + this .data.indexs)
if (pageValue.length !== 0 || dataValue.length !== 0){
let lArr = this .data.loading
lArr[n] = false
this .setData({
loading: lArr,
noMore: false
})
this .setData({
articles: dataValue,
pageNum: pageValue
})
var scrollTopNumber = this .data.scrollTop[n]
setTimeout(() => {
this .setData({
curScrollTop: scrollTopNumber
})
})
} else {
this .getData()
}
},
scroll (event) {
if ( this .data.noMore|| this .data.loading[ this .data.indexs]) return
this .setData({
curScrollTop: event.detail.scrollTop
})
console.log(event.detail)
},
navigateDetail: function (e){
let uri = e.currentTarget.dataset.uri
action.uriAction(uri)
},
clickURI (e) {
let uri = e.currentTarget.dataset.uri
action.uriAction(uri)
},
loadMore: function (e) {
if ( this .data.noMore|| this .data.loading[ this .data.indexs]) return
let lArr = this .data.loading
lArr[ this .data.indexs] = true
this .setData({
loading: lArr
})
wx.showToast({
title: '加载中' ,
icon: 'loading'
})
this .getData()
}
})
|