<template> <div> <!--查询结果Table显示--> <div> <el-table v-loading="listLoading" :data="list" class="table" size="mini" 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>{{ scope.row[column.value] }}</span> </template> </el-table-column> <el-table-column label="操作" align="center"> <template slot-scope="scope"> <el-button type="text" @click="del(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="[5,10]" :page-size="listQuery.limit" :total="total" align="center" layout="total, sizes, prev, pager, next" @size-change="handleSizeChange" @current-change="handleCurrentChange"/> </div> </div> </template> <script> import { getGroupUsers, delUserFromGroup } from '@/api/group' export default { name: 'GroupListUser', props: { id: { type: String, required: true }// 小组id }, data() { return { listQuery: { offset: 1, limit: 10, sort: '', order: '' }, // 筛选条件 columns: [ { text: '姓名', value: 'name', align: 'center' }, { text: '联系电话', value: 'phone', align: 'center' }, { text: '部门', value: 'deptname', align: 'center' } ], // 显示列 multipleSelection: [], // 多选选中项 list: [], // 列表数据 total: 0, // 数据总数 listLoading: true, // 加载动画 fullscreenLoading: false // 全屏加载动画 } }, created() { this.fetchData() }, methods: { // 获取组列表 fetchData(isNowPage = true) { this.listLoading = true if (!isNowPage) { // 是否显示当前页,否则跳转第一页 this.listQuery.offset = 1 } const listQuery = { id: this.id, ...this.listQuery } getGroupUsers(listQuery).then(response => { if (response.code === 200) { // response.data.rows = [ // { id: '1', name: '张三', phone: '19828192812', deptname: '执勤部' }, // { id: '1', name: '张三', phone: '19828192812', deptname: '执勤部' }, // { id: '1', name: '张三', phone: '19828192812', deptname: '执勤部' }, // { id: '1', name: '张三', phone: '19828192812', deptname: '执勤部' }, // { id: '1', name: '张三', phone: '19828192812', deptname: '执勤部' } // ] if (response.data.rows.length === 0 && this.listQuery.offset > 1) { this.listQuery.offset -= 1 this.listQuery.offset -= 1 this.fetchData() } else { this.list = response.data.rows this.total = parseInt(response.data.total) this.listLoading = false } } }) }, // 删除井 del(row) { this.$confirm( '确定要从该组中移除该通知人吗?', '确认操作', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' } ).then(() => { const params = { id: this.id, userId: row.id } delUserFromGroup(params).then(response => { if (response.code === 200) { this.$message.success('移除成功') this.fetchData() } }) }) }, 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 scoped> .table{ margin-bottom: 20px; } .pagination-container{ margin-bottom: 10px; } </style>