<template> <el-dialog :visible.sync="dialogFormVisible" title="添加告警通知接收人" width="700px" append-to-body> <div class="search-div"> <el-form ref="selectForm" :inline="true" :model="listQuery" size="small" class="form-container"> <el-row> <el-form-item class="selectForm-container-item"> <el-input v-model.trim="listQuery.keywords" placeholder="姓名/手机号" clearable/> </el-form-item> <el-form-item class="selectForm-container-item"> <dept-select v-model="listQuery.deptid" :need-top="false" dept-type="03" placeholder="选择部门"/> </el-form-item> <el-button class="filter-item" type="primary" icon="el-icon-search" size="small" @click="fetchData">搜索</el-button> </el-row> </el-form> </div> <!-- 查询结果 --> <div class="tablediv"> <!--<el-row class="table-title">--> <!--<el-col :span="6"><div class="title-header"><i class="el-icon-menu"/>搜索结果({{ list.length }})</div></el-col>--> <!--</el-row>--> <el-table v-loading="loading" :data="list" size="small" max-height="300" class="table" border @selection-change="handleSelectionChange"> <el-table-column align="center" type="selection" width="55"/> <el-table-column :index="indexMethod" label="#" 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 :class="column.class">{{ scope.row[column.value] }}</span> </template> </el-table-column> </el-table> </div> <!--分页--> <div class="pagination-container"> <el-pagination :current-page="listQuery.offset" :total="total" :page-sizes="[5,10]" :page-size="listQuery.limit" align="center" layout="total, prev, pager, next" background small @size-change="handleSizeChange" @current-change="handleCurrentChange"/> </div> <div slot="footer" class="dialog-footer"> <el-button :loading="btnLoading" type="primary" @click="saveData">保存</el-button> <el-button @click="cancel">取消</el-button> </div> </el-dialog> </template> <script> import { getUserList } from '@/api/user' import { addUsersToGroup } from '@/api/group' import DeptSelect from '@/components/DeptSelect' export default { name: 'AddUser', components: { DeptSelect }, data() { return { dialogFormVisible: false, // 对话框是否显示 multipleSelection: [], groupId: '', listQuery: { keywords: '', beginTime: '', endTime: '', deptid: '', offset: 1, limit: 10, sort: 'id' }, form: { // 表单 deptid: '', user: '' }, columns: [ { text: '真实姓名', value: 'name' }, { text: '手机号', value: 'phone' }, { text: '部门', value: 'deptName' } ], list: [], // 用户列表数据 total: 0, loading: false, // 加载动态效果 btnLoading: false } }, computed: { titleText: function() { return this.roleName + '' } }, methods: { // 初始化对话框 initDialog: function(groupId) { this.loading = true this.groupId = groupId this.dialogFormVisible = true this.btnLoading = false this.fetchData() }, fetchData() { this.listLoading = true getUserList(this.listQuery).then(response => { this.list = response.data.rows this.total = response.data.total this.loading = false }) }, saveData() { // 获取选择的用户列表 if (this.checkSelection()) { const list = [] this.multipleSelection.forEach(function(value, index) { list.push(value.id) }) const params = { id: this.groupId, userIds: list } this.btnLoading = true addUsersToGroup(params).then(response => { if (response.code === 200) { this.$message.success('添加成功') this.cancel() } this.btnLoading = false }).catch(() => { this.btnLoading = false }) } else { this.$message.error('至少选中一项') } }, // 检查多选情况,未选择返回false,已有选择返回true checkSelection() { if (this.multipleSelection.length === 0) { return false } else { return true } }, indexMethod(index) { return this.listQuery.limit * (this.listQuery.offset - 1) + index + 1 }, // 多选触发方法 handleSelectionChange(val) { this.multipleSelection = val }, // 改变页容量 handleSizeChange(val) { this.listQuery.limit = val this.fetchData() }, // 改变当前页 handleCurrentChange(val) { this.listQuery.offset = val this.fetchData() }, // 取消 cancel: function() { this.dialogFormVisible = false this.$emit('watchChild') } } } </script> <style rel="stylesheet/scss" lang="scss" scoped> .el-dialog{ min-width:350px !important; } .scrollbar{ max-height: 400px; } .el-tree{ } .el-select{ width: 100%; overflow-x: hidden; .el-scrollbar__wrap{ overflow-x: hidden; } } .list{ max-height:300px; } .pagination-container{ margin-top: 10px; } .dialog-footer { margin-top: -40px; text-align: right; } </style>