approvedContent.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. <template>
  2. <div class="flow-detail-content">
  3. <div class="flow-detail-container">
  4. <!-- 值为空 -->
  5. <div v-if="!currentTaskRow.instanceId" class="flow-empty-detail-box">
  6. <el-empty description="暂无数据" />
  7. </div>
  8. <!-- 值不为空 -->
  9. <template v-if="currentTaskRow.instanceId">
  10. <!-- 1、头部信息 -->
  11. <div class="flow-status-stamp">
  12. <div class="flow-stamp-container">
  13. <FlowStatusStamp :status="currentTaskRow.instanceState" />
  14. </div>
  15. </div>
  16. <div class="flow-header-box">
  17. <div class="flow-no">编号:{{ currentTaskRow.instanceId }}</div>
  18. <div class="action-area">
  19. <div class="action-item"></div>
  20. </div>
  21. </div>
  22. <!-- 2、内容体 -->
  23. <div class="flow-detail-box">
  24. <!--头部-->
  25. <div class="header-box">
  26. <div class="summary-info">
  27. <div class="title">{{ currentTaskRow.processName }}</div>
  28. <FlowStatusTag :status="0" />
  29. </div>
  30. <div class="initiator-info">
  31. <FlowNodeAvatar :name="currentTaskRow.createBy" />
  32. <div class="begin-time">{{ currentTaskRow.createTime }} 提交</div>
  33. </div>
  34. </div>
  35. <div class="area-divider"></div>
  36. <div class="scroll-wrap">
  37. <!-- 表单 -->
  38. <div v-loading="validateForm.loading" class="form-wrap">
  39. <FormCreate v-show="validateForm.rule.length" v-model:api="validateForm.api" :option="validateForm.option" :rule="validateForm.rule" />
  40. <LeNoData v-if="!validateForm.rule.length" message="表单无数据" />
  41. </div>
  42. <div class="area-divider"></div>
  43. <!--审批流-->
  44. <el-timeline style="margin-left: 50px">
  45. <el-timeline-item v-for="active in activeData" :key="active.id" hollow :timestamp="formatTimestamp(new Date(active.createTime))">
  46. <template #dot>
  47. <FlowTypeDot :status="active.taskState" :type="active.taskType" />
  48. </template>
  49. <div v-show="active.type === 0" class="timeline-box flex-1">
  50. <span style="font-size: 16px; color: #86909c; display: block; margin-bottom: 3px">评论</span>
  51. <div class="flex flex-align-center">
  52. <div class="timeline-box-user flex-1">
  53. {{ active.createBy }}
  54. <div class="comment">
  55. <div class="comment-content">{{ active.content }}</div>
  56. </div>
  57. </div>
  58. <span class="timeline-box-date">{{ formatTimestamp(active.finishTime) }}</span>
  59. </div>
  60. </div>
  61. <div v-show="active.type !== 0" class="timeline-box flex-1">
  62. <div class="flex flex-align-center">
  63. <div class="timeline-box-user flex-1">
  64. <FlowNodeAvatar :name="active.createBy" />
  65. <div class="comment">
  66. <div class="comment-content">{{ active.duration }}</div>
  67. </div>
  68. </div>
  69. <span class="timeline-box-date">{{ formatTimestamp(active.finishTime) }}</span>
  70. </div>
  71. </div>
  72. </el-timeline-item>
  73. </el-timeline>
  74. </div>
  75. </div>
  76. <!-- 3、底部操作按钮 审批拒绝 强制终止不展示操作按钮-->
  77. <!--
  78. 1、已审批的任务不显示操作按钮
  79. 2、我的申请显示撤回按钮
  80. 3、认领任务显示认领按钮
  81. 4、我收到的任务显示评论
  82. -->
  83. <div v-if="currentTaskRow.instanceState === 0" class="flow-actions">
  84. <el-button :icon="ChatLineSquare" @click="openComment('reviewVisible', 'review')">评论</el-button>
  85. <template v-if="currentTaskType !== 'myReceived' || currentTaskType !== 'approved'">
  86. <el-button
  87. v-if="currentTaskType === 'pendingApproval'"
  88. :icon="Check"
  89. type="primary"
  90. @click="openComment('consentOrRefuseVisible', 'agree')"
  91. >同意</el-button
  92. >
  93. <el-button
  94. v-if="currentTaskType === 'pendingApproval'"
  95. :icon="Close"
  96. type="danger"
  97. @click="openComment('consentOrRefuseVisible', 'reject')"
  98. >拒绝</el-button
  99. >
  100. <el-button v-if="currentTaskType === 'myApplication'" :icon="Close" @click="openComment('reviewVisible', 'revoke')">撤回</el-button>
  101. <el-button v-if="currentTaskType === 'pendingClaim'" :icon="Close" @click="claimTaskEv">认领</el-button>
  102. <el-dropdown v-if="currentTaskType === 'pendingApproval'" style="margin-left: 12px">
  103. <el-button :icon="More">更多</el-button>
  104. <template #dropdown>
  105. <el-dropdown-menu>
  106. <el-dropdown-item @click.native="openComment('deliverToReviewVisible')">
  107. <el-icon><DArrowLeft /></el-icon>
  108. 转交
  109. </el-dropdown-item>
  110. <el-dropdown-item @click.native="openComment('rollbackVisible')">
  111. <el-icon><Switch /></el-icon>
  112. 回退
  113. </el-dropdown-item>
  114. <el-dropdown-item @click.native="openComment('addSignVisible')">
  115. <el-icon><Plus /></el-icon>
  116. 加签
  117. </el-dropdown-item>
  118. <el-dropdown-item @click.native="openComment('loseSignVisible')">
  119. <el-icon><Minus /></el-icon>
  120. 减签
  121. </el-dropdown-item>
  122. </el-dropdown-menu>
  123. </template>
  124. </el-dropdown>
  125. </template>
  126. </div>
  127. </template>
  128. </div>
  129. <!-- 评论弹窗-->
  130. <review-dialog
  131. v-if="reviewVisible"
  132. v-model="reviewVisible"
  133. :instance-id="currentTaskRow.instanceId"
  134. :task-id="taskId"
  135. :current-type="currentType"
  136. @success-cb="closeDetailEv"
  137. ></review-dialog>
  138. <!-- 加签弹窗 -->
  139. <add-sign-dialog v-if="addSignVisible" v-model="addSignVisible" :task-id="taskId" @success-cb="closeDetailEv"></add-sign-dialog>
  140. <!-- 同意或拒绝弹窗 -->
  141. <consent-or-refuse-dialog
  142. v-if="consentOrRefuseVisible"
  143. v-model="consentOrRefuseVisible"
  144. :task-id="taskId"
  145. :current-type="currentType"
  146. :form-data="currentFormData"
  147. @success-cb="closeDetailEv"
  148. ></consent-or-refuse-dialog>
  149. <!-- 转交审批弹窗 -->
  150. <deliver-to-review-dialog
  151. v-if="deliverToReviewVisible"
  152. v-model="deliverToReviewVisible"
  153. :task-id="taskId"
  154. @success-cb="closeDetailEv"
  155. ></deliver-to-review-dialog>
  156. <!-- 减签弹窗 -->
  157. <lose-sign-dialog v-if="loseSignVisible" v-model="loseSignVisible" :task-id="taskId" @success-cb="closeDetailEv"></lose-sign-dialog>
  158. <!-- 回退弹窗 -->
  159. <rollback-dialog v-if="rollbackVisible" v-model="rollbackVisible" :task-id="taskId" @success-cb="closeDetailEv"></rollback-dialog>
  160. </div>
  161. </template>
  162. <script setup>
  163. import useTaskProcessStore from '@/store/modules/taskProcess'
  164. import { computed, ref, onMounted, nextTick, watch } from 'vue'
  165. import FlowStatusStamp from '@/components/Flow/FlowStatusStamp.vue'
  166. import FlowStatusTag from '@/components/Flow/FlowStatusTag.vue'
  167. import FlowNodeAvatar from '@/components/Flow/FlowNodeAvatar.vue'
  168. import FlowTypeDot from '@/components/Flow/FlowTypeDot.vue'
  169. import { ChatLineSquare, Check, Close, Switch, DArrowLeft, Plus, Minus, More } from '@element-plus/icons-vue'
  170. import { processTaskApprovalInfo, processClaimTaskApi } from '@/api/flow/processTask'
  171. import { formatTimestamp } from '@/utils/datetime'
  172. import ReviewDialog from './reviewDialog'
  173. import AddSignDialog from './addSignDialog'
  174. import ConsentOrRefuseDialog from './consentOrRefuseDialog'
  175. import DeliverToReviewDialog from './deliverToReviewDialog'
  176. import LoseSignDialog from './loseSignDialog'
  177. import RollbackDialog from './rollbackDialog'
  178. import viewForm from '@/utils/form'
  179. import { storeToRefs } from 'pinia'
  180. import {ElMessage, ElMessageBox} from "element-plus";
  181. defineProps({
  182. /**
  183. * pendingApproval 待审批
  184. * myApplication 我的申请
  185. * myReceived 我收到的
  186. * pendingClaim 认领任务
  187. * approved 已审批
  188. */
  189. currentTaskType: {
  190. type: String,
  191. default: ''
  192. }
  193. })
  194. // store值
  195. const taskProcessInfo = useTaskProcessStore()
  196. const { currentTaskRow } = storeToRefs(taskProcessInfo)
  197. // 各种操作弹窗显示隐藏 start
  198. const reviewVisible = ref(false)
  199. const addSignVisible = ref(false)
  200. const consentOrRefuseVisible = ref(false)
  201. const deliverToReviewVisible = ref(false)
  202. const loseSignVisible = ref(false)
  203. const rollbackVisible = ref(false)
  204. // 各种操作弹窗显示隐藏 end
  205. const activeData = ref([])
  206. const currentType = ref(null)
  207. const currentFormData = ref({})
  208. // 当前form 表单数据字符串
  209. let cur_processForm_str = '[]'
  210. const taskId = computed(() => {
  211. return currentTaskRow.value.taskId || ''
  212. })
  213. const FormCreate = viewForm.$form()
  214. const validateForm = ref({
  215. api: {},
  216. option: {
  217. submitBtn: false
  218. },
  219. rule: [],
  220. loading: false
  221. })
  222. /**
  223. * 详情按钮各个操作弹窗
  224. * @param visibleType 评论 拒绝 同意等
  225. */
  226. const openComment = async (visibleType, item) => {
  227. switch (visibleType) {
  228. case 'reviewVisible':
  229. currentType.value = item
  230. reviewVisible.value = !reviewVisible.value
  231. break
  232. case 'addSignVisible':
  233. addSignVisible.value = !addSignVisible.value
  234. break
  235. case 'consentOrRefuseVisible':
  236. currentFormData.value = {}
  237. // 点击同意
  238. let bool = true
  239. if (item === 'agree') {
  240. const api = validateForm.value.api
  241. bool = await api.validate((valid, fail) => {
  242. if (valid) {
  243. // 表单验证通过
  244. const values = api.formData()
  245. const processForm = JSON.parse(cur_processForm_str)
  246. processForm.forEach(v => {
  247. // 填写的数据存储(local_: 本地数据处理标识)
  248. v.local_value = values[v.field]
  249. })
  250. console.warn(processForm, 'processForm')
  251. // 流程表单JSON内容 & local_value 保存
  252. currentFormData.value = { processForm: JSON.stringify(processForm) }
  253. }
  254. })
  255. }
  256. if (!bool) return
  257. currentType.value = item
  258. consentOrRefuseVisible.value = !consentOrRefuseVisible.value
  259. break
  260. case 'deliverToReviewVisible':
  261. deliverToReviewVisible.value = !deliverToReviewVisible.value
  262. break
  263. case 'loseSignVisible':
  264. loseSignVisible.value = !loseSignVisible.value
  265. break
  266. case 'rollbackVisible':
  267. rollbackVisible.value = !rollbackVisible.value
  268. break
  269. }
  270. }
  271. /**
  272. * 获取taskId对应的详情
  273. */
  274. const getTaskDetail = () => {
  275. const cur = currentTaskRow.value || {}
  276. // 提交的表单 数据展示
  277. validateForm.value.loading = true
  278. processTaskApprovalInfo({
  279. taskId: cur.taskId,
  280. instanceId: cur.instanceId,
  281. instanceState: cur.instanceState
  282. })
  283. .then(data => {
  284. activeData.value = data.processApprovals
  285. console.log(data, 'data.......')
  286. // validateForm.value.origin = data
  287. try {
  288. /*descItemsData.value.list = JSON.parse(data.formContent).map(item => {
  289. const showLabel = item.title
  290. let showValue = item.local_value
  291. const options = item.options
  292. if (Array.isArray(options) && showValue !== undefined) {
  293. if (Array.isArray(showValue)) {
  294. showValue = showValue.reduce(val => {
  295. const cur = options.find(option => option.value === val)
  296. return cur?.label || val
  297. }, [])
  298. } else {
  299. const cur = options.find(option => option.value === showValue)
  300. showValue = cur?.label || showValue
  301. }
  302. }
  303. return {
  304. showLabel,
  305. showValue
  306. }
  307. })*/
  308. const forms = JSON.parse(data.formContent)
  309. cur_processForm_str = data.formContent
  310. if (Array.isArray(forms)) {
  311. validateForm.value.rule = forms
  312. const api = validateForm.value.api
  313. api.setValue(
  314. forms.reduce((obj, item) => {
  315. obj[item.field] = item.local_value
  316. return obj
  317. }, {})
  318. )
  319. api.nextTick(() => {
  320. // 是否有编辑权限 操作
  321. api.disabled(false /*true*/)
  322. })
  323. }
  324. } catch (e) {
  325. console.error('解析 descItems 数据出现问题', e)
  326. // descItemsData.value.list = []
  327. validateForm.value.rule = []
  328. }
  329. })
  330. .finally(() => {
  331. validateForm.value.loading = false
  332. })
  333. }
  334. /**
  335. * 详情页面操作按钮回调
  336. */
  337. const closeDetailEv = () => {
  338. // 存储表单 todo.....
  339. // 如果这里有表单,是否要把所有表单的内容进行存储,存储完毕后,才能关闭这个详情,刷新左侧的列表 todo
  340. if (currentType.value === 'review') {
  341. // 评论按钮,不要刷新左侧的列表,只更新右侧的详情即可
  342. getTaskDetail()
  343. return
  344. }
  345. taskProcessInfo.refresh = true
  346. taskProcessInfo.setCurrentTaskRow({})
  347. }
  348. /** 认领任务 **/
  349. const claimTaskEv = async () => {
  350. ElMessageBox.confirm('确定认领当前审批流程?', '提示', {
  351. confirmButtonText: '确认',
  352. cancelButtonText: '取消',
  353. type: 'warning',
  354. buttonSize: 'default'
  355. })
  356. .then(async () => {
  357. const { data } = await processClaimTaskApi(currentTaskRow.value.taskId)
  358. ElMessage({
  359. message: data ? '执行成功' : '执行失败',
  360. type: data ? 'success' : 'error'
  361. })
  362. if (!data) return
  363. closeDetailEv()
  364. })
  365. .catch(() => {
  366. console.log('取消')
  367. })
  368. }
  369. /**
  370. * 监听同级子组件的instanceId的值变化 这里可能也有实例Id
  371. * 1、监听instanceId的值变化,如果值有变化,则重新获取审批详情
  372. * 2、如果instanceId没有值,则不请求接口,暂时暂无数据img
  373. */
  374. watch(
  375. () => currentTaskRow.value.instanceId,
  376. (nValue, oValue) => {
  377. if (!nValue) return
  378. nextTick(() => {
  379. getTaskDetail()
  380. })
  381. }
  382. )
  383. </script>
  384. <style scoped lang="scss">
  385. .flow-detail-content {
  386. height: 100%;
  387. overflow: hidden;
  388. background: var(--el-bg-color);
  389. border-radius: 6px;
  390. flex: auto;
  391. .flow-detail-container {
  392. display: flex;
  393. flex-direction: column;
  394. position: relative;
  395. height: 100%;
  396. overflow: hidden;
  397. }
  398. // 通过、不通过样式
  399. .flow-status-stamp {
  400. position: absolute;
  401. right: 10px;
  402. top: 10px;
  403. z-index: 99;
  404. }
  405. // 头部
  406. .flow-header-box {
  407. font-weight: 400;
  408. font-size: 13px;
  409. border-bottom: 1px solid var(--el-border-color);
  410. padding: 0 20px;
  411. height: 39px;
  412. display: flex;
  413. align-items: center;
  414. justify-content: space-between;
  415. color: var(--el-color-info);
  416. .action-area {
  417. display: flex;
  418. gap: 4px;
  419. .action-item {
  420. cursor: pointer;
  421. padding: 4px;
  422. border-radius: 6px;
  423. width: fit-content;
  424. height: fit-content;
  425. }
  426. }
  427. }
  428. // 内容体
  429. .flow-detail-box {
  430. //height: calc(100% - 92px);
  431. //overflow: hidden;
  432. //overflow-y: auto;
  433. flex: 1;
  434. min-height: 0;
  435. padding: 0 20px;
  436. display: flex;
  437. flex-direction: column;
  438. height: 100%;
  439. .header-box {
  440. display: flex;
  441. flex-direction: column;
  442. justify-content: center;
  443. // padding-top: 20px;
  444. .summary-info {
  445. display: flex;
  446. align-items: center;
  447. padding-top: 10px;
  448. font-size: 24px;
  449. .title {
  450. font-family: PingFangSC-Semibold, PingFang SC;
  451. color: var(--el-text-color-primary);
  452. }
  453. }
  454. .initiator-info {
  455. display: flex;
  456. align-items: center;
  457. margin-top: 16px;
  458. .begin-time {
  459. margin-left: 16px;
  460. font-weight: 350;
  461. color: var(--el-text-color-placeholder);
  462. font-size: 13px;
  463. -webkit-user-select: none;
  464. user-select: none;
  465. }
  466. }
  467. }
  468. .area-divider {
  469. border-bottom: 1px solid var(--el-border-color);
  470. margin: 20px 0;
  471. //position: relative;
  472. }
  473. .scroll-wrap {
  474. overflow: hidden;
  475. overflow-y: auto;
  476. flex: 1;
  477. }
  478. }
  479. // 底部
  480. .flow-actions {
  481. display: flex;
  482. align-items: center;
  483. justify-content: flex-end;
  484. height: 52px;
  485. //border-top: 1px solid var(--color-neutral-3);
  486. border-top: 1px solid var(--el-border-color-light);
  487. padding: 0 20px;
  488. }
  489. }
  490. .comment-content {
  491. user-select: none;
  492. margin-top: 4px;
  493. padding: 8px;
  494. border-radius: 4px;
  495. background-color: var(--el-bg-color-page);
  496. }
  497. .timeline-box {
  498. margin-left: 5px;
  499. }
  500. </style>