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

<script>
import { getGasData } from '@/api/data'
import { compare } from '@/utils/compare'
import 'v-charts/lib/style.css'

export default {
  name: 'GasData',
  data() {
    this.title = {
      text: '燃气监测曲线图'
    }
    this.chartSettings = {
      labelMap: {
        'strength': '燃气(%LEL)',
        'uptime': '上报时间'
      },
      metrics: ['strength'],
      dimension: ['uptime']
    }
    return {
      listQuery: {
        keywords: '', // 关键字
        deptid: '', // 部门id
        beginTime: '', // 开始时间
        endTime: '', // 结束时间
        offset: 1,
        limit: 100000,
        sort: '',
        order: ''
      },
      chartData: {
        columns: ['uptime', 'strength'],
        rows: []
      }
    }
  },
  methods: {
    fetchData(params) {
      this.listQuery.keywords = params.wellCode
      this.listQuery.beginTime = params.beginTime
      this.listQuery.endTime = params.endTime
      getGasData(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>
