<script setup name="expertStatistics">
import { onMounted, ref } from 'vue'
import * as echarts from 'echarts'
import { meeting } from '@/http/apis/statisticAnalysis/reviewMeetingStatistics'
const
  formData = ref({}),
  chart1Ref = ref(), chart2Ref = ref(), chart3Ref = ref(), chart4Ref = ref()
let chart1, chart2, chart3, chart4
const color = new echarts.graphic.LinearGradient(0, 0, 1, 1, [{
  offset: 0,
  color: '#20DEEF'
}, {
  offset: 1,
  color: '#007FED'
}])
const
  getChartData = async () => {
    initChart1()
    initChart2()
    initChart3()
    initChart4()
  },
  initChart1 = () => {
    if (!chart1) chart1 = echarts.init(chart1Ref.value)
    const option = {
      tooltip: {
        show: true,
        trigger: 'axis',
        valueFormatter: (value) => value
      },
      grid: {
        bottom: 20,
        top: 10,
        right: 30
      },
      xAxis: {
        type: 'category',
        data: detailData.value?.regionMeetings.map(i => i.name),
        axisLabel: {
          align: 'center',
          interval: 0,
          rotate: 20
        }
      },
      yAxis: {
        type: 'value'
      },
      color,
      series: [
        {
          name: '召开会议数',
          data: detailData.value?.regionMeetings.map(i => i.num),
          type: 'bar',
          barWidth: 20
        }
      ]
    }
    chart1.setOption(option)
  },
  initChart2 = () => {
    if (!chart2) chart2 = echarts.init(chart2Ref.value)
    const colorList = [
      new echarts.graphic.LinearGradient(0, 0, 1, 1, [{
        offset: 0,
        color: 'rgba(32, 183, 96, 1)'
      }, {
        offset: 1,
        color: 'rgba(32, 183, 96, 0.5)'
      }]),
      new echarts.graphic.LinearGradient(0, 0, 1, 1, [{
        offset: 0,
        color: '#20DEEF'
      }, {
        offset: 1,
        color: '#007FED'
      }])
    ]
    const option = {
      legend: {
        show: false
      },
      tooltip: {
        show: true,
        trigger: 'item'
      },
      color: colorList,
      series: [
        {
          data: detailData.value?.meetingTypes.map(i => {
            return {
              value: i.num,
              name: i.name
            }
          }),
          type: 'pie',
          itemStyle: {
            borderRadius: 4
          },
          label: {
            formatter: '{b}\n{c}',
            color: '#333333'
          },
          emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)'
            }
          }
        }
      ]
    }
    chart2.setOption(option)
  },
  initChart3 = () => {
    if (!chart3) chart3 = echarts.init(chart3Ref.value)
    const option = {
      tooltip: {
        show: true,
        trigger: 'axis',
        valueFormatter: (value) => value
      },
      grid: {
        bottom: 20,
        top: 10,
        right: 30
      },
      xAxis: {
        type: 'category',
        data: detailData.value?.notPassRegionMeetings.map(i => i.name),
        axisLabel: {
          align: 'center',
          interval: 0,
          rotate: 20
        }
      },
      yAxis: {
        type: 'value'
      },
      color,
      series: [
        {
          name: '不通过率',
          data: detailData.value?.notPassRegionMeetings.map(i => i.rate),
          type: 'line'
        }
      ]
    }
    chart3.setOption(option)
  },
  initChart4 = () => {
    if (!chart4) chart4 = echarts.init(chart4Ref.value)
    const option = {
      tooltip: {
        show: true,
        trigger: 'axis',
        valueFormatter: (value) => value
      },
      grid: {
        bottom: 20,
        top: 10,
        right: 30
      },
      xAxis: {
        type: 'category',
        data: detailData.value?.notPassTop10.map(i => i.name),
        axisLabel: {
          align: 'center',
          interval: 0
        }
      },
      yAxis: {
        name: '',
        type: 'value'
      },
      color,
      series: [
        {
          name: '评审不通过数',
          data: detailData.value?.notPassTop10.map(i => i.rate),
          type: 'bar',
          barWidth: 20
        }
      ]
    }
    chart4.setOption(option)
  },
  detailData = ref(),
  getData = async () => {
    const res = await meeting({ year: formData.value.projectYear })
    detailData.value = res.data
    getChartData()
  }
onMounted(async () => {
  getData()
})
</script>

<template>
  <el-card class="mb-16">
    <el-form
      ref="formRef"
      :model="formData"
    >
      <el-form-item label="年度">
        <el-date-picker
          v-model="formData.projectYear"
          type="year"
          placeholder="全部"
          format="YYYY"
          value-format="YYYY"
          style="width: 200px"
          @change="getData"
        />
      </el-form-item>
    </el-form>
    <div class="flex justify-center text-center mt-24">
      <div class="flex-1">
        <p class="text-primary text-32 font-bold" style="font-family: DIN;">{{ detailData?.meetingTotal||0 }}</p>
        <p class="text-info text-14">评审会议召开总数</p>
      </div>
      <div class="flex-1">
        <p class="text-primary text-32 font-bold" style="font-family: DIN;">{{ detailData?.passReview||0 }}</p>
        <p class="text-info text-14">评审通过数</p>
      </div>
      <div class="flex-1">
        <p class="text-primary text-32 font-bold" style="font-family: DIN;">{{ detailData?.notPassRate||0 }}%</p>
        <p class="text-info text-14">评审不通过率</p>
      </div>
    </div>
  </el-card>
  <el-row :gutter="16">
    <el-col :span="12" class="mb-16">
      <el-card header="各区县召开会议总数">
        <div ref="chart1Ref" class="h-[230px]"></div>
      </el-card>
    </el-col>
    <el-col :span="12" class="mb-16">
      <el-card header="预审/验收会议情况">
        <div ref="chart2Ref" class="h-[230px]"></div>
      </el-card>
    </el-col>
    <el-col :span="12" class="mb-16">
      <el-card header="各区县评审不通过率">
        <div ref="chart3Ref" class="h-[230px]"></div>
      </el-card>
    </el-col>
    <el-col :span="12" class="mb-16">
      <el-card header="各区县评审不通过情况TOP10">
        <div ref="chart4Ref" class="h-[230px]"></div>
      </el-card>
    </el-col>
  </el-row>
</template>
