selectUser.vue 4.5 KB

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