Newer
Older
baseResourceFront / src / views / deviceManage / busLampbox.vue
yangqianqian on 6 Apr 2021 9 KB 按照新UI进行修改
<!--灯箱列表-->
<template>
  <app-container>
    <search-area :need-clear="true" :need-search-more="false" type="seperate" size="small" search-more-type="default" @search="fetchData" @clear="clearInput">
      <!--一般查询条件-->
      <search-item>
        <el-input v-model.trim="listQuery.boxName" size="small" placeholder="灯箱名称" clearable />
      </search-item>
      <search-item>
        <el-select v-model="listQuery.streetId" size="small" placeholder="所在道路" filterable clearable>
          <el-option v-for="item in streetList" :key="item.id" :label="item.streetName" :value="item.id"/>
        </el-select>
      </search-item>
    </search-area>
    <normal-table
      :data="list"
      :head="tableOption.head"
      :query="listQuery"
      :total="total"
      :list-loading="listLoading"
      :options="tableOption.options"
      :tools-option="tableOption.toolsOption"
      size="small"
      @selectionChange="handleSelectionChange"
      @change="changePage">
      <template slot="btns">
        <el-button size="small" class="edit_btn" @click="batchExport">导出</el-button>
        <el-button size="small" class="edit_btn" @click="add">新增</el-button>
        <el-button size="small" class="edit_btn" @click="del">删除</el-button>
      </template>
      <template slot="columns">
        <!--内容列-->
        <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">
            <div v-if="column.value === 'u'">
              <span v-html="allNum(scope.row.ua,scope.row.ub,scope.row.uc)"/>
            </div>
            <div v-else-if="column.value === 'i'">
              <span v-html="allNum(scope.row.ia,scope.row.ib,scope.row.ic)"/>
            </div>
            <div v-else>
              <span :class="column.class">{{ scope.row[column.value] }}</span>
            </div>
          </template>
        </el-table-column>
      </template>
      <template slot="columns">
        <el-table-column label="操作" align="center" width="160">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="detail(scope.row)">详情</el-button>
            <el-button type="text" size="small" @click.stop="edit(scope.row)">编辑</el-button>
          </template>
        </el-table-column>
      </template>
    </normal-table>
    <edit-Lampbox ref="editLampbox" @watchChild="fetchData"/>
  </app-container>
</template>

<script>
import DeptSelect from '@/components/DeptSelect'
import EditLampbox from '@/views/deviceManage/editLampbox'
import { getLampboxList, batchDelLampbox, batchExportLampbox } from '@/api/system/device'
import { getAllStreet } from '@/api/system/area'

export default {
  name: 'BusLampbox',
  components: { EditLampbox, DeptSelect },
  data() {
    return {
      listQuery: {
        boxName: '',
        streetId: '',
        offset: 1,
        limit: 20,
        sort: '',
        order: ''
      }, // 筛选条件
      columns: [
        {
          text: '灯箱编号',
          value: 'lampboxCode',
          align: 'center',
          width: 140
        },
        {
          text: '灯箱名称',
          value: 'lampboxName',
          align: 'center'
        },
        {
          text: '电信设备编号',
          value: 'teleId',
          align: 'center'
        },
        {
          text: '所在道路',
          value: 'streetName',
          align: 'center'
        },
        {
          text: '地址',
          value: 'address',
          align: 'center'
        },
        {
          text: '电压(V)',
          value: 'u',
          align: 'center'
        },
        {
          text: '电流(A)',
          value: 'i',
          align: 'center'
        }
      ], // 显示列
      list: [], // 列表数据
      total: 0, // 数据总数
      streetList: [], // 道路列表
      multipleSelection: [], // 多选选中项
      listLoading: false, // 加载动画
      fullscreenLoading: false, // 全屏加载动画
      dialogFormVisible: false,
      tableOption: {
        head: {
          show: true, // 是否需要标题栏,
          text: '数据列表' // 标题名称
        },
        options: {
          needIndex: true, // 是否需要序号列
          needMultSelect: true
        },
        toolsOption: {
          selectColumns: false, // 是否需要筛选列
          refresh: false // 是否需要刷新按钮
        }
      } // 表格属性
    }
  },
  created() {
    this.fetchStreetList() // 获取道路列表
    this.fetchData()// 获取数据
  },
  methods: {
    allNum(num1, num2, num3) {
      return num1 + '/' + num2 + '/' + num3
    },
    batchExport() {
      // 全屏加载动画
      const loading = this.$loading({
        lock: true,
        text: '下载中,请稍后...',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      })
      batchExportLampbox(this.listQuery).then(res => {
        loading.close() // 关闭加载动画
        console.log('download===', res)
        const blob = new Blob([res.data])
        const downloadElement = document.createElement('a')
        const href = window.URL.createObjectURL(blob) // 创建下载的链接
        downloadElement.href = href
        downloadElement.download = `灯箱列表.xlsx` // 下载后文件名
        document.body.appendChild(downloadElement)
        downloadElement.click() // 点击下载
        document.body.removeChild(downloadElement) // 下载完成移除元素
        window.URL.revokeObjectURL(href) // 释放blob对象
      }).catch((res) => {
        loading.close()
        this.$message.error(res.message)
      })
    },
    // 检查选择情况
    checkSelection() {
      if (this.multipleSelection.length === 0) {
        return false
      } else {
        return true
      }
    },
    // 重置
    clearInput() {
      this.listQuery = {
        boxName: '',
        streetId: '',
        offset: 1,
        limit: 20,
        sort: '',
        order: ''
      }
      this.fetchData(false)
    },
    // 新增设备
    add() {
      this.dialogFormVisible = true
      this.$refs.editLampbox.initDialog('create', this.dialogFormVisible)
    },
    // 编辑设备信息
    edit(row) {
      this.dialogFormVisible = true
      this.$refs.editLampbox.initDialog('update', this.dialogFormVisible, row)
    },
    // 查看设备信息
    detail(row) {
      this.dialogFormVisible = true
      this.$refs.editLampbox.initDialog('detail', this.dialogFormVisible, row)
    },
    // 删除设备
    del() {
      if (this.checkSelection()) {
        const devIds = []
        this.multipleSelection.forEach(function(value, index) {
          devIds.push(value.id)
        })
        this.$confirm(
          '确定要删除所选灯箱吗?',
          '确认操作',
          {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }
        ).then(() => {
          batchDelLampbox(devIds).then(response => {
            if (response.code === 200) {
              this.$message.success('删除成功')
              this.fetchData()
            }
          })
        })
      } else {
        this.$message.error('至少选中一项')
      }
    },
    // 查询数据
    search() {
      this.fetchData(false)
    },
    // 获取设备列表
    fetchData(isNowPage = true) {
      this.listLoading = true
      if (!isNowPage) { // 是否显示当前页,否则跳转第一页
        this.listQuery.offset = 1
      }
      getLampboxList(this.listQuery).then(response => {
        if (response.code === 200) {
          this.list = response.data.rows
          this.total = parseInt(response.data.total)
        } else {
          this.$message.error(response.message)
        }
        this.listLoading = false
      })
    },
    fetchStreetList() {
      getAllStreet().then(response => {
        if (response.code === 200) {
          this.streetList = response.data
        }
      })
    },
    indexMethod(index) {
      return this.listQuery.limit * (this.listQuery.offset - 1) + index + 1
    },
    // 改变页容量
    handleSizeChange(val) {
      this.listQuery.limit = val
      this.fetchData()
    },
    changePage(val) {
      if (val && val.size) {
        this.listQuery.limit = val.size
      }
      if (val && val.page) {
        this.listQuery.offset = val.page
      }
      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;
  .app-container{
    margin-bottom:20px
  }
  .table{
    margin-bottom: 20px;
  }
  .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>