<template> <app-container> <search-area :need-clear="true" :need-search-more="false" type="seperate" size="small" search-more-type="default" @search="fetchData(false)" @clear="clearInput"> <!--一般查询条件--> <search-item> <el-input v-model.trim="listQuery.gateCode" size="small" placeholder="门禁编号" @change="fetchData(false)" /> </search-item> <search-item> <el-input v-model.trim="listQuery.groupName" size="small" placeholder="门禁分组名称" @change="fetchData(false)" /> </search-item> <!-- <search-item>--> <!-- <el-select v-model="listQuery.status" size="small" placeholder="设备状态" clearable @change="fetchData(false)">--> <!-- <el-option--> <!-- v-for="item in statusList"--> <!-- :key="item.value"--> <!-- :label="item.name"--> <!-- :value="item.value"/>--> <!-- </el-select>--> <!-- </search-item>--> </search-area> <normal-table :data="list" :head="tableOption.head" :query="listQuery" :total="total" :columns="columns" :list-loading="listLoading" :options="tableOption.options" :tools-option="tableOption.toolsOption" size="small" @change="changePage" @selectionChange="handleSelectionChange" > <template slot="btns"> <el-button size="small" class="edit_btn" icon="el-icon-edit" @click="add()"> 添加 </el-button> <!-- <el-button size="small" class="edit_btn" icon="el-icon-delete" @click="batchDel()">--> <!-- 删除--> <!-- </el-button>--> </template> <template slot="columns"> <el-table-column label="通道控制" align="center" width="160"> <template slot-scope="scope"> <el-button type="text" v-for="item in statusList" :key="item.value" size="small" @click.stop="editStatus(scope.row, item.value)"> {{ item.name }} </el-button> <!-- <el-select v-model="scope.row.status" size="small" placeholder="通道控制" @change="editStatus(scope.row)">--> <!-- <el-option--> <!-- v-for="item in statusList"--> <!-- :key="item.value"--> <!-- :label="item.name"--> <!-- :value="item.value"--> <!-- />--> <!-- </el-select>--> </template> </el-table-column> <el-table-column label="操作" align="center" width="150"> <template slot-scope="scope"> <el-button type="text" size="small" @click.stop="detail(scope.row)"> 详情 </el-button> <el-button type="text" size="small" @click.stop="edit(scope.row)"> 编辑 </el-button> <!-- <el-button type="text" size="small" @click.stop="del(scope.row)">--> <!-- 删除--> <!-- </el-button>--> </template> </el-table-column> </template> </normal-table> <edit-group v-show="dialogFormVisible" ref="editGroup" @watchChild="fetchData" /> </app-container> </template> <script> import NormalTable from '@/components/NormalTable' import AppContainer from '@/components/layout/AppContainer' import SearchArea from '@/components/SearchArea/SearchArea' import SearchItem from '@/components/SearchArea/SearchItem' import { getGroupListPage, delGroup, controlGroup } from '@/api/device' import EditGroup from './editGroup' import { getDictByCode } from '@/api/system/dict' export default { name: 'GroupList', // eslint-disable-next-line vue/no-unused-components components: { SearchItem, SearchArea, AppContainer, NormalTable, EditGroup }, data() { return { listQuery: { groupName: '', gateCode: '', status: '', offset: 1, limit: 20 }, // 筛选条件 statusList: [], columns: [ { text: '门禁分组', value: 'groupName', align: 'center', width: 150 }, { text: '分组描述', value: 'description', align: 'center' }, { text: '门禁编号', value: 'gateCodes', align: 'center' }, { text: '备注', value: 'remarks', align: 'center' } ], // 显示列 dialogFormVisible: false, // 是否显示编辑框 timeRange: [], // 时间范围 multipleSelection: [], // 多选选中项 list: [], // 列表数据 total: 0, // 数据总数 listLoading: true, // 列表加载动画 filename: 'device_template.xlsx', fileList: [], tableOption: { head: { show: true, // 是否需要标题栏, text: '数据列表' // 标题名称 }, options: { needIndex: true // 是否需要序号列 }, toolsOption: { selectColumns: false, // 是否需要筛选列 refresh: false, // 是否需要刷新按钮 needCheckBox: false } } // 表格属性 } }, created() { this.fetchOptions() this.fetchData() }, methods: { fetchOptions() { getDictByCode('groupDeviceStatus').then(response => { if (response.code === 200) { this.statusList = response.data } }) }, fetchData(isNowPage = true) { this.listLoading = true if (!isNowPage) { // 是否显示当前页,否则跳转第一页 this.listQuery.offset = 1 } getGroupListPage(this.listQuery).then(response => { if (response.code === 200) { this.list = response.data.rows this.total = parseInt(response.data.total) this.listLoading = false } }) }, // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写 changePage(val) { if (val && val.size) { this.listQuery.limit = val.size } if (val && val.page) { this.listQuery.offset = val.page } this.fetchData() }, // batchDel() { // const ids = this.multipleSelection.map(item => item.id) // if (ids.length === 0) { // this.$message.warning('请至少选择一行') // return // } // this.$confirm( // '确定要删除所选数据吗?', // '确认操作', // { // confirmButtonText: '确定', // cancelButtonText: '取消', // type: 'warning' // } // ).then(() => { // batchDelDevice(ids).then(response => { // if (response.code === 200) { // this.$message.success('删除成功') // this.fetchData() // } // }) // }) // }, editStatus(row, status) { controlGroup(row.id, status).then(response => { if (response.code === 200) { this.$message.success('通道控制成功') this.fetchData() } }).catch(_ => { // 异常情况,loading置为false // this.$message.success('通道控制失败') }) }, // 打开详情对话框 detail(row) { this.$refs.editGroup.initDialog('detail', row) }, // 编辑区域信息 edit(row) { this.dialogFormVisible = true this.$refs.editGroup.initDialog('update', row) }, // 新增区域 add() { this.dialogFormVisible = true this.$refs.editGroup.initDialog('create') }, del(row) { this.$confirm( '确定要删除该条数据吗?', '确认操作', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' } ).then(() => { delGroup(row.id).then(response => { if (response.code === 200) { this.$message.success('删除成功') this.fetchData() } }) }) }, handleSelectionChange(val) { this.multipleSelection = val }, clearInput() { this.listQuery = { groupName: '', gateCode: '', status: '', offset: 1, limit: 20 } this.fetchData() } } } </script> <style scoped> </style>