lineBar.vue 3.18 KB
<!--
 * @Author: 前端 qianduan01@didihu.com.cn
 * @Date: 2022-10-25 10:43:46
 * @LastEditors: 前端 qianduan01@didihu.com.cn
 * @LastEditTime: 2022-10-27 11:30:04
 * @FilePath: \dj-data-view\src\components\barChart.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class='line-box'>
    <div :id='domId' class='line-chart' :style='{ height: boxHeight }'></div>
  </div>
</template>
<script>
import datas from '@/utils/data'
import * as echarts from 'echarts'
import { lineAndBarOptions, lineAndBarZoomOptions } from './options'

export default {
  name: 'lineBar',
  props: {
    domId: {
      type: String,
      default: 'line-chart'
    },
    isDatazoom: {
      type: Boolean,
      default: false
    },
    revese: {
      type: Boolean,
      default: false
    },
    boxHeight: {
      type: String,
      default: '13.83vh'
    },
    storeOrBrandTxt: {
      type: String,
      default: '品牌'
    },
    displayName: {
      type: Object,
      default: () => {
      }
    },
    dataList: {
      type: Array,
      default: () => []
    },
    // 0-月表;1-日表
    queryType: {
      type: Number,
      default: 0
    },
    tooltipFormatterObj: {
      type: Array,
      default: () => {
        return [
          {
            label: '数量',
            attrName: 'num'
          },
          {
            label: '环比',
            attrName: 'hrate',
            addSymbol: '%'
          },
          {
            label: '同比',
            attrName: 'trate',
            addSymbol: '%'
          }
        ]
      }
    }
  },
  data() {
    return {
      directionTimer: datas.DefaultData.directionTimer,
      delayTimer: datas.DefaultData.delayTimer,
      rankFlag: 'top',
      lineOptions: [],
      rankList: [],
      echartsLine: '',
      moveAttr: {
        // speed: 900,
        seriesIndex: 0,
        dataIndex: 0
      },
      timer: null
    }
  },
  watch: {
    dataList: {
      handler() {
        this.lineOptions = this.isDatazoom ? lineAndBarZoomOptions(this.dataList,this.displayName) : lineAndBarOptions(this.dataList,this.displayName)
        this.chartBindEvent()
      },
      deep: true
    }
  },
  mounted() {
    this.lineDom = document.getElementById(this.domId)
    this[this.domId] = echarts.init(this.lineDom)
  },
  methods: {
    chartBindEvent() {
      // window.addEventListener('resize', () => {
      //   this[this.domId].resize()
      // })
      this[this.domId].setOption(this.lineOptions)

      // if (this.domId === 'glLineBar' || this.domId == 'ghLineBar') (
      this[this.domId].on('click', (params) => {
        const month = params.name
        const type = this.domId
        if (this.domId === 'glLineBar') (
          this.$bus.$emit('updataGLRank', { month, type })
        )
        if (this.domId === 'ghLineBar') (
          this.$bus.$emit('updataGHRank', { month, type })
        )
      })
      // )
    }
  }
}
</script>
<style lang='scss' scoped>
.line-box {
  //height: 100%;
  color: #ffffff;

  .txt-orange {
    color: #eb6001;
  }

  .line-chart {
    width: 100%;
  }
}
</style>