Newer
Older
baseResourceFront / src / views / alarm / listRecord.vue
zhangyingjie on 24 Mar 2021 7 KB 合并master分支
<template>
  <app-container>
    <!--筛选条件-->
    <search-area size="small" type="seperate" @search="search">
      <search-item>
        <el-input v-model.trim="listQuery.description" placeholder="车辆描述" size="small" clearable/>
      </search-item>
      <search-item>
        <el-input v-model="listQuery.carCode" placeholder="车牌号" size="small" clearable/>
      </search-item>
      <search-item>
        <el-select v-model="listQuery.carType" filterable placeholder="车辆类型" size="small" clearable value="" @change="fetchData()">
          <el-option
            v-for="item in cartypelist"
            :key="item.value"
            :label="item.name"
            :value="item.value"/>
        </el-select>
      </search-item>
      <search-item>
        <dept-select v-model="listQuery.deptId" :dept-show="deptShow" size="small" placeholder="使用单位" clearable value=""/>
      </search-item>
      <search-item>
        <el-select v-model="listQuery.alarmType" :dept-show="deptShow" size="small" placeholder="报警类型" clearable value="" @change="fetchData()">
          <el-option
            v-for="item in alarmtypelist"
            :key="item.value"
            :label="item.name"
            :value="item.value"/>
        </el-select>
      </search-item>
      <search-item>
        <el-select v-model="listQuery.alarmReason" :dept-show="deptShow" size="small" placeholder="报警原因" clearable value="" @change="fetchData()">
          <el-option
            v-for="item in alarmreasonlist"
            :key="item.value"
            :label="item.name"
            :value="item.value"/>
        </el-select>
      </search-item>
      <search-item>
        <el-date-picker
          v-model="dateTimeRange"
          type="datetimerange"
          size="small"
          range-separator="至"
          value-format="yyyy-MM-dd HH:mm:ss"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
        />
      </search-item>
    </search-area>
    <!--查询结果Table显示-->
    <normal-table :data="list" :query="listQuery" :total="total" :columns="columns" :list-loading="listLoading" class="table" border size="small" @selection-change="handleSelectionChange" @change="changePage">
      <template slot="btns">
        <el-button size="small" class="edit_btn" icon="el-icon-receiving" @click="batchExport">导出</el-button>
      </template>
      <template slot="columns">
        <el-table-column label="操作" width="80" align="center">
          <template slot-scope="scope">
            <el-button type="text" size="mini" @click="detail(scope.row)">详情</el-button>
          </template>
        </el-table-column>
      </template>
    </normal-table>
    <!--编辑资源的对话框-->
    <detail-record v-show="dialogFormVisible" ref="detailRecord"/>
  </app-container>
</template>
<script>
import detailRecord from '@/views/alarm/detailRecord'
import { getRecordList, exportRecord } from '@/api/alarm'
import { getDictCode } from '@/api/dict'
import DeptSelect from '@/components/DeptSelect'
import { downloadFile } from '@/utils/downloadUtils'
export default {
  name: 'ListRecord',
  components: { DeptSelect, detailRecord },
  data() {
    return {
      deptShow: true,
      listQuery: {
        description: '',
        carCode: '',
        carType: '',
        deptId: '',
        alarmReason: '',
        alarmType: '',
        startTime: '',
        endTime: '',
        offset: 1,
        limit: 20
      }, // 查询条件
      columns: [{
        text: '车辆描述',
        value: 'description',
        align: 'center'
      },
      {
        text: '车辆类型',
        value: 'carTypeName',
        align: 'center',
        width: 150
      },
      {
        text: '车牌号',
        value: 'carCode',
        align: 'center',
        width: 100
      },
      {
        text: '使用单位',
        value: 'deptName',
        align: 'center'
      },
      {
        text: '报警类型',
        value: 'alarmTypeName',
        align: 'center',
        width: 120
      },
      {
        text: '报警原因',
        value: 'alarmReasonName',
        align: 'center',
        width: 120
      },
      {
        text: '报警时间',
        value: 'alarmTime',
        align: 'center',
        width: 180
      },
      {
        text: '报警信息',
        value: 'alarmMsg',
        align: 'center'
      }], // 动态加载的表头
      dateTimeRange: [],
      list: [], // 列表数据
      total: 0, // 数据总数
      listLoading: true, // 加载动画
      fullscreenLoading: false, // 全屏加载动画
      dialogFormVisible: false, // 是否显示编辑框
      cartypelist: [], // 类型列表
      alarmtypelist: [], // 类型列表
      alarmreasonlist: [], // 类型列表
      deptlist: [] // 类型列表
    }
  },
  watch: {
    dateTimeRange(val) {
      if (val && val.length > 0) {
        this.listQuery.startTime = val[0]
        this.listQuery.endTime = val[1]
      } else {
        this.listQuery.startTime = ''
        this.listQuery.endTime = ''
      }
    }
  },
  created() {
    getDictCode('carType').then(response => {
      this.cartypelist = response.data
    })
    getDictCode('alarmType').then(response => {
      this.alarmtypelist = response.data
    })
    getDictCode('alarmReason').then(response => {
      this.alarmreasonlist = response.data
    })
    this.fetchData()
  },
  methods: {
    batchExport() {
      // 全屏加载动画
      const loading = this.$loading({
        lock: true,
        text: '下载中,请稍后...',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      })
      exportRecord(this.listQuery).then(res => {
        loading.close() // 关闭加载动画
        downloadFile(res.data, '违规记录列表')
      }).catch((res) => {
        loading.close()
      })
    },
    detail(row) {
      this.dialogFormVisible = true
      this.$refs.detailRecord.initDialog(this.dialogFormVisible, row.alarmId)
    },
    search() {
      this.fetchData(false)
    },
    // detail(row) {
    //   this.$router.push({
    //     name: 'RecordDetail',
    //     query: {
    //       id: row.alarmId
    //     }
    //   })
    // },
    fetchData(isNowPage = true) {
      console.log('fetchData')
      this.listLoading = true
      if (!isNowPage) {
        this.listQuery.offset = 1
      }
      getRecordList(this.listQuery).then(response => {
        console.log(response)
        this.list = response.data.rows
        console.log(response.data)
        this.total = parseInt(response.data.total)
        // 如果当前页码数据为空,重新请求末页
        // if (this.listQuery.offset > Math.ceil(this.total / this.listQuery.limit)) {
        //   this.listQuery.offset = Math.ceil(this.total / this.listQuery.limit)
        //   getRecordList(this.listQuery).then(response => {
        //     this.list = response.data.rows
        //     this.total = parseInt(response.data.total)
        //     this.listLoading = false
        //   })
        // }
        this.listLoading = 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
    },
    // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
    changePage(val) {
      if (val && val.size) {
        this.listQuery.limit = val.size
      }
      if (val && val.page) {
        this.listQuery.offset = val.page
      }
      this.fetchData()
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
</style>