|
|
<template> <view> <view class="lf-p-t-20 head" v-if="tab_list.length"> <u-tabs :list="tab_list" :is-scroll="true" :current="current" @change="tabChange"></u-tabs> </view> <swiper :style="{height: 'calc('+ windowHeight +'px - 60rpx)', width: '750rpx'}" :current="current" @change="swiperChange"> <swiper-item v-for="(tabItem, tabIndex) in tab_list" :key="tabIndex"> <scroll-view class="com" :scroll-y="true" :refresher-enabled="true" :refresher-triggered="tabItem.isRefresher" @scrolltolower="onScrolltolower" @refresherrefresh="onRefresherrefresh"> <view class="lf-m-t-20"></view> <lf-waterfall :list="tabItem.list"></lf-waterfall> <view class="loading-more lf-m-b-10"> <text :class="{'loading-more-text': tabItem.loadingClass}" v-if="tabItem.list.length">{{tabItem.loadingText}}</text> <lf-nocontent v-else></lf-nocontent> </view> </scroll-view> </swiper-item> </swiper> </view></template>
<script> export default { data(){ return { tab_list: [], current: 0, windowHeight: 0, } }, onLoad(){ this.windowHeight = getApp().globalData.windowHeight; this.getCategory() }, methods: { getCategory(options = {}) { this.$http(this.API.API_CATEGORYLIST).then(res => { let res_list = res.data || []; let tab_list = res_list.map(item => { return { id: item.id, name: item.name, list: [], isRefresher: false, loadingClass: true, loadingText: '正在加载中', page: 1, isPage: true } }); if(options.type == 'pageRefresh'){ uni.stopPullDownRefresh(); }else if(options.type == 'scrollRefresh'){ this.tab_list[this.current].isRefresher = false; } this.tab_list = tab_list; this.getData() }).catch(err => { }) }, getData() { let tab_item = this.tab_list[this.current]; if(this.$shared.isValueType(tab_item) == 'undefined') return; this.$http(this.API.API_ADVICELIST,{page: tab_item.page,category_id: tab_item.id}).then(res => { let isPage = res.data.next_page_url == null?false:true; tab_item.isPage = isPage; if(!isPage){ tab_item.loadingClass = false; tab_item.loadingText = '没有更多数据啦~'; } console.log('page',tab_item.page) if(tab_item.page == 1){ console.log('zhix1') tab_item.list = res.data.data; console.log('zhix1数据',tab_item.list) }else{ console.log('zhix2') tab_item.list.push(...res.data.data); console.log('zhix2数据',tab_item.list) } }).catch(err => { }) }, tabChange(index){ this.current = index; if(this.tab_list[index].list.length <= 0){ this.getData(); // tab下没有数据,请求第一页
} }, // 滑块下标值变化
swiperChange(event){ this.current = event.detail.current; if(event.detail.source == '') return; // 如果是被动出发,没有事件类型则不做处理
if(this.tab_list[event.detail.current].list.length <= 0){ this.getData(); // tab下没有数据,请求第一页
} }, // 页面触底,加载下一页
onScrolltolower(){ let tab_item = this.tab_list[this.current]; if(tab_item.isPage){ tab_item.page = tab_item.page + 1; this.getData(); } }, // scroll-view 下拉刷新
onRefresherrefresh(){ this.$u.throttle(() => { this.tab_list[this.current].isRefresher = true; this.getCategory({type: 'scrollRefresh'}); }, 200); }, // page 下拉刷新
onPullDownRefresh(){ // 新版逻辑,刷新则整个数据全部重新获取
this.getCategory({type: 'pageRefresh'}); }, } }</script>
<style> page{ background-color: #F6F6F6; }</style><style lang="scss" scoped="scoped"> .head{ background-color: #FFFFFF; } .com{ width: 100%; height: 100%; box-sizing: border-box; padding: 0rpx 32rpx; }</style>
|