<template>
	<view class="center">
		<empty v-if="loaded === true && list.length === 0"></empty>
		<view class="message">
			<view class="item" v-for="l in list" @click="look(l.cate_id)">
				<view class="img"><image :src="l.image" mode=""></image></view>
				<view class="right">
					<view class="top">
						<view class="title">{{ l.name }}</view>
						<view class="time">{{ l.last_message.add_time }}</view>
					</view>
					<view class="bottom">
						<view class="concent clamp2">{{ l.last_message.detail }}</view>
						<view class="icon" v-show="l.unwatch_message > 0"></view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import { getTime } from '@/utils/rocessor.js';
import { messageList } from '@/api/finance.js';
import uniLoadMore from '@/uview-ui/components/u-loadmore/u-loadmore.vue';
import empty from '@/uview-ui/components/u-empty/u-empty.vue';
export default {
	data() {
		return {
			list: [],
			loaded: false
		};
	},
	components: {
		empty,
		uniLoadMore
	},
	onLoad() {
		this.loadData();
	},
	methods: {
		loadData() {
			uni.showLoading({
				title: '加载中'
			});
			messageList({ page: 1, limit: 10 }).then(({ data }) => {
				this.list = data;
				data.forEach(e => {
					e.last_message.add_time = getTime(e.last_message.add_time);
				});
				uni.hideLoading();
				this.loaded = true;
			});
		},
		look(id) {
			uni.navigateTo({
				url: './messageDetail?id=' + id
			});
		}
	}
};
</script>

<style lang="scss">
.center,
page {
	height: 100%;
	width: 100%;
	background: #f8f8f8;
}
.message {
	margin-top: 20rpx;
	font-family: PingFangSC-Medium;
	background-color: #fff;
	.item {
		display: flex;
		padding: 30rpx 0;
		margin: 0 30rpx;
		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>
