<template>
	<div class="resource-container">
		<!-- <BreadCrumb /> -->
		<div class="resource">
			<VideoDetails :isState="isState" ref="VideoDetailsRef" @onGetPageCommentNew="onGetPageCommentNew" />
			<TallList ref="tallList" v-show="!isState" />
		</div>
		<div class="btn-group" 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>
		<!-- <ResourceDetails v-if="indexType == 'resourceDetails'" ref="ResourceDetailsRef" /> -->
	</div>
</template>

<script setup>
	import VideoDetails from './components/VideoDetails.vue'
	import TallList from './components/TallList.vue'
	import { addViewCount, detail, add, queryList } from '@/api/portal'
	import resourceAuditApi from '@/api/resourceAudit.js'
	import { resourceAuditStore } from '@/store/resourceAudit'

	const auditStore = resourceAuditStore()
	const itemData = ref({})
	const tallList = ref(null)
	const VideoDetailsRef = ref(null)
	const emit = defineEmits(['auditComplete'])
	// 从store中获取参数，如果store中没有则从路由中获取
	const isState = ref(auditStore.auditParams.state || null)
	const isAudit = ref(auditStore.auditParams.audit || null)
	//     {
	//     "fileName": "Kettle文档",
	//     "courseType": "0",
	//     "courseTypeName": "必修",
	//     "collegeAllId": "1938796923484962817,1938796975385280513,1938797957397676033",
	//     "suffix": "doc",
	//     "collegeTwoId": "1938796975385280513",
	//     "verifyStatus": "2",
	//     "collegeThreeIdName": "维修部",
	//     "collegeThreeId": "1938797957397676033",
	//     "collegeId": "1938796923484962817",
	//     "resourceCreaterUserName": "超管",
	//     "coverImage": "",
	//     "coverImagePath": "",
	//     "fileUrl": "upload/20250626/a37672e03659d06fa618842c9c443910.doc",
	//     "courseIdName": "胸口碎大石2",
	//     "id": "1938857816211292161",
	//     "viewCount": 100,
	//     "courseId": "1937326992873689091",
	//     "collegeAllIdName": "汽车工程学院,汽车部门,维修部",
	//     "FILESIZE": 1105920,
	//     "majorId": "1",
	//     "uploadTime": "2025-06-26 18:32:18",
	//     "verifyStatusName": "已发布",
	//     "resourceDesc": "大东北，是我的家乡，唢呐吹出了美美滴模样",
	//     "collegeIdName": "汽车工程学院",
	//     "majorIdName": "草台班子",
	//     "collegeTwoIdName": "汽车部门",
	//     "fileId": "1938183534250917888"
	// }
	const onGetPageCommentNew = (item) => {
		// emit('handlerItemSidebar', item)
		tallList.value.onGetPageCommentNew(item)
	}
	const handleAuditResult = (val) => {
		// 优先从store中获取ID，如果没有则从路由中获取
		const id = auditStore.auditParams.id
		const params = {
			ids: id,
			verifyStatus: val
		}
		resourceAuditApi
			.updateStatus(params)
			.then((res) => {
				if (res.code == 200) {
					// 清空store中的审核参数
					auditStore.clearAuditParams()
					emit('auditComplete')
				}
			})
			.catch((err) => {
				console.error(err)
			})
	}

	const setData = (item) => {
		// emit('handlerItemSidebar', item)

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

					// VideoDetailsRef.value.setData(res.data)
				}
			})
			.catch((err) => {})
	}

	onMounted(() => {
		// 优先从store中获取ID，如果没有则从路由中获取
		const id = auditStore.auditParams.id
		if (id != undefined && id != '') {
			addViewCount({ id: id })
			getData({ id: id })
		}
	})
	defineExpose({
		setData
	})
</script>

<style lang="less" scoped>
	.resource-container {
		width: 100%;
		.resource {
			display: flex;
			justify-content: center;
			overflow: auto;
			width: 100%;
		}
		.btn-group {
			text-align: center;
			padding: 10px;
		}
	}
</style>
