<!-- 平台公告 -->
<template>
	<view class="platform">
		<navbar :config="config"></navbar>
		<div class="zhan" :style="{ top: top + 'px' }"></div>
				<scroll-view :style="{height:height+'px'}" :scroll-y="true"  @scrolltolower="getMoreList" :refresher-triggered="pullDownBool"  :refresher-enabled="true" @refresherrefresh="getpulling">
					<view class="background">
						<view class="item-list">
					<view v-if="itemList.length>=0">
					<view class="item" v-for="(item,index) in itemList" :key="item.id">
						<view class="content">
							{{item.detail}}
						</view>
						<view class="time">
							{{item.noticeTime.slice(0,10).replace(/-/g,"/")}}
						</view>
						
					</view>
					<loadMore v-if="itemList.length>0" :status="status" ></loadMore>
					<nodata v-else :config="{top:20,content:'暂无公告~'}"></nodata>
					</view>
					</view>
					</view>
				</scroll-view>
				

			
	</view>
</template>

<script>
	let app = getApp()
	import  {notice} from "../../../api/notice.js"
	export default{
		data(){
			return{
				config: {
					back: true, //false是tolbar页面 是则不写
					title: '平台公告',
					color: '#fff',
					//背景颜色;参数一：透明度（0-1）;参数二：背景颜色（array则为线性渐变，string为单色背景）
					backgroundColor: [1, "#0B844A"],
					statusBarFontColor: '#ffffff'
				},
				itemList:[],
				page:1,
				limit:10,
				status:"more",
				height: 0,
				pullDownBool: false,
				top: 0
			}
		},
		onReady() {
			let that = this
			uni.getSystemInfo({
				success: (res) => {
					that.height = res.windowHeight - res.statusBarHeight - 44;
				},
				
			});
		},
		//下拉刷新
		// onPullDownRefresh() {
		// 	this.page=1
		// 	this.itemList = []
		// 	this.getList()
		// },
		//上拉加载
		// onReachBottom() {
		// 	if(this.status=="more"){
		// 		this.page++
		// 		this.getList()
		// 	}
		
		// },
	

		onLoad(){
			this.top = app.globalData.barHeight + 44
			this.getList()
		},
		methods:{
			// // 上拉更多
			getMoreList(){
				if(this.status=="more"){
					this.page++
					this.getList()
				}
			},
			// 下拉刷新
			getpulling() {
				if (!this.pullDownBool) {
					this.pullDownBool = true;
					this.page=1
					this.itemList = []
					this.getList()
				}
			},
			//获取数据
			getList(){
				this.$http.get(notice,{
					page:this.page,
					limit:this.limit,		
				}).then(res=>{
					if(res&&res.code==200){
						uni.stopPullDownRefresh()
						this.itemList=this.itemList.concat(res.page.list)
						if(res.page.totalPage<=res.page.currPage){
							this.status="noMore";
						}else{
							this.status="more"
						}
						this.pullDownBool = false;
					}
				})
			}
		},
	}
</script>

<style lang="scss" scoped>
	.zhan {
		background-color: #0B844A;
		position: fixed;
		width: 100%;
		height: 20px;
	}
	.background{
		// background-color: #0B844A;
		.item-list{
			background: #ffffff;
			border-radius: 40rpx 40rpx 0 0;
			padding: 1rpx 48rpx 32rpx 30rpx;
			.item{
				border-bottom: 1rpx solid #e6e6e6;
				margin-top: 30rpx;
			
				.content{
					color: #1a1a1a;
					line-height: 38rpx;
					font-weight: 400;
					font-size: 28rpx;
				}
				.time{
					color: #999999;
					line-height: 30rpx;
					font-weight: 400;
					font-size: 28rpx;
					margin-top: 12rpx;
					margin-bottom: 32rpx;
					
				}
			}
		}
		
	}
</style>
