<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">设备编号</label>
        <el-input v-model="query.deviceIdentifier" clearable placeholder="设备编号" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">设备名称</label>
        <el-input v-model="query.deviceName" clearable placeholder="设备名称" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <date-range-picker
          v-model="query.createTime"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
          class="date-item"
        />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="id" label="主键" />
        <el-table-column prop="createTime" label="告警时间" />
        <el-table-column prop="deviceIdentifier" label="设备编号" />
        <el-table-column prop="deviceName" label="设备名称" />
        <el-table-column prop="warnIndex" label="告警指标" />
        <el-table-column prop="warnValue" label="告警值" />
        <el-table-column prop="warnContent" label="告警内容" />
        <el-table-column v-if="checkPer(['admin','dmEnvHistoryWarn:edit','dmEnvHistoryWarn:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudDmEnvHistoryWarn from '@/api/dm/envmonitor/historydata/dmEnvHistoryWarn'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import DateRangePicker from '@/components/DateRangePicker/index'

const defaultForm = { id: null, deviceIdentifier: null, deviceName: null, createBy: null, updateBy: null, createTime: null, updateTime: null, warnIndex: null, warnValue: null, warnContent: null }
export default {
  name: 'DmEnvHistoryWarn',
  components: { pagination, crudOperation, rrOperation, udOperation, DateRangePicker },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: '历史告警', url: 'api/dmEnvHistoryWarn', idField: 'id', sort: 'id,desc', crudMethod: { ...crudDmEnvHistoryWarn }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'dmEnvHistoryWarn:add'],
        edit: ['admin', 'dmEnvHistoryWarn:edit'],
        del: ['admin', 'dmEnvHistoryWarn:del']
      },
      rules: {
      },
      queryTypeOptions: [
        { key: 'deviceIdentifier', display_name: '设备编号' },
        { key: 'deviceName', display_name: '设备名称' }
      ]
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
