<template>
	<view class="xitong">
		<view class="item" v-for="(a,i) in list" :key="i" @click="toPage(a)">
			<view class="date">{{a.createTime}}</view>
			<view class="content">
				<view class="title">{{a.noticeTitle}}</view>
				<view class="desc" v-html="a.noticeContent"></view>
				<!-- <image mode="widthFix" v-if="i == 5" src="@/static/pic.jpg"></image> -->
			</view>
		</view>
		<view class="empty" v-if="total == 0">
			<image src="@/static/empty.png"></image>
			<view class="txt">暂无数据</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				total: 1,
				page: 1
			};
		},
		onLoad() {
			this.getList();
		},
		onReachBottom() {
			const that = this;
			uni.showLoading({
				title: "加载中"
			})
			if(that.list.length <= that.total){
				that.page ++;
				setTimeout(function() {
					that.getList(1);
				}, 1000);
			}
		},
		methods: {
			toPage(a) {
				uni.setStorageSync("pcontent",a);
				uni.navigateTo({
					url: "/pages/xiaoxi/detail"
				})
			},
			//数组对象去重
			arrayUnique (arr, name) {
				var hash = {};
				return arr.reduce(function (item, next) {
					hash[next[name]]
						? ""
						: (hash[next[name]] = true && item.push(next));
					return item;
				}, []);
			},
			async getList(type) {
				const {code,data} = await this.$api.systemNoticeList({
					userId: uni.getStorageSync("userInfo").id,
					limit: 20,
					page: this.page
				})
				if(type == 1){
					uni.hideLoading()
				}
				if(code == 200){
					this.isShow = data.total == 0?true:false;
					this.list = this.arrayUnique([...this.list,...data.list],"id");
				}
			}
		},
	}
</script>

<style scoped lang="scss">
.xitong{
	padding: 0 25rpx 25rpx;
	overflow: hidden;
	.item{
		margin-top: 30rpx;
		overflow: hidden;
		.date{
			text-align: center;
			font-weight: 500;
			font-size: 24rpx;
			color: #999999;
		}
		.content{
			background: #FFFFFF;
			border-radius: 20rpx;
			padding: 30rpx 30rpx;
			margin-top: 30rpx;
			.title{
				text-overflow: ellipsis;
				white-space: nowrap;
				overflow: hidden;
				font-weight: 500;
				font-size: 36rpx;
				color: #222222;
			}
			.desc{
				margin-top: 20rpx;
				font-weight: 500;
				font-size: 24rpx;
				color: #999999;
				line-height: 36rpx;
				word-break: break-all;
				text-overflow: ellipsis;
				overflow: hidden;
				display: -webkit-box;
				-webkit-box-orient: vertical;
				-webkit-line-clamp: 2; /* 这里是超出几行省略 */
			}
			image{
				width: 100%;
				margin-top: 30rpx;
				border-radius: 10rpx;
			}
		}
	}
}
</style>
