<template>
	<view class="container">
		<view class="top">
			<view class="iconfont icon-youjiantou" @click="goBack()">
			</view>
			<view style="width: 33%;text-align: right;">
				消息列表
			</view>
			<view class="clear" @click="oneKeyRead()">
				<text class="iconfont icon-weibiaoti544"></text>
				<text>清除未读</text>	
			</view>
		</view>
		<view class="content" v-if="system_msgs_list">
			<view class="announcement_wrapper" v-for="(item,index) in system_msgs_list" :key="index"
			@click="goToDetail(item.id)">
				<text class="iconfont icon-zizhutuiguang"></text>
				<view class="announcement_content">
					<view class="announcement_title">
						<text class="title" v-if="item.title">{{(item.title).substring(0,8)}}...</text> 
						<text class="title" v-if="!item.title">暂无标题</text>
						<text class="date">{{item.createdAt}}</text>
						<text class="readed" :class="{dot:item.isRead == 0}"></text>
					</view>
					<view class="announcement_des">
						{{matchReg(item.context).substring(0,15)}}...
					</view>
				</view>
			</view>
		</view>
		<view class="content" v-if="!system_msgs_list">
			<view style="text-align: center;">暂无消息</view>
		</view>
	</view>
</template>

<script>
	import api from '../../api/api';
	export default{
		data(){
			return{
				system_msgs_list:null,
			}
		},
		onLoad(){
			this.querySystemMessage();
		},
		methods:{
			querySystemMessage() {
			   api.querySystemMessage({systemType:1,userId:2}).then(res => {
			     if (res['success']) {
			       this.system_msgs_list = res['data']['dataList'];
			     }else{
					 this.system_msgs_list = null
				 }
			   });
			},
			matchReg(str){
			    let reg=/<\/?.+?\/?>/g;
			    return str.replace(reg,'');
			},
			goToDetail(id){
				uni.navigateTo({
					url:`../systemMsg/system_msg_detail?id=${id}`
				})
			},
			goBack(){
				uni.navigateTo({
					url:'../index/index'
				})
			},
			oneKeyRead(){
				api.oneKeyRead({systemType:1,userId:2}).then((res)=>{
					if(res['success']){
						uni.showToast({
							title: '已清除所有未读信息',
							duration: 2000,
							icon: 'none'
						})
						this.querySystemMessage();
					}else{
						uni.showToast({
							title: res['message'],
							duration: 2000,
							icon: 'none'
						})
					}
				})
			}
		}
	}
	
</script>

<style lang="scss">
	.top{
		display: flex;
		height: 100rpx;
		justify-content: space-between;
		align-items: center;
		position: relative;
		background: #fff;
		padding-right: 20rpx;
		.icon-youjiantou{
			display: inline-block;
			transform: rotate(180deg);
			font-size: 30rpx;
			width: 50rpx;
			height: 50rpx;
			z-index: 1;
		}
		.clear{
			display: flex;
			align-items: center;
			.icon-weibiaoti544{
				color: #5359cd;
				font-size: 50rpx;
			}
			text:nth-child(2){
				color: #999999;
				font-size: 20rpx;
			}
		}
		
	}
	.content{
		padding: 20rpx;
		.announcement_wrapper{
			display: flex;
			margin-bottom: 20rpx;
			background: #fff;
			align-items: center;
			flex-wrap: wrap;
			padding: 20rpx 10rpx;
			.icon-zizhutuiguang{
				color: #5359cd;
				background: #eff3ff;
				font-size: 40rpx;
				width: 70rpx;
				height:70rpx ;
				line-height: 70rpx;
				text-align: center;
				border-radius: 50%;
				margin-right: 30rpx;
			}
			.announcement_content{
				width:85%;
				.announcement_title{
					display: flex;
					justify-content: space-between;
					margin-bottom: 20rpx;
					padding-top: 20rpx;
					.title{
						font-size: 40rpx;
					}
					.date{
						color: #999999;
						font-size: 28rpx;
					}
					.readed{
						width: 20rpx;
						height: 20rpx;
						border-radius: 50%;
					}
					.dot{
						background: #EF6C40;
					}
				}
				.announcement_des{
					margin: 20rpx 0;
					color: #666666;
					font-size: 32rpx;
				}
			}
			.to_detail{
				display: flex;
				align-items: center;
				justify-content: space-between;
				color: #666666;
				font-size: 20rpx;
				margin-left: 100rpx;
				width: 100%;
				padding: 20rpx 0;
				border-top: 2rpx #F2F2F2 solid;
			}
		}
		
	}
</style>