<template>
	<view class="informantion_mask">
		<view class="informantion_content" @tap.stop.prevent>
			<view class="informantion-title">
				<view>
					<view @click="showCloseempty" style="height: 10%;">
						<p class="informantion-title-p">公告</p>
					</view>
					<view v-if="showClose >2" class="close-btn uni-column">
						<uni-icons class="icon-gear" type="closeempty" size="30" style="z-index: 5;"
							@click="close"></uni-icons>
					</view>
				</view>
				<div v-html="message" class="informantion-title-span"></div>
				<!-- {{message}} -->
			</view>

		</view>
	</view>
</template>

<script setup>
	import {
		onMounted,
		ref,
		getCurrentInstance
	} from 'vue'
	import {
		onLoad,
		onReady,
		onUnload,
		onShow,
		onReachBottom,

	} from '@dcloudio/uni-app'

	import {
		store
	} from '@/store/index.js'
	const message = ref('')
	const showClose = ref(0)
	onMounted(() => {
		uni.hideLoading();
		const instance = getCurrentInstance().proxy
		const eventChannel = instance.getOpenerEventChannel();
		eventChannel.on('notification', function(data) {
			console.log('notification', data)
			if (data && data.data) {
				message.value = data.data.content;

			}
		})

	})


	function showCloseempty() {
		showClose.value += 1
	}

	function close() {
		store.isNotification = true
		let pages = getCurrentPages();
		let index = 0
		for (let i = pages.length - 1; i >= 0; i--) {

			if (pages[i].$page.fullPath != "/pages/notification/index") {

				index = pages.length - i - 1;
				break
			}
		}
		uni.navigateBack({
			delta: index
		});
		console.log(pages)
	}
</script>

<style lang="scss">
	page {
		width: 100%;
		height: 100%;
		background: rgba(0, 0, 0, 0.4);
	}

	.informantion_mask {
		width: 100%;
		height: 100%;
		display: flex;
		flex-direction: row;
		justify-content: center;
		align-items: center;
	}

	.informantion_content {
		width: 600rpx;
		height: 820rpx;
		// height: 70%;
		overflow: hidden;
		border-radius: 10rpx;
		background-color: white;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		padding-bottom: 20rpx;
	}

	.informantion-title-span {
		height: 82%;
		overflow: auto;
		margin-bottom: -20px;
	}

	.mask-header {
		height: 400rpx;
		position: relative;
		background-image: url('../../static/images/bj.png');
		background-repeat: no-repeat;
		background-size: cover;

		image {
			width: 40rpx;
			height: 40rpx;
			position: absolute;
			top: 20rpx;
			right: 20rpx;
		}
	}

	.close-btn {
		position: absolute;
		right: 24rpx;
		top: 24rpx;
		width: 40rpx;
		height: 40rpx;
		z-index: 1003;

		.close-btn-icon {
			width: 40rpx;
		}
	}

	.informantion-title {
		overflow: auto;
		text-align: center;
		padding: 0 40rpx;

		p {
			font-size: 35rpx;
			font-weight: bold;
			line-height: 80rpx;
		}

		span {
			color: #6C6C6C;
		}
	}

	.informantion-btn {
		height: 93rpx;
		width: 80%;
		margin: 0 auto;
	}
</style>