<template>
	<div class="noticebody">
		<div class="notice-item" @click="titleClick(item)"  v-for="(item,index) in list" :key="index" >
		 <el-badge v-if="item.is_read == 0" is-dot class="item">
		    <img class="logo" src="@/assets/notice.png" />
		  </el-badge>
			   <img class="logo"  v-else   src="@/assets/notice.png"/>
			<div class="msg">
				<label class="notices" >{{item.title}}</label>
				<label class="notices" >{{item.created_at}}</label>
			</div>
		</div>
	</div>
	<div v-if="list.length < 1"  style="display: flex;justify-content: center;">
			<label style="color: darkgray;"> 暂无新通知</label>
	</div>
	<el-dialog draggable v-model="centerDialogVisible" :title="notice.title" width="30%" center>
		<div class="flex flex-wrap break-all" v-html="notice.content"></div>
	  <template #footer>
	    <span class="dialog-footer">
	      <el-button @click="readNotice">我知道了</el-button>
	    </span>
	  </template>
	</el-dialog>
</template>

<script lang="ts" setup>
	import notice_img from "";
	import { ref } from 'vue'
	import { Bell } from '@element-plus/icons-vue';
	import router from '@/router';
	import { noticeListMine, noticeDetail, noticeRead } from '@/api/notice/index';
	const centerDialogVisible = ref(false)
	const notice = ref({})
	const list = ref({});
	const readNotice = () => {
		if(notice.value.id > 0){
			noticeRead(notice.value.id);
		}
	  centerDialogVisible.value = false
	}
	const getList = () => {
		noticeListMine({limit:3}).then(res => {
			list.value = res.data;
		})
	};
	const titleClick = (e) => {
	  noticeDetail(e.id).then(res => {
	    centerDialogVisible.value = true;
	    notice.value.id = res.data.id
	    notice.value.title = res.data.title
	    notice.value.content = res.data.content
	  })
	}
	const go2page = () =>{
		router.push({ path: "/notice/mynotice" });
	}
	onMounted(() => {
		getList();
	});
</script>

<style lang="scss" scoped>
	
	.msg{
		width: 100%;
		display: flex;
		justify-content: space-between;
		margin-right: 50px;
	}
	.header-title {
	  display: flex;
	  align-items: center;
	  justify-content:space-between;
	  h4{
		  margin-right: 50px;
		  color: #29d;;
	  }
	}
	.notice-item{
		display: flex;
		margin-top: 18px;
	}
	.notices{
		margin-left: 10px;
		line-height: 18px;;
	}
	.logo{
		width: 18px;
		height: 18px;
	}
	.notices{
		font-size: 18px;
		margin-left: 10px;
		line-height: 18px;;
	}
	.n-time-text{
		margin-top: 5px;
		font-size: 14px;
	}
</style>