Newer
Older
smartwell_front / src / views / systemConfig / alarmContent / listContent.vue
<template>
  <app-container>
    <search-area
      class="searchBottom"
      :need-clear="false"
      :need-search-more="false"
      type="seperate"
      size="small"
      search-more-type="default"
      @search="fetchData"
    >
      <!--一般查询条件-->
      <search-item>
        <el-select
          v-model="listQuery.modelName"
          placeholder="设备类型"
          clearable
        >
          <el-option
            v-for="item in deviceModelList"
            :key="item.value"
            :label="item.name"
            :value="item.value"
          />
        </el-select>
      </search-item>
      <search-item>
        <el-select
          v-model="listQuery.alarmType"
          placeholder="告警类型"
          clearable
        >
          <el-option
            v-for="item in alarmTypeList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </search-item>
      <search-item>
        <el-input
          v-model="listQuery.alarmContent"
          placeholder="告警内容"
          clearable
        />
      </search-item>
    </search-area>
    <normal-table
      ref="normalTable"
      :data="list"
      :query="listQuery"
      :columns="columns"
      :list-loading="listLoading"
      :options="options"
      size="small"
    >
      <template slot="btns">
        <el-button size="small" @click="add">
          新增
        </el-button>
      </template>
      <template slot="columns">
        <el-table-column label="操作" width="160" align="center">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="edit(scope.row)">
              修改
            </el-button>
            <el-button type="text" size="small" @click="del(scope.row)">
              删除
            </el-button>
          </template>
        </el-table-column>
      </template>
    </normal-table>
    <dialog-Alarm-content ref="dialogAlarmContent" @watchChild="fetchData" />
  </app-container>
</template>

<script>
// 引用封装组件
import dialogAlarmContent from '@/views/systemConfig/alarmContent/components/dialogAlarmContent'
// 接口调用
import { getDevice, alarmContentList, delAlarmContent } from '@/api/systemConfig/alarmContent'

export default {
  name: 'ListContent',
  components: { dialogAlarmContent },
  data() {
    return {
      // 查询条件
      listQuery: {
        modelName: '',
        alarmType: '',
        alarmContent: '',
        offset: 1,
        sort: 'id',
        order: 'asc'
      },
      // 告警类型列表
      alarmTypeList: [
        {
          label: '告警类型一',
          value: '0'
        },
        {
          label: '告警类型二',
          value: '1'
        },
        {
          label: '告警类型三',
          value: '2'
        }
      ],
      columns: [
        {
          text: '设备编号',
          value: 'id',
          align: 'center'
        },
        {
          text: '告警类型',
          value: 'alarmType',
          align: 'center'
        },
        {
          text: '设备类型',
          value: 'deviceType',
          align: 'center'
        },
        {
          text: '告警内容',
          value: 'alarmContent',
          align: 'center'
        }
      ], // 显示列
      listLoading: false,
      deviceModelList: [], // 设备类型列表
      list: [], // 表格数据列表
      // 是否需要序号列
      options: {
        needIndex: false
      }
    }
  },
  created() {
    this.fetchDeviceType()
    this.fetchData()
  },
  mounted() {
    this.$refs.normalTable.initColumnsState(false)
  },
  methods: {
    // 获取设备类型
    fetchDeviceType() {
      getDevice(this.listQuery).then(response => {
        this.deviceModelList = response.data
      })
    },
    // 获取数据列表
    fetchData() {
      this.listLoading = true
      alarmContentList(this.listQuery).then(response => {
        this.list = response.data
        this.listLoading = false
      })
    },
    del(row) {
      this.$confirm(
        '确定要删除所选设备吗?',
        '确认操作',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      ).then(() => {
        delAlarmContent(row.id).then(response => {
          if (response.code === 200) {
            this.$message.success('删除成功')
            this.fetchData()
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    // 新增
    add() {
      this.$refs.dialogAlarmContent.initDialog('create')
    },
    // 修改
    edit(row) {
      this.$refs.dialogAlarmContent.initDialog('update', row)
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  $tableTitleHeight:46px;
  .table{
    margin-bottom: 20px;
  }
  .searchBottom{
    border-bottom: 12px solid #ebebeb;
  }
  .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>