<template>
	<view class="container club clearfix">
		<view class="club-main">
			<view v-if="isEmpty" class="empty-container">
				<image class="club-empty-image" src="https://img.caimei365.com/group1/M00/03/71/Cmis2F3wna6AY2ZjAABpmnBICH4247.png" mode="aspectFit"></image>
				<view class="txt">暂无公告~</view>
			</view>
			<view v-else class="club-list">
				<scroll-view scroll-y="true">
					<view class="list" v-for="(item, index) in clubList" :key="index" @tap='detail(item)'>
						<view class="list-left">
							<text class="iconfont icon-xiaochengxu"></text>
							<text class="txt">{{item.name == null ? item.username : item.name}}</text>
						</view>
						<view class="list-right">2022年03月07日</view>
					</view>
					<!--加载loadding-->
					<tui-loadmore :visible="loadding" :index="3" type="black"></tui-loadmore>
					<tui-nomore :visible="!pullUpOn" :backgroundColor="'#ffffff'" :text='nomoreText'></tui-nomore>
					<!--加载loadding-->
				</scroll-view>
			</view>
		</view>
	</view>
</template>

<script>
	import authorize from '@/common/config/authorize.js'	
	import tuiLoadmore from '@/components/tui-components/loadmore/loadmore'
	import tuiNomore from '@/components/tui-components/nomore/nomore'
	export default {
		components:{
			tuiLoadmore,
			tuiNomore,
		},
		data() {
			return {
				serviceProviderId:'',
				isShowClose:false,
				searchInputVal:'',
				isEmpty:false,
				listQuery:{
					searchWord:'',
					pageNum:1,
					pageSize:20,
				},
				nomoreText: '上拉显示更多',
				hasNextPage:false,
				loadding: false,
				pullUpOn: true,
				pullFlag: true,
				allowDataStatus:true,
				wrapperHeight:'100%',
				scrollHeight:'',
				deleteAddressId:'',
				currPage:'',//当前页面
				prevPage:'',//上一个页面
				tabCurrentIndex:0,
				listStatus:1,
				clubList:[],
				isIphoneX:this.$store.state.isIphoneX,
				show_index:0,//控制显示那个组件
			}
		},
		onLoad(){				
			this.setScrollHeight()
		},
		methods: {
			setScrollHeight() {
				// 窗口高度 - 底部距离
				setTimeout(()=> {
					const query = wx.createSelectorQuery().in(this)
					query.selectAll('.add-btn').boundingClientRect()
					query.exec(res => {
						if(res[0][0]){
							let winHeight = this.$api.getWindowHeight(),
								eleTop = res[0][0].top - 1
								this.scrollHeight =  eleTop
						}
					})
				}, 500)
			},
			searchClubList(){
				this.listQuery.pageNum=1
				this.GetFindAllClubList()
			},
			GetFindAllClubList(){	
				this.SellerService.GetFindAllClubList(this.listQuery).then(response =>{
					let responseData = response.data
					if(responseData.list&&responseData.list.length > 0){
						this.isEmpty = false
						this.hasNextPage = response.data.hasNextPage
						this.clubList =responseData.list
						this.pullFlag = false
						setTimeout(()=>{this.pullFlag = true},500)
						if(this.hasNextPage){
							this.pullUpOn = false
							this.nomoreText = '上拉显示更多'
						}else{
							this.pullUpOn = true
							this.loadding = false
							this.nomoreText = '已至底部'
						}
					}else{
						this.isEmpty = true
					}
				}).catch(error =>{
					this.$util.msg(error.msg,2000)
				})
			},	
			getOnReachBottomData(){
				this.listQuery.pageNum+=1
				this.SellerService.GetFindAllClubList(this.listQuery).then(response =>{
					let responseData = response.data
					if(responseData.list&&responseData.list.length > 0){
						this.hasNextPage = response.data.hasNextPage
						this.clubList = this.clubList.concat(responseData.list) 
						this.pullFlag = false// 防上拉暴滑
						setTimeout(()=>{this.pullFlag = true},500)
						if(this.hasNextPage){
							this.pullUpOn = false
							this.nomoreText = '上拉显示更多'
						}else{
							this.pullUpOn = false
							this.loadding = false
							this.nomoreText = '已至底部'
						}
					}
				}).catch(error =>{
					this.$util.msg(error.msg,2000)
				})
			},
			detail(item){// 跳转公告详情
				this.$api.navigateTo(`/pages/service/news-detailes?id=${item.id}`)
			},
		},
		onReachBottom() {
			if(this.hasNextPage){
				this.loadding = true
				this.pullUpOn = true
				this.getOnReachBottomData()
			}	
		},
		onPullDownRefresh() {
			setTimeout(() => {
				this.listQuery.pageNum = 1
				this.GetFindAllClubList()
				uni.stopPullDownRefresh()
			}, 200)
		},
		onShow() {
			this.$api.getStorage().then(response =>{
				this.serviceProviderId = response.serviceProviderId
				this.GetFindAllClubList()
			})
		}
	}
</script>

<style lang='scss'>
	page {
		height: auto;
	}
	page,.container{
		/* padding-bottom: 120upx; */
		background: #FFFFFF;
	}
	.container{
		position: relative;
	}
	.club-main{
		width: 100%;
		height: auto;
		box-sizing: border-box;
		padding: 0 24rpx;
		.list{
			display: flex;
			align-items: center;
			width: 100%;
			height: 100rpx;
			line-height: 100rpx;
			background: #FFFFFF;
			position: relative;
			border-bottom: 1px solid #EBEBEB;
			.list-left{
				display: flex;
				flex: 8;
				.icon-xiaochengxu{
					font-size: $font-size-22;
					color: #999999;
					margin-right: 10rpx;
				}
				.txt{
					display: flex;
					flex: 1;
					font-size: $font-size-26;
					color: $text-color;
					text-overflow: ellipsis;
					overflow: hidden;
					display: -webkit-box;
					-webkit-line-clamp: 1;
					line-clamp: 1;
					-webkit-box-orient: vertical;
				}
			}
			.list-right{
				font-size: $font-size-24;
				color: #999999;
				text-align: right;
			}
		}
	}
</style>

