<template>
	<ChartCard margin="0 0 30rpx 0" title="领导级安全检查数">
		<view class="big-crisis" @click="router.push('/pages/index/leadershipSafety/index')">
			<qiun-data-charts type="column" :opts="opts" :canvas2d="false" :chartData="chartData" @getIndex="handleTap" />
		</view>
	</ChartCard>
</template>

<script setup>
import ChartCard from '@/components/chartCard.vue';
import { ref, watch } from 'vue';
import { router } from '@/utils';
let props = defineProps({
	hsseProblemData: {
		type: Array,
		default: () => []
	},
	hsseProblemDataNum: {
		type: Array,
		default: () => []
	}
});
const opts = ref({
	padding: [15, 15, 0, 5],
	enableScroll: false,
	legend: {
		show: true,
		itemGap:10
	},
	xAxis: {
		disableGrid: true
	},
	yAxis: {
		data: [
			{
				min: 0
			}
		]
	},
	extra: {
		column: {
			type: 'group',
			width: 20,
			activeBgColor: '#000000',
			activeBgOpacity: 0.08,
			seriesGap:3
		}
	}
});

const chartData = ref({});

const handleTap = (e) => {
	console.log(e);
};
watch(
	() => props.hsseProblemData,
	(newVal) => {
		if (newVal && newVal.length) {
			// 只有当数据存在时才赋值
			let res = {
				categories: ['集团级检查数', '企业及分支机构检查数'],
				series: [
					{
						name: '总数',
						data: props.hsseProblemDataNum
					},
					{
						name: '未完成',
						data: newVal
					}
				]
			};
			chartData.value = JSON.parse(JSON.stringify(res));
		}
	},
	{ deep: true, immediate: true }
);
</script>

<style lang="scss">
.big-crisis {
	width: 100%;
	height: 400rpx;
}
</style>
