Newer
Older
baseResourceFront / src / views / alarm / listCarThreshold.vue
zhangyingjie on 22 Mar 2021 6 KB 原车辆子系统代码提交
<template xmlns:align="">
  <div class="app-container">
    <!--筛选条件-->
    <div class="search-div">
      <el-form ref="selectForm" :inline="true" :model="listQuery" class="form-container">
        <el-form ref="selectForm" :inline="true" :model="listQuery" class="form-container">
          <el-form-item class="selectForm-container-item" prop="keywords">
            <el-input v-model.trim="listQuery.description" placeholder="车辆描述" clearable/>
          </el-form-item>
          <el-form-item class="selectForm-container-item" prop="keywords">
            <el-input v-model="listQuery.carCode" placeholder="车牌号" clearable/>
          </el-form-item>

          <el-form-item class="selectForm-container-item" prop="keywords">
            <el-select v-model="listQuery.carType" filterable placeholder="车辆类型" clearable value="" @change="fetchData()">
              <el-option
                v-for="item in cartypelist"
                :key="item.value"
                :label="item.name"
                :value="item.value"/>
            </el-select>
          </el-form-item>
          <el-form-item class="selectForm-container-item" prop="keywords">
            <dept-select v-model="listQuery.deptId" :dept-show="deptShow" placeholder="使用单位" clearable value=""/>
          </el-form-item>
          <el-button class="filter-item" type="primary" icon="el-icon-search" @click="search">查 询</el-button>
        </el-form>
    </el-form></div>
    <!--查询结果Table显示-->
    <el-table v-loading="listLoading" :data="list" class="table" border @selection-change="handleSelectionChange">
      <el-table-column :index="indexMethod" align="center" type="index" label="序号" width="55"/>
      <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 :class="column.class">{{ scope.row[column.value] }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="100" align="center">
        <template slot-scope="scope">
          <el-button type="warning" size="mini" @click="edit(scope.row)">修改</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--分页-->
    <div class="pagination-container">
      <el-pagination
        v-show="total>listQuery.limit"
        :current-page="listQuery.offset"
        :page-sizes="[15,20,30]"
        :page-size="listQuery.limit"
        :total="total"
        align="center"
        layout="total, sizes, prev, pager, next"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"/>
    </div>
    <!--编辑资源的对话框-->
    <edit-car-threshold v-show="dialogFormVisible" ref="editCarThreshold" @watchChild="fetchData"/>
  </div>
</template>
<script>
import editCarThreshold from '@/views/alarm/editCarThreshold'
import { getThresholdList } from '@/api/alarm'
import { getDictCode } from '@/api/dict'
import DeptSelect from '@/components/DeptSelect'
export default {
  name: 'ListCarThreshold',
  components: { editCarThreshold, DeptSelect },
  data() {
    return {
      deptShow: true,
      listQuery: {
        description: '',
        carCode: '',
        carType: '',
        deptId: '',
        offset: 1,
        limit: 15
      }, // 查询条件
      columns: [
        {
          text: '车辆描述',
          value: 'description',
          align: 'center'
        },
        {
          text: '车辆类型',
          value: 'carTypeName',
          align: 'center'
        }, {
          text: '车牌号',
          value: 'carCode',
          align: 'center'
        },
        {
          text: '设备离线时长(分钟)',
          value: 'offlineTime',
          align: 'center',
          width: 150
        },
        {
          text: '最高限速(km/h)',
          value: 'limitSpeed',
          align: 'center',
          width: 150
        },
        {
          text: '停留超时时长(分钟)',
          value: 'stayTime',
          align: 'center',
          width: 150
        },
        {
          text: '停留距离(米)',
          value: 'stayDistance',
          align: 'center',
          width: 150
        }
      ], // 动态加载的表头
      list: [], // 列表数据
      total: 0, // 数据总数
      listLoading: true, // 加载动画
      fullscreenLoading: false, // 全屏加载动画
      dialogFormVisible: false, // 是否显示编辑框
      cartypelist: [], // 类型列表
      deptlist: [] // 类型列表
    }
  },
  created() {
    getDictCode('carType').then(response => {
      this.cartypelist = response.data
    })
    this.fetchData()
  },
  methods: {
    edit(row) {
      this.dialogStatus = 'update'
      this.dialogFormVisible = true
      this.$refs.editCarThreshold.initDialog(this.dialogStatus, this.dialogFormVisible, row)
    },
    search() {
      this.fetchData(false)
    },
    fetchData(isNowPage = true) {
      console.log('fetchData')
      this.listLoading = true
      if (!isNowPage) {
        this.listQuery.offset = 1
      }
      getThresholdList(this.listQuery).then(response => {
        this.list = response.data.rows
        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)
          getThresholdList(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
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .el-table__header tr,
  .el-table__header th {
    padding: 0;
    height: 40px;
    background-color: #f8f8f8;
  }
  .table{
    margin-bottom: 20px;
  }
  .pagination-container{
    margin-bottom: 100px;
  }
</style>