workTicketDialog.vue 16 KB

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