<template>
  <el-scrollbar height="100vh">
    <div class="wrapper">
      <datav-header/>
      <main>
        <el-row :gutter="16">

          <el-col :span="6">
            <datav-card title="日常督察情况">
              <datav-tabs
                  v-model="subOneRcdcProRankTab"
                  type="bottom-button"
                  ref="subOneSceneInspRcdcProRankTabs"
              >
                <datav-tab-item label="派出所" name="1">
                  <el-row class="mb-32">
                    <el-col :span="6">
                      <div class="descriptions_cell text-center">
                        <div class="descriptions_content">
                          {{ fxsjRankOverview.proTotal }}
                        </div>
                        <div class="descriptions_label">
                          问题数
                        </div>
                      </div>
                    </el-col>
                    <el-col :span="6">
                      <div class="descriptions_cell text-center">
                        <div class="descriptions_content">
                          {{ fxsjRankOverview.changing }}
                        </div>
                        <div class="descriptions_label">
                          整改中
                        </div>
                      </div>
                    </el-col>
                    <el-col :span="6">
                      <div class="descriptions_cell text-center">
                        <div class="descriptions_content">
                          {{ fxsjRankOverview.changed }}
                        </div>
                        <div class="descriptions_label">
                          已整改
                        </div>
                      </div>
                    </el-col>
                    <el-col :span="6">
                      <div class="descriptions_cell text-center">
                        <div class="descriptions_content">
                          {{ fxsjRankOverview.correctionRate }}%
                        </div>
                        <div class="descriptions_label">
                          整改率
                        </div>
                      </div>
                    </el-col>
                  </el-row>
                  <el-scrollbar height="350px">
                    <datav-chart-bar
                        :data="fxsjChangedRankList"
                        size="small"
                        title="整改率排名"
                        sub-title="已整改/问题数"
                        unit="%"
                        :label-width="110"
                        :color="dayTimeColors"
                    />
                  </el-scrollbar>
                </datav-tab-item>
                <datav-tab-item label="大队" name="2">
                  <el-row class="mb-32">
                    <el-col :span="6">
                      <div class="descriptions_cell text-center">
                        <div class="descriptions_content">
                          {{ jsdwRankOverview.proTotal }}
                        </div>
                        <div class="descriptions_label">
                          问题数
                        </div>
                      </div>
                    </el-col>
                    <el-col :span="6">
                      <div class="descriptions_cell text-center">
                        <div class="descriptions_content">
                          {{ jsdwRankOverview.changing }}
                        </div>
                        <div class="descriptions_label">
                          整改中
                        </div>
                      </div>
                    </el-col>
                    <el-col :span="6">
                      <div class="descriptions_cell text-center">
                        <div class="descriptions_content">
                          {{ jsdwRankOverview.changed }}
                        </div>
                        <div class="descriptions_label">
                          已整改
                        </div>
                      </div>
                    </el-col>
                    <el-col :span="6">
                      <div class="descriptions_cell text-center">
                        <div class="descriptions_content">
                          {{ jsdwRankOverview.correctionRate }}%
                        </div>
                        <div class="descriptions_label">
                          整改率
                        </div>
                      </div>
                    </el-col>
                  </el-row>
                  <el-scrollbar height="350px">
                    <datav-chart-bar
                        :data="jsdwChangedRankList"
                        size="small"
                        title="整改率排名"
                        sub-title="已整改/问题数"
                        unit="%"
                        :label-width="110"
                        :color="dayTimeColors"
                    />
                  </el-scrollbar>
                </datav-tab-item>
              </datav-tabs>
            </datav-card>


            <datav-card title="问题类型占比">
              <v-charts
                  style="height: 310px"
                  :option="wtlxPieOption"
                  autoresize
                  ref="subOneSceneProblemTypeRate"
              />
            </datav-card>
          </el-col>

          <el-col :span="12">
            <datav-date-picker v-model="time"/>
            <div class="flex gap-42">
              <datav-statistic
                  :value="overview.supervisionNotifyTotal"
                  title="通报问题数"
                  style="width: 16.66%"
              />
              <datav-statistic
                  :value="overview.supervisionNotifyChangingTotal"
                  title="整改中"
                  style="width: 16.66%"
              />
              <datav-statistic
                  :value="overview.supervisionNotifyChangedTotal"
                  title="已整改"
                  style="width: 16.66%"
              />
              <datav-statistic
                  :value="overview.supervisionNotifyOrgTotal"
                  title="涉及单位数"
                  style="width: 16.66%"
              />
              <datav-statistic
                  :value="overview.supervisionNotifyPreTotal"
                  title="涉及人数"
                  style="width: 16.66%"
              />
              <datav-statistic
                  :value="overview.correctionRate"
                  value-unit="%"
                  title="整改率"
                  style="width: 16.66%"
              />
            </div>
            <v-charts
                style="height: 450px"
                :option="option"
                autoresize
                ref="subOneSceneInspMapChart"
                @click="handleClick"
            />
            <datav-card title="问题趋势">
              <v-charts
                  style="height: 280px"
                  :option="proTrend"
                  autoresize
                  ref="subOneSceneInspProTrend"
              />
              <div class="gobal-dropdown-container">
                <el-dropdown class="test" @command="handleCommand">
                    <span class="el-dropdown-link my-gobal-yearselect">
                     {{ selectedYear + " 年" }}
                    </span>
                  <template #dropdown>
                    <el-dropdown-menu style="width: 90px">
                      <el-dropdown-item v-for="year in years" :key="year" :command="year">{{ year + " 年" }}
                      </el-dropdown-item>
                    </el-dropdown-menu>
                  </template>
                </el-dropdown>
              </div>
            </datav-card>
          </el-col>

          <el-col :span="6">
            <datav-card>
              <datav-tabs v-model="subOneZxdcProRankTab" size="small" ref="subOneSceneInspZxdcProRankTabs">
                <datav-tab-item label="黄赌毒" name="1">
                  <datav-tabs type="bottom-button">
                    <datav-tab-item label="派出所" name="1">
                      <el-row class="mb-32">
                        <el-col :span="6">
                          <div class="descriptions_cell text-center">
                            <div class="descriptions_content">
                              {{ fxsjYellowBetOverview.proTotal }}
                            </div>
                            <div class="descriptions_label">
                              问题数
                            </div>
                          </div>
                        </el-col>
                        <el-col :span="6">
                          <div class="descriptions_cell text-center">
                            <div class="descriptions_content">
                              {{ fxsjYellowBetOverview.changing }}
                            </div>
                            <div class="descriptions_label">
                              整改中
                            </div>
                          </div>
                        </el-col>
                        <el-col :span="6">
                          <div class="descriptions_cell text-center">
                            <div class="descriptions_content">
                              {{ fxsjYellowBetOverview.changed }}
                            </div>
                            <div class="descriptions_label">
                              已整改
                            </div>
                          </div>
                        </el-col>
                        <el-col :span="6">
                          <div class="descriptions_cell text-center">
                            <div class="descriptions_content">
                              {{ fxsjYellowBetOverview.correctionRate }}%
                            </div>
                            <div class="descriptions_label">
                              整改率
                            </div>
                          </div>
                        </el-col>
                      </el-row>
                      <el-scrollbar height="330px">
                        <datav-chart-bar
                            :data="fxsjYellowBetRankList"
                            size="large"
                            title="问题数排名"
                            sub-title="问题数"
                            :color="colors"
                            :label-width="110"
                        />
                      </el-scrollbar>
                    </datav-tab-item>
                    <datav-tab-item label="大队" name="2">
                      <el-row class="mb-32">
                        <el-col :span="6">
                          <div class="descriptions_cell text-center">
                            <div class="descriptions_content">
                              {{ jsdwYellowBetOverview.proTotal }}
                            </div>
                            <div class="descriptions_label">
                              问题数
                            </div>
                          </div>
                        </el-col>
                        <el-col :span="6">
                          <div class="descriptions_cell text-center">
                            <div class="descriptions_content">
                              {{ jsdwYellowBetOverview.changing }}
                            </div>
                            <div class="descriptions_label">
                              整改中
                            </div>
                          </div>
                        </el-col>
                        <el-col :span="6">
                          <div class="descriptions_cell text-center">
                            <div class="descriptions_content">
                              {{ jsdwYellowBetOverview.changed }}
                            </div>
                            <div class="descriptions_label">
                              已整改
                            </div>
                          </div>
                        </el-col>
                        <el-col :span="6">
                          <div class="descriptions_cell text-center">
                            <div class="descriptions_content">
                              {{ jsdwYellowBetOverview.correctionRate }}%
                            </div>
                            <div class="descriptions_label">
                              整改率
                            </div>
                          </div>
                        </el-col>
                      </el-row>
                      <el-scrollbar height="330px">
                        <datav-chart-bar
                            :data="jsdwYellowBetRankList"
                            size="large"
                            title="问题数排名"
                            sub-title="问题数"
                            :color="colors"
                            :label-width="110"
                        />
                      </el-scrollbar>
                    </datav-tab-item>
                  </datav-tabs>
                </datav-tab-item>
                <datav-tab-item label="枪支管理" name="2">
                  <datav-tabs
                      type="bottom-button">
                    <datav-tab-item label="派出所" name="1">
                      <el-row class="mb-32">
                        <el-col :span="6">
                          <div class="descriptions_cell text-center">
                            <div class="descriptions_content">
                              {{ fxsjGunControllerOverview.proTotal }}
                            </div>
                            <div class="descriptions_label">
                              问题数
                            </div>
                          </div>
                        </el-col>
                        <el-col :span="6">
                          <div class="descriptions_cell text-center">
                            <div class="descriptions_content">
                              {{ fxsjGunControllerOverview.changing }}
                            </div>
                            <div class="descriptions_label">
                              整改中
                            </div>
                          </div>
                        </el-col>
                        <el-col :span="6">
                          <div class="descriptions_cell text-center">
                            <div class="descriptions_content">
                              {{ fxsjGunControllerOverview.changed }}
                            </div>
                            <div class="descriptions_label">
                              已整改
                            </div>
                          </div>
                        </el-col>
                        <el-col :span="6">
                          <div class="descriptions_cell text-center">
                            <div class="descriptions_content">
                              {{ fxsjGunControllerOverview.correctionRate }}%
                            </div>
                            <div class="descriptions_label">
                              整改率
                            </div>
                          </div>
                        </el-col>
                      </el-row>
                      <el-scrollbar height="330px">
                        <datav-chart-bar
                            :data="fxsjGunControllerRankList"
                            size="large"
                            title="问题数排名"
                            sub-title="问题数"
                            :color="colors"
                        />
                      </el-scrollbar>
                    </datav-tab-item>
                    <datav-tab-item label="大队" name="2">
                      <el-row class="mb-32">
                        <el-col :span="6">
                          <div class="descriptions_cell text-center">
                            <div class="descriptions_content">
                              {{ jsdwGunControllerOverview.proTotal }}
                            </div>
                            <div class="descriptions_label">
                              问题数
                            </div>
                          </div>
                        </el-col>
                        <el-col :span="6">
                          <div class="descriptions_cell text-center">
                            <div class="descriptions_content">
                              {{ jsdwGunControllerOverview.changing }}
                            </div>
                            <div class="descriptions_label">
                              整改中
                            </div>
                          </div>
                        </el-col>
                        <el-col :span="6">
                          <div class="descriptions_cell text-center">
                            <div class="descriptions_content">
                              {{ jsdwGunControllerOverview.changed }}
                            </div>
                            <div class="descriptions_label">
                              已整改
                            </div>
                          </div>
                        </el-col>
                        <el-col :span="6">
                          <div class="descriptions_cell text-center">
                            <div class="descriptions_content">
                              {{ jsdwGunControllerOverview.correctionRate }}%
                            </div>
                            <div class="descriptions_label">
                              整改率
                            </div>
                          </div>
                        </el-col>
                      </el-row>
                      <el-scrollbar height="330px">
                        <datav-chart-bar
                            :data="jsdwGunControllerRankList"
                            size="large"
                            title="问题数排名"
                            sub-title="问题数"
                            :color="colors"
                        />
                      </el-scrollbar>
                    </datav-tab-item>

                  </datav-tabs>
                </datav-tab-item>
                <datav-tab-item label="涉企问题" name="3">
                  <datav-tabs
                      type="bottom-button">
                    <datav-tab-item label="派出所" name="1">
                      <el-row class="mb-32">
                        <el-col :span="6">
                          <div class="descriptions_cell text-center">
                            <div class="descriptions_content">
                              {{ fxsjCompanyProblemOverview.proTotal }}
                            </div>
                            <div class="descriptions_label">
                              问题数
                            </div>
                          </div>
                        </el-col>
                        <el-col :span="6">
                          <div class="descriptions_cell text-center">
                            <div class="descriptions_content">
                              {{ fxsjCompanyProblemOverview.changing }}
                            </div>
                            <div class="descriptions_label">
                              整改中
                            </div>
                          </div>
                        </el-col>
                        <el-col :span="6">
                          <div class="descriptions_cell text-center">
                            <div class="descriptions_content">
                              {{ fxsjCompanyProblemOverview.changed }}
                            </div>
                            <div class="descriptions_label">
                              已整改
                            </div>
                          </div>
                        </el-col>
                        <el-col :span="6">
                          <div class="descriptions_cell text-center">
                            <div class="descriptions_content">
                              {{ fxsjCompanyProblemOverview.correctionRate }}%
                            </div>
                            <div class="descriptions_label">
                              整改率
                            </div>
                          </div>
                        </el-col>
                      </el-row>
                      <el-scrollbar height="330px">
                        <datav-chart-bar
                            :data="fxsjCompanyProblemRankList"
                            size="large"
                            title="问题数排名"
                            sub-title="问题数"
                            :color="colors"
                        />
                      </el-scrollbar>
                    </datav-tab-item>
                    <datav-tab-item label="大队" name="2">
                      <el-row class="mb-32">
                        <el-col :span="6">
                          <div class="descriptions_cell text-center">
                            <div class="descriptions_content">
                              {{ jsdwCompanyProblemOverview.proTotal }}
                            </div>
                            <div class="descriptions_label">
                              问题数
                            </div>
                          </div>
                        </el-col>
                        <el-col :span="6">
                          <div class="descriptions_cell text-center">
                            <div class="descriptions_content">
                              {{ jsdwCompanyProblemOverview.changing }}
                            </div>
                            <div class="descriptions_label">
                              整改中
                            </div>
                          </div>
                        </el-col>
                        <el-col :span="6">
                          <div class="descriptions_cell text-center">
                            <div class="descriptions_content">
                              {{ jsdwCompanyProblemOverview.changed }}
                            </div>
                            <div class="descriptions_label">
                              已整改
                            </div>
                          </div>
                        </el-col>
                        <el-col :span="6">
                          <div class="descriptions_cell text-center">
                            <div class="descriptions_content">
                              {{ jsdwCompanyProblemOverview.correctionRate }}%
                            </div>
                            <div class="descriptions_label">
                              整改率
                            </div>
                          </div>
                        </el-col>
                      </el-row>
                      <el-scrollbar height="330px">
                        <datav-chart-bar
                            :data="jsdwCompanyProblemRankList"
                            size="large"
                            title="问题数排名"
                            sub-title="问题数"
                            :color="colors"
                        />
                      </el-scrollbar>
                    </datav-tab-item>

                  </datav-tabs>
                </datav-tab-item>
                <datav-tab-item label="执法办案" name="4">
                  <datav-tabs
                      type="bottom-button">
                    <datav-tab-item label="派出所" name="1">
                      <el-row class="mb-32">
                        <el-col :span="6">
                          <div class="descriptions_cell text-center">
                            <div class="descriptions_content">
                              {{ fxsjHandleCaseOverview.proTotal }}
                            </div>
                            <div class="descriptions_label">
                              问题数
                            </div>
                          </div>
                        </el-col>
                        <el-col :span="6">
                          <div class="descriptions_cell text-center">
                            <div class="descriptions_content">
                              {{ fxsjHandleCaseOverview.changing }}
                            </div>
                            <div class="descriptions_label">
                              整改中
                            </div>
                          </div>
                        </el-col>
                        <el-col :span="6">
                          <div class="descriptions_cell text-center">
                            <div class="descriptions_content">
                              {{ fxsjHandleCaseOverview.changed }}
                            </div>
                            <div class="descriptions_label">
                              已整改
                            </div>
                          </div>
                        </el-col>
                        <el-col :span="6">
                          <div class="descriptions_cell text-center">
                            <div class="descriptions_content">
                              {{ fxsjHandleCaseOverview.correctionRate }}%
                            </div>
                            <div class="descriptions_label">
                              整改率
                            </div>
                          </div>
                        </el-col>
                      </el-row>
                      <el-scrollbar height="330px">
                        <datav-chart-bar
                            :data="fxsjHandleCaseRankList"
                            size="large"
                            title="问题数排名"
                            sub-title="问题数"
                            :color="colors"
                        />
                      </el-scrollbar>
                    </datav-tab-item>
                    <datav-tab-item label="大队" name="2">
                      <el-row class="mb-32">
                        <el-col :span="6">
                          <div class="descriptions_cell text-center">
                            <div class="descriptions_content">
                              {{ jsdwHandleCaseOverview.proTotal }}
                            </div>
                            <div class="descriptions_label">
                              问题数
                            </div>
                          </div>
                        </el-col>
                        <el-col :span="6">
                          <div class="descriptions_cell text-center">
                            <div class="descriptions_content">
                              {{ jsdwHandleCaseOverview.changing }}
                            </div>
                            <div class="descriptions_label">
                              整改中
                            </div>
                          </div>
                        </el-col>
                        <el-col :span="6">
                          <div class="descriptions_cell text-center">
                            <div class="descriptions_content">
                              {{ jsdwHandleCaseOverview.changed }}
                            </div>
                            <div class="descriptions_label">
                              已整改
                            </div>
                          </div>
                        </el-col>
                        <el-col :span="6">
                          <div class="descriptions_cell text-center">
                            <div class="descriptions_content">
                              {{ jsdwHandleCaseOverview.correctionRate }}%
                            </div>
                            <div class="descriptions_label">
                              整改率
                            </div>
                          </div>
                        </el-col>
                      </el-row>
                      <el-scrollbar height="330px">
                        <datav-chart-bar
                            :data="jsdwHandleCaseRankList"
                            size="large"
                            title="问题数排名"
                            sub-title="问题数"
                            :color="colors"
                        />
                      </el-scrollbar>
                    </datav-tab-item>

                  </datav-tabs>
                </datav-tab-item>
                <datav-tab-item label="工作日测酒" name="5">
                  <datav-tabs
                      type="bottom-button">
                    <datav-tab-item label="派出所" name="1">
                      <el-row class="mb-32">
                        <el-col :span="6">
                          <div class="descriptions_cell text-center">
                            <div class="descriptions_content">
                              {{ fxsjCheckBeerOverview.proTotal }}
                            </div>
                            <div class="descriptions_label">
                              问题数
                            </div>
                          </div>
                        </el-col>
                        <el-col :span="6">
                          <div class="descriptions_cell text-center">
                            <div class="descriptions_content">
                              {{ fxsjCheckBeerOverview.changing }}
                            </div>
                            <div class="descriptions_label">
                              整改中
                            </div>
                          </div>
                        </el-col>
                        <el-col :span="6">
                          <div class="descriptions_cell text-center">
                            <div class="descriptions_content">
                              {{ fxsjCheckBeerOverview.changed }}
                            </div>
                            <div class="descriptions_label">
                              已整改
                            </div>
                          </div>
                        </el-col>
                        <el-col :span="6">
                          <div class="descriptions_cell text-center">
                            <div class="descriptions_content">
                              {{ fxsjCheckBeerOverview.correctionRate }}%
                            </div>
                            <div class="descriptions_label">
                              整改率
                            </div>
                          </div>
                        </el-col>
                      </el-row>
                      <el-scrollbar height="330px">
                        <datav-chart-bar
                            :data="fxsjCheckBeerRankList"
                            size="large"
                            title="问题数排名"
                            sub-title="问题数"
                            :color="colors"
                        />
                      </el-scrollbar>
                    </datav-tab-item>
                    <datav-tab-item label="大队" name="2">
                      <el-row class="mb-32">
                        <el-col :span="6">
                          <div class="descriptions_cell text-center">
                            <div class="descriptions_content">
                              {{ jsdwCheckBeerOverview.proTotal }}
                            </div>
                            <div class="descriptions_label">
                              问题数
                            </div>
                          </div>
                        </el-col>
                        <el-col :span="6">
                          <div class="descriptions_cell text-center">
                            <div class="descriptions_content">
                              {{ jsdwCheckBeerOverview.changing }}
                            </div>
                            <div class="descriptions_label">
                              整改中
                            </div>
                          </div>
                        </el-col>
                        <el-col :span="6">
                          <div class="descriptions_cell text-center">
                            <div class="descriptions_content">
                              {{ jsdwCheckBeerOverview.changed }}
                            </div>
                            <div class="descriptions_label">
                              已整改
                            </div>
                          </div>
                        </el-col>
                        <el-col :span="6">
                          <div class="descriptions_cell text-center">
                            <div class="descriptions_content">
                              {{ jsdwCheckBeerOverview.correctionRate }}%
                            </div>
                            <div class="descriptions_label">
                              整改率
                            </div>
                          </div>
                        </el-col>
                      </el-row>
                      <el-scrollbar height="330px">
                        <datav-chart-bar
                            :data="jsdwCheckBeerRankList"
                            size="large"
                            title="问题数排名"
                            sub-title="问题数"
                            :color="colors"
                        />
                      </el-scrollbar>
                    </datav-tab-item>

                  </datav-tabs>
                </datav-tab-item>
              </datav-tabs>
            </datav-card>


            <datav-card title="督察工作动态">
              <el-scrollbar height="310px" ref="subOneSceneScrollbar">
                <datav-message
                    v-for="(msg, index) in messages"
                    :key="index"
                    :type="msg.type"
                    :title="msg.workType"
                    :content="msg.contentTxt"
                    :date="msg.releaseTime"
                />
              </el-scrollbar>
            </datav-card>
          </el-col>

        </el-row>
      </main>
    </div>
  </el-scrollbar>
  <negative-info-depart-dialog v-model="showDialog" :departId="tempDepartId"/>
</template>

<script setup>
import vCharts from "vue-echarts";
import changshaMap from "@/assets/data/changsha.json";
import * as echarts from "echarts/core";
import moment from "moment";

import {getSubOneStreetMap} from "@/api/screen/subScreen/subOneGlobal.ts";
import {
  getSubOneChangedRank, getSubOneCheckBeer, getSubOneCompanyProblem, getSubOneGunController, getSubOneHandleCase,
  getSubOneProblemTypeRate, getSubOneSupervisionMap, getSubOneSupervisionNotifyCount,
  getSubOneSupervisionTrend, getSubOneWorkDynamics, getSubOneYellowBetDrug
} from "@/api/screen/subScreen/subOneSupervisionNotify.ts";
import {workDynamicColorMapping} from "@/enums/workDynamicColorMapping.js";

// region 所有变量
const time = ref([
  moment().subtract(1, "year").format("YYYY-MM-DD"),
  moment().format("YYYY-MM-DD"),
]);
const route = useRoute();
const currentDepartId = route.query.departId;
const currentYear = new Date().getFullYear();
const years = ref([currentYear.toString(), (currentYear - 1).toString(), (currentYear - 2).toString()]); // 年份列表
const selectedYear = ref(currentYear); // 当前选中的年份

const overview = ref({
  correctionRate: 0,
  supervisionNotifyPreTotal: 0,
  supervisionNotifyChangingTotal: 0,
  supervisionNotifyChangedTotal: 0,
  supervisionNotifyTotal: 0,
  supervisionNotifyOrgTotal: 0,
});  // 中央数据总览
const fxsjRankOverview = ref({});  // 日常督察总览分县市局
const jsdwRankOverview = ref({});  // 日常督察总览局属单位
const fxsjChangedRankList = ref([]);  // 日常督察问题排行分县市局
const jsdwChangedRankList = ref([]);  // 日常督察问题排行局属单位
const wtlxList = ref([]);  // 问题类型占比

const fxsjYellowBetOverview = ref({
  proTotal: 0,
  changing: 0,
  changed: 0,
  correctionRate: 0,
})  // 黄赌毒总览分县市局
const jsdwYellowBetOverview = ref({
  proTotal: 0,
  changing: 0,
  changed: 0,
  correctionRate: 0,
})  // 黄赌毒总览局属单位
const fxsjYellowBetRankList = ref([])  // 黄赌毒问题排行分县市局
const jsdwYellowBetRankList = ref([])  // 黄赌毒问题排行局属单位

const fxsjGunControllerOverview = ref({
  proTotal: 0,
  changing: 0,
  changed: 0,
  correctionRate: 0,
})  // 枪支管理总览分县市局
const jsdwGunControllerOverview = ref({
  proTotal: 0,
  changing: 0,
  changed: 0,
  correctionRate: 0,
})  // 枪支管理总览局属单位
const fxsjGunControllerRankList = ref([])  //  枪支管理排行分县市局
const jsdwGunControllerRankList = ref([])  //  枪支管理排行局属单位

const fxsjCompanyProblemOverview = ref({
  proTotal: 0,
  changing: 0,
  changed: 0,
  correctionRate: 0,
})  // 涉企问题总览分县市局
const jsdwCompanyProblemOverview = ref({
  proTotal: 0,
  changing: 0,
  changed: 0,
  correctionRate: 0,
})  // 涉企问题局属单位
const fxsjCompanyProblemRankList = ref([])  //  涉企问题排行分县市局
const jsdwCompanyProblemRankList = ref([])  //  涉企问题排行局属单位

const fxsjHandleCaseOverview = ref({
  proTotal: 0,
  changing: 0,
  changed: 0,
  correctionRate: 0,
})  // 执法办案总览分县市局
const jsdwHandleCaseOverview = ref({
  proTotal: 0,
  changing: 0,
  changed: 0,
  correctionRate: 0,
})  // 执法办案总览局属单位
const fxsjHandleCaseRankList = ref([])  //  执法办案排行分县市局
const jsdwHandleCaseRankList = ref([])  //  执法办案排行局属单位

const fxsjCheckBeerOverview = ref({
  proTotal: 0,
  changing: 0,
  changed: 0,
  correctionRate: 0,
})  // 工作日测酒总览分县市局
const jsdwCheckBeerOverview = ref({
  proTotal: 0,
  changing: 0,
  changed: 0,
  correctionRate: 0,
})  // 工作日测酒总览局属单位
const fxsjCheckBeerRankList = ref([])  //  工作日测酒排行分县市局
const jsdwCheckBeerRankList = ref([])  //  工作日测酒排行局属单位

const messages = ref([]);

const subOneZxdcProRankTab = ref("1"); // 专项督察问题排行tab
const subOneRcdcProRankTab = ref("1")
const subOneSceneInspRcdcProRankTabs = ref(null)
const subOneSceneProblemTypeRate = ref(null);
const subOneSceneInspMapChart = ref(null);
const subOneSceneInspProTrend = ref(null);
const subOneSceneInspZxdcProRankTabs = ref(null);
const subOneSceneScrollbar = ref(null);
const currentIndex = ref(0);
let subOneSceneInspRcdxIntervalId;
let subOneSceneProblemTypeRateIntervalId;
let subOneSceneInspMapIntervalId;
let subOneSceneInspTrendIntervalId;
let subOneSceneInspZxdxIntervalId;
let subOneSceneWorkDynamicsIntervalId;

const tempDepartId = ref(0);  // 临时部门id
const showDialog = ref(false);  // 负面信息弹窗显示

const colors = [
  {
    color: "linear-gradient( 270deg, #FB002D 0%, #822232 100%)",
    percentage: 80,
  },
  {
    color: "linear-gradient( 270deg, #FFB90E 0%, #71501D 100%)",
    percentage: 60,
  },
  {
    color: "linear-gradient( 270deg, #63E700 0%, #19674C 100%)",
    percentage: 0,
  },
];
const dayTimeColors = [
  {
    color: "linear-gradient( 270deg, #63E700 0%, #19674C 100%)",

    percentage: 80,
  },
  {
    color: "linear-gradient( 270deg, #FFB90E 0%, #71501D 100%)",
    percentage: 75,
  },
  {
    color: "linear-gradient( 270deg, #FB002D 0%, #822232 100%)",
    percentage: 0,
  },
];

// endregion

// region 所有图表
echarts.registerMap("changsha", changshaMap);
const option = ref({
  tooltip: {
    trigger: 'item',
    position: 'bottom',
    formatter: function (params) {
      const dataItem = superviseTempMapVoList.value.find(item => item.name === params.name) || {}; // 找到对应的数据项

      if (dataItem.name === params.name) {
        return `
        <div class="tooltip">
          <div class="tooltip-title">${params.name}</div>
          <div class="tooltip-content">
            <ul class="tooltip-ul" >
              <li>通报问题数 <span>${dataItem.totalPro}</span></li>
              <li>整改中 <span>${dataItem.changing}</span></li>
              <li>已整改 <span>${dataItem.changed}</span></li>
              <li>涉及单位数 <span>${dataItem.relationOrg}</span></li>
              <li>涉及人数 <span>${dataItem.personNum}</span></li>
              <li>整改率 <span>${dataItem.changedRate}%</span></li>
            </ul>
          </div>
        </div>`;
      } else {
        return `<div class="tooltip">
          <div class="tooltip-title">${params.name}</div>
          <div class="tooltip-content">
            <ul class="tooltip-ul"">
              <li>通报问题数 <span>-</span></li>
              <li>整改中 <span>-</span></li>
              <li>已整改 <span>-</span></li>
              <li>涉及单位数 <span>-</span></li>
              <li>涉及人数 <span>-</span></li>
              <li>整改率 <span>-</span></li>
            </ul>
          </div>
        </div>`;
      }
    },
  },
  visualMap: {
    type: "piecewise",
    bottom: 10,
    pieces: [
      {gte: 0, lte: 200, label: "低于平均问题30%", color: "#4987F6"},
      {gte: 200, lte: 400, label: "平均问题上下浮动30%内", color: "#F6A149"},
      {gte: 400, label: "高于平均问题30%", color: "#D34343"},],
    right: 10,
    realtime: false,
    orient: "horizontal",
    textStyle: {
      color: "#fff",
    },
    calculable: true,

  },
  series: [
    {
      name: "长沙",
      type: "map",
      map: "changsha",
      hoverAnimation: true,
      roam: true,
      label: {
        show: true,
        color: "white",
      },
      itemStyle: {
        normal: {
          areaColor: "#02215E",
          borderColor: "#24D2EE",
          borderWidth: 1 // 高亮时边框宽度
        },
      },
      emphasis: {
        areaColor: "#FFD700", // 高亮时区域颜色
        borderColor: "#FF0000", // 高亮时边框颜色
        borderWidth: 4 // 高亮时边框宽度
      },
      data: []
    }
  ],
})
const wtlxPieOption = computed(() => {
  return {
    tooltip: {
      trigger: "item",
    },
    series: [
      {
        type: "pie",
        radius: ["40%", "70%"],
        label: {
          color: "#fff",
        },
        data: wtlxList.value,
      },
    ],
  };
});
const superviseTempMapVoList = ref([]);
const proTrend = ref({
  grid: {
    left: '5%', // 图表距离容器左边的距离
    right: '2%', // 图表距离容器右边的距离
    top: '10%', // 图表距离容器上边的距离
    bottom: '20%', // 图表距离容器下边的距离
    containLabel: false // 是否包含坐标轴的标签
  },
  xAxis: {
    type: "category",
    data: [],
    boundaryGap: true,
    axisTick: {
      // 去掉X轴刻度线
      show: false
    },
  },
  yAxis: {
    type: "value",
    splitLine: {
      show: true,
      lineStyle: {
        color: "#193775",
      },
    }
  },
  tooltip: {
    trigger: 'axis',
    axisPointer: {
      type: 'line',
      label: {
        backgroundColor: '#6a7985'
      }
    }
  },
  series: [
    {
      type: "line",
      smooth: true,
      label: {
        show: false
      },
      lineStyle: {
        color: "#28E6FF",
        width: 4,
      },
      areaStyle: {
        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
          {
            offset: 0,
            color: "rgba(40,230,255,0.47)", // 渐变起始颜色
          },
          {
            offset: 1,
            color: "rgba(40,230,255,0)", // 渐变结束颜色
          },
        ]),
      },
      data: [],
    },
  ],
});
// endregion

// region 所有函数
const getMapJSON = async (departId = currentDepartId) => {
  const res = await getSubOneStreetMap(departId)
  echarts.registerMap("changsha", res);
  subOneSceneInspMapChart.value.chart.setOption(option.value);
}
const getSubOneChangedRankData = async (departId, times) => {
  const res = await getSubOneChangedRank(departId, times)
  fxsjRankOverview.value = res.fxsjRankOverview;
  jsdwRankOverview.value = res.jsdwRankOverview;
  fxsjChangedRankList.value = res.fxsjChangedRankList;
  jsdwChangedRankList.value = res.jsdwChangedRankList;
  console.log(res);

}
const getSubOneProblemTypeRateData = async (departId, times) => {
  const res = await getSubOneProblemTypeRate(departId, times)
  // wtlxList.value = circularChart;
  wtlxList.value = res.wtlxList
}
const getSubOneSupervisionNotifyCountData = async (departId, times) => {
  const res = await getSubOneSupervisionNotifyCount(departId, times)
  Object.assign(overview.value, {
    correctionRate: Number(res.overview.rectifyRate),
    supervisionNotifyPreTotal: Number(res.overview.personNumber),
    supervisionNotifyChangingTotal: Number(res.overview.rectifingNumber),
    supervisionNotifyChangedTotal: Number(res.overview.rectifedNumber),
    supervisionNotifyTotal: Number(res.overview.problemNumber),
    supervisionNotifyOrgTotal: Number(res.overview.departNumber),
  });
}
const getSubOneSupervisionMapData = async (departId, times) => {
  const res = await getSubOneSupervisionMap(departId, times);
  const mappedData = res.superviseTempMapVoList.map(item => {
    return {
      ...item,
      value: item.totalPro,
    };
  });
  const total = mappedData.reduce((sum, item) => sum + Number(item.value), 0);
  const avg = total / mappedData.length; // 计算平均值
  const range30Percent = avg * 0.3   // 不用取整，小数也可以
  option.value.visualMap.pieces = [
    {gte: 0, lte: avg - range30Percent, label: "低于平均问题30%", color: "#4987F6"},
    {gte: avg - range30Percent, lte: avg + range30Percent, label: "平均问题上下浮动30%内", color: "#F6A149"},
    {gte: avg + range30Percent, label: "高于平均问题30%", color: "#D34343"},
  ];
  superviseTempMapVoList.value = mappedData;
  option.value.series[0].data = mappedData;
}
const getSubOneSupervisionTrendData = async (departId, year) => {
  const res = await getSubOneSupervisionTrend(departId, year)
  const supervisionTrend = res.supervisionTrend;
  const categories = supervisionTrend.map(item => item.name);
  const values = supervisionTrend.map(item => item.value);
  proTrend.value.xAxis.data = categories;
  proTrend.value.series[0].data = values;
}
const getSubOneYellowBetDrugData = async (departId, times) => {
  const res = await getSubOneYellowBetDrug(departId, times)
  fxsjYellowBetOverview.value = res.fxsjYellowBetOverview
  jsdwYellowBetOverview.value = res.jsdwYellowBetOverview
  fxsjYellowBetRankList.value = res.fxsjYellowBetRankList
  jsdwYellowBetRankList.value = res.jsdwYellowBetRankList
}
const getSubOneGunControllerData = async (departId, times) => {
  const res = await getSubOneGunController(departId, times)
  fxsjGunControllerOverview.value = res.fxsjGunControllerOverview
  jsdwGunControllerOverview.value = res.jsdwGunControllerOverview
  fxsjGunControllerRankList.value = res.fxsjGunControllerRankList
  jsdwGunControllerRankList.value = res.jsdwGunControllerRankList
}
const getSubOneCompanyProblemData = async (departId, times) => {
  const res = await getSubOneCompanyProblem(departId, times)
  fxsjCompanyProblemOverview.value = res.fxsjCompanyProblemOverview
  jsdwCompanyProblemOverview.value = res.jsdwCompanyProblemOverview
  fxsjCompanyProblemRankList.value = res.fxsjCompanyProblemRankList
  jsdwCompanyProblemRankList.value = res.jsdwCompanyProblemRankList
}
const getSubOneHandleCaseData = async (departId, times) => {
  const res = await getSubOneHandleCase(departId, times)
  fxsjHandleCaseOverview.value = res.fxsjHandleCaseOverview
  jsdwHandleCaseOverview.value = res.jsdwHandleCaseOverview
  fxsjHandleCaseRankList.value = res.fxsjHandleCaseRankList
  jsdwHandleCaseRankList.value = res.jsdwHandleCaseRankList
}
const getSubOneCheckBeerData = async (departId, times) => {
  const res = await getSubOneCheckBeer(departId, times)
  fxsjCheckBeerOverview.value = res.fxsjCheckBeerOverview
  jsdwCheckBeerOverview.value = res.jsdwCheckBeerOverview
  fxsjCheckBeerRankList.value = res.fxsjCheckBeerRankList
  jsdwCheckBeerRankList.value = res.jsdwCheckBeerRankList
}

const getSubOneWorkDynamicsData = async (departId, times) => {
  const data = await getSubOneWorkDynamics(departId, times);
  const colorNewsVoList = workDynamicColorMapping(data);
  messages.value = colorNewsVoList;
}
const getData = async () => {
  getMapJSON(currentDepartId);
  getSubOneChangedRankData(currentDepartId, time.value);
  getSubOneProblemTypeRateData(currentDepartId, time.value);
  getSubOneSupervisionNotifyCountData(currentDepartId, time.value);
  getSubOneSupervisionMapData(currentDepartId, time.value);
  getSubOneSupervisionTrendData(currentDepartId, selectedYear.value);
  getSubOneYellowBetDrugData(currentDepartId, time.value);
  getSubOneGunControllerData(currentDepartId, time.value);
  getSubOneCompanyProblemData(currentDepartId, time.value);
  getSubOneHandleCaseData(currentDepartId, time.value);
  getSubOneCheckBeerData(currentDepartId, time.value);
  getSubOneWorkDynamicsData(currentDepartId, time.value);
}

// endregion

// region 动画
// 日常督察问题排行动画
const subOneSceneInspRcdxRankAnimation = () => {
  subOneRcdcProRankTab.value = (parseInt(subOneRcdcProRankTab.value) % 2 + 1).toString();
};
subOneSceneInspRcdxIntervalId = setInterval(subOneSceneInspRcdxRankAnimation, 3000);
// 问题类型占比
const subOneSceneProblemTypeRateAnimation = () => {
  const temp = subOneSceneProblemTypeRate?.value?.chart;
  if (!temp) return;
  const length = wtlxPieOption.value.series[0].data.length;
  const randomNum = Math.floor(Math.random() * length);
  temp?.dispatchAction({type: 'downplay', seriesIndex: 0});
  temp?.dispatchAction({type: 'highlight', seriesIndex: 0, dataIndex: randomNum}); // 显示
  temp?.dispatchAction({type: 'showTip', seriesIndex: 0, dataIndex: randomNum});
}
subOneSceneProblemTypeRateIntervalId = setInterval(subOneSceneProblemTypeRateAnimation, 2000);

// 地图动画
const subOneSceneInspMapAnimation = () => {
  const mapTemp = subOneSceneInspMapChart?.value?.chart;
  if (!mapTemp) return;
  // 来个随机数，9个图  0~8的整数就ok
  const randomNum = Math.floor(Math.random() * 9);
  mapTemp.dispatchAction({
    type: "downplay", //downplay 取消高亮
    seriesIndex: 0,
  });
  mapTemp.dispatchAction({
    type: "highlight", //highLight 高亮指定的数据图形
    seriesIndex: 0, //系列index
    dataIndex: randomNum, //数据index
  });
  mapTemp.dispatchAction({
    type: "showTip", //showTip 显示提示框
    seriesIndex: 0,
    dataIndex: randomNum,
  });
};
// 启动定时器，每隔 2 秒执行一次
subOneSceneInspMapIntervalId = setInterval(subOneSceneInspMapAnimation, 2000);
// 问题趋势动画
const subOneSceneInspTrendAnimation = () => {
  const trendTemp = subOneSceneInspProTrend?.value?.chart;
  if (!trendTemp) return;
  const randomNum = Math.floor(Math.random() * 12);
  trendTemp.dispatchAction({
    type: 'showTip',
    seriesIndex: 0,
    dataIndex: randomNum,
  });
}
subOneSceneInspTrendIntervalId = setInterval(subOneSceneInspTrendAnimation, 2000);
// // 专项督察问题排行动画  直接切换大tab，里面不管了
const subOneSceneInspZxdxRankAnimation = () => {
  subOneZxdcProRankTab.value = (parseInt(subOneZxdcProRankTab.value) % 5 + 1).toString();
};
subOneSceneInspZxdxIntervalId = setInterval(subOneSceneInspZxdxRankAnimation, 3000);
// 工作动态动画
const subOneSceneWorkDynamicsAnimation = () => {
  const sceneScrollTemp = subOneSceneScrollbar?.value;
  const maxScroll = sceneScrollTemp?.wrapRef?.scrollHeight - sceneScrollTemp?.wrapRef?.clientHeight;
  currentIndex.value > maxScroll ? currentIndex.value = 0 : currentIndex.value += 1;
  if (currentIndex.value === 0) {
    sceneScrollTemp?.scrollTo({top: currentIndex.value});
  } else {
    sceneScrollTemp?.scrollTo({top: currentIndex.value});
  }
}
subOneSceneWorkDynamicsIntervalId = setInterval(subOneSceneWorkDynamicsAnimation, 50);
// endregion

// region 监听
watch(time, () => {
  getData();
});
onMounted(() => {
  getData();
  setupEventListeners();
});
const handleCommand = (year) => {
  selectedYear.value = year; // 更新当前选中的年份
  getSubOneSupervisionTrendData(currentDepartId, selectedYear.value);
};
const handleClick = (params) => {
  const departId = params.data.departId;
  showDialog.value = true;
  tempDepartId.value = departId
  clearInterval(subOneGlobalMapIntervalId);
}

// 鼠标经过地图事件
const setupEventListeners = () => {
  subOneSceneInspRcdxRankAnimationStop();
  subOneSceneProblemTypeRateAnimationStop();
  subOneSceneInspMapAnimationStop();
  subOneSceneInspTrendAnimationStop();
  subOneSceneInspZxdxRankAnimationStop();
  subOneSceneWorkDynamicsAnimationStop();
};
const subOneSceneInspRcdxRankAnimationStop = () => {
  const temp = subOneSceneInspRcdcProRankTabs.value?.$el;
  temp.addEventListener('mouseenter', () => {
    clearInterval(subOneSceneInspRcdxIntervalId)
  });
  temp.addEventListener('mouseleave', () => {
    clearInterval(subOneSceneInspRcdxIntervalId);
    subOneSceneInspRcdxIntervalId = setInterval(subOneSceneInspRcdxRankAnimation, 3000);
  });
}
const subOneSceneProblemTypeRateAnimationStop = () => {
  const temp = subOneSceneProblemTypeRate?.value?.chart;
  temp.on('mousemove', (e) => {
    clearInterval(subOneSceneProblemTypeRateIntervalId);
    temp.dispatchAction({type: "downplay", seriesIndex: 0,});
    temp.dispatchAction({type: "highlight", seriesIndex: 0, dataIndex: e.dataIndex,});
    temp.dispatchAction({type: "showTip", seriesIndex: 0, dataIndex: e.dataIndex,});
  })
  temp.on('mouseout', () => {
    clearInterval(subOneSceneProblemTypeRateIntervalId);
    subOneSceneProblemTypeRateIntervalId = setInterval(subOneSceneProblemTypeRateAnimation, 2000);
  })
}
const subOneSceneInspMapAnimationStop = () => {
  const mapTemp = subOneSceneInspMapChart?.value?.chart;
  // 鼠标移入
  mapTemp.on('mousemove', (e) => {
    clearInterval(subOneSceneInspMapIntervalId);
    mapTemp.dispatchAction({type: "downplay", seriesIndex: 0,});
    mapTemp.dispatchAction({type: "highlight", seriesIndex: 0, dataIndex: e.dataIndex,});
    mapTemp.dispatchAction({type: "showTip", seriesIndex: 0, dataIndex: e.dataIndex,});
  });
  // 鼠标移出
  mapTemp.on('mouseout', () => {
    clearInterval(subOneSceneInspMapIntervalId); // 确保没有多个定时器同时运行
    subOneSceneInspMapIntervalId = setInterval(subOneSceneInspMapAnimation, 2000);
  });
}
const subOneSceneInspTrendAnimationStop = () => {
  const temp = subOneSceneInspProTrend?.value.getDom();
  temp.addEventListener('mouseenter', () => {
    clearInterval(subOneSceneInspTrendIntervalId);
  });
  temp.addEventListener('mouseleave', () => {
    clearInterval(subOneSceneInspTrendIntervalId);
    subOneSceneInspTrendIntervalId = setInterval(subOneSceneInspTrendAnimation, 2000);
  });
}
const subOneSceneInspZxdxRankAnimationStop = () => {
  const temp = subOneSceneInspZxdcProRankTabs.value?.$el;
  temp.addEventListener('mouseenter', () => {
    clearInterval(subOneSceneInspZxdxIntervalId)
  });
  temp.addEventListener('mouseleave', () => {
    clearInterval(subOneSceneInspZxdxIntervalId);
    subOneSceneInspZxdxIntervalId = setInterval(subOneSceneInspZxdxRankAnimation, 3000);
  });
}
const subOneSceneWorkDynamicsAnimationStop = () => {
  const temp = subOneSceneScrollbar.value?.$el;
  temp.addEventListener('mouseenter', () => {
    // alert(1);
    clearInterval(subOneSceneWorkDynamicsIntervalId)
  });
  temp.addEventListener('mouseleave', () => {
    clearInterval(subOneSceneWorkDynamicsIntervalId);
    subOneSceneWorkDynamicsIntervalId = setInterval(subOneSceneWorkDynamicsAnimation, 50);
  });
}

// endregion
</script>

<style lang="scss" scoped>
@import "@/style/datav.scss";

.message {
  padding: 10px;
  margin-bottom: 10px;
  background: linear-gradient(270deg, rgba(16, 151, 255, 0.1) 0%, rgba(0, 55, 236, 0.87) 100%);

  &[type=warning] {
    background: linear-gradient(270deg, rgba(255, 190, 16, 0.1) 0%, rgba(236, 84, 0, 0.87) 100%);
  }

  &[type=success] {
    background: linear-gradient(270deg, rgba(91, 216, 9, 0.14) 0%, #28813D 100%);
  }

  .message-title {
    font-size: 14px;
    margin-bottom: 10px;
  }

  .message-content {
    margin-bottom: 10px;
  }
}

:deep() {
  // 弹框整体
  .tooltip {
    position: relative;
    width: 160px;
    height: 194px;
    background: linear-gradient(180deg, rgba(1, 4, 87, 0.8) 0%, rgba(3, 21, 119, 0.8) 100%);
    border: 1px solid #4E8FFF;
    margin: -10px -10px -10px -10px;

  }

  ////浏阳市局
  .tooltip-title {
    width: 160px;
    height: 43px;
    background: linear-gradient(180deg, #0A2F86 0%, #04154E 100%);
    box-shadow: inset 0px -1px 0px 0px #253755;
    display: flex;
    justify-content: center; /* 水平居中 */
    align-items: center; /* 垂直居中 */
    font-weight: 400;
    font-size: 16px;
    color: #FFFFFF;
    border-bottom: 1px solid #253755; /* 设置下边框 */
  }

  .tooltip-content {
    width: 160px;
    height: 150px;
    background: linear-gradient(180deg, #010457 0%, #031577 100%)
  }

  .tooltip-content ul {
    list-style-type: none; /* 移除默认的小圆点 */
    padding-left: 5px;
    margin: 0;
  }

  .tooltip-content ul li {
    height: 24px;
    color: #597AE9;
    font-weight: 400;
    font-size: 14px;
  }

  .tooltip-ul span {
    float: right;
    width: 55px;
    color: #fff;
    font-size: 14px;
    text-align: center; /* 水平居中 */
  }

  //.tooltip::before {
  //  content: '';
  //  position: absolute;
  //  top: 90px; /* 调整尖角的垂直位置 */
  //  left: -10px; /* 调整尖角的水平位置 */
  //  width: 0;
  //  height: 0;
  //  //border-top: 10px solid red; /* 顶边颜色 */
  //  //border-bottom: 10px solid green; /* 底边颜色 */
  //  //border-right: 10px solid blue; /* 右边颜色，与背景颜色相同 */
  //}

}

.test {
  width: 95px;
  height: 25px;
  background: #1C3472;
}

.gobal-dropdown-container {
  position: absolute;
  right: 20px;
  top: 15px;
}

.my-gobal-yearselect {
  font-size: 14px;
  padding-top: 6px;
  padding-left: 20px;
  width: 90px;
  color: #fff;
}


</style>