selectUser.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <!-- 授权用户 -->
  3. <el-dialog title="选择用户" :visible.sync="visible" width="800px" top="5vh" append-to-body>
  4. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
  5. <el-form-item label="用户名称" prop="userName">
  6. <el-input
  7. v-model="queryParams.userName"
  8. placeholder="请输入用户名称"
  9. clearable
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item label="手机号码" prop="phonenumber">
  14. <el-input
  15. v-model="queryParams.phonenumber"
  16. placeholder="请输入手机号码"
  17. clearable
  18. @keyup.enter.native="handleQuery"
  19. />
  20. </el-form-item>
  21. <el-form-item>
  22. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  23. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  24. </el-form-item>
  25. </el-form>
  26. <el-row>
  27. <el-table @row-click="clickRow" ref="table" :data="userList" @selection-change="handleSelectionChange" height="260px">
  28. <el-table-column type="selection" width="55"></el-table-column>
  29. <el-table-column label="用户名称" prop="userName" :show-overflow-tooltip="true" />
  30. <el-table-column label="用户昵称" prop="nickName" :show-overflow-tooltip="true" />
  31. <el-table-column label="邮箱" prop="email" :show-overflow-tooltip="true" />
  32. <el-table-column label="手机" prop="phonenumber" :show-overflow-tooltip="true" />
  33. <el-table-column label="状态" align="center" prop="status">
  34. <template slot-scope="scope">
  35. <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status"/>
  36. </template>
  37. </el-table-column>
  38. <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  39. <template slot-scope="scope">
  40. <span>{{ parseTime(scope.row.createTime) }}</span>
  41. </template>
  42. </el-table-column>
  43. </el-table>
  44. <pagination
  45. v-show="total>0"
  46. :total="total"
  47. :page.sync="queryParams.pageNum"
  48. :limit.sync="queryParams.pageSize"
  49. @pagination="getList"
  50. />
  51. </el-row>
  52. <div slot="footer" class="dialog-footer">
  53. <el-button type="primary" @click="handleSelectUser">确 定</el-button>
  54. <el-button @click="visible = false">取 消</el-button>
  55. </div>
  56. </el-dialog>
  57. </template>
  58. <script>
  59. import { unallocatedUserList, authUserSelectAll } from "@/api/system/role";
  60. export default {
  61. dicts: ['sys_normal_disable'],
  62. props: {
  63. // 角色编号
  64. roleId: {
  65. type: [Number, String]
  66. }
  67. },
  68. data() {
  69. return {
  70. // 遮罩层
  71. visible: false,
  72. // 选中数组值
  73. userIds: [],
  74. // 总条数
  75. total: 0,
  76. // 未授权用户数据
  77. userList: [],
  78. // 查询参数
  79. queryParams: {
  80. pageNum: 1,
  81. pageSize: 10,
  82. roleId: undefined,
  83. userName: undefined,
  84. phonenumber: undefined
  85. }
  86. };
  87. },
  88. methods: {
  89. // 显示弹框
  90. show() {
  91. this.queryParams.roleId = this.roleId;
  92. this.getList();
  93. this.visible = true;
  94. },
  95. clickRow(row) {
  96. this.$refs.table.toggleRowSelection(row);
  97. },
  98. // 多选框选中数据
  99. handleSelectionChange(selection) {
  100. this.userIds = selection.map(item => item.userId);
  101. },
  102. // 查询表数据
  103. getList() {
  104. unallocatedUserList(this.queryParams).then(res => {
  105. this.userList = res.rows;
  106. this.total = res.total;
  107. });
  108. },
  109. /** 搜索按钮操作 */
  110. handleQuery() {
  111. this.queryParams.pageNum = 1;
  112. this.getList();
  113. },
  114. /** 重置按钮操作 */
  115. resetQuery() {
  116. this.resetForm("queryForm");
  117. this.handleQuery();
  118. },
  119. /** 选择授权用户操作 */
  120. handleSelectUser() {
  121. const roleId = this.queryParams.roleId;
  122. const userIds = this.userIds.join(",");
  123. if (userIds == "") {
  124. this.$modal.msgError("请选择要分配的用户");
  125. return;
  126. }
  127. authUserSelectAll({ roleId: roleId, userIds: userIds }).then(res => {
  128. this.$modal.msgSuccess(res.msg);
  129. if (res.code === 200) {
  130. this.visible = false;
  131. this.$emit("ok");
  132. }
  133. });
  134. }
  135. }
  136. };
  137. </script>