<template>
	<ChartCard margin="30rpx 0 0 0" title="QC活动数">
		<view class="inspection" @click="router.push('/pages/quality/QC/index')">
			<qiun-data-charts type="column" :canvas2d="false" :opts="opts" :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({
	awardStatsData: {
		type: Object,
		default: () => {}
	}
});
const opts = ref({
	padding: [15, 15, 0, 5],
	enableScroll: false,
	legend: { show: false },
	xAxis: {
		disableGrid: true
	},
	yAxis: {
		showTitle: true,
		data: [
			{
				title: '单位：项'
			}
		]
	},
	extra: {
		column: {
			type: 'group',
			width: 30,
			activeBgColor: '#000000',
			activeBgOpacity: 0.08
		}
	}
});

const chartData = ref({});

const handleTap = (e) => {
	console.log(e);
};

watch(
	() => props.awardStatsData.qc,
	(newVal) => {
		if (newVal && newVal.length) {
			console.log('监听数据', newVal);
			// 只有当数据存在时才赋值
			let res = {
				categories: ['省部级奖数量', '集团级奖项数量', '企业级奖项数量'],
				series: [
					{
						data: newVal
					}
				]
			};
			chartData.value = JSON.parse(JSON.stringify(res));
		}
	},
	{ deep: true, immediate: true }
);
</script>

<style lang="scss">
.inspection {
	width: 100%;
	height: 300rpx;
}
</style>
