<template>
	<view v-if="data.info">
		<!-- 详情页面 -->
		<view>校园动态</view>
		<!-- 导航 -->
		<view>首页>校园动态>学院新闻</view>
		<!-- 标题 -->
		<view>{{data.info.title}}</view>
		<!-- 时间 -->
		<view>{{formatDate.join('-') }}</view>
		<!-- 富文本 -->
		<mp-html :content="data.info.content" />
		
		<!-- PDF -->
		<web-view
		      v-if="pdfUrl" 
		      :src="pdfUrl" 
		      class="web-view"
		    ></web-view>
	</view>
</template>

<script setup>
	import {
		ref,
		reactive,
		computed
	} from "vue";
	import {
		onLoad
	} from "@dcloudio/uni-app"
	import * as httpApi from "@/api/common.js"
	import mpHtml from 'mp-html/dist/uni-app/components/mp-html/mp-html'
	import {formatDateToYearMonthDay } from "@/utils/common.js"

	const data = reactive({
		info: null,
		id: null
	})

	const formatDate = computed(() => {
      if (data.info && data.info.createTime) {
		return formatDateToYearMonthDay(data.info.createTime)
      }
        return []
    })

	const pdfUrl = "https://kf3.mtavip.com/api/upload/resource/uploadFile60eebb8881e94278bc46bedba12aece6.pdf"

	onLoad(({
		id
	}) => {
		data.id = id;
		pageInit();
	})

	function pageInit() {
		httpApi.getDangjianGongzuoInfo({
			id: data.id
		}).then(res => {
			data.info = res.data;
			console.log('dddd', data.info)
		})
	}
</script>

<style lang="scss">
.web-view {
	height: 200px;
	margin-top: 20px
}
</style>