<template>
	<view class="center">
		<view class="message">
			<view class="item" v-for="l in list" @click="look(l.cate_id)">
				<view class="img"><image :src="type.image" mode=""></image></view>
				<view class="right">
					<view class="top">
						<view class="title">{{ type.name }}</view>
						<view class="time">{{ l.add_time }}</view>
					</view>
					<view class="bottom">
						<view class="concent clamp2">{{ l.detail }}</view>
						<view class="icon" v-show="l.unwatch_message > 0"></view>
					</view>
				</view>
			</view>
			<uni-load-more :status="loadingType"></uni-load-more>
		</view>
	</view>
</template>

<script>
import { getTime } from '@/utils/rocessor.js';
import { message } from '@/api/finance.js';
import uniLoadMore from '@/uview-ui/components/u-loadmore/u-loadmore.vue';
export default {
	components: {
		uniLoadMore
	},
	data() {
		return {
			id: '',
			page: 1,
			limit: 10,
			list: [],
			type: {},
			loadingType: 'more'
		};
	},
	onLoad(option) {
		if (option.id) {
			this.id = option.id;
		}
		this.loadData();
	},
	//监听页面是否滚动到底部加载更多
	onReachBottom() {
		this.loadData();
	},
	methods: {
		loadData() {
			const obj = this;
			if (obj.loadingType == 'nomore' || obj.loadingType == 'loading') {
				return;
			}
			obj.loadingType == 'loading';
			message({ page: obj.page, limit: obj.limit }, obj.id).then(({ data }) => {
				console.log(data);
				if (obj.page == 1) {
					obj.type = data.cate;
				}
				data.list.forEach(e => {
					e.add_time = getTime(e.add_time);
				});
				obj.list = obj.list.concat(data.list);
				obj.page++;
				if (data.list.length == obj.limit) {
					obj.loadingType == 'more';
				} else {
					obj.loadingType == 'nomore';
				}
			});
		}
	}
};
</script>

<style lang="scss">
.center,
page {
	height: 100%;
	width: 100%;
	background: #f8f8f8;
}
.message {
	margin-top: 20rpx;
	font-family: PingFangSC-Medium;
	.item {
		background-color: #fff;
		display: flex;
		padding: 30rpx;
		width: 100%;
		border-bottom: solid 1rpx #f8f8f8;
		.img {
			margin: auto 0;
			width: 110rpx;
			margin-left: 0rpx;
			image {
				width: 80rpx;
				height: 80rpx;
			}
		}
		.right {
			width: calc(100% - 110rpx);
			display: grid;
			align-content: space-between;
			.top {
				display: flex;
				justify-content: space-between;
				.title {
					color: #000;
					font-size: 30rpx;
				}
				.time {
					color: #999999;
					font-size: 25rpx;
				}
			}
			.bottom {
				display: flex;
				justify-content: space-between;
				.concent {
					width: calc(100% - 30rpx);
					color: #999999;
					font-size: 26rpx;
				}
				.icon {
					margin: auto 0;
					width: 10rpx;
					height: 10rpx;
					background-color: #fb555c;
					border-radius: 50%;
				}
			}
		}
	}
}
</style>
