<template>
	<a-card>
		<div style="width: 100%">
			<VideoDetails :isState="isState" ref="VideoDetailsRef" @onGetPageCommentNew="onGetPageCommentNew" />
			<TallList ref="tallList" v-show="!isState" />
			<div style="display: flex; justify-content: flex-end; margin-top: 10px" v-if="isAudit && isState">
				<a-button @click="handleAuditResult(3)" style="margin-right: 10px">不同意</a-button>
				<a-button type="primary" @click="handleAuditResult(2)">同意</a-button>
			</div>
		</div>
		<forumBtn :forumData="forumData"></forumBtn>
	</a-card>
</template>

<script setup>
	import Header from '@/views/portal/components/Header.vue'
	import BreadCrumb from '@/views/portal/components/BreadCrumb.vue'
	import Footer from '@/views/portal/components/Footer.vue'
	import VideoDetails from './components/VideoDetails.vue'
	import { useRoute, useRouter } from 'vue-router'
	import TallList from './components/TallList.vue'
	import { addViewCount, detail, add, queryList } from '@/api/portal'
	import resourceAuditApi from '@/api/resourceAudit.js'
	import EventBus from '@/utils/EventBus'
	import classCentre from '@/api/student/classCentre'

	const router = useRouter()

	const indexType = ref('resourceCenter')
	const itemData = ref({})
	const tallList = ref(null)
	const VideoDetailsRef = ref(null)
	const route = useRoute()
	const isState = ref(route.query.state || null)
	const isAudit = ref(route.query.audit || null)
	const onGetPageCommentNew = (item) => {
		tallList.value.onGetPageCommentNew(item)
	}
	const handleAuditResult = (val) => {
		const params = {
			ids: route.query.id,
			verifyStatus: val
		}
		resourceAuditApi
			.updateStatus(params)
			.then((res) => {
				if (res.code == 200) {
					// auditModalVisible.value = false
					router.go(-1)
				}
				// getListData()
			})
			.catch((err) => {
				console.error(err)
			})
	}
	const onChangeCurrent = (current) => {
		indexType.value = current

		router.push({
			path: '/' + current
		})
	}

	const setData = (item) => {
		getData(item)
	}
	const getData = (item) => {
		detail({ id: item.id })
			.then((res) => {
				if (res.code == 200) {
					itemData.value = res.data
					addFootprint()
				}
			})
			.catch((err) => {})
	}

	onMounted(() => {
		const id = route.query.id
		if (id != undefined && id != '') {
			addViewCount({ id: id })
			getData({ id: id })
		}
	})
	const addFootprint = () => {
		classCentre.footprintAdd({
			userFileId: route.query.id, //userfile文件id
			extendName: itemData.value.suffix, //扩展名
			fileId: itemData.value.fileId, //文件id
			fileName: itemData.value.fileName, //文件名称
			filePath: itemData.value.fileUrl, //文件路劲
			resourceRecordId: itemData.value.id //文件记录id
		})
	}
	const forumData = computed(() => {
		return {
			postType: 2,
			id: route.query.id,
			title: itemData.value.fileName ,
		}
	})
	defineExpose({
		setData
	})
</script>

<style scoped>
	.content {
		border: 1px solid #00000011; /* 灰色细边框 */
	}
	.scroll-container {
		height: 100vh;
		overflow-y: auto;
	}
</style>
