<template>
	<view class="container">
		<uni-list border-full v-for="(item,index) in noticeList" :key="index">
			<uni-list-item showArrow clickable :title="item.title" :note="item.createTime" :thumb="item.img"
				thumb-size="lg" @click="targetToDetail(item.id)" />
		</uni-list>
		<view class="ivOver" v-if="flag">-----已经到底啦-----</view>
	</view>
</template>

<script>
	import {
		getNoticeList
	} from '@/api/userInfo.js'
	export default {
		data() {
			return {
				noticeList: [],
				pageSize: 10,
				pageNum: 1,
				flag: false
			}
		},
		created() {
			this.getNoticeList();
		},
		// 下拉刷新
		onPullDownRefresh() {
			this.pageNum = 1
			this.noticeList = []
			this.getNoticeList()
			uni.stopPullDownRefresh()
		},
		// 上划加载更多
		onReachBottom() {
			if (this.noticeList.length > this.pageSize*this.pageNum-1) {
				this.flag = false;
				this.pageNum += 1
				this.getNoticeList();
			}else{
				this.flag = true;
			}
		},
		methods: {

			// 获取公告分页
			async getNoticeList() {
				const res = await getNoticeList({
					pageSize: this.pageSize,
					pageNum: this.pageNum,
				})
				//console.log('res', res)
				if (res.data.code === 200) {
					this.noticeList.push(...res.data.rows)
					//console.log('noticeList', this.noticeList)
				} else {
					uni.showModal({
						content: '公告列表加载失败！',
						showCancel: false
					});
				}
			},

			targetToDetail(id) {
				console.log('id', id)
				if (id) {
					uni.navigateTo({
						url: 'noticeDetail?id=' + id
					})
				}
			}
		},
	}
</script>

<style lang="scss">
	.ivOver{
		width: 100%;
		height:100rpx;
		line-height: 100rpx;
		text-align: center;
		background: #fff;
		font-size: 20rpx;
	}
</style>
