Newer
Older
qd_cnooc_front / src / views / dashboard / components / waterCountByAreaBar.vue
<template>
  <div class="container">
    <function-area ref="func" select="week" @change="fetchData"/>
    <!--<div class="statistic-container">-->
      <!--<el-button round size="mini" @click="setDefaultTime('year')">本年</el-button>-->
      <!--<el-button round size="mini" @click="setDefaultTime('season')">本季</el-button>-->
      <!--<el-button round size="mini" @click="setDefaultTime('month')">本月</el-button>-->
      <!--<el-button round size="mini" @click="setDefaultTime('week')">本周</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 { countBySecondArea } from '@/api/dashboard'
import { getDayTime } from '@/utils/dateutils'
import { getDoorAreaTree } from '@/api/system/area'
import FunctionArea from "./FunctionArea";

export default {
  name: 'WaterCountByAreaBar',
  components: {FunctionArea},
  data() {
    this.extend = {
      legend: {
        show: true
      },
      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: {
        'areaName': '分区',
        'count': '用水量'
      },
      dimension: ['areaName'],
      metrics: ['count']
    }
    return {
      areaId: '',
      areaList: [],
      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', 'count'],
        rows: []
      }
    }
  },
  mounted() {
    this.$refs.func.init()
    // this.setDefaultTime('week')
    // this.fetchArea()
  },
  methods: {
    fetchArea() {
      getDoorAreaTree().then(response => {
        if (response.code === 200) {
          this.areaList = response.data.filter(item => {
            return item.pid === '1'
          }).map(function(item) {
            return {
              id: item.id, name: item.name
            }
          })
          if (this.areaList.length !== 0) { this.areaChange(this.areaList[0].id) }
        }
      })
    },
    areaChange(val) {
      this.areaId = val
      this.fetchData()
    },
    fetchData(timeRange) {
      const params = {
        areaId: '110000',
        startTime: timeRange[0],
        endTime: timeRange[1]
      }
      this.$emit('change', params)
      countBySecondArea(params).then(response => {
        this.isShow = false
        this.chartData.rows = response.data
        // this.chartData.rows = [
        //   { 'areaName': '科技楼及食堂', 'count': 53 },
        //   { 'areaName': 'A\\B\\C\\D\\E座', 'count': 78 },
        //   { 'areaName': '厂区', 'count': 78 },
        //   { 'areaName': '分段分区', 'count': 38 },
        //   { 'areaName': '船坞分区', 'count': 48 },
        //   { 'areaName': '刀把码头', 'count': 30 },
        //   { 'areaName': '制管作业区', 'count': 82 },
        //   { 'areaName': '滑道作业区', 'count': 34 },
        //   { 'areaName': '码头作业区', 'count': 26 },
        //   { 'areaName': '车间生产区', 'count': 45 }
        // ]
        this.isShow = true
      })
    },
    setDefaultTime(val) {
      if (val === 'year') {
        var today = new Date()
        var tYear = today.getFullYear()
        const beginTime = tYear + '-01-01'
        const endTime = getDayTime(new Date().getTime())
        this.timeRange = [beginTime, endTime.Format('yyyy-MM-dd')]
      }if (val === 'season') {
        var today = new Date()
        var tYear = today.getFullYear()
        var tMonth = today.getMonth() + 1
        const oldMonth = tMonth<4?'01':(tMonth<7?'04':(tMonth<10?'07':'10'))
        const beginTime = tYear + '-' + oldMonth + '-01'
        const endTime = getDayTime(new Date().getTime())
        this.timeRange = [beginTime, endTime.Format('yyyy-MM-dd')]
      }else 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') {
        // const nowDayOfWeek =  new Date().getDay()-1
        const nowDayOfWeek =  6
        this.timeRange = [getDayTime(new Date().getTime() - 24 * nowDayOfWeek * 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(this.timeRange)
    }
  }
}
</script>
<style lang="scss" scoped>
  .container{
    position:relative;
    .function{
      width:calc(100% - 120px);
      height: 28px;
      display: flex;
      justify-content: center;
    }
  }
  .statistic-container {
    .el-button{
      padding: 5px 10px;
    }
    /*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>