<template>
	<view class="list">
		<view class="item" v-for="(item, index) in list" :key="index" @click="detail(item.id)">
			<view class="time">
				<text>{{ item.createTime.substring(0, 11) }}</text>
				<text class="views">{{ item.views }}人看过</text>
			</view>
			<image :src="ip + item.pic"></image>
			<view class="title">【{{ item.title }}】</view>
			<view class="desc">{{ item.descs }}...</view>
		</view>
		<view class="loading" v-show="showLoadMore"><u-loading></u-loading></view>
		<u-empty class="noData" text="没有数据" :show="list.length == 0"></u-empty>
	</view>
</template>

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

<style lang="scss">
.list {
	padding: 0px 10px 30px 10px;
	.item {
		background-color: white;
		margin-top: 15px;
		border-radius: 7px;
		padding: 15px;
		image {
			width: 100%;
			height: 170px !important;
			border-radius: 7px;
		}
		.time {
			color: #818184;
			padding-bottom: 12px;
			font-size: 13px;
			.views {
				padding-left: 20px;
			}
		}
		.title {
			padding-top: 8px;
			font-size: 16px;
			color: #252525;
		}
		.desc {
			padding-top: 8px;
			font-size: 13px;
			color: #827d7d;
		}
	}
}
</style>
