<template>
	<view class="list">
		<view class="item" v-for="(item, index) in list" :key="index" @click="go('/pages/notice/detail?id=' + item.id)">
			<view class="title omit">
				<text class="icon" v-if="item.top === 1">&#xe61f;</text>
				<text>{{ item.title }}</text>
			</view>
			<view class="desc">
				<text>发布于 {{ item.createTime }}</text>
			</view>
		</view>
		<view class="loading" v-if="loadMore"><u-loadmore :status="loadMore ? 'loading' : 'nomore'" /></view>
		<u-empty v-if="!loadMore && list.length == 0"></u-empty>
	</view>
</template>

<script>
export default {
	data() {
		return {
			list: [],
			param: { pageNum: 1, pageSize: 10, type: '小程序通知' },
			loadMore: true
		};
	},
	onLoad(e) {
		this.getData();
	},
	methods: {
		getData() {
			this.http.request({
				url: '/app/notice/list',
				data: this.param,
				loading: 'false',
				success: (res) => {
					this.loadMore = res.data.pages > this.param.pageNum ? true : false;
					res.data.rows.forEach((item) => {
						item.createTime = uni.$u.timeFrom(Date.parse(item.createTime));
						this.list.push(item);
					});
				}
			});
		},
		go(url) {
			uni.navigateTo({ url: url });
		},
		//刷新数据
		refresh() {
			this.loadMore = true;
			this.param.pageNum = 1;
			this.list = [];
			this.getData();
		}
	},
	//下拉刷新
	onPullDownRefresh() {
		setTimeout(() => {
			this.refresh();
			uni.stopPullDownRefresh();
		}, 1000);
	},
	//上拉加载
	onReachBottom() {
		if (this.loadMore) {
			this.param.pageNum++;
			this.getData();
		}
	}
};
</script>

<style lang="scss">
.list {
	padding: 5px 12px 12px 12px;
	.item {
		background-color: white;
		border-radius: 5px;
		padding: 12px;
		margin-bottom: 10px;
		.title {
			font-size: 15px;
			font-weight: bold;
			.icon {
				color: orangered;
				padding-right: 3px;
			}
		}
		.desc {
			font-size: 14px;
			color: $font-c;
			padding-top: 7px;
			text {
				padding-right: 20px;
			}
		}
	}
}
</style>
