detail.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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="auditFormRefs"
  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. </div>
  43. </el-col>
  44. </el-card>
  45. <!-- 申请信息 -->
  46. <el-card class="box-card" v-loading="processInstanceLoading">
  47. <template #header>
  48. <span class="el-icon-document">申请信息【{{ processInstance.name }}】</span>
  49. </template>
  50. <!-- 情况一:流程表单 -->
  51. <el-col v-if="processInstance?.processDefinition?.formType === 10" :span="16" :offset="6">
  52. <form-create
  53. :rule="detailForm.rule"
  54. v-model:api="fApi"
  55. :option="detailForm.option"
  56. v-model="detailForm.value"
  57. />
  58. </el-col>
  59. <!-- 情况二:流程表单 -->
  60. <div v-if="processInstance?.processDefinition?.formType === 20">
  61. <router-link
  62. :to="
  63. processInstance.processDefinition.formCustomViewPath +
  64. '?id=' +
  65. processInstance.businessKey
  66. "
  67. >
  68. <XButton type="primary" preIcon="ep:view" title="点击查看" />
  69. </router-link>
  70. </div>
  71. </el-card>
  72. <!-- 审批记录 -->
  73. <el-card class="box-card" v-loading="tasksLoad">
  74. <template #header>
  75. <span class="el-icon-picture-outline">审批记录</span>
  76. </template>
  77. <el-col :span="16" :offset="4">
  78. <div class="block">
  79. <el-timeline>
  80. <el-timeline-item
  81. v-for="(item, index) in tasks"
  82. :key="index"
  83. :icon="getTimelineItemIcon(item)"
  84. :type="getTimelineItemType(item)"
  85. >
  86. <p style="font-weight: 700">任务:{{ item.name }}</p>
  87. <el-card :body-style="{ padding: '10px' }">
  88. <label v-if="item.assigneeUser" style="font-weight: normal; margin-right: 30px">
  89. 审批人:{{ item.assigneeUser.nickname }}
  90. <el-tag type="info" size="mini">{{ item.assigneeUser.deptName }}</el-tag>
  91. </label>
  92. <label style="font-weight: normal" v-if="item.createTime">创建时间:</label>
  93. <label style="color: #8a909c; font-weight: normal">
  94. {{ dayjs(item?.createTime).format('YYYY-MM-DD HH:mm:ss') }}
  95. </label>
  96. <label v-if="item.endTime" style="margin-left: 30px; font-weight: normal">
  97. 审批时间:
  98. </label>
  99. <label v-if="item.endTime" style="color: #8a909c; font-weight: normal">
  100. {{ dayjs(item?.endTime).format('YYYY-MM-DD HH:mm:ss') }}
  101. </label>
  102. <label v-if="item.durationInMillis" style="margin-left: 30px; font-weight: normal">
  103. 耗时:
  104. </label>
  105. <label v-if="item.durationInMillis" style="color: #8a909c; font-weight: normal">
  106. {{ formatPast2(item?.durationInMillis) }}
  107. </label>
  108. <p v-if="item.reason">
  109. <el-tag :type="getTimelineItemType(item)">{{ item.reason }}</el-tag>
  110. </p>
  111. </el-card>
  112. </el-timeline-item>
  113. </el-timeline>
  114. </div>
  115. </el-col>
  116. </el-card>
  117. </ContentWrap>
  118. </template>
  119. <script setup lang="ts">
  120. import dayjs from 'dayjs'
  121. import * as ProcessInstanceApi from '@/api/bpm/processInstance'
  122. import * as TaskApi from '@/api/bpm/task'
  123. import { formatPast2 } from '@/utils/formatTime'
  124. const { query } = useRoute() // 查询参数
  125. const message = useMessage() // 消息弹窗
  126. // ========== 审批信息 ==========
  127. const id = query.id as unknown as number
  128. const processInstanceLoading = ref(false) // 流程实例的加载中
  129. const processInstance = ref({}) // 流程实例
  130. const runningTasks = ref([]) // 运行中的任务
  131. const auditForms = ref([]) // 审批任务的表单
  132. const auditRule = reactive({
  133. reason: [{ required: true, message: '审批建议不能为空', trigger: 'blur' }]
  134. })
  135. // 处理审批通过和不通过的操作
  136. const handleAudit = async (task, pass) => {
  137. // 1.1 获得对应表单
  138. const index = runningTasks.value.indexOf(task)
  139. // const auditFormRef = ref<any>([]).value.get(index)
  140. // 1.2 校验表单
  141. // const elForm = unref(auditFormRef)
  142. // if (!elForm) return
  143. // const valid = await auditFormRef.validate()
  144. // if (!valid) return
  145. // 2.1 提交审批
  146. const data = {
  147. id: task.id,
  148. reason: auditForms.value[index].reason
  149. }
  150. if (pass) {
  151. await TaskApi.approveTask(data)
  152. message.success('审批通过成功')
  153. } else {
  154. await TaskApi.rejectTask(data)
  155. message.success('审批不通过成功')
  156. }
  157. // 2.2 加载最新数据
  158. getDetail()
  159. }
  160. // ========== 申请信息 ==========
  161. import { setConfAndFields2 } from '@/utils/formCreate'
  162. import { ApiAttrs } from '@form-create/element-ui/types/config'
  163. import { useUserStore } from '@/store/modules/user'
  164. const fApi = ref<ApiAttrs>()
  165. const userId = useUserStore().getUser.id // 当前登录的编号
  166. // 流程表单详情
  167. const detailForm = ref({
  168. rule: [],
  169. option: {},
  170. value: {}
  171. })
  172. // ========== 审批记录 ==========
  173. const tasksLoad = ref(true)
  174. const tasks = ref([])
  175. const getTimelineItemIcon = (item) => {
  176. if (item.result === 1) {
  177. return 'el-icon-time'
  178. }
  179. if (item.result === 2) {
  180. return 'el-icon-check'
  181. }
  182. if (item.result === 3) {
  183. return 'el-icon-close'
  184. }
  185. if (item.result === 4) {
  186. return 'el-icon-remove-outline'
  187. }
  188. return ''
  189. }
  190. const getTimelineItemType = (item) => {
  191. if (item.result === 1) {
  192. return 'primary'
  193. }
  194. if (item.result === 2) {
  195. return 'success'
  196. }
  197. if (item.result === 3) {
  198. return 'danger'
  199. }
  200. if (item.result === 4) {
  201. return 'info'
  202. }
  203. return ''
  204. }
  205. // ========== 初始化 ==========
  206. onMounted(() => {
  207. getDetail()
  208. })
  209. const getDetail = () => {
  210. // 1. 获得流程实例相关
  211. processInstanceLoading.value = true
  212. ProcessInstanceApi.getProcessInstanceApi(id)
  213. .then((data) => {
  214. if (!data) {
  215. message.error('查询不到流程信息!')
  216. return
  217. }
  218. processInstance.value = data
  219. // 设置表单信息
  220. const processDefinition = data.processDefinition
  221. if (processDefinition.formType === 10) {
  222. setConfAndFields2(
  223. detailForm,
  224. processDefinition.formConf,
  225. processDefinition.formFields,
  226. data.formVariables
  227. )
  228. nextTick().then(() => {
  229. fApi.value.btn.show(false)
  230. fApi.value.resetBtn.show(false)
  231. })
  232. }
  233. // TODO 加载流程图
  234. // TODO 加载活动列表
  235. })
  236. .finally(() => {
  237. processInstanceLoading.value = false
  238. })
  239. // 2. 获得流程任务列表(审批记录)
  240. tasksLoad.value = true
  241. runningTasks.value = []
  242. auditForms.value = []
  243. TaskApi.getTaskListByProcessInstanceId(id)
  244. .then((data) => {
  245. // 审批记录
  246. tasks.value = []
  247. // 移除已取消的审批
  248. data.forEach((task) => {
  249. if (task.result !== 4) {
  250. tasks.value.push(task)
  251. }
  252. })
  253. // 排序,将未完成的排在前面,已完成的排在后面;
  254. tasks.value.sort((a, b) => {
  255. // 有已完成的情况,按照完成时间倒序
  256. if (a.endTime && b.endTime) {
  257. return b.endTime - a.endTime
  258. } else if (a.endTime) {
  259. return 1
  260. } else if (b.endTime) {
  261. return -1
  262. // 都是未完成,按照创建时间倒序
  263. } else {
  264. return b.createTime - a.createTime
  265. }
  266. })
  267. // 需要审核的记录
  268. tasks.value.forEach((task) => {
  269. // 1.1 只有待处理才需要
  270. if (task.result !== 1) {
  271. return
  272. }
  273. // 1.2 自己不是处理人
  274. if (!task.assigneeUser || task.assigneeUser.id !== userId) {
  275. return
  276. }
  277. // 2. 添加到处理任务
  278. runningTasks.value.push({ ...task })
  279. auditForms.value.push({
  280. reason: ''
  281. })
  282. })
  283. })
  284. .finally(() => {
  285. tasksLoad.value = false
  286. })
  287. }
  288. </script>
  289. <style lang="scss">
  290. .my-process-designer {
  291. height: calc(100vh - 200px);
  292. }
  293. .box-card {
  294. width: 100%;
  295. margin-bottom: 20px;
  296. }
  297. </style>