From d00a9f035aec50c37c8e0a1363a1968672fb875f Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期二, 16 七月 2024 16:58:39 +0800
Subject: [PATCH] 2024.7.16

---
 src/views/inspection/problem/component/ProblemChangeChart.vue |  118 +++++++++++++++++++++++++++++++----------------------------
 1 files changed, 62 insertions(+), 56 deletions(-)

diff --git a/src/views/inspection/problem/component/ProblemChangeChart.vue b/src/views/inspection/problem/component/ProblemChangeChart.vue
index 3e6314d..73703d6 100644
--- a/src/views/inspection/problem/component/ProblemChangeChart.vue
+++ b/src/views/inspection/problem/component/ProblemChangeChart.vue
@@ -1,18 +1,18 @@
 <template>
   <el-row justify="space-between">
     <el-col :span="18">
-      <div>
+      <el-text size="small">
         鍦烘櫙鏁帮細{{ sceneNum }}锛岄棶棰樻�绘暟锛歿{ proNum }}锛屽崟鍦烘櫙闂鍧囧�硷細{{ proEachSceneNum }}锛�
-      </div>
-      <div>
+      </el-text>
+      <el-text size="small">
         鏁存敼鎬绘暟锛歿{ changeNum }}锛屾湁鏁堟暣鏀规暟锛歿{ changePassNum }}锛岄棶棰樻暣鏀圭巼锛歿{
           changePer
         }}锛屾湁鏁堟暣鏀圭巼锛歿{ changePassPer }}
-      </div>
+      </el-text>
     </el-col>
     <el-col :span="6">
       <el-row justify="end">
-        <OptionTime v-model="time"></OptionTime>
+        <!-- <OptionTime v-model="time"></OptionTime> -->
       </el-row>
     </el-col>
   </el-row>
@@ -20,17 +20,22 @@
 </template>
 <script>
 import * as echarts from 'echarts'
+import { barChartOption } from '@/utils/echart/bar-chart-option'
+import { useSubtaskStore } from '@/stores/subtask.js'
+import { mapStores } from 'pinia'
+import dayjs from 'dayjs'
 
 export default {
   data() {
     return {
-      sceneNum: 51,
-      proNum: 161,
-      changeNum: 40,
-      changePassNum: 40
+      sceneNum: 0,
+      proNum: 0,
+      changeNum: 0,
+      changePassNum: 0
     }
   },
   computed: {
+    ...mapStores(useSubtaskStore),
     proEachSceneNum() {
       return Math.round((this.proNum / this.sceneNum) * 10) / 10
     },
@@ -50,66 +55,67 @@
     }
   },
   methods: {
-    refresh() {
-      const fontSize = 12
-      const option = {
-        legend: {
-          data: ['闂鏁�', '鏁存敼鏁�'],
-          textStyle: {
-            fontSize: fontSize,
-            color: 'white'
-          }
-        },
-        grid: {
-          left: '3%',
-          right: '4%',
-          bottom: '3%',
-          containLabel: true
-        },
-        xAxis: {
-          type: 'category',
-          data: ['1鍙�', '2鍙�', '3鍙�', '4鍙�', '5鍙�', '6鍙�', '7鍙�', '8鍙�', '9鍙�'],
-          axisLabel: {
-            textStyle: {
-              fontSize: fontSize
-            },
-            color: '#ffffff',
-            textBorderColor: '#fff'
-          }
-        },
-        yAxis: {
-          type: 'value',
-          axisLabel: {
-            textStyle: {
-              fontSize: fontSize,
-              color: 'white'
-            }
-          }
-        },
-        series: [
+    fetchData() {
+      this.subtaskStore.getSummaryMap((map) => {
+        this.refresh(map)
+      })
+    },
+    refresh(map) {
+      let sceneNum = 0,
+        proNum = 0,
+        changeNum = 0,
+        changePassNum = 0
+      const chartData = {
+        xAxis: [],
+        yAxis: [
           {
             name: '闂鏁�',
-            type: 'bar',
-            data: [12, 8, 9, 7, 14, 19, 9, 7, 14]
+            data: []
           },
           {
             name: '鏁存敼鏁�',
-            type: 'bar',
-            data: [6, 2, 5, 3, 6, 3, 6, 2, 5]
+            data: []
           }
-          //   {
-          //     name: '鏁存敼鐜�',
-          //     type: 'bar',
-          //     data: [820, 832, 901, 934, 1290, 1330, 1320]
-          //   }
         ]
       }
+      const list = []
+      for (const key of map.keys()) {
+        const value = map.get(key)
+        list.push({ name: key, value: value })
+      }
+      // 鎸夋棩鏈熸搴忔帓鍒�
+      list
+        .sort(function (a, b) {
+          return b.name - a.name
+        })
+        .forEach((e) => {
+          chartData.xAxis.push(dayjs(e.name).format('DD鏃�'))
+          let pNum = 0,
+            cNum = 0
+
+          e.value.forEach((s) => {
+            sceneNum++
+            pNum += s.proNum
+            cNum += s.changeNum
+            changePassNum += s.changeCheckedNum
+          })
+          chartData.yAxis[0].data.push(pNum)
+          chartData.yAxis[1].data.push(cNum)
+          proNum += pNum
+          changeNum += cNum
+        })
+      const option = barChartOption(chartData)
       this.echart.setOption(option)
+
+      this.sceneNum = sceneNum
+      this.proNum = proNum
+      this.changeNum = changeNum
+      this.changePassNum = changePassNum
     }
   },
   mounted() {
     this.echart = echarts.init(this.$refs.echart)
-    this.refresh()
+    this.fetchData()
   }
 }
 </script>

--
Gitblit v1.9.3