Newer
Older
rescue_front / src / views / fire / listFireInfo.vue
[wangxitong] on 16 May 2022 8 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-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-button class="filter-item" type="primary" icon="el-icon-edit" @click="add">新 增</el-button>-->
        <!--<el-button class="edit_btn" type="primary" icon="el-icon-receiving" @click="batchExport">导 出</el-button>-->
      </el-form>
    </div>
    <el-row class="table-title">
      <el-col :span="6"><div class="title-header"><i class="el-icon-menu"/>数据列表</div></el-col>
      <el-col :span="12" :offset="6" class="edit_btns">
        <el-button class="edit_btn" size="small" @click="add">新 增</el-button>
        <!--<el-button class="edit_btn" size="small" @click="batchExport">导 出</el-button>-->
      </el-col>
    </el-row>
    <!--查询结果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="180" align="center">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" @click="detail(scope.row)">详情</el-button>
          <el-button type="warning" size="mini" @click="edit(scope.row)">修改</el-button>
          <el-button type="danger" size="mini" @click="del(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-fire-info v-show="dialogFormVisible" ref="editFireInfo" @watchChild="fetchData"/>
  </div>
</template>
<script>
import editFireInfo from '@/views/fire/editFireInfo'
import { getCarInfoList, delCarInfo, exportCar } from '@/api/carInfo'
import { getDictCode } from '@/api/dict'
import DeptSelect from '@/components/DeptSelect'
import { downloadFile } from '@/utils/downloadUtils'
export default {
  name: 'ListFireInfo',
  components: { DeptSelect, editFireInfo },
  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: 'brandModel',
          align: 'center'
        },
        {
          text: '设备编号',
          value: 'carCode',
          align: 'center'
        },
        {
          text: '使用单位',
          value: 'deptName',
          align: 'center',
          width: 180
        }
      ], // 动态加载的表头
      list: [], // 列表数据
      total: 0, // 数据总数
      listLoading: true, // 加载动画
      fullscreenLoading: false, // 全屏加载动画
      dialogFormVisible: false, // 是否显示编辑框
      cartypelist: [], // 类型列表
      deptlist: [] // 类型列表
    }
  },
  created() {
    getDictCode('carType').then(response => {
      this.cartypelist = response.data
    })
    this.fetchData()
  },
  methods: {
    batchExport() {
      // 全屏加载动画
      const loading = this.$loading({
        lock: true,
        text: '下载中,请稍后...',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      })
      exportCar(this.listQuery).then(res => {
        loading.close() // 关闭加载动画
        downloadFile(res.data, '车辆基础信息表')
      }).catch((res) => {
        loading.close()
      })
    },
    add() {
      this.dialogStatus = 'create'
      this.dialogFormVisible = true
      this.$refs.editFireInfo.initDialog(this.dialogStatus, this.dialogFormVisible)
    },
    edit(row) {
      this.dialogStatus = 'update'
      this.dialogFormVisible = true
      this.$refs.editFireInfo.initDialog(this.dialogStatus, this.dialogFormVisible, row)
    },
    detail(row) {
      this.dialogStatus = 'detail'
      this.dialogFormVisible = true
      this.$refs.editFireInfo.initDialog(this.dialogStatus, this.dialogFormVisible, row)
    },
    del(row) {
      this.$confirm(
        '确定要删除' + row.description + '吗?',
        '确认删除',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      ).then(() => {
        delCarInfo(row.id).then(response => {
          if (response.code === 200) {
            this.$message.success('删除成功')
            this.fetchData()
          }
        })
      })
    },
    search() {
      this.fetchData(false)
    },
    fetchData(isNowPage = true) {
      console.log('fetchData')
      this.listLoading = true
      if (!isNowPage) {
        this.listQuery.offset = 1
      }
      getCarInfoList(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)
          getCarInfoList(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>
  $tableTitleHeight:46px;
  .el-table__header tr,
  .el-table__header th {
    padding: 0;
    height: 40px;
    background-color: #f8f8f8;
  }
  .table{
    margin-bottom: 20px;
  }
  .pagination-container{
    margin-bottom: 100px;
  }
  .edit_btns{
    .edit_btn{
      float:right;
      margin:7px 3px;//为了需要居中显示margin-top和bottom要用$tableTitleHeight减去按钮原高度除以2
    }
  }
  .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;
      }
    }
  }
</style>