<template>
	<view class="container">
		<view class="searchBox" :style="{ height: localHeight + 'px', paddingTop: top + 'px' }">
			<view class="searchBox_add">
				<u-icon bold color="#000" size="40" name="arrow-left" @click="back"></u-icon>
			</view>
		</view>


		<view class="Tit">{{ Info.title }}</view>
		<!-- <view class="subTit" v-if="Info.author || Info.publish_time">{{ Info.author }} {{ Info.publish_time }}</view>
		<view class="subTit" v-else>
			<text>发布时间：{{ new Date().toLocaleDateString() }}</text>
		</view> -->
		<view class="Con">
			<rich-text :nodes="Info.content"></rich-text>
		</view>

	</view>

</template>

<script>
import {
	picUrl,
	uniqueByField,
	menuButtonInfo
} from '../../../utils';

// 引入数据文件
import dataJson from '../index/data.json';

export default {
	data() {
		return {
			top: "",
			localHeight: "",
			id: "",
			Info: {},
			defaultNoticeList: dataJson.defaultNoticeList
		}
	},
	onLoad(options) {
		const meun = menuButtonInfo();
		this.top = meun.top;
		// this.top = meun.height + meun.top;
		this.localHeight = meun.height;
		this.id = options.id;
		this.getInfo();
	},


	methods: {
		// 获取公告详情
		getInfo() {
			console.log("🚀 ~ getInfo ~ this.defaultNoticeList:", this.defaultNoticeList)
			// 从本地数据中查找对应ID的内容
			const detailData = this.defaultNoticeList.find(item => item.id === Number(this.id));
			console.log("🚀 ~ getInfo ~ detailData:", detailData)
			if (detailData) {
				// 复制数据以避免修改原始数据
				const info = { ...detailData };
				// 将换行符转换为HTML的<br>标签，确保rich-text正确渲染换行
				if (info.content) {
					info.content = info.content.replace(/\n/g, '<br>');
				}
				this.Info = info;
			}
		},
		back() {
			uni.navigateBack({
				delta: 1
			});
		},
	},


}
</script>

<style>
@import url("./index.css");
</style>