<template>
	<view>
		<view class="list">
			<u-time-line>
				<u-time-line-item nodeTop="2" v-for="(item, index) in list" :key="index">
					<template v-slot:node>
						<view class="u-node" style="background: #19be6b;"><u-icon name="volume-up" color="#fff" :size="30"></u-icon></view>
					</template>
					<template v-slot:content>
						<view class="content" @click="detail(item)">
							<view class="title">{{ item.title }}</view>
							<view class="ck">点击查看活动内容</view>
							<view class="time">{{ item.createTime }}</view>
						</view>
					</template>
				</u-time-line-item>
			</u-time-line>
			<view class="loading"><u-loadmore :status="loadMore ? 'loading' : 'nomore'" /></view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			list: [],
			param: { pageNum: 1, pageSize: 10, type: 4 },
			loadMore: true
		};
	},
	onLoad() {
		this.getData();
	},
	methods: {
		//获取数据
		getData() {
			this.$http.request({
				url: this.$http.urls.getPageContent,
				data: this.param,
				loading: 'false',
				success: res => {
					this.loadMore = res.data.pages > this.param.pageNum ? true : false;
					res.data.rows.forEach(item => {
						this.list.push(item);
					});
				}
			});
		},
		//详情
		detail(item) {
			uni.navigateTo({ url: '/pages/government/detail?id=' + item.contentId });
		},
		//刷新数据
		refresh() {
			this.loadMore = true;
			this.param.pageNum = 1;
			this.list = [];
			this.getData();
		}
	},
	//下拉刷新
	onPullDownRefresh() {
		setTimeout(() => {
			uni.stopPullDownRefresh();
			this.refresh();
		}, 1000);
	},
	//上拉加载
	onReachBottom() {
		if (this.loadMore) {
			this.param.pageNum++;
			this.getData();
		}
	}
};
</script>

<style lang="scss">
.list {
	padding: 15px 20px 30px 20px;
	.u-node {
		width: 44rpx;
		height: 44rpx;
		border-radius: 100rpx;
		display: flex;
		justify-content: center;
		align-items: center;
	}
	.content {
		box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
		padding: 13px;
		border-radius: 5px;
	}
	.title {
		color: #333333;
		font-weight: bold;
		font-size: 17px;
	}
	.ck {
		color: $dar2;
		font-size: 13px;
		padding-top: 5px;
	}
	.time {
		font-size: 13px;
		padding-top: 5px;
		color: $dar2;
	}
}
</style>
