selectProjectMembers.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <template>
  2. <el-dialog :visible="visible" :title="title" class="select-members" width="900px" @close="dialogClose">
  3. <div class="query-criteria">
  4. <span class="criteria-label">真实姓名</span>
  5. <el-input v-model="real_name" placeholder="请输入姓名" @change="getUserList" />
  6. <span>所属机构</span>
  7. <el-select v-model="org_id_list" placeholder="请选择机构" multiple @change="getUserList">
  8. <el-option v-for="item in org_list" :key="item.id" :label="item.name" :value="item.id" />
  9. </el-select>
  10. <span class="query-button">
  11. <el-button type="primary" @click="getUserList">查询</el-button>
  12. </span>
  13. </div>
  14. <el-table ref="user" :data="user_list">
  15. <el-table-column type="selection" width="55" align="center" />
  16. <el-table-column prop="real_name" label="真实姓名" width="140" />
  17. <el-table-column prop="user_name" label="用户名" width="140" />
  18. <el-table-column prop="email" label="邮箱" width="200" />
  19. <el-table-column prop="phone" label="电话" width="120" />
  20. <el-table-column prop="org_name" label="所属机构" />
  21. </el-table>
  22. <PaginationPage :total="total" @getList="getUserList" />
  23. <div class="member-container">
  24. <div class="top">
  25. <span class="title">已选成员</span>
  26. <span class="link" @click="addSelectedUsers">添加</span>
  27. </div>
  28. <div class="member-list">
  29. <div class="member-header">
  30. <span class="header-item">序号</span>
  31. <span class="header-item">真实姓名</span>
  32. <span class="header-item">用户名</span>
  33. <span class="header-item">邮箱</span>
  34. <span class="header-item">电话</span>
  35. <span class="header-item">操作</span>
  36. </div>
  37. <div v-for="(user, index) in selectedUsers" :key="user.id" class="member-row">
  38. <span class="item">{{ index + 1 }}</span>
  39. <span class="item">{{ user.real_name }}</span>
  40. <span class="item">{{ user.user_name }}</span>
  41. <span class="item">{{ user.email }}</span>
  42. <span class="item">{{ user.phone }}</span>
  43. <span class="item button">
  44. <el-button type="text" @click="removeUser(index)">删除</el-button>
  45. </span>
  46. </div>
  47. </div>
  48. </div>
  49. <div slot="footer">
  50. <el-button @click="dialogClose">取消</el-button>
  51. <el-button type="primary" @click="confirm">确定</el-button>
  52. </div>
  53. </el-dialog>
  54. </template>
  55. <script>
  56. import { queryUserList } from '@/api/list';
  57. import { orgIndexList } from '@/api/user';
  58. import PaginationPage from '@/components/PaginationPage.vue';
  59. export default {
  60. name: 'SelectProjectMembers',
  61. components: {
  62. PaginationPage,
  63. },
  64. props: {
  65. visible: {
  66. type: Boolean,
  67. required: true,
  68. },
  69. title: {
  70. type: String,
  71. default: '选择项目成员',
  72. },
  73. },
  74. data() {
  75. return {
  76. real_name: '', // 真实姓名
  77. org_list: [], // 机构列表
  78. org_id_list: [], // 机构id列表
  79. user_list: [], // 用户列表
  80. total: 0,
  81. page_capacity: 10,
  82. cur_page: 1,
  83. selectedUsers: [], // 选中的用户
  84. };
  85. },
  86. created() {
  87. this.getOrgIndexList();
  88. this.getUserList();
  89. },
  90. methods: {
  91. getUserList(data) {
  92. const params = {
  93. real_name: this.real_name,
  94. org_id_list: this.org_id_list,
  95. page_capacity: this.page_capacity,
  96. cur_page: this.cur_page,
  97. };
  98. queryUserList({ ...params, ...data }).then(({ user_list, total_count, cur_page }) => {
  99. this.user_list = user_list;
  100. this.total = total_count;
  101. this.page_capacity = data?.page_capacity || this.page_capacity;
  102. this.cur_page = cur_page;
  103. });
  104. },
  105. getOrgIndexList() {
  106. orgIndexList().then(({ org_list }) => {
  107. this.org_list = org_list;
  108. });
  109. },
  110. // 添加选中的用户
  111. addSelectedUsers() {
  112. // 获取选中的用户
  113. const selected = this.$refs.user.selection;
  114. if (selected.length === 0) {
  115. this.$message.warning('请至少选择一名成员');
  116. return;
  117. }
  118. // 通过 id 去重
  119. const uniqueSelectedUsers = selected.filter(({ id }) => {
  120. return this.selectedUsers.findIndex((user) => user.id === id) === -1;
  121. });
  122. // 合并选中的用户
  123. this.selectedUsers = [...this.selectedUsers, ...uniqueSelectedUsers];
  124. // 清空选中的用户
  125. this.$refs.user.clearSelection();
  126. },
  127. // 删除用户
  128. removeUser(index) {
  129. this.selectedUsers.splice(index, 1);
  130. },
  131. dialogClose() {
  132. this.$emit('update:visible', false);
  133. this.real_name = '';
  134. this.org_id_list = [];
  135. this.selectedUsers = [];
  136. this.$refs.user.clearSelection();
  137. },
  138. confirm() {
  139. this.$emit('confirm', this.selectedUsers);
  140. this.dialogClose();
  141. },
  142. },
  143. };
  144. </script>
  145. <style lang="scss" scoped>
  146. .select-members {
  147. .query-criteria {
  148. display: flex;
  149. column-gap: 8px;
  150. align-items: center;
  151. margin-bottom: 12px;
  152. .criteria-label {
  153. white-space: nowrap;
  154. }
  155. .el-input {
  156. width: 200px;
  157. }
  158. .el-select {
  159. width: 360px;
  160. }
  161. :deep .el-input__inner {
  162. background-color: #fff;
  163. border-color: #dcdcdc;
  164. }
  165. .query-button {
  166. display: flex;
  167. flex: 1;
  168. justify-content: flex-end;
  169. }
  170. }
  171. .member-container {
  172. padding: 8px 0;
  173. margin-top: 12px;
  174. border-top: 1px solid #dcdcdc;
  175. .top {
  176. display: flex;
  177. align-items: center;
  178. justify-content: space-between;
  179. padding: 0 12px;
  180. }
  181. .member-list {
  182. margin-top: 10px;
  183. .member-header {
  184. display: flex;
  185. font-size: 15px;
  186. font-weight: bold;
  187. text-align: center;
  188. background-color: $main-background-color;
  189. border: $border;
  190. .header-item {
  191. padding: 8px 12px;
  192. &:first-child {
  193. width: 55px;
  194. }
  195. &:nth-child(2) {
  196. width: 140px;
  197. }
  198. &:nth-child(3) {
  199. width: 140px;
  200. }
  201. &:nth-child(4) {
  202. width: 200px;
  203. }
  204. &:nth-child(5) {
  205. width: 200px;
  206. }
  207. &:last-child {
  208. flex: 1;
  209. }
  210. }
  211. }
  212. .member-row {
  213. display: flex;
  214. align-items: center;
  215. text-align: center;
  216. .item {
  217. height: 40px;
  218. padding: 8px 12px;
  219. border-bottom: 1px solid #dcdcdc;
  220. &:first-child {
  221. width: 55px;
  222. }
  223. &:nth-child(2) {
  224. width: 140px;
  225. }
  226. &:nth-child(3) {
  227. width: 140px;
  228. }
  229. &:nth-child(4) {
  230. width: 200px;
  231. }
  232. &:nth-child(5) {
  233. width: 200px;
  234. }
  235. &:last-child {
  236. flex: 1;
  237. }
  238. &.button {
  239. display: flex;
  240. align-items: center;
  241. justify-content: center;
  242. }
  243. }
  244. }
  245. }
  246. }
  247. }
  248. </style>