<template>
	<div class="wrapper">
		<div class="left">
			<div class="box1">
				<div class="box-header">
					<div class="icon"></div>
					<div class="title">{{ "涉及行业" }}</div>
					<div class="header-right1">
						<el-checkbox v-model="isCRelated" label="只看中国企业" size="large" />
					</div>
					<div class="header-right">
						<div class="header-right-icon">
							<img src="@/assets/icons/box-header-icon2.png" alt="" />
						</div>
						<div class="header-right-icon">
							<img src="@/assets/icons/box-header-icon3.png" alt="" />
						</div>
					</div>
				</div>
				<div class="box1-top" id="chart1"></div>
				<div class="box1-tab-box">
					<div
						class="tab"
						:class="{ tabActive: box1BtnActiveName === item.name }"
						v-for="(item, index) in box1BtnList"
						:key="index"
						@click="handleClickBox1Btn(item)"
					>
						{{ item.name }}
					</div>
				</div>
				<div class="box1-list-box">
					<div class="box1-item" v-for="(item, index) in showCompanyList" :key="index" @click="handleToCompanyDetail">
						<div class="id">{{ index + 1 }}</div>
						<div class="title">{{ item.name }}</div>
						<div class="icon">
							<img v-if="item.status >= 0" src="./assets/images/up.png" alt="" />
							<img v-else src="./assets/images/down.png" alt="" />
						</div>
					</div>
				</div>
				<div class="box1-footer">
					<div class="box1-footer-left">{{ `共${companyTotalNum}家企业` }}</div>
					<div class="box1-footer-right">
						<el-pagination
							@current-change="handleCurrentChange"
							:pageSize="pageSize"
							:current-page="currentPage"
							background
							layout="prev, pager, next"
							size="small"
							:total="companyTotalNum"
						/>
					</div>
				</div>
			</div>
		</div>
		<div class="right">
			<div class="box2">
				<div class="box-header">
					<div class="icon"></div>
					<div class="title">{{ "产业链分析" }}</div>
					<div class="header-right">
						<div class="header-right-icon">
							<img src="@/assets/icons/box-header-icon1.png" alt="" />
						</div>
						<div class="header-right-icon">
							<img src="@/assets/icons/box-header-icon2.png" alt="" />
						</div>
						<div class="header-right-icon">
							<img src="@/assets/icons/box-header-icon3.png" alt="" />
						</div>
					</div>
				</div>
				<div class="box2-main">
					<div class="box2-main-header">
						<div class="box2-main-header-left">
							<img src="@/assets/icons/box-footer-left-icon.png" alt="" />
						</div>
						<div class="box2-main-header-center">
							{{
								"法案核心意图在于通过税收优惠吸引制造业回流美国​，并在关键科技领域对中国进行遏制，限制中国获取先进技术、资本和市场渠道，从而延缓中国科技产业的发展速度。给半导体、新能源、人工智能等相关科技行业带来不小的短期压力。"
							}}
						</div>
						<div class="box2-main-header-right">
							<img src="@/assets/icons/box-footer-right-icon.png" alt="" />
						</div>
					</div>
					<div class="box2-main-main">
						<Fishbone :chainId="2" />
					</div>
					<div class="box2-main-footer">
						<div class="box2-main-footer-left">
							<div class="top">
								<div class="icon">
									<img src="@/assets/icons/warning.png" alt="" />
								</div>
								<div class="text">{{ "中国企业45家（51.00%），受制裁5家（7.00%）" }}</div>
							</div>
							<div class="bottom">{{ "基础支撑" }}</div>
						</div>
						<div class="box2-main-footer-center">
							<div class="top">
								<div class="icon">
									<img src="@/assets/icons/warning.png" alt="" />
								</div>
								<div class="text">{{ "中国企业45家（51.00%），受制裁8家（7.00%）" }}</div>
							</div>
							<div class="bottom">{{ "软件算法" }}</div>
						</div>
						<div class="box2-main-footer-right">
							<div class="top">
								<div class="icon">
									<img src="@/assets/icons/warning.png" alt="" />
								</div>
								<div class="text">{{ "中国企业45家（51.00%），受制裁8家（7.00%）" }}</div>
							</div>
							<div class="bottom">{{ "行业应用" }}</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</template>

<script setup>
import { ref, computed, watch, onMounted } from "vue";
import Fishbone from "./fishbone.vue";
import { useRoute } from "vue-router";
import router from "@/router";
import setChart from "@/utils/setChart";
import getBarChart from "./utils/barChart";
import { getDecreeIndustry, getDecreehylyList, getDecreeCompany, getDecreeAction } from "@/api/decree/influence";

const route = useRoute();

// 跳转企业详情
const handleToCompanyDetail = () => {
	const route = router.resolve("/companyPages");
	window.open(route.href, "_blank");
};

// 企业影响分析
const companyTotalNum = ref(0); // 企业数量
const isCRelated = ref(false); // 只看中国企业

const chart1Data = ref({
	// title: ["集成电路", "新能源", "人工智能", "先进制造", "量子科技"],
	// value: [109, 95, 79, 25, 11]
});

const handleGetChart1Data = async () => {
	const params = {
		cRelated: isCRelated.value,
		id: 147
	};

	try {
		const res = await getDecreeIndustry(params);
		console.log("企业影响分析", res);
		if (res.code === 200 && res.data) {
			chart1Data.value.title = res.data.map(item => {
				return item.hylyName;
			});
			chart1Data.value.value = res.data.map(item => {
				return item.companyNum;
			});
		} else {
			chart1Data.value.title = [];
			chart1Data.value.value = [];
		}
	} catch (error) {
		chart1Data.value.title = [];
		chart1Data.value.value = [];
	}
};

const handelBox1 = async () => {
	await handleGetChart1Data();
	let chart1 = getBarChart(chart1Data.value.title, chart1Data.value.value);
	setChart(chart1, "chart1");
};

const box1BtnActiveName = ref("");
const curAreaId = ref(0);
const box1BtnList = ref([
	// "集成电路",
	// "新能源",
	// "人工智能",
	// "先进制造",
	// "量子科技"
]);
const handleClickBox1Btn = btn => {
	box1BtnActiveName.value = btn.name;
	curAreaId.value = btn.id;
	handleGetCompanyListByArea();
};

// 获取行业领域列表
const handleGetHylyList = async () => {
	try {
		const res = await getDecreehylyList();
		console.log("行业领域列表", res);
		if (res.code === 200 && res.data) {
			box1BtnList.value = res.data;
			box1BtnActiveName.value = box1BtnList.value[0].name;
			curAreaId.value = box1BtnList.value[0].id;
			handleGetCompanyListByArea();
		}
	} catch (error) {}
};

const companyList = ref([
	// {
	// 	name: "宁德时代新能源科技股份有限公司",
	// 	status: "down"
	// },
	// {
	// 	name: "比亚迪股份有限公司",
	// 	status: "down"
	// },
	// {
	// 	name: "隆基绿能科技股份有限公司",
	// 	status: "down"
	// },
	// {
	// 	name: "晶科能源控股有限公司",
	// 	status: "down"
	// },
	// {
	// 	name: "厦门海辰储能科技股份有限公司",
	// 	status: "down"
	// }
]);
const currentPage = ref(1);
const pageSize = ref(10);
// 处理页码改变事件
const handleCurrentChange = page => {
	currentPage.value = page;
};

const showCompanyList = computed(() => {
	const startIndex = (currentPage.value - 1) * pageSize.value;
	const endIndex = startIndex + pageSize.value;
	return companyList.value.slice(startIndex, endIndex);
});

const handleGetCompanyListByArea = async () => {
	const params = {
		cRelated: isCRelated.value,
		id: curAreaId.value
	};
	try {
		const res = await getDecreeCompany(params);
		console.log("行业领域公司列表", res);
		if (res.code === 200 && res.data) {
			companyList.value = res.data.map(item => {
				return {
					name: item.name,
					id: item.id,
					status: item.marketChange
				};
			});
			companyTotalNum.value = companyList.value.length;
		} else {
			companyList.value = [];
			companyTotalNum.value = 0;
		}
	} catch (error) {
		companyList.value = [];
		companyTotalNum.value = 0;
	}
};

// 政令举措落实分析
const timeLineList = ref([
	// {
	// 	time: "2025年7月25日",
	// 	content: "商务部已成立AI出口计划办公室，并开始招募专业人员。"
	// },
	// {
	// 	time: "2025年7月31日",
	// 	content: "英伟达、微软、谷歌等企业已提交初步技术栈提案。"
	// }
]);

const handleGetAction = async () => {
	const params = {
		id: route.query.id
	};
	try {
		const res = await getDecreeAction(params);
		console.log("政令举措落实分析", res);
		if (res.code === 200 && res.data) {
			timeLineList.value = res.data.map(item => {
				return {
					time: item.time,
					content: item.describe
				};
			});
		} else {
			timeLineList.value = [];
		}
	} catch (error) {
		timeLineList.value = [];
	}
};

// 历史相似举措及落实情况
const box3List = ref([
	// {
	// 	type: "科技法案",
	// 	title: "瓦森纳安排",
	// 	content: "落实情况：持续有效，但面临技术快速迭代挑战。",
	// 	time: "1996-至今",
	// 	tag: "人工智能"
	// },
	// {
	// 	type: "科技法案",
	// 	title: "云计算出口管制",
	// 	content: "落实情况：部分有效，但执行难度大。",
	// 	time: "1996-至今",
	// 	tag: "人工智能"
	// },
	// {
	// 	type: "科技法案",
	// 	title: "芯片与科学法案",
	// 	content: "落实情况：正在实施，效果待观察。",
	// 	time: "2022-至今",
	// 	tag: "人工智能"
	// },
	// {
	// 	type: "科技法案",
	// 	title: "AI芯片出口管制",
	// 	content: "落实情况：部分有效，但催生中国自主创新。",
	// 	time: "1996-至今",
	// 	tag: "人工智能"
	// },
	// {
	// 	type: "科技法案",
	// 	title: "瓦森纳安排",
	// 	content: "落实情况：持续有效，但面临技术快速迭代挑战。",
	// 	time: "1996-至今",
	// 	tag: "人工智能"
	// },
	// {
	// 	type: "科技法案",
	// 	title: "瓦森纳安排",
	// 	content: "落实情况：持续有效，但面临技术快速迭代挑战。",
	// 	time: "1996-至今",
	// 	tag: "人工智能"
	// }
]);

watch(
	() => isCRelated.value,
	val => {
		handleGetCompanyListByArea();
		handelBox1();
	}
);

onMounted(() => {
	handleGetChart1Data();
	handleGetHylyList();
	handleGetAction();
	handelBox1();
});
</script>

<style lang="scss" scoped>
.wrapper {
	width: 100%;
	height: 879px;
	display: flex;
	.box-header {
		display: flex;
		height: 48px;
		position: relative;
		.icon {
			margin-top: 18px;
			width: 8px;
			height: 20px;
			border-radius: 0 4px 4px 0;
			background: var(--color-main-active);
		}
		.title {
			height: 26px;
			margin-left: 14px;
			margin-top: 14px;
			color: var(--color-main-active);
			font-family: Microsoft YaHei;
			font-size: 20px;
			font-weight: 700;
			line-height: 26px;
		}
		.header-right {
			position: absolute;
			top: 14px;
			right: 12px;
			display: flex;
			justify-content: flex-end;
			gap: 4px;
			.header-right-icon {
				width: 28px;
				height: 28px;
				img {
					width: 100%;
					height: 100%;
				}
			}
		}
		.header-right1 {
			position: absolute;
			top: 8px;
			right: 84px;
		}
	}
	.left {
		margin-left: 160px;
		margin-top: 16px;
		.box1 {
			width: 480px;
			height: 845px;
			border-radius: 4px;
			box-shadow: 0px 0px 15px 0px rgba(60, 87, 126, 0.2);
			background: rgba(255, 255, 255, 1);
			.box1-top {
				width: 446px;
				height: 188px;
				margin: 7px auto 0;
				box-sizing: border-box;
				border: 1px solid rgba(234, 236, 238, 1);
				border-radius: 4px;
				background: rgba(247, 248, 249, 1);
			}
			.box1-tab-box {
				height: 60px;
				width: 446px;
				margin: 0 auto;
				overflow-x: auto;
				display: flex;
				white-space: nowrap;
				gap: 8px;
				.tab {
					min-width: min-content;
					margin-top: 18px;
					padding: 0 8px;
					height: 28px;
					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;
					cursor: pointer;
					&:hover {
						background: var(--btn-active-bg-color);
						border: 1px solid var(--btn-active-border-color);
					}
				}
				.tabActive {
					color: var(--btn-active-text-color);
					background: var(--btn-active-bg-color);
					border: 1px solid var(--btn-active-border-color);
				}
			}
			.box1-list-box {
				height: 480px;
				width: 446px;
				margin: 0 auto;
				.box1-item {
					width: 446px;
					height: 48px;
					box-sizing: border-box;
					border-bottom: 1px solid rgba(234, 236, 238, 1);
					border-radius: 4px;
					display: flex;
					cursor: pointer;
					&:hover {
						background: var(--color-bg-hover);
					}
					.id {
						width: 24px;
						height: 24px;
						margin-top: 12px;
						margin-left: 12px;
						border-radius: 12px;
						background: #e7f3ff;
						font-size: 14px;
						font-family: Microsoft YaHei;
						text-align: center;
						line-height: 24px;
						color: var(--color-main-active);
					}
					.title {
						margin-left: 10px;
						color: rgba(59, 65, 75, 1);
						font-family: Microsoft YaHei;
						font-size: 16px;
						font-weight: 400;
						line-height: 48px;
					}
					.icon {
						width: 8px;
						height: 6px;
						margin-top: 14px;
						margin-left: 6px;
						img {
							width: 100%;
							height: 100%;
						}
					}
				}
			}
			.box1-footer {
				height: 65px;
				width: 446px;
				margin: 0 auto;
				display: flex;
				justify-content: space-between;
				box-sizing: border-box;
				.box1-footer-left {
					margin-top: 25px;
					height: 18px;
					color: rgba(95, 101, 108, 1);
					font-family: Microsoft YaHei;
					font-size: 14px;
					font-weight: 400;
					line-height: 18px;
				}
				.box1-footer-right {
					margin-top: 23px;
				}
			}
		}
	}
	.right {
		margin-top: 16px;
		margin-left: 16px;
		.box2 {
			width: 1105px;
			height: 847px;
			background: rgba(255, 255, 255);
			border-radius: 4px;
			position: relative;
			.box2-main {
				height: 799px;
				.box2-main-header {
					margin: 14px auto 36px;
					width: 1066px;
					height: 64px;
					box-sizing: border-box;
					border: 1px solid rgba(231, 243, 255, 1);
					border-radius: 4px;
					background: rgba(246, 250, 255, 1);
					padding: 6px 12px;
					display: flex;
					align-items: center;
					justify-content: center;
					gap: 13px;
					.box2-main-header-left {
						width: 19px;
						height: 20px;
						img {
							width: 100%;
							height: 100%;
						}
					}
					.box2-main-header-center {
						width: 973px;
						height: 48px;
						color: var(--color-main-active);
						font-family: Microsoft YaHei;
						font-style: Regular;
						font-size: 16px;
						font-weight: 400;
						line-height: 24px;
						letter-spacing: 0px;
						text-align: left;
					}
					.box2-main-header-right {
						width: 24px;
						height: 24px;
						img {
							width: 100%;
							height: 100%;
						}
					}
				}
				.box2-main-main {
					width: 1053px;
					height: 568px;
					margin: 0 auto;
				}
				.box2-main-footer {
					margin-left: 24px;
					width: 1053px;
					height: 117px;
					display: flex;
					box-sizing: border-box;
					padding-top: 36px;
					overflow-x: auto;
					.box2-main-footer-left {
						width: 408px;
						text-align: center;
						position: relative;
						z-index: 3;
						.top {
							height: 22px;
							display: flex;
							justify-content: center;
							gap: 6px;
							align-items: center;
							.icon {
								width: 16px;
								height: 16px;
								img {
									width: 100%;
									height: 100%;
								}
							}
							.text {
								color: rgba(206, 79, 81, 1);
								font-family: Microsoft YaHei;
								font-style: Regular;
								font-size: 14px;
								font-weight: 400;
								line-height: 22px;
								letter-spacing: 0px;
								text-align: left;
							}
						}
						.bottom {
							margin-top: 13px;
							width: 408px;
							height: 28px;
							color: rgba(22, 119, 255, 1);
							font-family: Microsoft YaHei;
							font-style: Bold;
							font-size: 16px;
							font-weight: 700;
							line-height: 24px;
							letter-spacing: 1px;
							text-align: center;
							background: url("./assets/images/bg1.png");
						}
					}
					.box2-main-footer-center {
						width: 408px;
						text-align: center;
						margin-left: -10px;
						position: relative;
						z-index: 2;
						.top {
							height: 22px;
							display: flex;
							justify-content: center;
							gap: 6px;
							align-items: center;
							.icon {
								width: 16px;
								height: 16px;
								img {
									width: 100%;
									height: 100%;
								}
							}
							.text {
								color: rgba(206, 79, 81, 1);
								font-family: Microsoft YaHei;
								font-style: Regular;
								font-size: 14px;
								font-weight: 400;
								line-height: 22px;
								letter-spacing: 0px;
								text-align: left;
							}
						}
						.bottom {
							margin-top: 13px;
							width: 408px;
							height: 28px;
							color: rgba(19, 168, 168, 1);
							font-family: Microsoft YaHei;
							font-style: Bold;
							font-size: 16px;
							font-weight: 700;
							line-height: 24px;
							letter-spacing: 1px;
							text-align: center;
							background: url("./assets/images/bg2.png");
						}
					}
					.box2-main-footer-right {
						width: 408px;
						text-align: center;
						margin-left: -10px;
						position: relative;
						z-index: 1;
						.top {
							height: 22px;
							display: flex;
							justify-content: center;
							gap: 6px;
							align-items: center;
							.icon {
								width: 16px;
								height: 16px;
								img {
									width: 100%;
									height: 100%;
								}
							}
							.text {
								color: rgba(206, 79, 81, 1);
								font-family: Microsoft YaHei;
								font-style: Regular;
								font-size: 14px;
								font-weight: 400;
								line-height: 22px;
								letter-spacing: 0px;
								text-align: left;
							}
						}
						.bottom {
							margin-top: 13px;
							width: 408px;
							height: 28px;
							color: rgba(146, 84, 222, 1);
							font-family: Microsoft YaHei;
							font-style: Bold;
							font-size: 16px;
							font-weight: 700;
							line-height: 24px;
							letter-spacing: 1px;
							text-align: center;
							background: url("./assets/images/bg3.png");
						}
					}
				}
			}
		}
	}
}
</style>