<template>
	<view class="dynamic-list">
		<view @click="toShowDetail(item.title,item.id)" class="dynamic-item" v-for="(item,index) in list" :key="index">
			<view class="item-left">
				<view class="ilo">
					<text class="item-title">
						<text class="item-top" v-if="item.top">{{ tip }}</text>
						{{ item.title }}
					</text>
				</view>
				<view class="ilt">
					<text class="item-content" decode>{{ getContent(item.text) }}</text>
				</view>
				<view class="ilth">
					<view class="ilth-left">
						<u-icon size="28rpx" name="eye" :label="item.view+' 人阅读'"></u-icon>
					</view>
					<view class="ilth-right">
						{{ getDate(item.createtime) }}
					</view>
				</view>
			</view>
			<view class="item-right">
				<image :src="getImg(item.photo)"></image>
			</view>
		</view>
	</view>
</template>

<script>
import configService from '../../../common/config.service';
export default {
	props:{
		list:{
			type: Array,
			default: []
		},
		tip:{
			type: String,
			default: '置顶'
		}
	},
	data() {
		return {};
	},
	methods: {
		// 将富文本内容中标签删除，提取文字部分作为内容展示
		getContent(content){
			const reg = /<[^>]+>/gi; //筛选标签
			return content?.split(reg)
			.filter(item => (item !== '')&&(item !== '\n')).join('');
		},
		toShowDetail(title,id){
			uni.navigateTo({
				url: `/pages/article/articleDetails?title=${title}&id=${id}`
			})
		},
		getImg(path){
			return encodeURI(configService.ip + path);
		},
		getDate(date){
			const showDate = new Date(date);
			return `${showDate.getFullYear()}-${showDate.getMonth()+1}-${showDate.getDate()}`;
		}
	}
}
</script>

<style scoped lang="scss">
.dynamic-list {
	margin-top: 30rpx;
	.dynamic-item{
		min-height: 190rpx;
		display: flex;
		justify-content: space-between;
		padding-bottom: 30rpx;
		margin-bottom: 30rpx;
		border-bottom: 3rpx solid #eeeeee;
		.item-left{
			width: 65%;
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			.ilo{
				color: #000;
				display: flex;
				align-items: center;
				.item-title{
					font-size: 34rpx;
					.item-top{
						color: #e5463d;
						font-size: 28rpx;
						padding: 4rpx;
						border: 2rpx solid #e5463d;
						margin-right: 12rpx;
						border-radius: 12rpx;
					}
				}
			}
			.ilt{
				color: #9b9b9b;
				font-size: 28rpx;
				overflow: hidden;
				white-space: nowrap;
				text-overflow: ellipsis;
				margin: 10rpx 0;
			}
			.ilth{
				color: #9b9b9b;
				display: flex;
				justify-content: space-between;
				align-items: flex-end;
				font-size: 28rpx;
			}
		}
		.item-right{
			// width: 25%;
			image{
				border-radius: 12rpx;
				width: 200rpx;
				height: 150rpx;
			}
		}
	}
}
</style>