<!--  -->
<template>
  <el-skeleton :loading="loading" animated>
    <el-card shadow="never">
      <template #header>
        <CardTitle title="职位发布时间数量统计" />
      </template>
      <div>
        <Echart :height="300" :options="chartOptions" />
      </div>
    </el-card>      
  </el-skeleton>
</template>

<script lang="ts" setup>
defineOptions({name: 'JobCount'})
import { EChartsOption } from 'echarts'
import { statisticAnalysisApi } from '@/api/menduner/system/analysis/statisticAnalysis'

const props = defineProps({
  queryParams: Object
})

const loading = ref(false)
const chartOptions = reactive<EChartsOption>({
  tooltip: {
    trigger: 'axis',
    axisPointer: {
      type: 'shadow'
    }
  },
  grid: {
    left: 20,
    bottom: 10,
    right: 40,
    top: 30,
    containLabel: true
  },
  xAxis: {
    type: 'category',
    name: '时间',
    data: []
  },
  yAxis: {
    type: 'value',
    name: '个'
  },
  series: [
    {
      data:  [],
      type: 'line',
      label: { show: true }
    }
  ]
}) as EChartsOption

const getData = async (queryParams: any) => {
  loading.value = true
  try {
    const data = await statisticAnalysisApi.getJobCount(queryParams)
    chartOptions.xAxis.data = data.x || []
    chartOptions.series![0].data = data.y || []
  } catch (err) {
    console.log(err);
    loading.value = false
  } finally {
    loading.value = false
  }
}

watch(() => props.queryParams, (newVal) => {
  getData(newVal)
}, { immediate: true, deep: true })
</script>
