Newer
Older
smartcity_env_front / src / views / alarmRule / simpleDeviceList.vue
<template>
  <app-container>
    <search-area :need-clear="true" :need-search-more="false" type="seperate" size="small" search-more-type="default" @search="fetchData" @clear="clearInput" >
      <!--一般查询条件-->
      <search-item>
        <el-input v-model.trim="listQuery.keywords" size="small" placeholder="编号/点位名称" clearable/>
      </search-item>
      <search-item>
        <el-input v-model.trim="listQuery.position" size="small" placeholder="详细地址" clearable/>
      </search-item>
    </search-area>
    <normal-table :data="list" :head="tableOption.head" :query="listQuery" :total="total" :columns="columns" :list-loading="listLoading" :options="tableOption.options" :tools-option="tableOption.toolsOption" @change="changePage">
      <template slot="btns">
        <el-upload
          v-if="hasPerm('/environment/alarmRule/import')"
          :limit="1"
          :show-file-list="false"
          :http-request="uploadFile"
          :file-list="fileList"
          action="string"
          accept=".xls,.xlsx"
          class="edit_btn">
          <el-button slot="trigger" size="small">批量导入</el-button>
        </el-upload>
      </template>
      <template slot="columns">
        <el-table-column label="操作" align="center" width="120">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click.stop="goDetail(scope.row)">查看报警阈值</el-button>
          </template>
        </el-table-column>
      </template>
    </normal-table>
  </app-container>
</template>

<script>
  import { getDeviceListPage } from '@/api/environment/device'
  import {batchImportAlarmRule} from '@/api/environment/alarmRule'
export default {
  name: 'SimpleDeviceList',
  data() {
    return {
      listQuery: {
        keywords: '', // 关键字
        online: '', // 在线状态
        position: '', // 位置
        offset: 1,
        limit: 20,
        sort: '',
        order: 'desc'
      }, // 筛选条件
      columns: [
        {
          text: '设备编号',
          value: 'deviceNo',
          align: 'center',
          width: 160
        },
        {
          text: '点位名称',
          value: 'deviceName',
          align: 'center'
        },
        // {
        //   text: '市',
        //   value: 'responsiblePerson',
        //   align: 'center',
        //   width: 80
        // },
        // {
        //   text: '区/县',
        //   value: 'area',
        //   align: 'center'
        // },
        {
          text: '详细地址',
          value: 'position',
          align: 'center'
        },
        {
          text: '权属单位',
          value: 'deptName',
          align: 'center'
        },
        {
          text: '备注',
          value: 'notes',
          align: 'center'
        },
        {
          text: '安装时间',
          value: 'installDate',
          align: 'center'
        }
      ], // 显示列
      options:[
        {value:'1',name:'在线'},
        {value:'2',name:'离线'}
      ],
      timeRange: [], // 时间范围
      list: [], // 列表数据
      total: 0, // 数据总数
      listLoading: true, // 列表加载动画
      typeList: [],
      fileList: [],
      tableOption: {
        head: {
          show: true, // 是否需要标题栏,
          text: '数据列表' // 标题名称
        },
        options: {
          needIndex: true // 是否需要序号列
        },
        toolsOption: {
          selectColumns: false, // 是否需要筛选列
          refresh: false // 是否需要刷新按钮
        }
      }, // 表格属性
      editShow: false // 编辑页面是否显示
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      this.listLoading = true
      getDeviceListPage(this.listQuery).then(response => {
        this.list = response.data.rows
        this.total = response.data.total
        this.listLoading = false
      })
    },
    // 点击详情
    goDetail(row) {
      const params = { deviceNo: row.deviceNo }
      this.$router.push({ name: 'DeviceAlarmRule', query: params })
    },
    // 批量导入
    uploadFile(param) {
      // 判断文件大小是否符合要求
      const _file = param.file
      const isLt5M = _file.size / 1024 / 1024 < 5
      if (!isLt5M) {
        this.$message.error('请上传5M以下的excel文件')
        return false
      }
      // 全屏加载动画
      const loading = this.$loading({
        lock: true,
        text: '导入中,请稍后...',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      })
      // 发起导入请求
      batchImportAlarmRule(_file).then(res => {
        loading.close() // 关闭加载动画
        if (res.code === 200) {
          this.$message.success('导入成功')
          this.fetchData()
        } else {
          this.$message.error(res.message)
        }
      }).catch(() => {
        loading.close() // 关闭加载动画
      })
      this.fileList = []
    },
    // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
    changePage(val) {
      if (val && val.size) {
        this.listQuery.limit = val.size
      }
      if (val && val.page) {
        this.listQuery.offset = val.page
      }
      this.fetchData()
    },
    // 重置后的操作, 若不需要显示重置按钮则不需要写
    clearInput() {
      this.listQuery = {
        keywords: '', // 关键字
        online: '', // 在线状态
        position: '', // 位置
        offset: 1,
        limit: 20,
        sort: '',
        order: 'desc'
      }
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .edit_btns{
    .edit_btn{
      float:right;
      margin-left:5px;
    }
  }
</style>