multiInstanceUser.vue 12 KB

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