|
|
<template> <view> <lf-nav title="我的报名" :showIcon="true" bgColor="#fff" @changeHeight="e => nav_height = e"></lf-nav> <view v-if="tab_list.length"> <u-tabs :list="tab_list" active-color="#15716E" inactive-color='#777777' :is-scroll="true" :current="tab_current" @change="tabChange"></u-tabs> </view> <swiper :style="{height: autoHeight}" :current="tab_current" @change="swiperChange"> <swiper-item v-for="(tab, tabIndex) in tab_list" :key="tabIndex"> <scroll-view :style="{height: autoHeight}" :scroll-y="true" :refresher-enabled="true" :refresher-triggered="isRefresher" @scrolltolower="onScrolltolower" @refresherrefresh="onRefresherrefresh"> <view class="scroll-content"> <view class="card" v-for="(item, index) in tab.list" :key="index" @click="$url('/pages/user/my/myregister?activity_id='+item.activity_id)"> <view class="cover"> <image class="img" :src="item.activity.image"></image> <view class="label" :class="'theme-'+ (index+1)">{{item.state}}</view> </view> <view class="info"> <view class="title">{{item.name}}</view> <view class="date">{{item.created_at}}</view> </view> </view> <!-- 空数据的情况 --> <view class="loading-more"> <text v-if="tab.list.length" :class="{'loading-more-text': tab.loadingClass}">{{ tab.loadingText }}</text> <lf-nocontent v-else></lf-nocontent> </view> </view> <view style="height: 30rpx;"></view> </scroll-view> </swiper-item> </swiper> </view></template>
<script> export default { data(){ let _public = { page: 1, isPage: true, loadingClass: true, loadingText: '正在加载中' } return { tab_current: 0, tab_list: [{ name: '全部', state: '', list: [], ..._public },{ name: '待参加', state: '待使用', list: [], ..._public },{ name: '已参加', state: '已使用', list: [], ..._public },{ name: '已过期', state: '已过期', list: [], ..._public }], scrollH: 0, nav_height: 0, isRefresher: true, pageSize: 10 } }, computed: { autoHeight(){ return `calc(${this.scrollH}px - ${this.nav_height}px - 86rpx)`; } }, onLoad(){ let info = uni.getSystemInfoSync(); this.scrollH = info.screenHeight; this.getMyActivity() }, methods: { // 页面触底,加载下一页
onScrolltolower(){ let tab_item = this.tab_list[this.tab_current]; if(tab_item.isPage){ tab_item.page = tab_item.page + 1; this.getMyActivity(); } }, // 下拉刷新处理
refreshFn(options){ let tab_item = this.tab_list[this.tab_current]; tab_item.page = 1; tab_item.isPage = true; tab_item.loadingClass = true; tab_item.list = [] tab_item.loadingText = '正在加载中'; this.getMyActivity(options); }, // scroll-view 下拉刷新
onRefresherrefresh(){ this.isRefresher = true; this.refreshFn({type: 'scrollRefresh'}); }, tabChange(event){ this.tab_current = event; this.getMyActivity(); }, swiperChange(event){ this.tab_current = event.detail.current; if (event.detail.source == '') return; // 如果是被动出发,没有事件类型则不做处理
this.getMyActivity(); }, getMyActivity(options = {}) { let tab_item = this.tab_list[this.tab_current]; this.$http .get({ api: 'api/activity/my', data:{ state: tab_item.state, page: tab_item.page, page_size: this.pageSize }, header: { Authorization: `Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IjczYTViNTA1NDNlYmNmMjFkNmZiMGJlNzc0NmJmMDE4MDc3MTRkY2Y1MjBiMjM3MGQyZDAyYzQxMTlmMDU4ZTkwMTUxNDQwOTk4MjJhODFhIn0.eyJhdWQiOiIzIiwianRpIjoiNzNhNWI1MDU0M2ViY2YyMWQ2ZmIwYmU3NzQ2YmYwMTgwNzcxNGRjZjUyMGIyMzcwZDJkMDJjNDExOWYwNThlOTAxNTE0NDA5OTgyMmE4MWEiLCJpYXQiOjE2MzExNjk1MDIsIm5iZiI6MTYzMTE2OTUwMiwiZXhwIjoxNjYyNzA1NTAyLCJzdWIiOiIxIiwic2NvcGVzIjpbXX0.p0YoIC_bhOxIOugYxDQTOFIK9t2ORiHQq9H6JWzdByBJKWkFDBisKaXZJvzn1HdU5cjNQnHaBfWpG1Ed15cQlB2LdpXxxc38iaaGW2J6WhlLhVkehloii-TtlZTOeqNrpAHbSe5DRrmm_L07Llm9wr1T1A6pP3MhzdHiZ9d6748j3_cJjK4CJUl3WfYRTaozLFlI00OCW4zzGfgivSighjSFyhqMoHnQ2iSoeWdcJnYpXzXQdc5AXvXOt6eIIa7o2F6Ma1tUseTYVijEVfngdfd21JI1eH6tHrSqUItkQHAart9o74dJn9micI3WrN5yEBXgzemqWkQGV4QzFHLyd3wk-XvP1s2GhCeWlJZOQADzgzhLoxzFUbgM5xULWHp3yfpePGISlM4ZpBwTHcqQt1i_UkNX_zCxa3RYQbZFDfWW0-UPbvHw40t5BY6X7nTPMhPjPGnnPq18jyYBrWBbC9vBWs2o2IHAe5VlkHtmy_v5fymFJLfFzS784Nxp2qPJFWxI7IfrpNckHxohhs5LoieQivw2MyU2shFOUjgwe0xQgyg6UBg5PwNknGTTmzYdavCM4BiQ7moqOuoI15ccIEmc_uMiuLVEfDPlzejP9PQv6mj6IlkJ8HSu4KZU-LxKmtLnGeEwMjVAZBIhsOwzMkaMF1nZ70pgv2YYwBQyVVs` }, }) .then(res => { if (res.data.code == 200) { if (res.data.status) { let isPage = res.data.next_page_url == null?false:true; tab_item.isPage = isPage; if(!isPage) { tab_item.loadingClass = false; tab_item.loadingText = '没有更多数据啦~'; } if(options.type == 'pageRefresh') { uni.stopPullDownRefresh(); }else if(options.type == 'scrollRefresh') { this.isRefresher = false; } if(tab_item.page == 1) { tab_item.list = res.data.data.data; }else { tab_item.list.push(...res.data.data.data); } console.log('数组列表',tab_item.list) } else { wx.showModal({ content: res.data.message || '请下拉页面刷新重试', showCancel: false }); } } else { wx.showModal({ content: res.data.message || '请下拉页面刷新重试', showCancel: false }); } wx.hideLoading(); }) .catch(() => { wx.hideLoading(); wx.showModal({ content: '请求失败', showCancel: false }); }); } } }</script>
<style lang="scss" scoped="scoped"> .scroll-content{ width: 100%; display: flex; flex-wrap: wrap; justify-content: center; .card{ width: 686rpx; height: max-content; background-color: #FFFFFF; box-shadow: 1rpx 1rpx 6rpx 3rpx #e5e5e5; margin-top: 30rpx; border-radius: 20rpx; overflow: hidden; .cover{ width: 686rpx; height: 300rpx; position: relative; .img{ width: 100%; height: 100%; background-color: #EEEEEE; } .label{ position: absolute; top: 0; left: 0; width: 118rpx; height: 57rpx; border-radius: 20rpx 0rpx 20rpx 0rpx; text-align: center; line-height: 57rpx; color: #FFFFFF; font-size: 26rpx; } } .info{ width: 686rpx; height: max-content; padding: 20rpx 30rpx; box-sizing: border-box; .title{ font-size: 28rpx; color: #222222; font-weight: bold; } .date{ margin-top: 20rpx; font-size: 24rpx; color: #555555; } } } } .theme-1{ background-color: #15716E; } .theme-2{ background-color: #1789E4; } .theme-3{ background-color: #777777; } // tabs 样式修改
/deep/.u-scroll-box { display: flex; justify-content: center; align-items: center; border-bottom: 1rpx solid rgba(0, 0, 0, 0.1); } /deep/.u-scroll-box .u-tab-bar { background-color: #15716E!important; width: 80rpx!important; position: absolute; left: 0; bottom: -12rpx; } /deep/.special_tab .u-tabs .u-scroll-box .u-tab-bar { background-color: #15716E!important; width: 56rpx!important; position: absolute; height: 5rpx!important; left: 8rpx; bottom: -4rpx; } /deep/ .u-tab-item { font-size: 28rpx!important; }</style>
|