workTicketDialog.vue 17 KB

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