Newer
Older
laserPTZFront / src / views / dataManage / components / listGasHistory.vue
[wangxitong] on 10 May 2022 5 KB first commit
<template>
  <div class="app-container">
    <div>
      <el-row class="table-title">
        <el-col :span="6"><div class="title-header"><i class="el-icon-menu"/>甲烷历史数据列表</div></el-col>
        <el-col :span="12" :offset="6" class="edit_btns">
          <el-button class="edit_btn" size="small" @click="batchExport">导出记录</el-button>
        </el-col>
      </el-row>
      <el-table v-loading="listLoading" :data="list" class="table" border>
        <el-table-column :index="indexMethod" align="center" type="index" />
        <el-table-column v-for="column in columns" :key="column.value" :label="column.text" :width="column.width" :align="column.align" show-overflow-tooltip>
          <template slot-scope="scope">
            <span :class="column.class">{{ scope.row[column.value] }}</span>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!--分页-->
    <div class="pagination-container">
      <el-pagination
        v-show="total>listQuery.limit"
        :current-page="listQuery.offset"
        :page-sizes="[20,30,50]"
        :page-size="listQuery.limit"
        :total="total"
        align="center"
        layout="total, sizes, prev, pager, next"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"/>
    </div>
  </div>
</template>

<script>
import { getHistoryList, batchExport } from '@/api/data'

export default {
  name: 'ListGasHistory',
  components: { },
  data() {
    return {
      listQuery: {
        monitorId: '',
        startTime: '',
        endTime: '',
        offset: 1,
        limit: 20,
        sort: 'logtime',
        order: 'desc'
      }, // 筛选条件
      columns: [
        {
          text: '监控点',
          value: 'monitorName',
          align: 'center',
          width: 140
        },
        {
          text: '场站名称',
          value: 'stationName',
          align: 'center'
        },
        {
          text: '浓度值(ppm.m)',
          value: 'concentration',
          align: 'center'
        },
        {
          text: '阈值(ppm.m)',
          value: 'threshold',
          align: 'center'
        },
        {
          text: '采集时间',
          value: 'logTime',
          align: 'center'
        },
        {
          text: '采集水平角度',
          value: 'direction',
          align: 'center'
        },
        {
          text: '采集垂直角度',
          value: 'pitch',
          align: 'center'
        }
      ], // 显示列
      list: [], // 列表数据
      total: 0, // 数据总数
      listLoading: true, // 加载动画
      high: '',
      filename: 'device_template.xlsx'
    }
  },
  mounted() {
  },
  methods: {
    // 获取列表
    fetchData(params) {
      this.listQuery.monitorId = params.monitorId
      this.listQuery.startTime = params.startTime
      this.listQuery.endTime= params.endTime
      this.listLoading = true
      getHistoryList(this.listQuery).then(response => {
        this.list = response.data.rows
        this.total = parseInt(response.data.total)
        this.listLoading = false
      })
    },
    batchExport() {
      // 全屏加载动画
      const loading = this.$loading({
        lock: true,
        text: '数据处理中,请稍后...',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      })
      batchExport(this.listQuery).then(res => {
        loading.close() // 关闭加载动画
        console.log('download===', res)
        const blob = new Blob([res.data])
        const downloadElement = document.createElement('a')
        const href = window.URL.createObjectURL(blob) // 创建下载的链接
        downloadElement.href = href
        downloadElement.download = `甲烷历史数据.xlsx` // 下载后文件名
        document.body.appendChild(downloadElement)
        downloadElement.click() // 点击下载
        document.body.removeChild(downloadElement) // 下载完成移除元素
        window.URL.revokeObjectURL(href) // 释放blob对象
      }).catch(() => {
        loading.close()
      })
    },
    indexMethod(index) {
      return this.listQuery.limit * (this.listQuery.offset - 1) + index + 1
    },
    // 改变页容量
    handleSizeChange(val) {
      this.listQuery.limit = val
      this.fetchData(this.listQuery, this.high)
    },
    // 改变当前页
    handleCurrentChange(val) {
      this.listQuery.offset = val
      this.fetchData(this.listQuery, this.high)
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  $tableTitleHeight:46px;
  .table{
    margin-bottom: 20px;
  }
  .pagination-container{
    margin-bottom: 50px;
  }
  .table-title{
    background-color:rgba(243, 243, 243, 1);
    height: $tableTitleHeight;
    .title-header{
      line-height:$tableTitleHeight;
      color: #606266;
      font-size: 15px;
      i{
        margin-left: 5px;
        margin-right: 5px;
      }
    }
  }
  .edit_btns{
    .edit_btn{
      float:right;
      margin:7px 3px;//为了需要居中显示margin-top和bottom要用$tableTitleHeight减去按钮原高度除以2
    }
  }
</style>