From e2fdfe540eaf160dc7d063c60667041edcc64e86 Mon Sep 17 00:00:00 2001
From: gaoshp <291585735@qq.com>
Date: 星期二, 05 十一月 2024 22:55:14 +0800
Subject: [PATCH] 处理显示名称

---
 src/views/mdc/components/Time.vue |   91 +++++++++++++++++++++++++++++++++------------
 1 files changed, 66 insertions(+), 25 deletions(-)

diff --git a/src/views/mdc/components/Time.vue b/src/views/mdc/components/Time.vue
index 5bb8fcd..63ad963 100644
--- a/src/views/mdc/components/Time.vue
+++ b/src/views/mdc/components/Time.vue
@@ -1,16 +1,15 @@
 <!--
  * @Date: 2024-04-18 21:52:18
  * @LastEditors: Sneed
- * @LastEditTime: 2024-06-17 23:37:51
+ * @LastEditTime: 2024-06-21 00:15:44
  * @FilePath: /belleson-frontend/Users/mache/Documents/demo/cps-web/src/views/mdc/components/Time.vue
 -->
 <template>
     <el-row>
         <el-col>
             <el-button-group>
-                <el-button size="small" @click="statisticalMethod = item.value"
-                    :type="statisticalMethod == item.value ? 'primary' : ''" v-for="item in btnList"
-                    :key="item.value">{{
+                <el-button size="small" @click="change(item)" :type="statisticalMethod == item.value ? 'primary' : ''"
+                    v-for="item in btnList" :key="item.value">{{
                         item.label }}</el-button>
             </el-button-group>
         </el-col>
@@ -39,10 +38,11 @@
 
 <script>
 import scEcharts from '@/components/scEcharts';
+import moment from 'moment'
 export default {
     props: {
         url: {
-            default: '/api/blade-mdc/efficiency-analysis',
+            default: '/api/mdc/efficiency-analysis',
             type: String,
         },
         options: {
@@ -90,19 +90,26 @@
             cols: [],
             chartsData: [],
             option2: {},
+            btnListNew: []
         }
     },
     watch: {
         statisticalMethod(val) {
-            this.query({
-                ...this.params,
-            })
-            this.queryChart({
-                ...this.params,
-            })
+            // this.query({
+            //     ...this.params,
+            // })
+            // this.queryChart({
+            //     ...this.params,
+            // })
         }
     },
     methods: {
+        change(item) {
+            this.statisticalMethod = item.value
+            this.init({
+                ...this.params
+            })
+        },
         init(params) {
             this.params = params
             this.getTime({
@@ -110,26 +117,61 @@
                 startDate: params.startDate,
                 statisticalMethod: this.statisticalMethod
             }).then(res => {
-                this.query({
+                if (!res?.length) return
+                let startDate = Math.min(...res?.map(v => new Date(v.startDate).getTime()))
+                let endDate = Math.max(...res?.map(v => new Date(v.endDate).getTime()))
+                console.log('------')
+                let data = {
                     ...params,
                     statisticalMethod: this.statisticalMethod
+                }
+                if (this.statisticalMethod !== 'Day') {
+                    data = {
+                        ...data,
+                        startDate: moment(startDate).format('YYYY-MM-DD'),
+                        endDate: moment(endDate).format('YYYY-MM-DD'),
+                        statisticalMethod: this.statisticalMethod
+                    }
+                }
+                console.log(startDate, endDate)
+                this.query({
+                    ...data
                 })
                 this.queryChart({
-                    ...params,
-                    statisticalMethod: this.statisticalMethod
+                    ...data,
+                    // statisticalMethod: this.statisticalMethod
                 })
             })
 
         },
         getTime(data) {
-            return Promise.resolve()
-            // return this.$HTTP.post('/api/blade-mdc/efficiency-analysis/interval', {
-            //     ...data
-            // }).then(res => {
-            //     if (res.code === 200) {
-            //         this.btnList = res.data
-            //     }
-            // })
+            //return Promise.resolve()
+            return this.$HTTP.post('/api/mdc/efficiency-analysis/interval', {
+                ...data
+            }).then(res => {
+                if (res.code === 200) {
+                    this.btnListNew = res.data
+                    if (data.statisticalMethod === 'MONTH') {
+                        return res?.data?.map(v => {
+                            return {
+                                ...v,
+                                startDate: moment(v.id).startOf('month').format('YYYY-MM-DD'),
+                                endDate: moment(v.id).endOf('month').format('YYYY-MM-DD')
+                            }
+                        })
+                    } else if (data.statisticalMethod === 'DAY') {
+                        return res?.data?.map(v => {
+                            return {
+                                ...v,
+                                startDate: v.id,
+                                endDate: v.id
+                            }
+                        })
+                    } else {
+                        return res.data
+                    }
+                }
+            })
         },
         queryChart(data) {
             let params = {
@@ -201,8 +243,7 @@
                 console.log(option2)
             })
         },
-        query(params) {
-            this.params = params
+        query(res) {
             this.apiObj = {
                 get: async (data) => {
                     let params = {
@@ -210,7 +251,7 @@
                         size: data.size
                     }
                     let dataSend = {
-                        ...data,
+                        ...res,
                         queryType: 1,
                         statisticalMethod: this.statisticalMethod
                     }

--
Gitblit v1.9.3