multiInstanceUser.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. <template>
  2. <el-dialog v-model="visible" draggable :title="title" :width="width" :height="height" append-to-body :close-on-click-modal="false">
  3. <div v-if="multiInstance === 'add'" class="p-2">
  4. <el-row :gutter="20">
  5. <!-- 部门树 -->
  6. <el-col :lg="4" :xs="24" style="">
  7. <el-card shadow="hover">
  8. <el-input v-model="deptName" placeholder="请输入部门名称" prefix-icon="Search" clearable />
  9. <el-tree
  10. ref="deptTreeRef"
  11. class="mt-2"
  12. node-key="id"
  13. :data="deptOptions"
  14. :props="{ label: 'label', children: 'children' }"
  15. :expand-on-click-node="false"
  16. :filter-node-method="filterNode"
  17. highlight-current
  18. default-expand-all
  19. @node-click="handleNodeClick"
  20. ></el-tree>
  21. </el-card>
  22. </el-col>
  23. <el-col :lg="20" :xs="24">
  24. <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
  25. <div v-show="showSearch" class="search">
  26. <el-form ref="queryFormRef" :model="queryParams" :inline="true">
  27. <el-form-item label="用户名称" prop="userName">
  28. <el-input v-model="queryParams.userName" placeholder="请输入用户名称" clearable @keyup.enter="handleQuery" />
  29. </el-form-item>
  30. <el-form-item label="手机号码" prop="phonenumber">
  31. <el-input v-model="queryParams.phonenumber" placeholder="请输入手机号码" clearable @keyup.enter="handleQuery" />
  32. </el-form-item>
  33. <el-form-item>
  34. <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
  35. <el-button icon="Refresh" @click="resetQuery">重置</el-button>
  36. </el-form-item>
  37. </el-form>
  38. </div>
  39. </transition>
  40. <el-card shadow="hover">
  41. <template #header>
  42. <el-row :gutter="10">
  43. <right-toolbar v-model:showSearch="showSearch" :search="true" @query-table="handleQuery"></right-toolbar>
  44. </el-row>
  45. </template>
  46. <el-table ref="multipleTableRef" v-loading="loading" :data="userList" row-key="userId" @selection-change="handleSelectionChange">
  47. <el-table-column type="selection" width="50" align="center" />
  48. <el-table-column key="userId" label="用户编号" align="center" prop="userId" />
  49. <el-table-column key="userName" label="用户名称" align="center" prop="userName" :show-overflow-tooltip="true" />
  50. <el-table-column key="nickName" label="用户昵称" align="center" prop="nickName" :show-overflow-tooltip="true" />
  51. <el-table-column key="phonenumber" label="手机号码" align="center" prop="phonenumber" width="120" />
  52. <el-table-column label="创建时间" align="center" prop="createTime" width="160">
  53. <template #default="scope">
  54. <span>{{ scope.row.createTime }}</span>
  55. </template>
  56. </el-table-column>
  57. </el-table>
  58. <pagination
  59. v-show="total > 0"
  60. v-model:page="queryParams.pageNum"
  61. v-model:limit="queryParams.pageSize"
  62. :total="total"
  63. @pagination="handleQuery"
  64. />
  65. </el-card>
  66. <el-card shadow="hover">
  67. <el-tag v-for="(user, index) in chooseUserList" :key="user.userId" style="margin: 2px" closable @close="handleCloseTag(user, index)"
  68. >{{ user.userName }}
  69. </el-tag>
  70. </el-card>
  71. </el-col>
  72. </el-row>
  73. </div>
  74. <div v-if="multiInstance === 'delete'" class="p-2">
  75. <el-table v-loading="loading" :data="taskList" @selection-change="handleTaskSelection">
  76. <el-table-column type="selection" width="55" />
  77. <el-table-column prop="name" label="任务名称" />
  78. <el-table-column prop="assigneeName" label="办理人" />
  79. </el-table>
  80. </div>
  81. <template #footer>
  82. <div class="dialog-footer">
  83. <el-button type="primary" @click="submitFileForm">确 定</el-button>
  84. <el-button @click="visible = false">取 消</el-button>
  85. </div>
  86. </template>
  87. </el-dialog>
  88. </template>
  89. <script setup name="User" lang="ts">
  90. import { deptTreeSelect, listUser, optionSelect } from '@/api/system/user';
  91. import {
  92. addMultiInstanceExecution,
  93. deleteMultiInstanceExecution,
  94. getTaskUserIdsByAddMultiInstance,
  95. getListByDeleteMultiInstance
  96. } from '@/api/workflow/task';
  97. import { UserVO } from '@/api/system/user/types';
  98. import { DeptVO } from '@/api/system/dept/types';
  99. import { ComponentInternalInstance } from 'vue';
  100. import { ElTree, ElTable } from 'element-plus';
  101. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  102. const props = defineProps({
  103. // 宽
  104. width: {
  105. type: String,
  106. default: '70%'
  107. },
  108. // 高
  109. height: {
  110. type: String,
  111. default: '100%'
  112. },
  113. // 标题
  114. title: {
  115. type: String,
  116. default: '加签人员'
  117. },
  118. //是否多选
  119. multiple: {
  120. type: Boolean,
  121. default: true
  122. },
  123. //回显用户id
  124. userIdList: {
  125. type: Array,
  126. default: () => []
  127. }
  128. });
  129. const deptTreeRef = ref(ElTree);
  130. const multipleTableRef = ref(ElTable);
  131. const userList = ref<UserVO[]>();
  132. const taskList = ref<Array<any>[]>();
  133. const loading = ref(true);
  134. const showSearch = ref(true);
  135. const selectionTask = ref<Array<any>[]>();
  136. const visible = ref(false);
  137. const total = ref(0);
  138. const deptName = ref('');
  139. const deptOptions = ref<DeptVO[]>([]);
  140. const chooseUserList = ref(ref<UserVO[]>());
  141. const userIds = ref<Array<number | string>>([]);
  142. //加签或者减签
  143. const multiInstance = ref('');
  144. const queryParams = ref<Record<string, any>>({
  145. pageNum: 1,
  146. pageSize: 10,
  147. userName: '',
  148. nickName: '',
  149. taskId: ''
  150. });
  151. /** 查询用户列表 */
  152. const getAddMultiInstanceList = async (taskId: string, userIdList: Array<number | string>) => {
  153. deptOptions.value = [];
  154. getTreeSelect();
  155. multiInstance.value = 'add';
  156. userIds.value = userIdList;
  157. visible.value = true;
  158. queryParams.value.taskId = taskId;
  159. loading.value = true;
  160. const res1 = await getTaskUserIdsByAddMultiInstance(taskId);
  161. queryParams.value.excludeUserIds = res1.data;
  162. const res = await listUser(queryParams.value);
  163. loading.value = false;
  164. userList.value = res.rows;
  165. total.value = res.total;
  166. if (userList.value && userIds.value.length > 0) {
  167. const data = await optionSelect(userIds.value);
  168. if (data.data && data.data.length > 0) {
  169. chooseUserList.value = data.data;
  170. data.data.forEach((user: UserVO) => {
  171. multipleTableRef.value!.toggleRowSelection(
  172. userList.value.find((item) => {
  173. return item.userId == user.userId;
  174. }),
  175. true
  176. );
  177. });
  178. }
  179. }
  180. };
  181. const getList = async () => {
  182. loading.value = true;
  183. const res1 = await getTaskUserIdsByAddMultiInstance(queryParams.value.taskId);
  184. queryParams.value.excludeUserIds = res1.data;
  185. const res = await listUser(queryParams.value);
  186. loading.value = false;
  187. userList.value = res.rows;
  188. total.value = res.total;
  189. if (userList.value && userIds.value.length > 0) {
  190. const data = await optionSelect(userIds.value);
  191. if (data.data && data.data.length > 0) {
  192. chooseUserList.value = data.data;
  193. data.data.forEach((user: UserVO) => {
  194. multipleTableRef.value!.toggleRowSelection(
  195. userList.value.find((item) => {
  196. return item.userId == user.userId;
  197. }),
  198. true
  199. );
  200. });
  201. }
  202. }
  203. };
  204. const getDeleteMultiInstanceList = async (taskId: string) => {
  205. deptOptions.value = [];
  206. loading.value = true;
  207. queryParams.value.taskId = taskId;
  208. multiInstance.value = 'delete';
  209. visible.value = true;
  210. const res = await getListByDeleteMultiInstance(taskId);
  211. taskList.value = res.data;
  212. loading.value = false;
  213. };
  214. /** 搜索按钮操作 */
  215. const handleQuery = () => {
  216. queryParams.value.pageNum = 1;
  217. getAddMultiInstanceList(queryParams.value.taskId, userIds.value);
  218. };
  219. /** 重置按钮操作 */
  220. const resetQuery = () => {
  221. queryParams.value.pageNum = 1;
  222. queryParams.value.deptId = undefined;
  223. queryParams.value.userName = undefined;
  224. queryParams.value.nickName = undefined;
  225. deptTreeRef.value.setCurrentKey(null);
  226. handleQuery();
  227. };
  228. /** 选择条数 */
  229. const handleSelectionChange = (selection: UserVO[]) => {
  230. if (props.multiple) {
  231. chooseUserList.value = selection.filter((element, index, self) => {
  232. return self.findIndex((x) => x.userId === element.userId) === index;
  233. });
  234. selection.forEach((u) => {
  235. if (chooseUserList.value && !chooseUserList.value.includes(u)) {
  236. multipleTableRef.value!.toggleRowSelection(u, undefined);
  237. }
  238. });
  239. userIds.value = chooseUserList.value.map((item) => {
  240. return item.userId;
  241. });
  242. } else {
  243. chooseUserList.value = selection;
  244. if (selection.length > 1) {
  245. let delRow = selection.shift();
  246. multipleTableRef.value!.toggleRowSelection(delRow, undefined);
  247. }
  248. if (selection.length === 0) {
  249. chooseUserList.value = [];
  250. }
  251. }
  252. };
  253. /** 选择条数 */
  254. const handleTaskSelection = (selection: any) => {
  255. selectionTask.value = selection;
  256. };
  257. /** 查询部门下拉树结构 */
  258. const getTreeSelect = async () => {
  259. const res = await deptTreeSelect();
  260. deptOptions.value = res.data;
  261. };
  262. /** 通过条件过滤节点 */
  263. const filterNode = (value: string, data: any) => {
  264. if (!value) return true;
  265. return data.label.indexOf(value) !== -1;
  266. };
  267. /** 根据名称筛选部门树 */
  268. watchEffect(
  269. () => {
  270. if (visible.value && deptOptions.value && deptOptions.value.length > 0) {
  271. deptTreeRef.value.filter(deptName.value);
  272. }
  273. },
  274. {
  275. flush: 'post' // watchEffect会在DOM挂载或者更新之前就会触发,此属性控制在DOM元素更新后运行
  276. }
  277. );
  278. /** 节点单击事件 */
  279. const handleNodeClick = (data: DeptVO) => {
  280. queryParams.value.deptId = data.id;
  281. getList();
  282. };
  283. //删除tag
  284. const handleCloseTag = (user: UserVO, index: any) => {
  285. if (multipleTableRef.value.selection && multipleTableRef.value.selection.length > 0) {
  286. multipleTableRef.value.selection.forEach((u: UserVO, i: number) => {
  287. if (user.userId === u.userId) {
  288. multipleTableRef.value.selection.splice(i, 1);
  289. }
  290. });
  291. }
  292. if (chooseUserList.value && chooseUserList.value.length > 0) {
  293. chooseUserList.value.splice(index, 1);
  294. }
  295. multipleTableRef.value.toggleRowSelection(user, undefined);
  296. if (userIds.value && userIds.value.length > 0) {
  297. userIds.value.forEach((userId, i) => {
  298. if (userId === user.userId) {
  299. userIds.value.splice(i, 1);
  300. }
  301. });
  302. }
  303. };
  304. const submitFileForm = async () => {
  305. if (multiInstance.value === 'add') {
  306. if (chooseUserList.value && chooseUserList.value.length > 0) {
  307. loading.value = true;
  308. let userIds = chooseUserList.value.map((item) => {
  309. return item.userId;
  310. });
  311. let nickNames = chooseUserList.value.map((item) => {
  312. return item.nickName;
  313. });
  314. let params = {
  315. taskId: queryParams.value.taskId,
  316. assignees: userIds,
  317. assigneeNames: nickNames
  318. };
  319. await addMultiInstanceExecution(params);
  320. emits('submitCallback');
  321. loading.value = false;
  322. proxy?.$modal.msgSuccess('操作成功');
  323. visible.value = false;
  324. }
  325. } else {
  326. if (selectionTask.value && selectionTask.value.length > 0) {
  327. loading.value = true;
  328. let taskIds = selectionTask.value.map((item: any) => {
  329. return item.id;
  330. });
  331. let executionIds = selectionTask.value.map((item: any) => {
  332. return item.executionId;
  333. });
  334. let assigneeIds = selectionTask.value.map((item: any) => {
  335. return item.assignee;
  336. });
  337. let assigneeNames = selectionTask.value.map((item: any) => {
  338. return item.assigneeName;
  339. });
  340. let params = {
  341. taskId: queryParams.value.taskId,
  342. taskIds: taskIds,
  343. executionIds: executionIds,
  344. assigneeIds: assigneeIds,
  345. assigneeNames: assigneeNames
  346. };
  347. await deleteMultiInstanceExecution(params);
  348. emits('submitCallback');
  349. loading.value = false;
  350. proxy?.$modal.msgSuccess('操作成功');
  351. visible.value = false;
  352. }
  353. }
  354. };
  355. //事件
  356. const emits = defineEmits(['submitCallback']);
  357. /**
  358. * 对外暴露子组件方法
  359. */
  360. defineExpose({
  361. getAddMultiInstanceList,
  362. getDeleteMultiInstanceList
  363. });
  364. </script>