<template>
	<Card title="政治面貌">
		<div class="leftBottomBox">
			<div id="politicalOutlook" style="width: 100%; height: 100%"></div>
		</div>
	</Card>
</template>

<script lang="ts" setup>
import { onMounted, ref } from "vue";
import * as echarts from "echarts";
import Card from "@/components/card.vue";
import { GlobalStore } from "@/stores";
const store = GlobalStore();
const airType = ref(1);
let rangeTime = ref("" as any);
let dataList = ref([
	{
		value: 37,
		show: true,
		name: "中共党员",

		itemStyle: {
			normal: {
				color: "#82FBEA",
				borderWidth: 20
			}
		}
	},
	{
		value: 74,
		show: true,
		name: "中共预备党员",
		itemStyle: {
			normal: {
				color: "#EEC459",
				borderWidth: 20
			}
		}
	},
	{
		value: 73,
		show: true,
		name: "共青团员",
		itemStyle: {
			normal: {
				color: "#65D7F9"
			}
		}
	}
]);
function Pie() {
	let dataArr = [];
	for (var i = 0; i < 150; i++) {
		if (i % 2 === 0) {
			dataArr.push({
				name: (i + 1).toString(),
				value: 10,
				itemStyle: {
					normal: {
						color: "#7cf4f1",
						borderWidth: 0,
						borderColor: "#7f6546"
					}
				}
			});
		} else {
			dataArr.push({
				name: (i + 1).toString(),
				value: 10,
				itemStyle: {
					normal: {
						color: "rgba(0,0,0,0)",
						borderWidth: 0,
						borderColor: "rgba(0,0,0,0)"
					}
				}
			});
		}
	}
	return dataArr;
}

onMounted(() => {
	drawEchart();
});

function drawEchart() {
	let max = 0;
	dataList.value.map(item => {
		max = max + item.value;
	});
	let echartsTest = echarts.init(document.getElementById("politicalOutlook"));
	let option = {
		tooltip: {
			trigger: "item"
		},
		title: {
			text: max,
			subtext: "总数",
			x: "23%",
			y: "41%",
			textAlign: "center",
			textStyle: {
				color: "#fff",
				fontSize: 22,
				fontWeight: "normal",
				textAlign: "left",
				fontFamily: "sadigitalNumber"
			},
			subtextStyle: {
				color: "#ccc",
				fontSize: 14,
				lineHeight: 30
			}
		},
		legend: {
			selectedMode: false, // 取消图例上的点击事件
			icon: "rect",
			type: "plain",
			orient: "vertical",
			left: "50%",
			top: "30%",
			align: "left",
			itemGap: 30,
			itemWidth: 8, // 设置宽度
			itemHeight: 7, // 设置高度
			symbolKeepAspect: false,
			textStyle: {
				color: "#000",
				rich: {
					name: {
						verticalAlign: "right",
						align: "left",
						width: 120,
						fontSize: 14,
						color: "#FFFFFF"
					},
					value: {
						align: "left",
						width: 50,
						fontSize: 14,
						color: "#FFFFFF"
					}
				}
			},
			data: dataList.value.map(item => {
				if (item.show) {
					return item.name;
				}
			}),
			formatter: function (data) {
				if (dataList.value && dataList.value.length) {
					for (let i = 0; i < dataList.value.length; i++) {
						if (data === dataList.value[i].name) {
							let value = dataList.value[i].value;
							let percentage = value + "%";
							return "{name| " + data + "}" + "{value| " + value + "}" + "{value| " + percentage + "}";
						}
					}
				}
			}
		},
		series: [
			// 外侧光线
			{
				name: "",
				type: "gauge",
				center: ["25%", "55%"],
				radius: "80%",
				startAngle: 235,
				endAngle: -50,
				min: 0,
				max: 100,
				axisLine: {
					show: true,
					lineStyle: {
						width: 2,
						color: [
							[
								100 / 100,
								new echarts.graphic.LinearGradient(0, 0, 1, 0, [
									{
										offset: 0,
										color: "#52bef0"
									},
									{
										offset: 1,
										color: "rgba(54, 128, 174,0.4)"
									}
								])
							],
							[1, "rgba(255,255,255,0)"]
						]
					}
				},

				axisTick: {
					show: 0
				},
				splitLine: {
					show: 0
				},
				axisLabel: {
					show: 0
				},
				pointer: {
					show: 0
				},
				detail: {
					show: 0
				}
			},
			{
				name: "",
				type: "gauge",
				center: ["25%", "55%"],
				radius: "71%",
				startAngle: 245,
				endAngle: -115,
				min: 0,
				max: 100,
				axisLine: {
					show: true,
					lineStyle: {
						width: 2,
						color: [
							[
								200 / 100,
								new echarts.graphic.LinearGradient(0, 0, 1, 0, [
									{
										offset: 0.8,
										color: "#52bef0"
									},
									{
										offset: 0.5,
										color: "#13356b"
									}
								])
							],
							[1, "rgba(255,255,255,0)"]
						]
					}
				},

				axisTick: {
					show: 0
				},
				splitLine: {
					show: 0
				},
				axisLabel: {
					show: 0
				},
				pointer: {
					show: 0
				},
				detail: {
					show: 0
				}
			},
			{
				name: "",
				type: "pie",
				radius: ["60", "65"],
				center: ["25%", "55%"],
				hoverAnimation: true,
				itemStyle: {
					borderRadius: 10,
					borderWidth: 10
				},
				label: {
					show: false,
					position: "center"
				},
				emphasis: {
					label: {
						show: false
					}
				},
				labelLine: {
					show: false
				},
				data: dataList.value
			},
			{
				type: "pie",
				radius: ["53", "55"],
				center: ["25%", "55%"],
				label: {
					show: false
				},

				data: Pie()
			}
		]
	};
	echartsTest.setOption(option, true);
}
</script>

<style lang="scss" scoped>
.leftBottomBox {
	width: 100%;
	height: 100%;
	position: relative;
}
.num {
	width: 66px;
	text-align: center;
	font-family: sadigitalNumber;
	font-size: calc(100vw * 24 / 1920);
	color: #fff;
	position: absolute;
	top: 45%;
	left: 18%;
	z-index: 9;
}
// .styleImg {
// 	left: 6%;
// 	top: 17%;
// 	width: 40%;
// 	position: absolute;
// 	height: 60%;
// 	background: url("@/assets/images/dustNoise/motionEffect.webp") no-repeat;
// 	background-size: cover;
// }
.rightHeader {
	width: 65%;
	display: flex;
	position: absolute;
	z-index: 99;
	color: #fff;
	font-size: 10px;
	text-align: center;
	line-height: 2.5vh;
	left: 34%;
	top: 23%;
	.Selected {
		height: 5%;
		background: url("@/assets/images/dustNoise/rightImg2.png") no-repeat;
		background-size: 100% 100%;
		cursor: pointer;
	}
	.day {
		height: 5%;
		width: 15%;
		margin-right: 5%;
		z-index: 99;
		margin-top: -17%;
		cursor: pointer;
	}
	.year {
		height: 5%;
		width: 15%;
		margin-right: 8%;
		z-index: 99;
		margin-top: -17%;
		cursor: pointer;
	}
	.active {
		height: 5%;
		background: url("@/assets/images/dustNoise/rightImg.png") no-repeat;
		background-size: 100% 100%;
	}
}
.time {
	position: absolute;
	z-index: 999;
	left: 37%;
	margin-top: -18%;
}
::v-deep .el-input__wrapper {
	width: 85%;
	height: 0%;
	background: #0d2956;
}
::v-deep .el-range-separator {
	color: #ccc;
	font-size: 10px;
}
::v-deep .el-range-input {
	color: #ccc;
	font-size: 10px;
}
</style>
