<template>
	<div class="introduction-wrap">
		<div class="left">
			<div class="box1">
				<div class="box-header">
					<div class="header-left"></div>
					<div class="title">基本信息</div>

					<div class="header-right">
						<div class="icon">
							<img src="../assets/icons/header-right-icon1.png" alt="" />
						</div>
						<div class="icon">
							<img src="../assets/icons/header-right-icon2.png" alt="" />
						</div>
					</div>
				</div>
				<div class="box1-main">
					<div class="box1-main-left">
						<img :src="basicInfo.img" alt="" />
					</div>
					<div class="box1-main-right">
						<div class="item">
							<div class="item-left">{{ "政令全称：" }}</div>
							<div class="item-right">{{ basicInfo.name }}</div>
						</div>
						<div class="item">
							<div class="item-left">{{ "英文全称：" }}</div>
							<div class="item-right text" v-if="basicInfo.eName?.length < 60">
								{{ basicInfo.eName }}
							</div>
							<el-popover v-else effect="dark" :width="500" :content="basicInfo.eName" placement="top-start">
								<template #reference>
									<div class="item-right text">
										{{ basicInfo.eName }}
									</div>
								</template>
							</el-popover>
						</div>
						<div class="item">
							<div class="item-left">{{ "相关领域：" }}</div>
							<div class="item-right tag-box">
								<div class="tag" v-for="(area, index) in basicInfo.areaList" :key="index">
									{{ area.industryName }}
								</div>
							</div>
						</div>
						<div class="item">
							<div class="item-left">{{ "签署时间：" }}</div>
							<div class="item-right text">{{ basicInfo.signTime }}</div>
						</div>
						<div class="item">
							<div class="item-left">{{ "发布机构：" }}</div>
							<div class="item-right text">
								{{ basicInfo.proposeOrgName }}
							</div>
						</div>
						<div class="item">
							<div class="item-left">{{ "政令编号：" }}</div>
							<div class="item-right text">
								{{ basicInfo.bh }}
							</div>
						</div>
						<div class="item">
							<div class="item-left">{{ "执行期限：" }}</div>
							<div class="item-right text">
								{{ basicInfo.deadline+ ' 天' }}
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="box2">
				<div class="box-header">
					<div class="header-left"></div>
					<div class="title">主要指令</div>
					<div class="header-right">
						<div class="icon">
							<img src="../assets/icons/header-right-icon1.png" alt="" />
						</div>
						<div class="icon">
							<img src="../assets/icons/header-right-icon2.png" alt="" />
						</div>
					</div>
				</div>
				<div class="box2-main">
					<div class="box2-item" v-for="(item, index) in curmajorList" :key="index">
						<div class="id">{{ index + 1 }}</div>
						<div class="title">{{ item.content }}</div>
						<!-- <div class="open">
							<img src="./assets/images/open-icon.png" alt="" />
						</div> -->
					</div>
				</div>
				<div class="box2-footer">
					<div class="box2-footer-left">{{ `共计${majorListNum}条指令` }}</div>
					<div class="box2-footer-right">
						<el-pagination
							@current-change="handleCurrentChange"
							:page-size="5"
							background
							layout="prev, pager, next"
							:total="majorListNum"
						/>
					</div>
				</div>
			</div>
		</div>
		<div class="right">
			<div class="box3">
				<div class="box-header">
					<div class="header-left"></div>
					<div class="title">执行机构</div>
					<div class="header-btn-box">
						<div
							class="btn"
							:class="{ btnActive: box3ActiveBtn === item }"
							v-for="(item, index) in box3BtnList"
							:key="index"
							@click="handleClickBox3Btn(item, index)"
						>
							{{ item }}
						</div>
					</div>
					<div class="header-right">
						<div class="icon">
							<img src="../assets/icons/header-right-icon1.png" alt="" />
						</div>
						<div class="icon">
							<img src="../assets/icons/header-right-icon2.png" alt="" />
						</div>
					</div>
				</div>
				<div class="box3-top">
					<div class="box3-top-top" @click="handleToInstitution(box3TopData)">
						<div class="left">
							<img :src="box3TopData.logo ? box3TopData.logo : DefaultIcon2" alt="" />
						</div>
						<div class="right">
							<div class="name">{{ box3TopData.name }}</div>
							<div class="ename">{{ box3TopData.eName }}</div>
						</div>
						<!-- <div class="more">
							<div class="text">{{ "查看官网" }}</div>
							<div class="icon">
								<img src="./assets/images/open-icon.png" alt="" />
							</div>
						</div> -->
					</div>
					<div class="box3-top-bottom">
						<div class="box3-top-right-main">
							<div class="main-item">
								<div class="item-icon"></div>
								<div class="item-left">{{ "成立时间:" }}</div>
								<div class="item-right">{{ box3TopData.clsj }}</div>
							</div>
							<div class="main-item">
								<div class="item-icon"></div>
								<div class="item-left">{{ "总部地址:" }}</div>
								<div class="item-right">
									{{ box3TopData.zbdz }}
								</div>
							</div>
							<div class="main-item">
								<div class="item-icon"></div>
								<div class="item-left">{{ "部长:" }}</div>
								<div class="item-right">{{ box3TopData.bz }}</div>
							</div>
						</div>
					</div>
				</div>
				<div class="box3-bottom">
					<div class="box3-bottom-header">
						<div class="header-icon">
							<img src="./assets/images/box3-bottom-header-icon.png" alt="" />
						</div>
						<div class="header-title">{{ "机构动态" }}</div>
					</div>
					<div class="box3-bottom-main">
						<el-timeline style="max-width: 500px">
							<el-timeline-item
								:timestamp="item.time"
								placement="top"
								v-for="(item, index) in eventList"
								:key="index"
							>
								<div class="timeline-content">
									{{ item.title }}
								</div>
							</el-timeline-item>
						</el-timeline>
					</div>
					<!-- <div class="box3-bottom-footer">
						<img src="./assets/images/more-icon.png" alt="" />
					</div> -->
				</div>
			</div>
		</div>
	</div>
</template>

<script setup>
import { ref, computed, onMounted } from "vue";
import { useRoute } from "vue-router";
import router from "@/router";
import box1Img from "./assets/images/box1-img.png";
import Box3Logo from "./assets/images/box3-img.png";
import { getDecreeBasicInfo, getDecreeMainContent, getDecreeOrganization } from "@/api/decree/introduction";

import DefaultIcon1 from "@/assets/icons/default-icon1.png";
import DefaultIcon2 from "@/assets/icons/default-icon2.png";

const route = useRoute();
const decreeId = ref(route.query.id);

// 基本信息
const basicInfo = ref({
	img: "",
	name: "",
	eName: "",
	areaList: [],
	signTime: "",
	signPeople: "",
	bh: "",
	deadline: ""
});

const handleGetBasicInfo = async () => {
	const params = {
		id: decreeId.value
	};
	try {
		const res = await getDecreeBasicInfo(params);
		console.log("基本信息", res);
		if (res.code === 200 && res.data) {
			basicInfo.value.img = res.data.picture;
			basicInfo.value.name = res.data.name;
			basicInfo.value.eName = res.data.ename;
			basicInfo.value.areaList = res.data.industryList;
			basicInfo.value.signTime = res.data.postDate;
			basicInfo.value.bh = res.data.order;
			basicInfo.value.deadline = res.data.deadline;
			basicInfo.value.proposeOrgName = res.data.proposeOrgName;
		}
	} catch (error) {
		console.error("基本信息error", error);
	}
};
handleGetBasicInfo();

// 主要指令
const majorList = ref([
	// {
	// 	id: 1,
	// 	content: '要求商务部在90天内建立"全栈式"美国AI出口机制。'
	// }
]);
const currentPage = ref(1);
const pageSize = ref(5);
// 处理页码改变事件
const handleCurrentChange = page => {
	currentPage.value = page;
};
const curmajorList = computed(() => {
	const startIndex = (currentPage.value - 1) * pageSize.value;
	const endIndex = startIndex + pageSize.value;
	return majorList.value.slice(startIndex, endIndex);
});

const majorListNum = ref(0);
const handleMajorList = async () => {
	const params = {
		currentPage: 0,
		pageSize: 999999,
		id: decreeId.value
	};
	try {
		const res = await getDecreeMainContent(params);
		console.log("主要指令", res);
		if (res.code === 200 && res.data) {
			majorList.value = res.data.content;
			majorListNum.value = res.data.numberOfElements;
		} else {
			majorList.value = [];
			majorListNum.value = 0;
		}
	} catch (error) {}
};
handleMajorList();

// 执行机构
const box3BtnList = ref([]);
const box3ActiveBtn = ref("");
const box3BtnActiveIndex = ref(0);
const handleClickBox3Btn = (btn, index) => {
	box3ActiveBtn.value = btn;
	box3BtnActiveIndex.value = index;
	box3TopData.value.id = box3Data.value[index].id;
	box3TopData.value.logo = box3Data.value[index].url;
	box3TopData.value.name = box3Data.value[index].name;
	box3TopData.value.eName = box3Data.value[index].ename;
	box3TopData.value.clsj = box3Data.value[index].foundingDate;
	box3TopData.value.zbdz = box3Data.value[index].address;
	box3TopData.value.bz = box3Data.value[index].leaderName;
	eventList.value = box3Data.value[index].newsList.map(val => {
		return {
			time: val.newsDate,
			title: val.newsContent
		};
	});
};

const box3Data = ref([]);

const box3TopData = ref({
	id: "",
	logo: "",
	name: "",
	eName: "",
	clsj: "",
	zbdz: "",
	bz: ""
});

// 跳转行政机构主页
const handleToInstitution = item => {
	const curRoute = router.resolve({
		path: "/institution",
		query: {
			id: item.id
		}
	});
	window.open(curRoute.href, "_blank");
};

// 机构动态
const eventList = ref([
	// {
	// 	time: "2025-07-31",
	// 	title: "美商务部发布指南，警告全球企业使用华为昇腾芯片可能违反美国出口管制。意在限制中国AI产业发展，阻碍其获得先进算力。"
	// },
	// {
	// 	time: "2025-07-25",
	// 	title: "美商务部持续对多种中国产品发起“双反”（反倾销、反补贴）调查并作出裁决，涉及产品从工业原料到日常用品，且裁定的税率普遍较高。"
	// },
	// {
	// 	time: "2025-07-21",
	// 	title: "美商务部进一步收紧对华先进半导体出口管制，将更多中国实体列入“实体清单”。限制14纳米及以下先进芯片、DRAM等对华出口"
	// }
]);

const handleGetOrgnization = async () => {
	const params = {
		id: decreeId.value
	};
	try {
		const res = await getDecreeOrganization(params);
		console.log("执行机构", res);
		if (res.code === 200 && res.data) {
			box3BtnList.value = res.data.map(item => {
				return item.name;
			});
			box3Data.value = res.data;
			box3TopData.value.logo = res.data[0].url;
			box3TopData.value.name = res.data[0].name;
			box3TopData.value.eName = res.data[0].ename;
			box3TopData.value.clsj = res.data[0].foundingDate;
			box3TopData.value.zbdz = res.data[0].address;
			box3TopData.value.bz = res.data[0].leaderName;
			box3ActiveBtn.value = res.data[0].name;
			eventList.value = res.data[0].newsList.map(val => {
				return {
					time: val.newsDate,
					title: val.newsTitle
				};
			});
		} else {
			box3BtnList.value = [];
			box3TopData.value = {
				logo: "",
				name: "",
				eName: "",
				clsj: "",
				zyzz: "",
				zbdz: "",
				bz: ""
			};
			eventList.value = [];
		}
	} catch (error) {
		console.error("执行机构error", error);
		box3BtnList.value = [];
		box3TopData.value = {
			logo: "",
			name: "",
			eName: "",
			clsj: "",
			zbdz: "",
			bz: ""
		};
		eventList.value = [];
	}
};

onMounted(() => {
	handleGetOrgnization();
});
</script>

<style lang="scss" scoped>
.introduction-wrap {
	display: flex;
	.box-header {
		height: 56px;
		display: flex;
		position: relative;
		.header-left {
			margin-top: 18px;
			width: 8px;
			height: 20px;
			border-radius: 0 4px 4px 0;
			background: var(--color-main-active);
		}
		.title {
			margin-left: 14px;
			margin-top: 14px;
			height: 26px;
			line-height: 26px;
			color: var(--color-main-active);
			font-family: Microsoft YaHei;
			font-size: 20px;
			font-weight: 700;
		}
		.header-btn-box {
			position: absolute;
			z-index: 9999;
			width: 325px;
			height: 64px;
			top: 14px;
			right: 82px;
			display: flex;
			justify-content: flex-end;
			flex-wrap: wrap;
			gap: 5px 8px;
			white-space: nowrap;
			overflow:hidden;
			overflow-y: auto;
			padding-right: 5px;
			.btn {
				min-width: min-content;
				height: 28px;
				padding: 0 8px;
				box-sizing: border-box;
				border: 1px solid rgba(230, 231, 232, 1);
				border-radius: 4px;
				background: rgba(255, 255, 255, 1);
				color: rgba(59, 65, 75, 1);
				font-family: Microsoft YaHei;
				font-size: 16px;
				font-weight: 400;
				line-height: 28px;
				cursor: pointer;
			}
			.btnActive {
				border: 1px solid var(--color-main-active);
				color: var(--color-main-active);
				background: rgba(231, 243, 255, 1);
			}
		}
		.header-right {
			position: absolute;
			top: 14px;
			right: 12px;
			height: 28px;
			display: flex;
			gap: 4px;
			.icon {
				width: 28px;
				height: 28px;
				img {
					width: 100%;
					height: 100%;
				}
			}
		}
	}
	.left {
		width: 1064px;
		.box1 {
			margin-top: 16px;
			width: 1064px;
			height: 414px;
			border-radius: 10px;
			box-shadow: 0px 0px 15px 0px rgba(60, 87, 126, 0.2);
			background: rgba(255, 255, 255, 1);
			.box1-main {
				display: flex;
				.box1-main-left {
					width: 395px;
					height: 332px;
					margin-left: 42px;
					img {
						width: 100%;
						// height: 100%;
					}
				}
				.box1-main-right {
					width: 590px;
					margin-left: 20px;
					color: rgba(59, 65, 75, 1);
					font-family: Microsoft YaHei;
					font-size: 16px;
					font-weight: 700;
					line-height: 24px;
					.item {
						height: 30px;
						display: flex;
						margin-bottom: 17px;
						.item-left {
							width: 100px;
						}
						.item-right {
							width: 470px;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
						}
						.tag-box {
							display: flex;
							.tag {
								height: 24px;
								line-height: 24px;
								color: rgba(22, 119, 255, 1);
								font-family: Microsoft YaHei;
								font-size: 14px;
								font-weight: 400;
								box-sizing: border-box;
								border: 1px solid rgba(186, 224, 255, 1);
								border-radius: 4px;
								background: rgba(230, 244, 255, 1);
								padding: 0px 8px;
								margin-right: 8px;
							}
						}
						.text {
							font-weight: normal !important;
						}
					}
				}
			}
		}
		.box2 {
			margin-top: 16px;
			width: 1064px;
			height: 415px;
			border-radius: 10px;
			box-shadow: 0px 0px 15px 0px rgba(60, 87, 126, 0.2);
			background: rgba(255, 255, 255, 1);
			.box2-main {
				margin-left: 22px;
				height: 280px;
				overflow: hidden;
				overflow-y: auto;
				.box2-item {
					width: 1015px;
					// height: 48px;
					margin-bottom: 8px;
					box-sizing: border-box;
					border: 1px solid rgba(234, 236, 238, 1);
					border-radius: 2px;
					background: rgba(255, 255, 255, 1);
					display: flex;
					align-items: center;
					padding: 12px 0;
					&:nth-child(2n-1) {
						background: rgba(247, 248, 249, 1);
					}
					.id {
						margin-left: 15px;
						width: 24px;
						height: 24px;
						text-align: center;
						line-height: 24px;
						border-radius: 12px;
						background: #e7f3ff;
						color: #0a57a6;
					}
					.title {
						width: 1020px;
						line-height: 24px;
						margin-left: 10px;
						color: rgba(59, 65, 75, 1);
						font-family: Microsoft YaHei;
						font-size: 16px;
						font-weight: 700;
						// overflow: hidden;
						// text-overflow: ellipsis;
						// white-space: nowrap;
					}
					.open {
						width: 16px;
						height: 16px;
						margin-top: 16px;
						img {
							width: 100%;
							height: 100%;
						}
					}
				}
			}
			.box2-footer {
				margin: 20px 22px;
				display: flex;
				justify-content: space-between;
				.box2-footer-left {
					height: 20px;
					color: rgba(132, 136, 142, 1);
					font-family: Microsoft YaHei;
					font-size: 14px;
					font-weight: 400;
					line-height: 20px;
				}
			}
		}
	}
	.right {
		width: 520px;
		margin-left: 16px;
		.box3 {
			margin-top: 16px;
			width: 520px;
			height: 845px;
			border-radius: 10px;
			box-shadow: 0px 0px 15px 0px rgba(60, 87, 126, 0.2);
			background: rgba(255, 255, 255, 1);
			.box3-top {
				margin-top: 30px;
				height: 241px;
				border-bottom: 1px solid rgba(234, 236, 238, 1);
				.box3-top-top {
					width: 473px;
					height: 88px;
					box-sizing: border-box;
					border: 1px solid rgba(234, 236, 238, 1);
					border-radius: 4px;
					background: rgba(247, 248, 249, 1);
					display: flex;
					align-items: center;
					margin: 0 auto;
					position: relative;
					cursor: pointer;
					.more {
						position: absolute;
						right: 17px;
						top: 17px;
						display: flex;
						gap: 3px;
						.text {
							height: 16px;
							color: rgba(5, 95, 194, 1);
							font-family: Microsoft YaHei;
							font-size: 14px;
							font-weight: 400;
							line-height: 16px;
						}
						.icon {
							width: 16px;
							height: 16px;
							img {
								width: 100%;
								height: 100%;
							}
						}
					}
					.left {
						width: 64px;
						height: 64px;
						margin-left: 17px;
						img {
							width: 100%;
							height: 100%;
						}
					}
					.right {
						width: 370px;
						margin-left: 15px;
						.name {
							height: 26px;
							color: rgba(59, 65, 75, 1);
							font-family: Microsoft YaHei;
							font-size: 20px;
							font-weight: 700;
							line-height: 26px;
						}
						.ename {
							margin-top: 6px;
							height: 24px;
							color: rgba(95, 101, 108, 1);
							font-family: Microsoft YaHei;
							font-size: 16px;
							font-weight: 400;
							line-height: 24px;
						}
					}
				}
				.box3-top-bottom {
					margin-left: 50px;
					.box3-top-right-main {
						height: 150px;
						overflow: hidden;
						overflow-y: auto;
						color: rgba(59, 65, 75, 1);
						font-family: Microsoft YaHei;
						font-size: 16px;
						font-weight: 400;
						line-height: 24px;
						margin-top: 4px;
						.main-item {
							display: flex;
							margin-top: 12px;
							// height: 26px;
							line-height: 26px;
							.item-icon {
								width: 4px;
								height: 4px;
								border-radius: 2px;
								background: #3b414b;
								margin-top: 11px;
								margin-right: 19px;
							}
							.item-left {
								height: 24px;
								width: 80px;
							}
							.item-right {
								width: 291px;
							}
						}
					}
				}
			}
			.box3-bottom {
				.box3-bottom-header {
					height: 59px;
					display: flex;
					.header-icon {
						margin-left: 22px;
						margin-top: 27px;
						width: 16px;
						height: 16px;
						img {
							width: 100%;
							height: 100%;
						}
					}
					.header-title {
						margin-left: 12px;
						margin-top: 23px;
						height: 24px;
						color: rgba(59, 65, 75, 1);
						font-family: Microsoft YaHei;
						font-size: 16px;
						font-weight: 700;
						line-height: 24px;
					}
				}
				.box3-bottom-main {
					width: 510px;
					height: 440px;
					overflow: hidden;
					overflow-y: auto;
				}
				// .box3-bottom-footer {
				// 	width: 108px;
				// 	height: 32px;
				// 	margin: 5px auto;
				// 	cursor: pointer;
				// 	img {
				// 		width: 100%;
				// 		height: 100%;
				// 	}
				// }
			}
		}
	}
	.report {
		padding: 10px 150px;
		position: absolute;
		left: 0;
		top: 0;
		z-index: 999999;
		width: 100%;
		height: 100%;
		background: #f7f8f9;
		.report-close {
			position: absolute;
			top: 20px;
			right: 230px;
			width: 20px;
			height: 20px;
			cursor: pointer;
			img {
				width: 100%;
				height: 100%;
			}
		}
		.report-header {
			width: 100%;
			height: 50px;
			color: rgba(59, 65, 75, 1);
			font-family: Microsoft YaHei;
			font-style: Bold;
			font-size: 20px;
			font-weight: 700;
			line-height: 50px;
			letter-spacing: 0px;
			text-align: left;
			padding-left: 30px;
			border-bottom: 1px solid rgba(234, 236, 238, 1);
		}
		.report-main {
			display: flex;
			height: calc(100% - 100px);
			justify-content: space-between;
			.left {
				width: 800px;
				.noContent {
					height: 100px;
					line-height: 100px;
					text-align: center;
					color: rgba(59, 65, 75, 1);
					font-family: Microsoft YaHei;
					font-style: Regular;
					font-size: 20px;
					font-weight: 400;
				}
			}
			.right {
				width: 800px;
				.noContent {
					height: 100px;
					line-height: 100px;
					text-align: center;
					color: rgba(59, 65, 75, 1);
					font-family: Microsoft YaHei;
					font-style: Regular;
					font-size: 20px;
					font-weight: 400;
				}
			}
		}
	}
}
</style>