From b313f3cb40a336c96d86edec8d93336244eba5b5 Mon Sep 17 00:00:00 2001
From: gaoshp <291585735@qq.com>
Date: 星期二, 18 六月 2024 22:21:52 +0800
Subject: [PATCH] update

---
 src/views/mdc/components/Time.vue |  110 +++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 78 insertions(+), 32 deletions(-)

diff --git a/src/views/mdc/components/Time.vue b/src/views/mdc/components/Time.vue
index b552b66..cd12ccb 100644
--- a/src/views/mdc/components/Time.vue
+++ b/src/views/mdc/components/Time.vue
@@ -1,22 +1,21 @@
 <!--
  * @Date: 2024-04-18 21:52:18
  * @LastEditors: Sneed
- * @LastEditTime: 2024-06-17 22:37:51
+ * @LastEditTime: 2024-06-18 20:09:02
  * @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>
         <el-col style="margin-top: 12px;">
             <el-card shadow="never">
-                <scEcharts height="300px" :option="option2"></scEcharts>
+                <scEcharts height="300px" :option="option2" v-if="option2.title" />
             </el-card>
         </el-col>
         <el-col>
@@ -39,6 +38,7 @@
 
 <script>
 import scEcharts from '@/components/scEcharts';
+import moment from 'moment'
 export default {
     props: {
         url: {
@@ -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,9 +117,22 @@
                 startDate: params.startDate,
                 statisticalMethod: this.statisticalMethod
             }).then(res => {
-                this.query({
+                let startDate = Math.min(...res.data.map(v => new Date(v.startDate).getTime()))
+                let endDate = Math.max(...res.data.map(v => new Date(v.startDate).getTime()))
+                let data = {
                     ...params,
                     statisticalMethod: this.statisticalMethod
+                }
+                if (this.statisticalMethod !== 'Day') {
+                    data = {
+                        ...data,
+                        endDate: moment(endDate).format('YYYY-MM-DD'),
+                        statisticalMethod: this.statisticalMethod
+                    }
+                }
+                console.log(startDate, endDate)
+                this.query({
+                    ...data
                 })
                 this.queryChart({
                     ...params,
@@ -122,14 +142,15 @@
 
         },
         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/blade-mdc/efficiency-analysis/interval', {
+                ...data
+            }).then(res => {
+                if (res.code === 200) {
+                    this.btnListNew = res.data
+                    return res
+                }
+            })
         },
         queryChart(data) {
             let params = {
@@ -140,19 +161,46 @@
                 queryType: 0,
                 statisticalMethod: this.statisticalMethod
             }
-            // console.log(this.option2.series, '>>>>>>>>>>???')
-            try {
-                this.option2.dataset.source = []
-                this.option2.series = []
-            } catch (error) {
-
-            }
+            this.option2 = {}
             return this.$HTTP.post(this.url, dataSend, { params }).then(res => {
                 this.chartsData = res.data.items.records
                 let option2 = {
-                    ...this.options
+                    // legend: {
+                    //     type: 'plain',
+                    // },
+                    title: {
+                        text: '缁熻鍥捐〃',
+                        subtext: '',
+                    },
+                    grid: {
+                        top: '80px'
+                    },
+                    tooltip: {
+                        trigger: 'axis'
+                    },
+                    xAxis: {
+                        type: 'category',
+                        axisLabel: {
+                            interval: 'auto',
+                        }
+                    },
+                    yAxis: {
+                        type: 'value',
+                        axisLabel: {
+                            formatter: (value) => {
+                                return value + '%'
+                            }
+                        },
+                    },
+                    dataZoom: [
+                        { type: 'slider' }
+                    ],
+                    dataset: {
+                        source: []
+                    },
+                    ...this.options,
+                    series: [],
                 }
-                option2.series = []
                 let source1 = ['product']
                 let row = res.data.items.records[0]
                 Object.values(row.nameData).forEach(v => {
@@ -161,7 +209,6 @@
                     })
                     source1.push(v)
                 })
-
                 option2.dataset.source = [source1]
                 res.data.items.records.forEach(v => {
                     let current = [v.id]
@@ -175,8 +222,7 @@
                 console.log(option2)
             })
         },
-        query(params) {
-            this.params = params
+        query() {
             this.apiObj = {
                 get: async (data) => {
                     let params = {

--
Gitblit v1.9.3