<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">
								{{ basicInfo.eName }}
							</div>
						</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.signPeople }}
							</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">
						<div class="left">
							<img :src="box3TopData.logo" 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.zyzz }}
								</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 box1Img from "./assets/images/box1-img.png";
import Box3Logo from "./assets/images/box3-img.png";
import { getDecreeBasicInfo, getDecreeMainContent, getDecreeOrganization } from "@/api/decree/introduction";

const route = useRoute();

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

// 基本信息
const basicInfo = ref({
	img: box1Img,
	name: "推动美国人工智能技术栈出口",
	eName: "Promoting the Export of the American AI Technology Stack",
	areaList: ["人工智能", "出口管制", "半导体产业", "关税", "光伏产业"],
	signTime: "2025年7月23日",
	signPeople: "唐纳德·约翰·特朗普(Donald John Trump)",
	bh: "第14320号行政命令 (EO 14320)",
	deadline: "签署后90天内建立机制并开始实施"
});

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;
		}
	} 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.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.zyzz = "暂无数据";
	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: newsTitle
		};
	});
};

const box3Data = ref([]);

const box3TopData = ref({
	logo: Box3Logo,
	name: "美国商务部",
	eName: "United States Department of Commerce",
	clsj: "1903年2月14日",
	zbdz: "华盛顿宪法大道1401号胡佛大楼",
	bz: "霍华德·卢特尼克"
});

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

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;
			eventList.value = res.data[0].newsList.map(val => {
				return {
					time: val.newsDate,
					title: 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 = [];
	}
};
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;
			top: 14px;
			right: 84px;
			display: flex;
			justify-content: flex-end;
			gap: 8px;
			.btn {
				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: 1150px;
		.box1 {
			margin-top: 16px;
			width: 1150px;
			height: 414px;
			border-radius: 4px;
			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: 235px;
					height: 332px;
					margin-left: 42px;
					img {
						width: 100%;
						height: 100%;
					}
				}
				.box1-main-right {
					margin-left: 40px;
					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;
						}
						.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: 1150px;
			height: 415px;
			border-radius: 4px;
			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;
				.box2-item {
					width: 1101px;
					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;
					&:nth-child(2n-1) {
						background: rgba(247, 248, 249, 1);
					}
					.id {
						margin-top: 12px;
						margin-left: 15px;
						width: 24px;
						height: 24px;
						text-align: center;
						line-height: 24px;
						border-radius: 12px;
						background: #e7f3ff;
						color: #0a57a6;
					}
					.title {
						width: 1000px;
						line-height: 48px;
						margin-left: 13px;
						color: rgba(59, 65, 75, 1);
						font-family: Microsoft YaHei;
						font-size: 16px;
						font-weight: 700;
					}
					.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 {
		margin-left: 16px;
		.box3 {
			margin-top: 16px;
			width: 576px;
			height: 845px;
			border-radius: 4px;
			box-shadow: 0px 0px 15px 0px rgba(60, 87, 126, 0.2);
			background: rgba(255, 255, 255, 1);
			.box3-top {
				margin-top: 10px;
				height: 261px;
				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;
					.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 {
						margin-left: 22px;
						.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 {
						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 {
					height: 410px;
				}
				.box3-bottom-footer {
					width: 108px;
					height: 32px;
					margin: 5px auto;
					cursor: pointer;
					img {
						width: 100%;
						height: 100%;
					}
				}
			}
		}
	}
}
</style>