<template>
	<view class="center">
		<view class="massage" v-for="(item, index) in list" :key="index"
			@click="nav('/pages/index/artDetail?id=' + item.id)">
			<view class="title">{{ item.title }}</view>
			<view class="time">{{ item.add_time }}</view>
		</view>
		<uni-load-more :status="loadingType"></uni-load-more>
	</view>
</template>

<script>
	import {
		article
	} from '@/api/user.js';
	export default {
		data() {
			return {
				list: [],
				type: '',
				page: 1,
				limit: 10,
				loadingType: 'more',
			};
		},
		onLoad(opt) {
			let obj = this;
			obj.type = opt.id
			obj.loadData()
		},
		onReachBottom() {
			this.loadData()
		},
		methods: {
			nav(url) {
				uni.navigateTo({
					url
				});
			},
			loadData() {
				let obj = this
				if (obj.loadingType === 'loading' || obj.loadingType === 'noMore') {
					//防止重复加载
					return;
				}
				obj.loadingType = 'loading'
				article({
					page: obj.page,
					limit: obj.limit
				}, this.type).then(({
					data
				}) => {
					obj.list = obj.list.concat(data);
					obj.page++
					if (data.length == obj.limit) {
						obj.loadingType = 'more';
					} else {
						obj.loadingType = 'noMore';
					}
				});
			}
		}
	};
</script>

<style lang="less">
	.center {
		background: #f3f3f3;
	}

	.massage {
		background: #ffffff;
		padding: 30rpx;
		border-bottom: 1px solid #e9e9e9;

		.title {
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #333333;
		}

		.time {
			margin-top: 18rpx;
			font-size: 20rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #999999;
		}
	}
</style>