<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.keywords" size="small" placeholder="公厕编号/名称" clearable/> </search-item> <search-item> <el-input v-model.trim="listQuery.owner" size="small" placeholder="建设单位" clearable/> </search-item> <search-item> <el-input v-model.trim="listQuery.position" size="small" placeholder="位置" clearable/> </search-item> </search-area> <!--查询结果Table显示--> <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"> <template slot="btns"> <el-button :disabled="total===0" class="edit_btn" size="small" @click="batchExport">导出记录</el-button> <el-button size="small" class="edit_btn" @click="add">添加</el-button> </template> <template slot="columns"> <el-table-column label="操作" align="center" width="160"> <template slot-scope="scope"> <el-button type="text" size="small" @click.stop="goDetail(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-toilet v-show="editShow" ref="edittoilet" @watchChild="fetchData"/> </app-container> </template> <script> import { getToiletList, delToilet } from '@/api/sanitation/toilet' import EditToilet from './components/editToilet' export default { name: 'ListToilet', components: { EditToilet }, data() { return { listQuery: { keywords: '', // 关键字(编号、名称) owner: '', // 建设单位 position: '', // 道路 offset: 1, limit: 20, sort: 'ts', order: 'desc' }, // 筛选条件 timeRange: [], columns: [ { text: '公厕编号', value: 'code', align: 'center' }, { text: '公厕名称', value: 'name', align: 'center' }, { text: '建设单位', value: 'owner', align: 'center' }, { text: '建设时间', value: 'ts', align: 'center' }, { text: '街道', value: 'position', align: 'center' }, { text: '占地面积', value: 'area', align: 'center' }, { text: '责任人', value: 'responsiblePerson', align: 'center' }, { text: '责任人电话', value: 'responsiblePersonTel', align: 'center' } ], // 显示列 list: [], // 列表数据 total: 0, // 数据总数 listLoading: true, // 加载动画 fullscreenLoading: false, // 全屏加载动画 editShow: false, // 是否显示编辑框 tableOption: { head: { show: true, // 是否需要标题栏, text: '数据列表' // 标题名称 }, options: { needIndex: false // 是否需要序号列 }, toolsOption: { selectColumns: false, // 是否需要筛选列 refresh: false // 是否需要刷新按钮 } } // 表格属性 } }, mounted() { this.fetchData(false)// 获取数据 }, methods: { // 查询数据 search() { this.fetchData(false) }, // 获取列表 fetchData(isNowPage = true) { this.listLoading = true if (!isNowPage) { // 是否显示当前页,否则跳转第一页 this.listQuery.offset = 1 } getToiletList(this.listQuery).then(response => { debugger this.list = response.data.rows this.total = parseInt(response.data.total) this.listLoading = false }) }, add() { this.editShow = true this.$refs.edittoilet.initDialog('create', true, null) }, detail(row) { this.editShow = true this.$refs.edittoilet.initDialog('detail', true, row) }, edit(row) { this.editShow = true this.$refs.edittoilet.initDialog('update', true, row) }, // 删除单个公厕 del(row) { const deleteIds = [row.id] this.$confirm( '确定要删除该公厕吗?', '确认操作', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' } ).then(() => { delToilet(deleteIds).then(response => { if (response.code === 200) { this.$message.success('删除成功') this.fetchData() } }) }) }, batchExport() { // 全屏加载动画 // const loading = this.$loading({ // lock: true, // text: '下载中,请稍后...', // spinner: 'el-icon-loading', // background: 'rgba(0, 0, 0, 0.7)' // }) // exportRecords(this.listQuery).then(res => { // loading.close() // 关闭加载动画 // downloadFile(res.data, '识别记录列表') // }).catch((res) => { // loading.close() // }) }, 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; } } } .edit_btns{ .edit_btn{ float:right; margin:7px 3px;//为了需要居中显示margin-top和bottom要用$tableTitleHeight减去按钮原高度除以2 } } .form-container { .selectForm-container-item { width: 220px; } } </style>