detail.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. <template>
  2. <ContentWrap>
  3. <!-- 审批信息 -->
  4. <el-card
  5. class="box-card"
  6. v-loading="processInstanceLoading"
  7. v-for="(item, index) in runningTasks"
  8. :key="index"
  9. >
  10. <template #header>
  11. <span class="el-icon-picture-outline">审批任务【{{ item.name }}】</span>
  12. </template>
  13. <el-col :span="16" :offset="6">
  14. <el-form
  15. :ref="'form' + index"
  16. :model="auditForms[index]"
  17. :rules="auditRule"
  18. label-width="100px"
  19. >
  20. <el-form-item label="流程名" v-if="processInstance && processInstance.name">
  21. {{ processInstance.name }}
  22. </el-form-item>
  23. <el-form-item label="流程发起人" v-if="processInstance && processInstance.startUser">
  24. {{ processInstance.startUser.nickname }}
  25. <el-tag type="info" size="small">{{ processInstance.startUser.deptName }}</el-tag>
  26. </el-form-item>
  27. <el-form-item label="审批建议" prop="reason">
  28. <el-input
  29. type="textarea"
  30. v-model="auditForms[index].reason"
  31. placeholder="请输入审批建议"
  32. />
  33. </el-form-item>
  34. </el-form>
  35. <div style="margin-left: 10%; margin-bottom: 20px; font-size: 14px">
  36. <XButton
  37. pre-icon="ep:select"
  38. type="success"
  39. title="通过"
  40. @click="handleAudit(item, true)"
  41. />
  42. <XButton
  43. pre-icon="ep:close"
  44. type="danger"
  45. title="不通过"
  46. @click="handleAudit(item, false)"
  47. />
  48. <XButton
  49. pre-icon="ep:edit"
  50. type="primary"
  51. title="转办"
  52. @click="handleUpdateAssignee(item)"
  53. />
  54. <XButton
  55. pre-icon="ep:position"
  56. type="primary"
  57. title="委派"
  58. @click="handleDelegate(item)"
  59. />
  60. <XButton pre-icon="ep:back" type="warning" title="委派" @click="handleBack(item)" />
  61. </div>
  62. </el-col>
  63. </el-card>
  64. <!-- 申请信息 -->
  65. <el-card class="box-card" v-loading="processInstanceLoading">
  66. <template #header>
  67. <span class="el-icon-document">申请信息【{{ processInstance.name }}】</span>
  68. </template>
  69. <!-- 情况一:流程表单 -->
  70. <el-col v-if="processInstance?.processDefinition?.formType === 10" :span="16" :offset="6">
  71. <form-create
  72. :rule="detailForm.rule"
  73. v-model:api="fApi"
  74. :option="detailForm.option"
  75. v-model="detailForm.value"
  76. />
  77. </el-col>
  78. <!-- 情况二:流程表单 -->
  79. <div v-if="processInstance?.processDefinition?.formType === 20">
  80. <router-link
  81. :to="
  82. processInstance.processDefinition.formCustomViewPath +
  83. '?id=' +
  84. processInstance.businessKey
  85. "
  86. >
  87. <XButton type="primary" preIcon="ep:view" title="点击查看" />
  88. </router-link>
  89. </div>
  90. </el-card>
  91. <!-- 审批记录 -->
  92. <el-card class="box-card" v-loading="tasksLoad">
  93. <template #header>
  94. <span class="el-icon-picture-outline">审批记录</span>
  95. </template>
  96. <el-col :span="16" :offset="4">
  97. <div class="block">
  98. <el-timeline>
  99. <el-timeline-item
  100. v-for="(item, index) in tasks"
  101. :key="index"
  102. :icon="getTimelineItemIcon(item)"
  103. :type="getTimelineItemType(item)"
  104. >
  105. <p style="font-weight: 700">任务:{{ item.name }}</p>
  106. <el-card :body-style="{ padding: '10px' }">
  107. <label v-if="item.assigneeUser" style="font-weight: normal; margin-right: 30px">
  108. 审批人:{{ item.assigneeUser.nickname }}
  109. <el-tag type="info" size="mini">{{ item.assigneeUser.deptName }}</el-tag>
  110. </label>
  111. <label style="font-weight: normal" v-if="item.createTime">创建时间:</label>
  112. <label style="color: #8a909c; font-weight: normal">
  113. {{ dayjs(item?.createTime).format('YYYY-MM-DD HH:mm:ss') }}
  114. </label>
  115. <label v-if="item.endTime" style="margin-left: 30px; font-weight: normal">
  116. 审批时间:
  117. </label>
  118. <label v-if="item.endTime" style="color: #8a909c; font-weight: normal">
  119. {{ dayjs(item?.endTime).format('YYYY-MM-DD HH:mm:ss') }}
  120. </label>
  121. <label v-if="item.durationInMillis" style="margin-left: 30px; font-weight: normal">
  122. 耗时:
  123. </label>
  124. <label v-if="item.durationInMillis" style="color: #8a909c; font-weight: normal">
  125. {{ formatPast2(item?.durationInMillis) }}
  126. </label>
  127. <p v-if="item.reason">
  128. <el-tag :type="getTimelineItemType(item)">{{ item.reason }}</el-tag>
  129. </p>
  130. </el-card>
  131. </el-timeline-item>
  132. </el-timeline>
  133. </div>
  134. </el-col>
  135. </el-card>
  136. <!-- 高亮流程图 -->
  137. <el-card class="box-card" v-loading="processInstanceLoading">
  138. <template #header>
  139. <span class="el-icon-picture-outline">流程图</span>
  140. </template>
  141. <my-process-viewer
  142. key="designer"
  143. v-model="bpmnXML"
  144. v-bind="bpmnControlForm"
  145. :activityData="activityList"
  146. :processInstanceData="processInstance"
  147. :taskData="tasks"
  148. />
  149. </el-card>
  150. <!-- 对话框(转派审批人) -->
  151. <XModal v-model="updateAssigneeVisible" title="转派审批人" width="500">
  152. <el-form
  153. ref="updateAssigneeFormRef"
  154. :model="updateAssigneeForm"
  155. :rules="updateAssigneeRules"
  156. label-width="110px"
  157. >
  158. <el-form-item label="新审批人" prop="assigneeUserId">
  159. <el-select v-model="updateAssigneeForm.assigneeUserId" clearable style="width: 100%">
  160. <el-option
  161. v-for="item in userOptions"
  162. :key="parseInt(item.id)"
  163. :label="item.nickname"
  164. :value="parseInt(item.id)"
  165. />
  166. </el-select>
  167. </el-form-item>
  168. </el-form>
  169. <!-- 操作按钮 -->
  170. <template #footer>
  171. <!-- 按钮:保存 -->
  172. <XButton
  173. type="primary"
  174. :title="t('action.save')"
  175. :loading="updateAssigneeLoading"
  176. @click="submitUpdateAssigneeForm"
  177. />
  178. <!-- 按钮:关闭 -->
  179. <XButton
  180. :loading="updateAssigneeLoading"
  181. :title="t('dialog.close')"
  182. @click="updateAssigneeLoading = false"
  183. />
  184. </template>
  185. </XModal>
  186. </ContentWrap>
  187. </template>
  188. <script setup lang="ts">
  189. import dayjs from 'dayjs'
  190. import * as UserApi from '@/api/system/user'
  191. import * as ProcessInstanceApi from '@/api/bpm/processInstance'
  192. import * as DefinitionApi from '@/api/bpm/definition'
  193. import * as TaskApi from '@/api/bpm/task'
  194. import * as ActivityApi from '@/api/bpm/activity'
  195. import { formatPast2 } from '@/utils/formatTime'
  196. import { setConfAndFields2 } from '@/utils/formCreate'
  197. import { ApiAttrs } from '@form-create/element-ui/types/config'
  198. import { useUserStore } from '@/store/modules/user'
  199. const { query } = useRoute() // 查询参数
  200. const message = useMessage() // 消息弹窗
  201. const { t } = useI18n() // 国际化
  202. const { proxy } = getCurrentInstance()
  203. // ========== 审批信息 ==========
  204. const id = query.id as unknown as number
  205. const processInstanceLoading = ref(false) // 流程实例的加载中
  206. const processInstance = ref() // 流程实例
  207. const runningTasks = ref() // 运行中的任务
  208. const auditForms = ref() // 审批任务的表单
  209. const auditRule = reactive({
  210. reason: [{ required: true, message: '审批建议不能为空', trigger: 'blur' }]
  211. })
  212. // 处理审批通过和不通过的操作
  213. const handleAudit = async (task, pass) => {
  214. // 1.1 获得对应表单
  215. const index = runningTasks.value.indexOf(task)
  216. const auditFormRef = proxy.$refs['form' + index][0]
  217. // alert(auditFormRef)
  218. // 1.2 校验表单
  219. const elForm = unref(auditFormRef)
  220. if (!elForm) return
  221. const valid = await elForm.validate()
  222. if (!valid) return
  223. // 2.1 提交审批
  224. const data = {
  225. id: task.id,
  226. reason: auditForms.value[index].reason
  227. }
  228. if (pass) {
  229. await TaskApi.approveTask(data)
  230. message.success('审批通过成功')
  231. } else {
  232. await TaskApi.rejectTask(data)
  233. message.success('审批不通过成功')
  234. }
  235. // 2.2 加载最新数据
  236. getDetail()
  237. }
  238. // ========== 申请信息 ==========
  239. const fApi = ref<ApiAttrs>()
  240. const userId = useUserStore().getUser.id // 当前登录的编号
  241. // 流程表单详情
  242. const detailForm = ref({
  243. rule: [],
  244. option: {},
  245. value: {}
  246. })
  247. // ========== 审批记录 ==========
  248. const tasksLoad = ref(true)
  249. const tasks = ref()
  250. const getTimelineItemIcon = (item) => {
  251. if (item.result === 1) {
  252. return 'el-icon-time'
  253. }
  254. if (item.result === 2) {
  255. return 'el-icon-check'
  256. }
  257. if (item.result === 3) {
  258. return 'el-icon-close'
  259. }
  260. if (item.result === 4) {
  261. return 'el-icon-remove-outline'
  262. }
  263. return ''
  264. }
  265. const getTimelineItemType = (item) => {
  266. if (item.result === 1) {
  267. return 'primary'
  268. }
  269. if (item.result === 2) {
  270. return 'success'
  271. }
  272. if (item.result === 3) {
  273. return 'danger'
  274. }
  275. if (item.result === 4) {
  276. return 'info'
  277. }
  278. return ''
  279. }
  280. // ========== 审批记录 ==========
  281. const updateAssigneeVisible = ref(false)
  282. const updateAssigneeLoading = ref(false)
  283. const updateAssigneeForm = ref({
  284. id: undefined,
  285. assigneeUserId: undefined
  286. })
  287. const updateAssigneeRules = ref({
  288. assigneeUserId: [{ required: true, message: '新审批人不能为空', trigger: 'change' }]
  289. })
  290. const updateAssigneeFormRef = ref()
  291. const userOptions = ref()
  292. // 处理转派审批人
  293. const handleUpdateAssignee = (task) => {
  294. // 设置表单
  295. resetUpdateAssigneeForm()
  296. updateAssigneeForm.value.id = task.id
  297. // 设置为打开
  298. updateAssigneeVisible.value = true
  299. }
  300. // 提交转派审批人
  301. const submitUpdateAssigneeForm = async () => {
  302. // 1. 校验表单
  303. const elForm = unref(updateAssigneeFormRef)
  304. if (!elForm) return
  305. const valid = await elForm.validate()
  306. if (!valid) return
  307. // 2.1 提交审批
  308. updateAssigneeLoading.value = true
  309. try {
  310. await TaskApi.updateTaskAssignee(updateAssigneeForm.value)
  311. // 2.2 设置为隐藏
  312. updateAssigneeVisible.value = false
  313. // 加载最新数据
  314. getDetail()
  315. } finally {
  316. updateAssigneeLoading.value = false
  317. }
  318. }
  319. // 重置转派审批人表单
  320. const resetUpdateAssigneeForm = () => {
  321. updateAssigneeForm.value = {
  322. id: undefined,
  323. assigneeUserId: undefined
  324. }
  325. updateAssigneeFormRef.value?.resetFields()
  326. }
  327. /** 处理审批退回的操作 */
  328. const handleDelegate = async (task) => {
  329. message.error('暂不支持【委派】功能,可以使用【转派】替代!')
  330. console.log(task)
  331. }
  332. /** 处理审批退回的操作 */
  333. const handleBack = async (task) => {
  334. message.error('暂不支持【退回】功能!')
  335. // 可参考 http://blog.wya1.com/article/636697030/details/7296
  336. // const data = {
  337. // id: task.id,
  338. // assigneeUserId: 1
  339. // }
  340. // backTask(data).then(response => {
  341. // this.$modal.msgSuccess("回退成功!");
  342. // this.getDetail(); // 获得最新详情
  343. // });
  344. console.log(task)
  345. }
  346. // ========== 高亮流程图 ==========
  347. const bpmnXML = ref(null)
  348. const bpmnControlForm = ref({
  349. prefix: 'flowable'
  350. })
  351. const activityList = ref([])
  352. // ========== 初始化 ==========
  353. onMounted(() => {
  354. // 加载详情
  355. getDetail()
  356. // 加载用户的列表
  357. UserApi.getListSimpleUsersApi().then((data) => {
  358. userOptions.value.push(...data)
  359. })
  360. })
  361. const getDetail = () => {
  362. // 1. 获得流程实例相关
  363. processInstanceLoading.value = true
  364. ProcessInstanceApi.getProcessInstanceApi(id)
  365. .then((data) => {
  366. if (!data) {
  367. message.error('查询不到流程信息!')
  368. return
  369. }
  370. processInstance.value = data
  371. // 设置表单信息
  372. const processDefinition = data.processDefinition
  373. if (processDefinition.formType === 10) {
  374. setConfAndFields2(
  375. detailForm,
  376. processDefinition.formConf,
  377. processDefinition.formFields,
  378. data.formVariables
  379. )
  380. nextTick().then(() => {
  381. fApi.value?.btn.show(false)
  382. fApi.value?.resetBtn.show(false)
  383. })
  384. }
  385. // 加载流程图
  386. DefinitionApi.getProcessDefinitionBpmnXMLApi(processDefinition.id).then((data) => {
  387. bpmnXML.value = data
  388. })
  389. // 加载活动列表
  390. ActivityApi.getActivityList({
  391. processInstanceId: data.id
  392. }).then((data) => {
  393. activityList.value = data
  394. })
  395. })
  396. .finally(() => {
  397. processInstanceLoading.value = false
  398. })
  399. // 2. 获得流程任务列表(审批记录)
  400. tasksLoad.value = true
  401. runningTasks.value = []
  402. auditForms.value = []
  403. TaskApi.getTaskListByProcessInstanceId(id)
  404. .then((data) => {
  405. // 审批记录
  406. tasks.value = []
  407. // 移除已取消的审批
  408. data.forEach((task) => {
  409. if (task.result !== 4) {
  410. tasks.value.push(task)
  411. }
  412. })
  413. // 排序,将未完成的排在前面,已完成的排在后面;
  414. tasks.value.sort((a, b) => {
  415. // 有已完成的情况,按照完成时间倒序
  416. if (a.endTime && b.endTime) {
  417. return b.endTime - a.endTime
  418. } else if (a.endTime) {
  419. return 1
  420. } else if (b.endTime) {
  421. return -1
  422. // 都是未完成,按照创建时间倒序
  423. } else {
  424. return b.createTime - a.createTime
  425. }
  426. })
  427. // 需要审核的记录
  428. tasks.value.forEach((task) => {
  429. // 1.1 只有待处理才需要
  430. if (task.result !== 1) {
  431. return
  432. }
  433. // 1.2 自己不是处理人
  434. if (!task.assigneeUser || task.assigneeUser.id !== userId) {
  435. return
  436. }
  437. // 2. 添加到处理任务
  438. runningTasks.value.push({ ...task })
  439. auditForms.value.push({
  440. reason: ''
  441. })
  442. })
  443. })
  444. .finally(() => {
  445. tasksLoad.value = false
  446. })
  447. }
  448. </script>
  449. <style lang="scss">
  450. .my-process-designer {
  451. height: calc(100vh - 200px);
  452. }
  453. .box-card {
  454. width: 100%;
  455. margin-bottom: 20px;
  456. }
  457. </style>