approvedContent.vue 16 KB

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