<template>
	<div>
		<common @asynCallBack="asynCallBack"></common>
		<top-header :pageTitle="pageTitle" headerClass="vongi-bar" :leftShow="false"></top-header>

		<div class="mui-content margin49">
			<ul class="mui-table-view vongi-news">
				<li class="mui-table-view-cell mui-media">
					<router-link :to="{name:'CommonNotice',query:{type:noticeInfo.type}}">
						<img class="mui-media-object mui-pull-left" src="~$project/assets/img/bell1.png">
						<div class="mui-media-body">
							<h3 class="flew-sp">{{noticeInfo.name}}<span class="mui-h6" v-text="noticeInfo.message?noticeInfo.message.date:''"></span></h3>
							<p class='mui-ellipsis' v-text="noticeInfo.message?noticeInfo.message.title:''"></p>
						</div>
						<span v-if="noticeInfo.total" class="mui-badge mui-badge-danger" v-text="noticeInfo.total"></span>
					</router-link>
				</li>
			</ul>
			<ul class="mui-table-view vongi-news">
				<li v-for="(item,index) in messageList" class="mui-table-view-cell mui-media">
					<router-link :to="{name:'CommonNotice',query:{type:item.type}}">
						<img class="mui-media-object mui-pull-left" src="~$project/assets/img/kaoqin1.png">
						<div class="mui-media-body">
							<h3 class="flew-sp">{{item.name}}<span class="mui-h6" v-text="item.message?item.message.date:''"></span></h3>
							<p class='mui-ellipsis' v-text="item.message?item.message.title:''"></p>
						</div>
						<span v-if="item.total" class="mui-badge mui-badge-danger" v-text="item.total"></span>
					</router-link>
				</li>
			</ul>
		</div>

		<nav-menu :router="[{name:'Master'},{name:'MasterMineMessage'},{name:'MasterMineCenter'}]"></nav-menu>

		<loading :visible="isLoading"></loading>
	</div>
</template>

<script>
	import * as API_Notice from '@/apis/Common/notice'
	import Common from '$project/components/Common.vue'
	import Loading from '$project/components/Loading.vue'
	import TopHeader from '$project/components/TopHeader.vue'
	import NavMenu from '@/components/NavMenu.vue'
	import {
		mapGetters,
		mapMutations
	} from 'vuex'
	export default {
		name: 'MasterMineMessage',
		components: {
			Common,
			Loading,
			TopHeader,
			NavMenu
		},
		data() {
			return {
				pageTitle: '消息',

				isLoading: false,

				noticeInfo: {
					message: {}
				},
				messageList: [],
			}
		},
		created() {
			//如果不存在则跳转到注册页面
			if (!this.person_data) {
				window.location.href = '../home/#/user/login'
			}
		},
		methods: {
			//获取消息分组
			getGroupList() {
				this.isLoading = true;
				API_Notice.getGroupList().then(response => {
					this.noticeInfo = response[0];
					this.messageList = response.slice(1)
					this.isLoading = false;
				}).catch(error => {
					this.isLoading = false;
					mui.toast(error);
				})
			},
			asynCallBack() {},
		},
		mounted() {
			//获取分组通知消息
			this.getGroupList();
		},
		destroyed() {

		},
		computed: {
			...mapGetters({
				openId: 'wx_openid',
				token: 'token',
				person_data: 'person_data',
				person_popedom: 'person_popedom',
			})
		}
	}
</script>

<style scoped src="$project/assets/css/pension.css"></style>
<style scoped src="$project/assets/css/xpgj.css"></style>
<style src="$project/assets/css/iconfont.css"></style>
<style scoped>
</style>
