Newer
Older
qd_cnooc_front / src / views / dataManage / deviceData / watchSevenDay.vue
<template>
  <el-dialog :visible.sync="dialogFormVisible" width="1200px" title="历史数据" append-to-body class="lineDialog">
    <div style="margin-bottom: 10px">
      <el-date-picker
        v-model="timeRange"
        type="datetimerange"
        range-separator="至"
        value-format="yyyy-MM-dd HH:mm:ss"
        start-placeholder="开始时间"
        end-placeholder="结束时间"
        size="small"/>
      <el-button class="filter-item" type="primary" icon="el-icon-search" size="small" @click="fetchData">搜索</el-button>
    </div>
    <div v-loading="loading" style="display: flex" >
      <ve-line :data="chartData" :settings="chartSettings" :title="title" style="flex: 1"/>
      <div style="width: 300px">
        <el-table :data="chartData.rows" size="mini" height="380px">
          <el-table-column label="日期" prop="time" width="150" align="center"/>
          <el-table-column label="用水量(立方米)" prop="value" align="center"/>
        </el-table>
      </div>
    </div>
    <div v-loading="loading1" style="display: flex">
      <ve-line :data="chartData1" :settings="chartSettings1" :title="title1" style="flex: 1"/>
      <div style="width: 300px">
        <el-table :data="chartData1.rows" size="mini" height="380px" >
          <el-table-column label="抄表时间" prop="uptime" width="140" align="center"/>
          <el-table-column label="总用水量(立方米)" prop="total" align="center"/>
          <!--<el-table-column label="阀门状态" align="center" width="70">-->
          <!--<template slot-scope="scope">{{scope.status=='1'?'开':(scope.status=='0'?'关':'&#45;&#45;')}}</template>-->
          <!--</el-table-column>-->
        </el-table>
      </div>
    </div>
  </el-dialog>
</template>

<script>
import { getDayTime } from '@/utils/dateutils'
import { sevenDayData, totalData } from '@/api/device'

export default {
  name: 'WatchSevenDay',
  data() {
    return {
      loading: true,
      loading1: true,
      title: {
        text: '日用水量(立方米)'
      },
      title1: {
        text: '累计用水量(立方米)'
      },
      timeRange: [],
      dialogFormVisible: false, // 对话框是否显示
      listQuery: {
        devCode: '',
        beginTime: '',
        endTime: ''
      },
      chartData: {
        columns: ['time', 'value'],
        rows: []
      },
      chartData1: {
        columns: ['uptime', 'total'],
        rows: []
      },
      chartSettings: {
        labelMap: {
          'value': '用水量(立方米)'
        },
        metrics: ['value'],
        dimension: ['time']
      },
      chartSettings1: {
        labelMap: {
          'total': '总用水量(立方米)'
        },
        metrics: ['total'],
        dimension: ['uptime']
      },
      data: []

    }
  },
  watch: {
    timeRange(val) {
      if (val && val.length > 0) {
        this.listQuery.beginTime = val[0]
        this.listQuery.endTime = val[1]
      } else {
        this.listQuery.beginTime = ''
        this.listQuery.endTime = ''
      }
    }
  },
  methods: {
    initDialog: function(dialogFormVisible, row = null) {
      this.listQuery.devCode = row.devcode
      this.dialogFormVisible = dialogFormVisible
      const beginTime = getDayTime(new Date().getTime() - 24 * 7 * 60 * 60 * 1000).Format('yyyy-MM-dd hh:mm:ss')
      const endTime = new Date().Format('yyyy-MM-dd hh:mm:ss')
      this.timeRange = [beginTime, endTime]
      this.fetchData() // 传row
    },
    fetchData() {
      if (this.timeRange && this.timeRange.length === 2) {
        this.listQuery.beginTime = this.timeRange[0]
        this.listQuery.endTime = this.timeRange[1]
      } else {
        this.listQuery.beginTime = ''
        this.listQuery.endTime = ''
      }
      sevenDayData(this.listQuery).then(response => {
        this.loading = true
        this.chartData.rows = response.data
        this.loading = false
      })
      totalData(this.listQuery).then(response => {
        this.loading1 = true
        this.chartData1.rows = response.data
        this.chartData1.rows.reverse()
        this.data = response.data
        this.loading1 = false
      })
    }
  }
}
</script>
<style>
  .el-dialog__header {
    padding: 10px !important;
  }
  .el-dialog__body {
    padding: 10px !important;
  }
  .lineDialog .el-table th{
    color: white !important;
    background-color: #52a4fa !important;
  }

</style>