workTicketDialog.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. <template>
  2. <div>
  3. <ele-modal
  4. :visible.sync="visible"
  5. title="作业票管理"
  6. width="80vw"
  7. append-to-body
  8. :close-on-click-modal="false"
  9. @close="handleClose"
  10. >
  11. <div>
  12. <!-- 搜索区域 -->
  13. <div class="search-area">
  14. <seek-page
  15. ref="seekPage"
  16. :seekList="seekList"
  17. @search="handleSearch"
  18. :formLength="4"
  19. />
  20. </div>
  21. <!-- 列表视图 -->
  22. <div class="list-view">
  23. <!--
  24. v-if="work.id":el-dialog 首次打开才会渲染弹窗内容,表格也是此时才挂载。
  25. 表格挂载后由自身 mounted 触发首次加载,避免首次打开时 $refs.table 还不存在而不发请求。
  26. -->
  27. <ele-pro-table
  28. v-if="work.id"
  29. ref="table"
  30. row-key="id"
  31. :columns="columns"
  32. :datasource="datasource"
  33. :cache-key="cacheKeyUrl"
  34. max-height="500px"
  35. @columns-change="handleColumnChange"
  36. @selection-change="handleSelectionChange"
  37. >
  38. <template v-slot:toolbar>
  39. <div class="toolbar-left">
  40. <el-button
  41. type="primary"
  42. size="small"
  43. icon="el-icon-plus"
  44. @click="handleAdd"
  45. >申请作业票</el-button
  46. >
  47. <el-button
  48. type="danger"
  49. size="small"
  50. icon="el-icon-delete"
  51. :disabled="!selectedRows.length"
  52. @click="handleBatchDelete"
  53. >批量删除</el-button
  54. >
  55. </div>
  56. </template>
  57. <template v-slot:workType="{ row }">
  58. <span>{{ getWorkTypeName(row.workType) }}</span>
  59. </template>
  60. <template v-slot:status="{ row }">
  61. <el-tag :type="getStatusType(row.status)" size="small">
  62. {{ row.statusName || getStatusName(row.status) }}
  63. </el-tag>
  64. </template>
  65. <template v-slot:action="{ row }">
  66. <div class="action-links">
  67. <el-link
  68. type="primary"
  69. :underline="false"
  70. @click="handleView(row)"
  71. >查看</el-link
  72. >
  73. <el-link
  74. type="primary"
  75. :underline="false"
  76. @click="handleEdit(row)"
  77. >编辑</el-link
  78. >
  79. <el-link
  80. v-if="canSubmit(row)"
  81. type="success"
  82. :underline="false"
  83. :disabled="submittingId === row.id"
  84. @click="handleSubmit(row)"
  85. >提交</el-link
  86. >
  87. <el-link
  88. v-if="!isDraft(row)"
  89. type="primary"
  90. :underline="false"
  91. @click="handleFlow(row)"
  92. >流程</el-link
  93. >
  94. <el-link
  95. type="danger"
  96. :underline="false"
  97. @click="handleDelete(row)"
  98. >删除</el-link
  99. >
  100. </div>
  101. </template>
  102. </ele-pro-table>
  103. </div>
  104. </div>
  105. <add ref="addRef" @reload="reloadTable"> </add>
  106. </ele-modal>
  107. <!-- 审批流程(审批记录 + 高亮流程图) -->
  108. <ele-modal
  109. title="审批流程"
  110. :visible.sync="flowVisible"
  111. width="90%"
  112. append-to-body
  113. :close-on-click-modal="false"
  114. :maxable="true"
  115. >
  116. <flow v-if="flowVisible" :id="currentProcessInstanceId" />
  117. </ele-modal>
  118. </div>
  119. </template>
  120. <script>
  121. import tabMixins from '@/mixins/tableColumnsMixin';
  122. import dictMixins from '@/mixins/dictMixins';
  123. import dictEnum from '@/enum/dict';
  124. import add from './add.vue';
  125. import flow from '@/views/bpm/processInstance/detail.vue';
  126. import {
  127. ticketPage,
  128. ticketRemove,
  129. ticketSubmit,
  130. ticketGetById
  131. } from '@/api/dangerousWork';
  132. import {
  133. TICKET_STATUS,
  134. DRAFT_STATUS,
  135. REJECTED_STATUS,
  136. canSubmitStatus,
  137. canDeleteStatus,
  138. canEditStatus,
  139. getProcessDefinitionKey,
  140. getProcessInstanceId
  141. } from './constants';
  142. import { buildWorkTypeOptions, resolveWorkTypeLabel } from './workTypes';
  143. // 仅待提交(草稿)、已驳回状态的作业票可以删除
  144. const DELETE_TIP = '仅待提交(草稿)或已驳回状态的作业票可以删除';
  145. export default {
  146. mixins: [tabMixins, dictMixins],
  147. components: { add, flow },
  148. data() {
  149. return {
  150. visible: false,
  151. // 所属的危险作业
  152. work: {},
  153. // 表格选中的作业票
  154. selectedRows: [],
  155. // 正在提交审批的作业票 id
  156. submittingId: null,
  157. // 审批流程弹窗
  158. flowVisible: false,
  159. // 当前查看的流程实例 id
  160. currentProcessInstanceId: '',
  161. columns: [
  162. {
  163. columnKey: 'selection',
  164. type: 'selection',
  165. width: 50,
  166. align: 'center',
  167. fixed: 'left',
  168. // 只有待提交(草稿)、已驳回状态的作业票允许勾选,避免误删审批中或已通过的票
  169. selectable: (row) => this.canDelete(row)
  170. },
  171. {
  172. columnKey: 'index',
  173. label: '序号',
  174. type: 'index',
  175. width: 60,
  176. align: 'center'
  177. },
  178. {
  179. prop: 'workType',
  180. label: '作业类型',
  181. align: 'center',
  182. minWidth: 120,
  183. slot: 'workType'
  184. },
  185. {
  186. prop: 'applyDeptName',
  187. label: '申请单位',
  188. align: 'center',
  189. minWidth: 120,
  190. showOverflowTooltip: true
  191. },
  192. {
  193. prop: 'applicantName',
  194. label: '申请人',
  195. align: 'center',
  196. minWidth: 100
  197. },
  198. {
  199. prop: 'workLocation',
  200. label: '作业地点',
  201. align: 'center',
  202. minWidth: 140,
  203. showOverflowTooltip: true
  204. },
  205. {
  206. prop: 'startTime',
  207. label: '作业开始时间',
  208. align: 'center',
  209. minWidth: 160
  210. },
  211. {
  212. prop: 'endTime',
  213. label: '作业结束时间',
  214. align: 'center',
  215. minWidth: 160
  216. },
  217. {
  218. prop: 'status',
  219. label: '状态',
  220. align: 'center',
  221. minWidth: 100,
  222. slot: 'status'
  223. },
  224. {
  225. prop: 'createTime',
  226. label: '申请时间',
  227. align: 'center',
  228. minWidth: 160
  229. },
  230. {
  231. columnKey: 'action',
  232. label: '操作',
  233. width: 220,
  234. align: 'center',
  235. slot: 'action'
  236. }
  237. ],
  238. cacheKeyUrl: 'ehs-dangerousWorkTicket-list'
  239. };
  240. },
  241. computed: {
  242. seekList() {
  243. return [
  244. {
  245. label: '作业类型:',
  246. value: 'workType',
  247. type: 'select',
  248. width: 220,
  249. placeholder: '请选择作业类型',
  250. planList: this.workTypeList
  251. },
  252. {
  253. label: '申请人:',
  254. value: 'applicantName',
  255. type: 'input',
  256. width: 220,
  257. placeholder: '请输入申请人'
  258. },
  259. {
  260. label: '状态:',
  261. value: 'status',
  262. type: 'select',
  263. width: 220,
  264. placeholder: '请选择状态',
  265. planList: Object.keys(TICKET_STATUS).map((key) => ({
  266. label: TICKET_STATUS[key],
  267. value: Number(key)
  268. }))
  269. }
  270. ];
  271. },
  272. // 作业类型下拉(字典 ehs_hazardous_work_type)
  273. // 与申请作业票弹窗共用同一套构建逻辑,保证列表展示与申请页选择一致
  274. workTypeList() {
  275. return buildWorkTypeOptions(this.dict[dictEnum['危险作业类型']]);
  276. }
  277. },
  278. created() {
  279. this.requestDict('危险作业类型');
  280. },
  281. watch: {
  282. work: {
  283. immediate: true,
  284. handler(val) {
  285. // 首次打开弹窗时表格尚未挂载(el-dialog 懒渲染),由表格自身 mounted 触发加载;
  286. // 这里只处理弹窗已打开、切换所属危险作业的场景
  287. if (val?.id && this.$refs.table) {
  288. this.$refs.table.reload({ page: 1 });
  289. }
  290. }
  291. }
  292. },
  293. methods: {
  294. // 打开弹窗,work 可以是危险作业对象或危险作业id
  295. open(work) {
  296. this.work = work && work.id ? work : { id: work };
  297. // 重置上一次打开时残留的查询条件,保证界面条件与本次请求参数一致
  298. this.$refs.seekPage?.reset();
  299. this.visible = true;
  300. },
  301. handleAdd() {
  302. this.$refs.addRef.open(this.work);
  303. },
  304. // 查看作业票(详情由弹窗内部调 getById 查询,列表行数据不含作业票内容)
  305. handleView(row) {
  306. this.$refs.addRef.openTicket(row, this.work, 'view');
  307. },
  308. // 编辑作业票:待提交(草稿)与已驳回状态允许编辑
  309. handleEdit(row) {
  310. if (!this.canEdit(row)) {
  311. this.$message.warning('仅待提交(草稿)或已驳回状态的作业票可以编辑');
  312. return;
  313. }
  314. this.$refs.addRef.openTicket(row, this.work, 'edit');
  315. },
  316. // 提交作业票并发起审批流:审批流编码按作业类型取
  317. // 待提交(草稿)与已驳回状态都允许提交,已驳回的为重新提交
  318. handleSubmit(row) {
  319. if (!this.canSubmit(row)) {
  320. this.$message.warning('该作业票当前状态不可提交');
  321. return;
  322. }
  323. const processDefinitionKey = getProcessDefinitionKey(
  324. row.workType,
  325. this.getWorkTypeName(row.workType)
  326. );
  327. if (!processDefinitionKey) {
  328. this.$message.warning(
  329. '该作业类型暂未接入审批流,请联系管理员配置审批流编码'
  330. );
  331. return;
  332. }
  333. this.$confirm(
  334. Number(row?.status) === REJECTED_STATUS
  335. ? '该作业票已被驳回,重新提交后将重新发起审批流,确认提交吗?'
  336. : '提交后将发起审批流,作业票内容不可再修改,确认提交吗?',
  337. '提示',
  338. {
  339. confirmButtonText: '确定',
  340. cancelButtonText: '取消',
  341. type: 'warning'
  342. }
  343. )
  344. .then(() => {
  345. this.submittingId = row.id;
  346. return ticketSubmit({ id: row.id, processDefinitionKey })
  347. .then(async (data) => {
  348. this.$message.success('提交成功,已发起审批');
  349. this.reloadTable();
  350. // 提交后自动打开审批流程:优先用响应里的流程实例 id,没有则回查作业票详情
  351. // 已驳回重新提交时,行数据里是上一轮审批的实例 id,必须回查详情取最新一轮
  352. const processInstanceId =
  353. getProcessInstanceId(data) ||
  354. (await this.resolveProcessInstanceId(row, true));
  355. if (processInstanceId) {
  356. this.openFlow(processInstanceId);
  357. }
  358. })
  359. .finally(() => {
  360. this.submittingId = null;
  361. });
  362. })
  363. .catch(() => {});
  364. },
  365. // 查看审批流程
  366. async handleFlow(row) {
  367. const processInstanceId = await this.resolveProcessInstanceId(row);
  368. if (!processInstanceId) {
  369. this.$message.warning('该作业票暂无审批流程');
  370. return;
  371. }
  372. this.openFlow(processInstanceId);
  373. },
  374. // 打开审批流程弹窗
  375. openFlow(processInstanceId) {
  376. this.currentProcessInstanceId = processInstanceId;
  377. this.flowVisible = true;
  378. },
  379. // 取作业票的流程实例 id:优先用列表行数据,没有再查作业票详情
  380. // @param preferDetail 为 true 时直接查详情(行数据里的实例 id 可能是上一轮审批的)
  381. async resolveProcessInstanceId(row, preferDetail = false) {
  382. if (!preferDetail) {
  383. const fromRow = getProcessInstanceId(row);
  384. if (fromRow) {
  385. return fromRow;
  386. }
  387. }
  388. try {
  389. const detail = await ticketGetById(row.id, {
  390. showErrorToast: false
  391. });
  392. return getProcessInstanceId(detail);
  393. } catch (e) {
  394. return '';
  395. }
  396. },
  397. handleClose() {
  398. this.work = {};
  399. this.visible = false;
  400. },
  401. handleSearch(where) {
  402. this.reloadTable({ page: 1, where });
  403. },
  404. // 表格可能尚未挂载(弹窗首次打开时),此处统一做存在性判断
  405. reloadTable(option) {
  406. this.$refs.table && this.$refs.table.reload(option);
  407. },
  408. // 作业类型名称:后端字典值 -> 内置作业类型名称 -> 原始编码
  409. getWorkTypeName(workType) {
  410. return (
  411. resolveWorkTypeLabel(workType, this.dict[dictEnum['危险作业类型']]) ||
  412. '-'
  413. );
  414. },
  415. // 作业票状态名称
  416. getStatusName(status) {
  417. return TICKET_STATUS[status] || '-';
  418. },
  419. getStatusType(status) {
  420. const typeMap = {
  421. 1: 'info',
  422. 2: 'warning',
  423. 3: 'success',
  424. 4: 'danger'
  425. };
  426. return typeMap[status] || 'info';
  427. },
  428. handleDelete(row) {
  429. if (!this.canDelete(row)) {
  430. this.$message.warning(DELETE_TIP);
  431. return;
  432. }
  433. this.$confirm(
  434. Number(row?.status) === REJECTED_STATUS
  435. ? '确认删除该已驳回的作业票吗?删除后不可恢复。'
  436. : '确认删除该草稿作业票吗?删除后不可恢复。',
  437. '提示',
  438. {
  439. confirmButtonText: '确定',
  440. cancelButtonText: '取消',
  441. type: 'warning'
  442. }
  443. )
  444. .then(() => {
  445. ticketRemove([row.id]).then(() => {
  446. this.$message.success('删除成功');
  447. this.clearSelection();
  448. this.reloadTable();
  449. });
  450. })
  451. .catch(() => {});
  452. },
  453. // 批量删除:仅允许删除待提交(草稿)、已驳回状态的作业票
  454. handleBatchDelete() {
  455. const rows = this.selectedRows || [];
  456. if (!rows.length) {
  457. this.$message.warning('请至少选择一条数据');
  458. return;
  459. }
  460. if (rows.some((row) => !this.canDelete(row))) {
  461. this.$message.warning(DELETE_TIP);
  462. return;
  463. }
  464. this.$confirm(
  465. `确认删除选中的 ${rows.length} 条作业票吗?删除后不可恢复。`,
  466. '提示',
  467. {
  468. confirmButtonText: '确定',
  469. cancelButtonText: '取消',
  470. type: 'warning'
  471. }
  472. )
  473. .then(() => {
  474. ticketRemove(rows.map((row) => row.id)).then(() => {
  475. this.$message.success('删除成功');
  476. this.clearSelection();
  477. this.reloadTable();
  478. });
  479. })
  480. .catch(() => {});
  481. },
  482. // 是否草稿(待提交)状态:草稿没有审批流实例,因此不展示「流程」入口
  483. isDraft(row) {
  484. return Number(row?.status) === DRAFT_STATUS;
  485. },
  486. // 是否允许编辑:待提交(草稿)与已驳回都允许
  487. canEdit(row) {
  488. return canEditStatus(row?.status);
  489. },
  490. // 是否允许提交(发起审批):待提交(草稿)与已驳回都允许
  491. canSubmit(row) {
  492. return canSubmitStatus(row?.status);
  493. },
  494. // 是否允许删除:待提交(草稿)与已驳回都允许
  495. canDelete(row) {
  496. return canDeleteStatus(row?.status);
  497. },
  498. // 多选
  499. handleSelectionChange(rows) {
  500. this.selectedRows = rows || [];
  501. },
  502. // 清空选中项
  503. clearSelection() {
  504. this.selectedRows = [];
  505. this.$refs.table && this.$refs.table.clearSelection();
  506. },
  507. async datasource({ page, limit, where }) {
  508. const body = {
  509. ...where,
  510. workId: this.work.id,
  511. pageNum: page,
  512. size: limit
  513. };
  514. // 去掉未填写的查询条件,避免空字符串传给后端类型转换报错
  515. Object.keys(body).forEach((key) => {
  516. if (
  517. body[key] === '' ||
  518. body[key] === null ||
  519. body[key] === undefined
  520. ) {
  521. delete body[key];
  522. }
  523. });
  524. return await ticketPage(body);
  525. }
  526. }
  527. };
  528. </script>
  529. <style lang="scss" scoped>
  530. .search-area {
  531. margin-bottom: 15px;
  532. padding-bottom: 15px;
  533. border-bottom: 1px solid #ebeef5;
  534. }
  535. .list-view {
  536. ::v-deep .ele-pro-table {
  537. .el-table {
  538. border: 1px solid #ebeef5;
  539. border-radius: 4px;
  540. }
  541. }
  542. }
  543. .action-links {
  544. display: flex;
  545. flex-wrap: wrap;
  546. justify-content: center;
  547. gap: 8px;
  548. .el-link {
  549. font-size: 12px;
  550. }
  551. }
  552. </style>