<template>
<div class="app-container">
<!--查询结果Table显示-->
<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="open_btns"/>
</el-row>
<el-table v-loading="listLoading" :data="list" class="table" border @selection-change="handleSelectionChange">
<el-table-column :index="indexMethod" align="center" type="index" />
<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 v-if="column.type!='Button'" :class="column.class">{{ scope.row[column.value] }}</span>
<el-button v-if="column.type=='Button'" type="text" @click="showWellDetail(scope.row)">{{ scope.row[column.value] }}</el-button>
</template>
</el-table-column>
<el-table-column label="操作" align="center" width="220">
<template slot-scope="scope">
<el-button v-if="hasPerm('/door/control')" type="text" @click="open(scope.row)">远程开门</el-button>
<el-button v-if="hasPerm('/door/control')" type="text" @click="control(scope.row)">常开/闭设置</el-button>
</template>
</el-table-column>
</el-table>
</div>
<!--分页-->
<div class="pagination-container">
<el-pagination
v-show="total>listQuery.limit"
:current-page="listQuery.offset"
:page-sizes="[20,30,50]"
:page-size="listQuery.limit"
:total="total"
align="center"
layout="total, sizes, prev, pager, next"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"/>
</div>
<control-door ref="controldoor" @watchChild="fetchData"/>
</div>
</template>
<script>
import controlDoor from '@/views/doorManage/controlDoor'
import { getDoorListPage, openDoor } from '@/api/door'
export default {
name: 'ListDoor',
components: { controlDoor },
data() {
return {
listQuery: {
offset: 1,
limit: 20,
sort: 'id',
order: 'asc'
}, // 筛选条件
columns: [
{
text: '门禁编号',
value: 'doorCode',
align: 'center'
},
{
text: '门禁名称',
value: 'doorName',
align: 'center'
},
{
text: '描述',
value: 'description',
align: 'center'
},
{
text: '门禁状态',
value: 'openStatusName',
align: 'center'
},
{
text: '生效日期',
value: 'beginDatetime',
align: 'center'
}
], // 显示列
doorForm: {
doorName: '', // 门禁名称
alwaysOpen: '', // 常开/常闭状态
beginDatetime: '', // 生效时间
endDatetime: '' // 失效时间
},
multipleSelection: [], // 多选选中项
list: [], // 列表数据
total: 0, // 数据总数
listLoading: true // 加载动画
}
},
mounted() {
this.fetchData()// 获取数据
},
methods: {
// 检查选择情况
checkSelection() {
if (this.multipleSelection.length === 0) {
return false
} else {
return true
}
},
// 控制门禁常开常闭
control(row) {
this.dialogFormVisible = true
this.$refs.controldoor.initDialog(row)
},
// 打开门禁
open(row) {
this.$confirm(
'确定打开此门禁吗?',
'确认操作',
{
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}
).then(() => {
openDoor(row.id).then(response => {
if (response.code === 200) {
this.$message.success('开门成功')
}
})
})
},
// 查询数据
search() {
this.fetchData(false)
},
// 获取门禁数据
fetchData(isNowPage = true) {
this.listLoading = true
if (!isNowPage) { // 是否显示当前页,否则跳转第一页
this.listQuery.offset = 1
}
getDoorListPage(this.listQuery).then(response => {
this.list = response.data.rows
this.total = parseInt(response.data.total)
this.listLoading = false
})
},
// 处理关闭
handleClose() {
},
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;
.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;
}
}
}
.open_btns{
.open_btn{
float:right;
margin:7px 3px;//为了需要居中显示margin-top和bottom要用$tableTitleHeight减去按钮原高度除以2
}
}
</style>