<template>
	<div class="page-box">
		<div class="page-top">
			<div class="head-box">
				<div class="head-icon">
					<img :src="codeInfo.sortImageUrl || Img337" alt="" />
				</div>
				<div class="head-info">
					<div class="head-name one-line-ellipsis">{{ baseInfo.SEARCHNAME }}</div>
					<div class="head-text">{{ baseInfo.SEARCHDATE }}</div>
				</div>
				<div :class="`item-tag tag-${codeInfo.sortCode}`">{{ codeInfo.sortName }}</div>
			</div>
			<div class="page-tabs">
				<div :class="['tab-item', {'tab-active': activeName==1}]" @click="handleClickBtn(1)">
					<div class="icon">
						<img :src="activeName==2 ? NavIcon1Active : NavIcon1" alt="" />
					</div>
					<div class="text" :class="{ textActive: activeName==1 }">调查概况</div>
				</div>
				<div :class="['tab-item', {'tab-active': activeName==2}]" @click="handleClickBtn(2)" v-if="codeInfo.sortCode==337 || codeInfo.sortCode==232">
					<div class="icon">
						<img :src="activeName==2 ? NavIcon3Active : NavIcon3" alt="" />
					</div>
					<div class="text" :class="{ textActive: activeName==2 }">{{ codeInfo.sortCode==337 ? '影响分析' : '报告解析' }}</div>
				</div>

				<div style="width:20px; flex:auto;"></div>
				<div class="head-button" @click="handleAnalysisClick()">
					<div class="button-icon">
						<img src="./assets/images/btn-icon2.png" alt="" />
					</div>
					<div class="button-text">{{ "分析报告" }}</div>
				</div>
			</div>
		</div>
		<div class="main">
			<router-view />
		</div>
	</div>
</template>

<script setup>
import { ref, onMounted, reactive } from "vue";
import { ElMessage } from "element-plus";

import { getSurvyInfo, getSearchBlurb } from "@/api/marketAccessRestrictions/index.js"
import router from "@/router";
import NavIcon1 from "./assets/images/nav-icon1.png";
import NavIcon1Active from "./assets/images/nav-icon1-active.png";
import NavIcon3 from "./assets/images/nav-icon2.png";
import NavIcon3Active from "./assets/images/nav-icon2-active.png";
import Img337 from "./assets/images/337.png";

import { useRoute } from "vue-router";
const route = useRoute();

const activeName = ref(1);
const handleClickBtn = index => {
	activeName.value = index;
	router.push({
		path: ['', "/marketSingleCaseLayout/overview", "/marketSingleCaseLayout/deepdig"][index],
		query: { ...route.query }
	});
};

// 分析报告
const handleAnalysisClick = () => {
	ElMessage.warning("当前功能正在开发中，敬请期待！");
	// router.push({
	// 	path: "/writtingAsstaint",
	// 	query: {
	// 		topic: "市场准入限制",
	// 		fileId: route.query.id
	// 	}
	// });
};

const codeInfo = reactive({
	sortCode: route.query.id,
	sortName: "",
	sortImageUrl: "",
})
const onSurvyInfo = async () => {
	const res = await getSurvyInfo({sortCode: route.query.id})
	console.log("调查分类信息", res)
	if (res.code == 200) {
		Object.assign(codeInfo, res.data)
	}
}

const baseInfo = reactive({
	SEARCHNAME: "调查详情",
	SEARCHDATE: "",
})
const onSearchBlurb = async () => {
	const res = await getSearchBlurb({sortCode: route.query.id, searchId: route.query.searchId})
	console.log("调查简介", res)
	if (res.code == 200) {
		baseInfo.SEARCHNAME = res.data.SEARCHNAME
		baseInfo.SEARCHDATE = res.data.SEARCHDATE
	}
	document.title = baseInfo.SEARCHNAME;
}

onMounted(() => {
	onSurvyInfo()
	onSearchBlurb()
	if (route.path === "/marketSingleCaseLayout/overview") {
		activeName.value = 1;
	} else {
		activeName.value = 2;
	}
});
</script>

<style lang="scss" scoped>
.page-box {
	width: 100%;
	height: 100%;
	overflow-y: auto;
	background: rgba(255, 255, 255, 1);
	.page-top {
		width: 1600px;
		margin: 0 auto;
		box-sizing: border-box;
		.head-box {
			width: 100%;
			display: flex;
			padding: 30px 0 20px;
			.head-icon {
				width: 54px;
				height: 54px;
				font-size: 0px;
				margin-right: 16px;
				img {
					width: 100%;
					height: 100%;
				}
			}
			.head-info {
				width: 20px;
				flex: auto;
				.head-name {
					width: 100%;
					height: 26px;
					color: rgba(59, 65, 75, 1);
					font-family: Microsoft YaHei;
					font-size: 20px;
					font-weight: bold;
					line-height: 26px;
				}
				.head-text {
					margin-top: 4px;
					width: 100%;
					height: 24px;
					color: rgba(95, 101, 108, 1);
					font-family: Microsoft YaHei;
					font-size: 16px;
					font-weight: 400;
					line-height: 24px;
				}
			}
			.item-tag {
        height: 24px;
        line-height: 24px;
        padding: 0 8px;
        border-radius: 4px;
        font-weight: bold;
        font-size: 16px;
				letter-spacing: 2px;
      }
      .tag-337 {
        border: 1px solid #91caff;
        background: #e6f4ff;
        color: #055fc2;
      }
      .tag-232 {
        border: 1px solid #b37feb;
        background: #f9f0ff;
        color: #722ed1;
      }
      .tag-301 {
        border: 1px solid #ffd591;
        background: #fff7e6;
        color: #fa8c16;
      }
			.head-button {
				margin-left: 100px;
				width: 120px;
				height: 36px;
				border-radius: 6px;
				background: var(--color-main-active);
				display: flex;
				justify-content: center;
				align-items: center;
				cursor: pointer;
				.button-icon {
					width: 16px;
					height: 16px;
					font-size: 0;
					img {
						width: 100%;
						height: 100%;
					}
				}
				.button-text {
					margin-left: 8px;
					color: rgba(255, 255, 255, 1);
					font-family: Microsoft YaHei;
					font-size: 16px;
					font-weight: 400;
				}
			}
		}
		.page-tabs {
			display: flex;
			align-items: flex-start;
			.tab-item {
				height: 40px;
				display: flex;
				align-items: center;
				gap: 4px;
				cursor: pointer;
				margin-right: 24px;
				.icon {
					width: 16px;
					height: 16px;
					font-size: 0;
					img {
						width: 100%;
						height: 100%;
					}
				}
				.text {
					height: 24px;
					color: rgba(59, 65, 75, 1);
					font-family: Microsoft YaHei;
					font-size: 18px;
					font-weight: 400;
					line-height: 24px;
				}
				.textActive {
					color: var(--color-main-active);
					font-weight: 700;
				}
			}
			.tab-active {
				position: relative;
				&::after {
					content: "";
					position: absolute;
					bottom: 0px;
					left: 0;
					width: 100%;
					height: 3px;
					background-color: var(--color-main-active);
				}
			}

			.head-button {
				position: relative;
				top: -5px;
				width: 120px;
				height: 36px;
				border-radius: 6px;
				background: var(--color-main-active);
				display: flex;
				justify-content: center;
				align-items: center;
				cursor: pointer;
				.button-icon {
					width: 16px;
					height: 16px;
					font-size: 0;
					img {
						width: 100%;
						height: 100%;
					}
				}
				.button-text {
					margin-left: 8px;
					color: rgba(255, 255, 255, 1);
					font-family: Microsoft YaHei;
					font-size: 16px;
					font-weight: 400;
				}
			}
		}
	}
	.main {
		border-top: 1px solid rgba(230, 231, 232, 1);
		background-color: #f7f8f9;
		width: 100%;
	}
}
</style>