<template>
	<div>
		<common @asynCallBack="asynCallBack"></common>
		<top-header :pageTitle="pageTitle"></top-header>

		<div class="mui-content">
			<div class="vongi-notice">
				<div class="mui-h3">
					{{detail.title}}
					<h6 v-text="detail.createTime"></h6>
				</div>
				<p v-html="detail.content"></p>
			</div>
			<div v-if="noticeList.length" class="vongi-notice-list">
				<h3><img src="~$project/assets/img/text.png" width="12" />相关内容</h3>
				<div class="vongi-floor-padded">
					<a @click="getDetail(item.messageId)" v-for="(item,index) in noticeList" :key="index" class="mui-ellipsis" v-text="item.title"></a>
				</div>
			</div>
		</div>

		<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 {
		mapGetters,
		mapMutations
	} from 'vuex'
	export default {
		name: 'CommonNoticeInfo',
		components: {
			Common,
			Loading,
			TopHeader
		},
		data() {
			return {
				pageTitle: '消息详情',

				isLoading: false,

				id: '',
				detail: [],

				noticeList: [],
			}
		},
		created() {
			this.id = this.$route.query.id ? this.$route.query.id : '';
		},
		methods: {
			//获取详情
			getDetail(id) {
				this.id = id || this.id;
				this.isLoading = true;
				API_Notice.getMessageInfo(this.id).then(response => {

					this.detail = response;
                    this.$nextTick(()=>{
                        var list =document.getElementsByClassName("vongi-notice")[0].getElementsByTagName("img");
                        for(var i=0;i<list.length;i++){
                            list[i].style='width: 100%;height: 100%;'
                        }
                    })
					this.isLoading = false;
					//获取最新5条通知消息
					this.getLastNotice();
				}).catch(error => {
					this.isLoading = false;
					mui.toast(error);
				})
			},
			//获取最新5条通知消息
			getLastNotice() {
				this.isLoading = true;
				API_Notice.getTopList({
					type: this.detail.type,
					limit: 5,
					excludeMessageId: this.id
				}).then(response => {
					this.noticeList = response;
					this.isLoading = false;
				}).catch(error => {
					this.isLoading = false;
					mui.toast(error);
				})
			},
			asynCallBack() {

			},
		},
		mounted() {
			//获取详情
			this.getDetail();
		},
		destroyed() {},
		computed: {
			...mapGetters({
				openId: 'wx_openid',
				token: 'token',
			})
		},
	}
</script>

<style scoped src="$project/assets/css/xpwyfyy.css"></style>
<style scoped>
</style>
