Newer
Older
smartwell_front / src / views / alarmRule / listRule.vue
StephanieGitHub on 4 Jul 2019 6 KB first commit
<template>
  <div class="app-container">
    <!--筛选条件-->
    <div class="search-div">
      <el-form ref="selectForm" :inline="true" :model="listQuery" class="form-container">
        <el-row>
          <el-form-item class="selectForm-container-item" prop="keywords">
            <el-input v-model.trim="listQuery.keywords" placeholder="闸井编号/设备编号" clearable/>
          </el-form-item>
          <el-form-item v-if="showDeviceType" class="selectForm-container-item" prop="wellType">
            <el-select v-model="listQuery.deviceType" placeholder="设备类型" clearable>
              <el-option
                v-for="item in deviceTypeList"
                :key="item.value"
                :label="item.name"
                :value="item.value"/>
            </el-select>
          </el-form-item>
          <el-button class="filter-item" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
        </el-row>
      </el-form>
    </div>
    <!--查询结果Table显示-->
    <div>
      <el-row class="table-title">
        <el-col :span="6"><div class="title-header"><i class="el-icon-menu"/>数据列表</div></el-col>
      </el-row>
      <el-table v-loading="listLoading" :data="list" class="table" border @selection-change="handleSelectionChange">
        <!--<el-table-column align="center" type="selection" width="55"/>-->
        <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 v-if="column.type!='Button'" :class="column.class">{{ scope.row[column.value] }}</span>
            <el-button v-if="column.type=='Button'" type="text" @click="showWellDetail(scope.row)">{{ scope.row.wellCode }}</el-button>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="80">
          <template slot-scope="scope">
            <el-button type="text" @click="edit(scope.row)">编辑</el-button>
          </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>

    <edit-rule v-show="editShow" ref="editrule" @watchChild="fetchData"/>
    <info-well v-show="wellShow" ref="wellInfo"/>

  </div>
</template>

<script>
import infoWell from '@/views/wellManage/infoWell'
import editRule from '@/views/alarmRule/editRule'
import { getDeviceType } from '@/api/device'
import { getAlarmRuleList } from '@/api/alarmRule'

export default {
  name: 'ListRule',
  components: { editRule, infoWell },
  data() {
    return {
      listQuery: {
        keywords: '',
        status: '',
        offset: 1,
        limit: 20,
        sort: '',
        order: ''
      }, // 筛选条件
      columns: [
        {
          text: '闸井编号',
          value: 'wellCode',
          align: 'center',
          type: 'Button'
        },
        {
          text: '闸井名称',
          value: 'wellName',
          align: 'center'
        },
        {
          text: '井深',
          value: 'deep',
          align: 'center'
        },
        {
          text: '设备类型',
          value: 'deviceTypeName',
          align: 'center'
        },
        {
          text: '设备编号',
          value: 'devcode',
          align: 'center'
        },
        {
          text: '告警上限(m)',
          value: 'highValue',
          align: 'center'
        },
        {
          text: '操作人',
          value: 'user',
          width: 100,
          align: 'center'
        }
      ], // 显示列
      multipleSelection: [], // 多选选中项
      list: [], // 列表数据
      total: 0, // 数据总数
      deviceTypeList: [], // 设备类型列表
      showDeviceType: true,
      listLoading: true, // 加载动画
      editShow: false, // 是否显示编辑框
      wellShow: false // 是否显示闸井详情
    }
  },
  created() {
    this.fetchDeviceType()// 获取部门树
    this.fetchData()// 获取数据
  },
  methods: {
    // 显示闸井详情
    showWellDetail(row) {
      this.wellShow = true
      this.$refs.wellInfo.initDialog(row.wellId)
    },
    checkSelection() {
      if (this.multipleSelection.length === 0) {
        return false
      } else {
        return true
      }
    },
    // 编辑告警规则信息
    edit(row) {
      this.editShow = true
      this.$refs.editrule.initDialog('update', true, row)
    },
    // 查询数据
    search() {
      this.fetchData(false)
    },
    // 获取数据
    fetchData(isNowPage = true) {
      this.listLoading = true
      if (!isNowPage) { // 是否显示当前页,否则跳转第一页
        this.listQuery.offset = 1
      }
      getAlarmRuleList(this.listQuery).then(response => {
        this.list = response.data.rows
        this.total = parseInt(response.data.total)
        this.listLoading = false
      })
    },
    // 获取设备类型
    fetchDeviceType() {
      getDeviceType(this.listQuery).then(response => {
        this.deviceTypeList = []
        const supportDeviceTypes = this.$store.getters.deviceTypes
        for (const item of response.data) {
          if (supportDeviceTypes.indexOf(item.value) !== -1) {
            this.deviceTypeList.push(item)
          }
        }
        if (this.deviceTypeList.length <= 1) {
          this.showDeviceType = false
        }
      })
    },
    indexMethod(index) {
      return this.listQuery.limit * (this.listQuery.offset - 1) + index + 1
    },
    // 改变页容量
    handleSizeChange(val) {
      this.listQuery.limit = val
      this.fetchData()
    },
    // 改变当前页
    handleCurrentChange(val) {
      this.listQuery.offset = val
      this.fetchData()
    },
    // 多选触发方法
    handleSelectionChange(val) {
      this.multipleSelection = val
    }
  }
}
</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>