Newer
Older
ganzhou-feidu / src / pages / ywts / shms / tcy / components / income.vue
dutingting 22 days ago 4 KB 停车云完成
<!-- 近一年车场收入趋势 -->
<template>
  <div id="income-line" class="container"/>
</template>

<script>

import * as echarts from 'echarts';
import { getCarsIncome } from '@/api/ywts/shms/tcy'
export default {
  name: 'CaseLineBar',
  data() {
    return {
      isShow: true,
      myChart: null,
      height: '0',
      width: '0',
      chartSettings: {
        labelMap: { date: '时间' },
        metrics: [],
        dimension: ['date']
      },
      extend: {
        color: ['#0071ff88', '#00afff88', '#00fdc088'],
        legend: {
          textStyle: {
            color: '#cce9ff',
            fontWeight: 'bold'
          },
          lineStyle: {
            width: 10
          },
          data: ['收入'],
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#092647',  // 修改背景颜色
              borderColor: '#404a59',      // 修改边框颜色
              borderWidth: 1,
              textStyle: {
                color: '#ffffff',          // 修改文本颜色
                fontSize: 12
              }
            }
          },
          textStyle: {
            align: 'left'  // 左对齐 tooltip 内容
          }
        },
        grid: {
          left: '5%',
          right: '5%',
          bottom: '10%',
          top: '15%',
          containLabel: true
        },
        xAxis: {
          type: 'category',
          axisLine: {
            lineStyle: {
              color: '#cce9ff'
            }
          },
          axisLabel: {
            color: '#cce9ff'
          }
        },
        yAxis: [
          {
            name: '',
            type: 'value',
            axisLine: {
              lineStyle: {
                color: '#cce9ff'
              }
            },
            axisLabel: {
              color: '#cce9ff'
            },
            nameTextStyle: {
              color: '#cce9ff',
              fontSize: 14,
              verticalAlign: 'middle',
            },
            splitLine: {
              show: true,
              lineStyle: {
                color: ['#c8d0da'],
                type: 'dashed',
              },
            },
          },
        ],
        series: [
          {
            name: '收入',
            type: 'line',
            symbol: 'circle',
            // showSymbol: false,
            symbolSize: 3,
            smooth: true, // 添加平滑效果
            color: '#a708dc',
            areaStyle: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {
                  offset: 0.5,
                  color: '#a708dc',
                },
                {
                  offset: 1,
                  color: 'rgba(10,25,124,0.2)'
                }
              ])
            },
          },
        ]
      },
      chartData: {
        columns: [],
        rows: []
      }
    }
  },
  mounted() {
    this.myChart = echarts.init(document.getElementById('income-line'))
    this.height = document.getElementById('income-line').clientHeight - 40 + 'px'
    this.width = document.getElementById('income-line').clientWidth - 10 + 'px'
    const that = this
    window.addEventListener('resize', function() {
      if(!document.getElementById('income-line')) {
        return
      }
      that.reload()
    })

  },

  methods: {
    async reload() {
      this.isShow = false
      await this.$nextTick()
      this.height = document.getElementById('income-line').clientHeight - 10 + 'px'
      this.width = document.getElementById('income-line').clientWidth - 10 + 'px'
      this.isShow = true
    },
    // 获取数据
    fetchData(id) {
      console.log('获取到的id',id);

      getCarsIncome({id}).then(response => {
        if (response.code === 200) {
          const res = response.data.value.slice(0, 12)
          this.extend.series[0].data = res.map(item => item.income)
          this.extend.xAxis.data = res.map(item => item.month)
          this.myChart.setOption(this.extend, true)
        }
      })
      console.log('近1年车场收入态势初始化');

      // this.extend.series[0].data = [5154,4545,2455,7212,4545,2455,7212]
      // this.extend.xAxis.data = ['07-01','07-02','07-03','07-04','07-05','07-06','07-07']
      // this.myChart.setOption(this.extend, true)
    }
  }
}
</script>
<style lang="scss" scoped>
.container{
  position:relative;
  width: 100%;
  height:100%;
}
</style>