index.vue 8.63 KB
<template>
  <!-- 监控日志 -->
  <div class="jktjDetail form-clues">
    <!-- 头部搜索 -->
    <div class="from-clues-header">
      <el-form ref="form" :model="form" label-width="100px">
        <el-row>
          <el-col :span="4">
            <el-form-item label="开始日期" prop="startTime">
              <el-date-picker
                type="datetime"
                placeholder="开始日期"
                :picker-options="pickerOptionsStart"
                clearable
                v-model="form.startTime"
                value-format="yyyy/MM/dd HH:mm:ss"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="结束日期" prop="endTime">
              <el-date-picker
                type="datetime"
                placeholder="结束日期"
                :picker-options="pickerOptionsEnd"
                clearable
                v-model="form.endTime"
                value-format="yyyy/MM/dd HH:mm:ss"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <!-- 操作按钮 -->
          <el-col :span="3" class="btnColRight">
            <btn nativeType="cz" @click="resetForm">重置</btn>
            <btn nativeType="cx" @click="getProcessCounts">查询</btn>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- 表格 -->
    <div class="form-clues-content echarts-box" v-if="pieChartsData.length">
      <div id="myChart" class="chart"></div>
      <div id="myChart-bar" class="chart-bar"></div>
    </div>
    <div class="form-clues-content echarts-box center" v-else>暂无数据</div>
  </div>
</template>
<script>
import { mapGetters } from "vuex";
import efficient from "@/api/efficient";
import { getFirstDayOfSeason, timeFormat } from "@/utils/operation";
export default {
  name: "jktj",
  data() {
    return {
      // 开始结束日期限制
      pickerOptionsStart: {
        disabledDate: (time) => {
          if (this.form.endTime) {
            return time.getTime() >= new Date(this.form.endTime).getTime();
          }
        },
      },
      // 结束日期限制
      pickerOptionsEnd: {
        disabledDate: (time) => {
          if (this.form.startTime) {
            return time.getTime() <= new Date(this.form.startTime).getTime();
          }
        },
      },
      form: {
        startTime: getFirstDayOfSeason(),
        endTime: timeFormat(new Date(), true),
      },
      // 搜索表单
      pieChartsData: [],
    };
  },
  created() {},
  mounted() {
    this.getProcessCounts();
  },
  computed: {
    ...mapGetters(["dicData"]),
  },
  methods: {
    //查询各区县办件数量
    async getProcessCounts() {
      this.pieChartsData = [];
      let { result: res } = await efficient.getProcessCounts(
        this.form.startTime,
        this.form.endTime
      );
      //获取图表配置项需要的数据
      res.length > 0 &&
        res.forEach((item) => {
          this.pieChartsData.push({
            //登记数量
            value: item.counts,
            //登记数量
            name: item.recTypeName,
            //登记类型代码
            groupId: item.recType,
          });
        });
      this.$nextTick(() => {
        // 初始化图表
        this.echartInit();
        this.barChartInit(res[0].recType);
      });
    },
    // 重置
    resetForm() {
      this.form = {
        startTime: getFirstDayOfSeason(),
        endTime: timeFormat(new Date(), true),
      };
      this.getProcessCounts();
    },
    //玫瑰图初始化
    echartInit() {
      let _this = this;
      // 基于准备好的dom,初始化echarts实例
      let myChart = this.$echarts.init(document.getElementById("myChart"));
      // 绘制图表
      myChart.setOption({
        legend: {
          bottom: "2%",
          left: "center",
          textStyle: {
            color: "#fff",
          },
        },
        tooltip: {
          trigger: "item",
          formatter: "{b} : {c}",
        },
        series: [
          {
            name: "各业务类型办理数量",
            type: "pie",
            radius: [0, 250],
            center: ["50%", "45%"],
            roseType: "area",
            itemStyle: {
              borderRadius: 8,
            },
            data: this.pieChartsData,
          },
        ],
      });
      //添加点击事件
      myChart.on("click", function (param) {
        _this.barChartInit(param.data.groupId);
      });
      //默认选中第一个
      let index = 1;
      myChart.dispatchAction({
        type: "highlight",
        seriesIndex: 0,
        dataIndex: 0,
      });
      myChart.on("mouseover", function (e) {
        if (e.dataIndex != index) {
          myChart.dispatchAction({
            type: "downplay",
            seriesIndex: 0,
            dataIndex: index,
          });
        }
      });
      myChart.on("mouseout", function (e) {
        index = e.dataIndex;
        myChart.dispatchAction({
          type: "highlight",
          seriesIndex: 0,
          dataIndex: e.dataIndex,
        });
      });
    },
    //柱图初始化
    async barChartInit(recType) {
      //请求recType对应业务的各区县数据
      let { result: res } = await efficient.getProcessDays(
        recType,
        this.form.startTime,
        this.form.endTime
      );
      //行政区数组
      let xzqArr = [];
      this.dicData["A20"].forEach((item) => {
        xzqArr.push(item.DNAME);
        let tempArr = res.filter((i) => {
          return i.qxdm == item.DCODE;
        });
        if (tempArr.length) {
          item.avgDay = tempArr[0].avgDay;
          item.maxDay = tempArr[0].maxDay;
          item.minDay = tempArr[0].minDay;
        } else {
          item.avgDay = 0;
          item.maxDay = 0;
          item.minDay = 0;
        }
      });
      //补全无数据行政区后的结果数组
      let dealArr = [...this.dicData["A20"]];
      // //行政区代码过滤
      // res.length > 0 &&
      //   res.forEach((item) => {
      //     xzqArr.push(
      //       this.dicData["A20"].filter((i) => {
      //         return i.DCODE == item.qxdm;
      //       })[0].DNAME
      //     );
      //   });
      let myChartBar = this.$echarts.init(
        document.getElementById("myChart-bar")
      );
      myChartBar.setOption({
        color: ["#00bdb1", "#ff6e6e", "#3f99ff", "#ffaf48"],
        tooltip: {
          show: true,
          trigger: "axis",
          textStyle: {
            fontSize: 16, // 字体大小
          },
          extraCssText: "width:220px;height:160px;", // 背景色
        },
        grid: {
          top: 120,
        },
        legend: {
          data: ["最短用时", "平均用时", "最长用时"],
          top: 20,
          textStyle: {
            show: true,
            color: "#fff",
            fontSize: "16",
          },
        },
        xAxis: [
          {
            type: "category",
            data: xzqArr,
            axisLabel: {
              interval: 0,
              textStyle: {
                show: true,
                color: "#fff",
                fontSize: "16",
              },
            },
          },
        ],
        yAxis: [
          {
            type: "value",
            name: "单位:天",
            nameTextStyle: {
              color: "#fff",
              fontSize: "16",
            },
            axisLabel: {
              textStyle: {
                show: true,
                color: "#fff",
                fontSize: "16",
              },
            },
          },
        ],
        series: [
          {
            type: "bar",
            barMaxWidth: '60',
            name: "最短用时",
            data: dealArr.map((item) => item.minDay),
          },
          {
            type: "bar",
            barMaxWidth: '60',
            name: "平均用时",
            data: dealArr.map((item) => item.avgDay),
          },
          {
            type: "bar",
            barMaxWidth: '60',
            name: "最长用时",
            data: dealArr.map((item) => item.maxDay),
          },
        ],
      });
    },
  },
};
</script>
<style scoped lang="scss">
@import "~@/styles/public.scss";

.jktjDetail {
  height: 100%;
  display: flex;
  flex-direction: column;
  .rows {
    margin-left: 100px;
  }
  .center {
    line-height: 50vh;
    text-align: center;
  }
  .echarts-box {
    display: flex;
    justify-content: center;
    .chart {
      width: 40%;
      height: 100%;
      float: left;
    }
    .chart-bar {
      width: 60%;
    }
  }

  .form-clues-content {
    flex: 1;
    height: 100%;
    color: #b6b5b5;
  }
}
</style>
<style scoped lang="scss">
@import "~@/styles/public.scss";
</style>