UserList.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px"
  4. @submit.prevent="handleQuery">
  5. <el-form-item label="用户昵称" prop="nickName">
  6. <el-input v-model="queryParams.nickName" placeholder="请输入用户昵称" clearable size="small"
  7. @keydown.enter.native="handleQueryEnter" />
  8. </el-form-item>
  9. <el-form-item>
  10. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  11. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">刷新/重置</el-button>
  12. </el-form-item>
  13. </el-form>
  14. <el-table v-loading="loading" :data="userList" ref="userList" @selection-change="handleSelectionChange">
  15. <el-table-column type="selection" width="55" align="center"/>
  16. <el-table-column label="用户id" align="center" prop="userId"/>
  17. <!-- <el-table-column label="用户账户" align="center" prop="username"/> -->
  18. <el-table-column label="用户昵称" align="center" prop="nickName"/>
  19. </el-table>
  20. <div style="margin-top: 30px;display: flex;justify-content: center">
  21. <el-button type="warning" icon="el-icon-search" @click="confirmSelect">确定选择</el-button>
  22. </div>
  23. <pagination v-show="total > 0" :total="total" :page.sync="queryParams.startIndex" :limit.sync="queryParams.pageLimit"
  24. @pagination="handlePaginationChange" />
  25. </div>
  26. </template>
  27. <script>
  28. import { listUser } from "@/api/app/user/userList";
  29. export default {
  30. name: "userList",
  31. data() {
  32. return {
  33. type: null,
  34. sendType: null,
  35. // 遮罩层
  36. loading: true,
  37. // 导出遮罩层
  38. exportLoading: false,
  39. // 选中数组
  40. selectUsers: [],
  41. // 非单个禁用
  42. single: true,
  43. // 非多个禁用
  44. multiple: true,
  45. // 显示搜索条件
  46. showSearch: true,
  47. // 总条数
  48. total: 0,
  49. // 企微用户表格数据
  50. userList: [],
  51. // 弹出层标题
  52. title: "",
  53. // 是否显示弹出层
  54. open: false,
  55. // 查询参数
  56. queryParams: {
  57. startIndex: 1,
  58. pageLimit: 5,
  59. nickName: null
  60. },
  61. // 表单校验
  62. rules: {
  63. }
  64. };
  65. },
  66. created() {
  67. this.getList();
  68. },
  69. methods: {
  70. /** 查询用户列表 */
  71. getList() {
  72. this.loading = true;
  73. listUser(this.queryParams).then(response => {
  74. // 如果 companyUserId 为 null,移除列
  75. this.userList = response.rows;
  76. this.total = response.total;
  77. this.loading = false;
  78. });
  79. },
  80. handlePaginationChange(row) {
  81. this.queryParams.startIndex = row.page;
  82. this.queryParams.pageLimit = row.limit;
  83. this.getList();
  84. },
  85. // 取消按钮
  86. cancel() {
  87. this.open = false;
  88. this.reset();
  89. },
  90. // 表单重置
  91. reset() {
  92. this.queryParams = {
  93. startIndex: 1,
  94. pageLimit: 5,
  95. nickName: null,
  96. }
  97. this.resetForm("form");
  98. },
  99. //确定选择
  100. confirmSelect() {
  101. this.$emit("selectUserList", this.selectUsers);
  102. this.resetSelect();
  103. },
  104. //重置选择
  105. resetSelect() {
  106. this.$refs.userList.clearSelection();
  107. this.selectUsers = [];
  108. this.reset();
  109. this.getList();
  110. },
  111. /** 搜索按钮操作 */
  112. handleQuery() {
  113. this.queryParams.startIndex = 1;
  114. this.getList();
  115. },
  116. handleQueryEnter(event) {
  117. // 确保事件对象存在
  118. if (event && event.preventDefault) {
  119. event.preventDefault(); // 阻止默认提交行为
  120. }
  121. this.handleQuery();
  122. },
  123. /** 重置按钮操作 */
  124. resetQuery() {
  125. this.resetForm("queryForm");
  126. this.handleQuery();
  127. },
  128. // 多选框选中数据
  129. handleSelectionChange(selection) {
  130. // 保存当前页的选中项
  131. const currentPageSelections = selection.map(item => item.userId);
  132. // 合并选中项
  133. this.selectUsers = this.selectUsers.filter(item =>
  134. this.userList.some(tag => tag.userId === item.id) ? currentPageSelections.includes(item.userId) : true
  135. ).concat(selection.filter(item => !this.selectUsers.some(selected => selected.userId === item.userId)));
  136. // 更新 single 和 multiple
  137. this.single = this.selectUsers.length !== 1;
  138. this.multiple = !this.selectUsers.length;
  139. },
  140. }
  141. };
  142. </script>