selectPersonDialog.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <template>
  2. <el-dialog
  3. title="选择考试人员"
  4. :visible.sync="visible"
  5. width="900px"
  6. :close-on-click-modal="false"
  7. append-to-body
  8. @closed="handleClose"
  9. >
  10. <!-- 搜索区域 -->
  11. <div class="search-area">
  12. <el-form :inline="true" size="small" @submit.native.prevent>
  13. <el-form-item label="姓名:">
  14. <el-input
  15. v-model="where.name"
  16. placeholder="支持模糊查询"
  17. clearable
  18. style="width: 180px"
  19. @keyup.enter.native="handleSearch"
  20. />
  21. </el-form-item>
  22. <el-form-item label="所属部门:">
  23. <dept-select
  24. v-model="where.groupId"
  25. placeholder="请选择所属部门"
  26. style="width: 220px"
  27. @changeGroup="handleDeptChange"
  28. />
  29. </el-form-item>
  30. <el-form-item>
  31. <el-button type="primary" icon="el-icon-search" @click="handleSearch"
  32. >查询</el-button
  33. >
  34. <el-button icon="el-icon-refresh-left" @click="handleReset"
  35. >重置</el-button
  36. >
  37. </el-form-item>
  38. </el-form>
  39. </div>
  40. <!-- 列表 -->
  41. <ele-pro-table
  42. ref="table"
  43. row-key="id"
  44. :columns="columns"
  45. :datasource="datasource"
  46. :cache-key="cacheKeyUrl"
  47. height="400px"
  48. @selection-change="handleSelectionChange"
  49. >
  50. </ele-pro-table>
  51. <template slot="footer">
  52. <el-button @click="visible = false">取消</el-button>
  53. <el-button
  54. type="primary"
  55. :disabled="!selectedRows.length"
  56. @click="handleConfirm"
  57. >确定</el-button
  58. >
  59. </template>
  60. </el-dialog>
  61. </template>
  62. <script>
  63. import DeptSelect from '@/components/CommomSelect/dept-select.vue';
  64. import { getUserPage } from '@/api/system/organization';
  65. export default {
  66. components: { DeptSelect },
  67. data() {
  68. return {
  69. visible: false,
  70. cacheKeyUrl: 'ehs-examSelectPerson-list',
  71. selectedRows: [],
  72. excludeIds: [],
  73. where: {
  74. name: '',
  75. groupId: ''
  76. },
  77. columns: [
  78. {
  79. type: 'selection',
  80. width: 55,
  81. align: 'center',
  82. selectable: (row) => !this.isExcluded(row.id)
  83. },
  84. {
  85. columnKey: 'index',
  86. label: '序号',
  87. type: 'index',
  88. width: 60,
  89. align: 'center'
  90. },
  91. {
  92. prop: 'name',
  93. label: '姓名',
  94. align: 'center',
  95. minWidth: 120
  96. },
  97. {
  98. prop: 'groupName',
  99. label: '所属部门',
  100. align: 'center',
  101. minWidth: 180,
  102. showOverflowTooltip: true
  103. },
  104. {
  105. prop: 'jobNumber',
  106. label: '工号',
  107. align: 'center',
  108. minWidth: 120
  109. },
  110. {
  111. prop: 'phone',
  112. label: '联系方式',
  113. align: 'center',
  114. minWidth: 130
  115. }
  116. ]
  117. };
  118. },
  119. methods: {
  120. open(excludeIds = []) {
  121. this.visible = true;
  122. this.selectedRows = [];
  123. this.excludeIds = Array.isArray(excludeIds) ? excludeIds : [];
  124. this.$nextTick(() => {
  125. this.$refs.table && this.$refs.table.reload({ page: 1 });
  126. });
  127. },
  128. handleDeptChange(id, node) {
  129. this.where.groupId = node ? id : '';
  130. },
  131. isExcluded(id) {
  132. if (id === undefined || id === null || id === '') return false;
  133. const target = String(id);
  134. return (this.excludeIds || []).some((item) => String(item) === target);
  135. },
  136. handleSelectionChange(rows) {
  137. this.selectedRows = rows;
  138. },
  139. handleSearch() {
  140. const where = { ...this.where };
  141. // 清空选择时,把 groupId 置空防止传 undefined
  142. if (!where.groupId) delete where.groupId;
  143. this.$refs.table.reload({ page: 1, where });
  144. },
  145. handleReset() {
  146. this.where = {
  147. name: '',
  148. groupId: ''
  149. };
  150. this.handleSearch();
  151. },
  152. handleClose() {
  153. this.selectedRows = [];
  154. this.where = {
  155. name: '',
  156. groupId: ''
  157. };
  158. },
  159. async datasource({ page, limit, where }) {
  160. const body = {
  161. ...where,
  162. pageNum: page,
  163. size: limit
  164. };
  165. // 兜底清理空值
  166. Object.keys(body).forEach((key) => {
  167. if (body[key] === '' || body[key] === null || body[key] === undefined) {
  168. delete body[key];
  169. }
  170. });
  171. return getUserPage(body);
  172. },
  173. handleConfirm() {
  174. if (!this.selectedRows.length) {
  175. this.$message.warning('请至少选择一名考试人员');
  176. return;
  177. }
  178. const persons = this.selectedRows.map((row) => ({
  179. userId: row.id,
  180. userName: row.name || '',
  181. departmentId: row.groupId || row.deptId || '',
  182. departmentName: row.groupName || row.deptName || '',
  183. // 兼容 publish 表单里既有字段
  184. id: row.id,
  185. deptId: row.groupId || row.deptId || '',
  186. deptName: row.groupName || row.deptName || ''
  187. }));
  188. this.visible = false;
  189. this.$emit('confirm', persons);
  190. }
  191. }
  192. };
  193. </script>
  194. <style lang="scss" scoped>
  195. .search-area {
  196. margin-bottom: 15px;
  197. padding-bottom: 15px;
  198. border-bottom: 1px solid #ebeef5;
  199. }
  200. </style>