Newer
Older
qd_cnooc_front / src / views / dashboard / components / waterCountByAreaBar.vue
[wangxitong] on 17 Mar 2022 5 KB 添加三级分区
<template>
  <div class="container">
    <div class="statistic-container">
      <el-button round size="mini" @click="setDefaultTime('month')">本月</el-button>
      <el-button round size="mini" @click="setDefaultTime('week')">近7日</el-button>
      <el-button round size="mini" @click="setDefaultTime('yesterday')">昨日</el-button>
      <el-button round size="mini" @click="setDefaultTime('today')">今日</el-button>
      <el-date-picker
        v-model="timeRange"
        :picker-options="pickerOptions"
        type="daterange"
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        value-format="yyyy-MM-dd"
        size="mini"
        style="width:250px;margin-right: 20px"
        @change="fetchData"/>
    </div>
    <ve-histogram v-if="isShow" :data="chartData" :grid="grid" :title="title" :extend="extend" :settings="chartSettings"/>
    <div class="function">
      <el-button
        v-for="item in areaList"
        :key="item.id"
        round
        size="mini"
        @click="areaChange(item.id)">{{ item.name }}</el-button>
    </div>
  </div>
</template>

<script>
// 引入视觉映射组件
import 'echarts/lib/component/visualMap'
import { wellStaticByType } from '@/api/dataStatics'
import { getDayTime } from '@/utils/dateutils'

export default {
  name: 'WaterCountByAreaBar',
  data() {
    this.extend = {
      legend: {
        show: false
      },
      xAxis: {
        axisLabel: {
          rotate: 30,
          margin: 30,
          textStyle: {
            align: 'center'
          }
        }
      },
      yAxis: {
        name: '用水量(吨)',
        position: 'left'
      },
      series: {
        label: { show: true, position: 'top', formatter: '{c}' },
        barWidth: 25
      },
      tooltip: { trigger: 'item', formatter: '{b}<br/>用水量:{c}吨' }
    }
    this.grid = {
      right: 40,
      top: 100,
      bottom: 5
    }
    this.title = {
      text: '分区用水统计图'
    }
    this.chartSettings = {
      itemStyle: {
        barCategoryGap: 10
      },

      labelMap: {
        'dept': '分区',
        'wellCount': '用水量'
      },
      dimension: ['dept'],
      metrics: ['wellCount']
    }
    return {
      areaId: '',
      areaList: [{ id: '', name: '生产厂区' }, { id: '', name: '科技楼及食堂' }, { id: '', name: 'A/B/C/D/E座' }],
      isShow: true,
      defaultTimeRange: [],
      timeRange: [],
      pickerOptions: {
        disabledDate: function(date) {
          var oDate1 = new Date(date)
          var oDate2 = new Date()
          if (oDate1.getTime() > oDate2.getTime()) {
            return true
          } else {
            return false
          }
        }
      },
      chartData: {
        columns: ['wellTypeName', 'wellCount'],
        rows: []
      }
    }
  },
  watch: {
    timeRange(val) {
    }
  },
  mounted() {
    this.setDefaultTime('today')
    this.fetchData()
  },
  methods: {
    areaChange(val) {
      this.areaId = val
      this.fetchData()
    },
    fetchData() {
      wellStaticByType().then(response => {
        this.isShow = false
        this.chartData.rows = response.data
        this.chartData.rows = [
          { 'dept': '科技楼及食堂', 'wellCount': 53 },
          { 'dept': 'A\\B\\C\\D\\E座', 'wellCount': 78 },
          { 'dept': '厂区', 'wellCount': 78 },
          { 'dept': '分段分区', 'wellCount': 38 },
          { 'dept': '船坞分区', 'wellCount': 48 },
          { 'dept': '刀把码头', 'wellCount': 30 },
          { 'dept': '制管作业区', 'wellCount': 82 },
          { 'dept': '滑道作业区', 'wellCount': 34 },
          { 'dept': '码头作业区', 'wellCount': 26 },
          { 'dept': '车间生产区', 'wellCount': 45 }
        ]
        this.isShow = true
      })
    },
    setDefaultTime(val) {
      if (val === 'month') {
        var today = new Date()
        var tYear = today.getFullYear()
        var tMonth = today.getMonth() + 1
        if (tMonth.toString().length === 1) {
          tMonth = '0' + tMonth
        }
        const beginTime = tYear + '-' + tMonth + '-01'
        const endTime = getDayTime(new Date().getTime())
        this.timeRange = [beginTime, endTime.Format('yyyy-MM-dd')]
      } else if (val === 'week') {
        this.timeRange = [getDayTime(new Date().getTime() - 24 * 6 * 60 * 60 * 1000).Format('yyyy-MM-dd'), getDayTime(new Date().getTime()).Format('yyyy-MM-dd')]
      } else if (val === 'yesterday') {
        this.timeRange = [getDayTime(new Date().getTime() - 24 * 60 * 60 * 1000).Format('yyyy-MM-dd'), getDayTime(new Date().getTime() - 24 * 60 * 60 * 1000).Format('yyyy-MM-dd')]
      } else if (val === 'today') {
        this.timeRange = [getDayTime(new Date().getTime()).Format('yyyy-MM-dd'), getDayTime(new Date().getTime()).Format('yyyy-MM-dd')]
      }
      this.fetchData()
    }
  }
}
</script>
<style lang="scss" scoped>
  .container{
    position:relative;
    .function{
      width:calc(100% - 120px);
      height: 28px;
      display: flex;
      justify-content: center;
    }
  }
  .statistic-container {
    /*margin-bottom: 10px;*/
    text-align: center;
    .chart-tool-button {
      padding: 5px;
      line-height: 16px;
      margin-top: 5px;
      font-size: 14px;
    }
    .chart-tool-button:hover {
      background-color: #8cc5ff;
      cursor: pointer;
      color: white;
    }
    .chart-tool-button:active {
      background-color: #8cc5ff;
      color: white;
    }
  }
  .selected {
    background-color: #8cc5ff;
    color: white;
  }
</style>