Blame view

src/views/tjfx/cstj/index.vue 10.7 KB
renchao@pashanhoo.com committed
1
<!--
“miaofang committed
2
 * @Description:
renchao@pashanhoo.com committed
3 4 5 6
 * @Autor: renchao
 * @LastEditTime: 2023-08-25 08:59:04
-->
<template>
“miaofang committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
  <div class="tjltj">
    <div class="inquire">
      <el-form :model="queryForm" ref="queryForm" label-width="100px">
        <el-row>
          <el-col :span="19">
            <div class="rowAc">
              <div
                v-for="(item, index) in dateQuickSelection"
                :key="index"
                class="rowAc dateQuickItem"
                @click="chooseDateQuick(index)"
              >
                {{ item.name }}
              </div>
              <el-date-picker
                v-model="dateRange"
                type="daterange"
                value-format="yyyy-MM-dd"
                end-placeholder="结束日期"
                start-placeholder="开始日期"
                :clearable="false"
                range-separator="-"
                class="dataRangePicker"
                @change="chooseDateRange"
              ></el-date-picker>
            </div>
          </el-col>

          <el-col :span="5" class="btnColRight">
            <el-form-item>
“miaofang committed
37
              <el-button type="primary" native-type="submit" @click="chchch"
“miaofang committed
38 39 40 41 42 43 44 45 46 47 48
                >查询</el-button
              >
              <el-button type="primary" native-type="submit" @click="derive"
                >导出</el-button
              >
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div ref="chart" style="width: 100%; height: 92%"></div>
renchao@pashanhoo.com committed
49 50 51
  </div>
</template>
<script>
“miaofang committed
52
import * as echarts from "echarts";
赵千 committed
53
import {cstj, exportCstj} from "@/api/tjfx.js";
“miaofang committed
54
import XLSX from "xlsx";
“miaofang committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
export default {
  components: {},
  data() {
    return {
      dateQuickSelection: [
        // 日期快捷选择列表
        { code: "1", name: "今日" },
        { code: "2", name: "昨日" },
        { code: "3", name: "本周" },
        { code: "4", name: "上周" },
        { code: "5", name: "本月" },
        { code: "6", name: "上月" },
        { code: "7", name: "今年" },
        { code: "8", name: "去年" },
      ],
      chooseIndex: 0, // 日期快捷选择项索引
      dateRange: [], // 自定义列表 - 日期范围
      queryForm: {},
赵千 committed
73 74
      data1: [],
      data2: [],
“miaofang committed
75
      data3: [],
赵千 committed
76 77 78 79
      selectDate : {
        startAt:'2020-01-03 02:57:57',
        endAt:'2025-01-03 02:57:57'
      },
“miaofang committed
80
      xAxisData: [
赵千 committed
81

“miaofang committed
82 83 84 85
      ],
    };
  },
  mounted() {
“miaofang committed
86
    this.setdata();
赵千 committed
87

“miaofang committed
88 89
  },
  methods: {
赵千 committed
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112

    cstj () {
      cstj(this.selectDate).then(res => {
        if (res.code == 200) {
          let dataSource = res.result;
          if (dataSource != null) {
            this.xAxisData = dataSource.map(item => item.assignee)
            this.data1 = dataSource.map(item => item.total)
            this.data2 = dataSource.map(item => item.count)
            this.data3 = dataSource.map(item => item.cumulativeTimeout)
          }
          console.log(this.xAxisData)
          console.log(this.data1)
          console.log(this.data2)
          console.log(this.data3)
          // 创建一个 ECharts 实例
          this.chart = echarts.init(this.$refs.chart);
          // 在 ECharts 实例中配置图表
          this.chart.setOption(this.getOption());
        }
      })
    },

“miaofang committed
113
    setdata() {
赵千 committed
114 115
      this.chooseDateQuick(7)
      this.cstj()
“miaofang committed
116 117
    },
    // 导出
“miaofang committed
118
    derive() {
赵千 committed
119 120 121 122 123 124 125 126 127 128
      exportCstj(this.selectDate).then(res => {
        const link=document.createElement("a");
        let blob=new Blob([res], { type: "application/vnd.ms-excel" }); //类型excel
        link.style.display="none";
        link.href=URL.createObjectURL(blob);
        link.setAttribute("download", this.dateRange[0]+'~'+ this.dateRange[1] +'超时统计');
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link);
      })
“miaofang committed
129
    },
“miaofang committed
130
    // 查询
“miaofang committed
131
    chchch() {
“miaofang committed
132 133 134
      console.log("dateRange", this.dateRange);
    },
    getOption() {
renchao@pashanhoo.com committed
135
      return {
“miaofang committed
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
        title: {
          text: "收件与超时统计情况 ", // 主标题名称

          textStyle: {
            //主标题文本设置
            fontSize: 26, //大小
          },

          itemGap: 3, //主副标题间距
          x: "center", //主副标题的水平位置
          y: "top", //主副标题的垂直位置
        },
        tooltip: {
          trigger: "item",
          textStyle: {
            fontSize: 14,
            lineHeight: 22,
          },
          // 如果需要自定义 tooltip样式,需要使用formatter
          formatter: (params) => {
赵千 committed
156 157 158 159 160 161 162 163 164
            if (params.seriesName == '超时时间') {
              return `<div font-size: 14px;line-height: 24px>
                  ${params.seriesName}
                 <br>
              <span  font-size: 16px; font-weight: 600;">  ${params.name}:  ${
                Number(params.value).toFixed(2) + "小时"
              }  </span>
              </div>`;
            }
“miaofang committed
165 166 167 168
            return `<div font-size: 14px;line-height: 24px>
                  ${params.seriesName}
                 <br>
              <span  font-size: 16px; font-weight: 600;">  ${params.name}:  ${
赵千 committed
169
              Number(params.value).toFixed(2) + ""
“miaofang committed
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
            }  </span>
              </div>`;
          },
        },

        legend: {
          data: ["办件数", "超时数", "超时时间"],
          bottom: "3%",
          itemWidth: 20,
          itemHeight: 20,
          //文字样式
          textStyle: {
            fontSize: 17, //设置文字大小
          },
        },
        grid: [{ right: "3%", top: "10%", bottom: "15%", left: "3%" }],
        color: ["#94ae0a", "#115fa6", "#a61120"],
        xAxis: {
          data: this.xAxisData,
          axisLabel: {
            // 轴文字
            fontSize: 18,
          },
        },
        yAxis: {
          axisLabel: {
            // 轴文字
            fontSize: 18,
          },
        },
        series: [
          {
            name: "办件数",
            type: "bar",
            data: this.data1,
            label: {
              normal: {
                show: true,
                fontSize: 13,
                position: "top",
              },
            },
          },
          {
            name: "超时数",
            type: "bar",
            data: this.data2,
            label: {
              normal: {
                show: true,
                fontSize: 13,
                position: "top",
              },
            },
          },
          {
            name: "超时时间",
            type: "bar",
            data: this.data3,
            label: {
              normal: {
                show: true,
                fontSize: 13,
                position: "top",
              },
            },
          },
        ],
      };
    },
    // 日期快捷选择事件
    chooseDateQuick(index) {
      this.chooseIndex = index;
      var tempCode = this.dateQuickSelection.find(
        (ele) => this.chooseIndex === Number(ele.code) - 1
      ).code;
      var tempDate = new Date();
      var year = tempDate.getFullYear();
      var month = tempDate.getMonth();
      var day = tempDate.getDate();
      var week = tempDate.getDay();
      this.dateRange = [];
      if (tempCode === "1") {
        // 今日
        this.dateRange.push(
          this.formatDate(tempDate),
          this.formatDate(tempDate)
        );
      } else if (tempCode === "2") {
        // 昨日
        this.dateRange.push(
          this.jumpNumDay(tempDate, -1, "-"),
          this.jumpNumDay(tempDate, -1, "-")
        );
      } else if (tempCode === "3") {
        // 本周
        this.dateRange.push(
          this.formatDate(new Date(year, month, day - week + 1)),
          this.formatDate(tempDate)
        );
      } else if (tempCode === "4") {
        // 上周
        this.dateRange.push(
          this.formatDate(new Date(year, month, day - week - 6)),
          this.formatDate(new Date(year, month, day - week))
        );
      } else if (tempCode === "5") {
        // 本月
        this.dateRange.push(
          this.formatDate(new Date(year, month, 1)),
          this.formatDate(tempDate)
        );
      } else if (tempCode === "6") {
        // 上月
        this.dateRange.push(
          this.formatDate(new Date(year, month - 1, 1)),
          this.formatDate(new Date(year, month, 0))
        );
      } else if (tempCode === "7") {
        // 今年
        this.dateRange.push(
          this.formatDate(new Date(year, 0, 1)),
          this.formatDate(tempDate)
        );
      } else if (tempCode === "8") {
        // 去年
        this.dateRange.push(
          this.formatDate(new Date(year - 1, 0, 1)),
          this.formatDate(new Date(year - 1, 11, 31))
        );
renchao@pashanhoo.com committed
300
      }
赵千 committed
301 302 303
      this.selectDate.startAt = this.dateRange[0] + " 00:00:00"
      this.selectDate.endAt = this.dateRange[1] + " 00:00:00"
      this.cstj()
“miaofang committed
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
    },
    // 日期范围选择器事件
    chooseDateRange() {
      this.chooseIndex = null;
    },
    // 数字转换
    changeNum(num) {
      if (num >= 10) {
        return num;
      } else {
        return "0" + num;
      }
    },
    // 格式化日期
    formatDate(date) {
      var year = date.getFullYear();
      var month = this.changeNum(date.getMonth() + 1);
      var day = this.changeNum(date.getDate());
      return `${year}-${month}-${day}`;
    },
    // 某日期向前/向后num天
“miaofang committed
325 326 327 328 329 330 331 332 333 334
    jumpNumDay(date, num, linkStr = "-") {
      date = new Date(date.getTime() + num * 24 * 60 * 60 * 1000);
      return (
        date.getFullYear() +
        linkStr +
        this.changeNum(date.getMonth() + 1) +
        linkStr +
        this.changeNum(date.getDate())
      );
    },
“miaofang committed
335 336
  },
};
renchao@pashanhoo.com committed
337
</script>
“miaofang committed
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
<style scoped lang="scss">
.tjltj {
  width: 100%;
  height: 100%;
  .inquire {
    width: 100%;
    height: 40px;
    padding-top: 3px;
    background-color: #ffffff;
    margin-bottom: 10px;
  }
  .rowAc {
    margin-left: 10px;
    display: flex;
    justify-content: flex-start;
    align-items: center;
  }
  .dateQuickItem {
    padding: 1px 8px;
    margin-right: 16px;
    color: #3c4353;
    font-size: 14px;
    line-height: 22px;
    font-weight: 400;
    border: 1px solid #dcdee0;
    border-radius: 16px;
    background: #ffffff;
    cursor: pointer;
    box-sizing: border-box;
  }
  .dateQuickItem:hover,
  .dateQuickItem.active {
    color: #1b58f4;
    border: 1px solid #1b58f4;
  }
  .dateQuickItem.disabled {
    color: #c8c9cc;
    border: 1px solid #dcdee0;
    background: #f7f8f9;
    cursor: not-allowed; // 禁止鼠标事件
  }
  .dataRangePicker {
    width: 240px !important;
    height: 32px !important;
  }
  .dataRangePicker.el-date-editor .el-range-separator {
    line-height: 24px;
  }
  .dataRangePicker.el-date-editor .el-range__icon {
    margin-left: 0px;
    line-height: 24px;
  }
  .dataRangePicker.el-date-editor .el-range-input {
    width: 95px;
  }
}
</style>