<template>
  <ve-line ref="linechart" :title="title" :data="chartData" :settings="chartSettings"/>
</template>

<script>
import { getHarmfulData } from '@/api/data'
import { compare } from '@/utils/compare'

export default {
  name: 'HamfulData',
  data() {
    this.title = {
      text: '有害气体监测曲线图'
    }
    this.chartSettings = {
      labelMap: {
        'CO': '一氧化碳(ppm)',
        'CH4': '甲烷(%VOL)',
        'H2S': '硫化氢(ppm)',
        'O2': '氧气(%VOL)',
        'uptime': '上报时间'
      },
      metrics: ['CO', 'CH4', 'H2S', 'O2'],
      dimension: ['uptime']
    }
    return {
      listQuery: {
        keywords: '', // 关键字
        deptid: '', // 部门id
        beginTime: '', // 开始时间
        endTime: '', // 结束时间
        offset: 1,
        limit: 100000,
        sort: '',
        order: ''
      },
      chartData: {
        columns: ['uptime', 'CO'],
        rows: []
      }
    }
  },
  methods: {
    fetchData(params) {
      this.listQuery.keywords = params.wellCode
      this.listQuery.beginTime = params.beginTime
      this.listQuery.endTime = params.endTime
      getHarmfulData(this.listQuery).then(response => {
        if (response.data.rows.length === 0) {
          this.$message.error('该井此段时间内无有害气体数据，请修改监测指标或查询范围')
        }
        this.chartData.rows = response.data.rows.sort(compare('uptime'))
        this.$refs['linechart'].echarts.resize()
      })
    }
  }
}
</script>
