multiInstanceUser.vue 12 KB

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