| | |
| | | import type { VxeTableGridOptions } from '#/adapter/vxe-table'; |
| | | import type { MesWmMiscReceiptApi } from '#/api/mes/wm/miscreceipt'; |
| | | |
| | | import { useRouter } from 'vue-router'; |
| | | import { ref } from 'vue'; |
| | | |
| | | import { Page, useVbenModal } from '@vben/common-ui'; |
| | | import { MesWmMiscReceiptStatusEnum } from '@vben/constants'; |
| | | import { useUserStore } from '@vben/stores'; |
| | | import { downloadFileFromBlobPart } from '@vben/utils'; |
| | | |
| | | import { Button, message } from 'ant-design-vue'; |
| | |
| | | cancelMiscReceipt, |
| | | deleteMiscReceipt, |
| | | exportMiscReceipt, |
| | | getMiscReceiptApproveProcessList, |
| | | getMiscReceiptApproverIds, |
| | | getMiscReceiptPage, |
| | | submitMiscReceiptApproval, |
| | | } from '#/api/mes/wm/miscreceipt'; |
| | | import { $t } from '#/locales'; |
| | | |
| | | import ProcessSelectModal from '#/views/wls/components/process-select-modal.vue'; |
| | | import { useGridColumns, useGridFormSchema } from './data'; |
| | | import AuditModal from './modules/audit-modal.vue'; |
| | | import Form from './modules/form.vue'; |
| | | |
| | | const router = useRouter(); |
| | | const userStore = useUserStore(); |
| | | const currentUserId = userStore.userInfo?.id; // 当前登录用户 ID,用于审核人权限判断 |
| | | |
| | | /** 审批配置中该业务的审核人编号集合,决定「审核 / 审核不通过」按钮是否展示 */ |
| | | const approverIds = ref<number[]>([]); |
| | | |
| | | /** 拉取审核人集合;失败时保持为空(按钮不展示),不阻断列表加载 */ |
| | | async function loadApproverIds() { |
| | | try { |
| | | approverIds.value = (await getMiscReceiptApproverIds()) ?? []; |
| | | } catch { |
| | | approverIds.value = []; |
| | | } |
| | | } |
| | | |
| | | /** 当前登录用户是否为该业务的审核人,且单据处于审批中状态 */ |
| | | function canAudit(row: MesWmMiscReceiptApi.MiscReceipt) { |
| | | return ( |
| | | row.status === MesWmMiscReceiptStatusEnum.APPROVING && |
| | | !!currentUserId && |
| | | approverIds.value.includes(currentUserId) |
| | | ); |
| | | } |
| | | |
| | | const [FormModal, formModalApi] = useVbenModal({ |
| | | connectedComponent: Form, |
| | | destroyOnClose: true, |
| | | }); |
| | | |
| | | const [ProcessModal, processModalApi] = useVbenModal({ |
| | | connectedComponent: ProcessSelectModal, |
| | | const [AuditModalComp, auditModalApi] = useVbenModal({ |
| | | connectedComponent: AuditModal, |
| | | destroyOnClose: true, |
| | | }); |
| | | |
| | | /** 刷新表格 */ |
| | | /** 刷新表格与审核人集合 */ |
| | | function handleRefresh() { |
| | | gridApi.query(); |
| | | loadApproverIds(); |
| | | } |
| | | |
| | | /** 创建杂项入库单 */ |
| | |
| | | formModalApi.setData({ formType: 'finish', id: row.id }).open(); |
| | | } |
| | | |
| | | /** 提交审批 - 先获取流程列表 */ |
| | | /** 提交审批 - 审核人由「系统管理 - 审批配置」统一指定,此处无需选择 */ |
| | | async function handleSubmitApproval(row: MesWmMiscReceiptApi.MiscReceipt) { |
| | | const hideLoading = message.loading({ |
| | | content: '获取审批流程...', |
| | | content: '正在提交审批...', |
| | | duration: 0, |
| | | }); |
| | | try { |
| | | const processList = await getMiscReceiptApproveProcessList(); |
| | | hideLoading(); |
| | | if (!processList || processList.length === 0) { |
| | | message.warning('暂无可用审批流程,请先配置 BPM 流程'); |
| | | return; |
| | | } |
| | | processModalApi |
| | | .setData({ |
| | | id: row.id, |
| | | processList, |
| | | submitFn: submitMiscReceiptApproval, |
| | | }) |
| | | .open(); |
| | | } catch { |
| | | await submitMiscReceiptApproval(row.id!); |
| | | message.success('提交审批成功'); |
| | | handleRefresh(); |
| | | } finally { |
| | | hideLoading(); |
| | | } |
| | | } |
| | | |
| | | /** 查看审批详情 */ |
| | | function handleProcessDetail(row: MesWmMiscReceiptApi.MiscReceipt) { |
| | | if (!row.processInstanceId) { |
| | | message.warning('该单据尚未提交审批'); |
| | | return; |
| | | } |
| | | router.push({ |
| | | name: 'BpmProcessInstanceDetail', |
| | | query: { id: row.processInstanceId }, |
| | | }); |
| | | /** 审核 - 通过 / 不通过 */ |
| | | function handleAudit(row: MesWmMiscReceiptApi.MiscReceipt, pass: boolean) { |
| | | auditModalApi.setData({ pass, row }).open(); |
| | | } |
| | | |
| | | /** 删除杂项入库单 */ |
| | |
| | | }, |
| | | } as VxeTableGridOptions<MesWmMiscReceiptApi.MiscReceipt>, |
| | | }); |
| | | |
| | | // 进入页面即拉取审核人集合,用于控制审核按钮显隐 |
| | | loadApproverIds(); |
| | | </script> |
| | | |
| | | <template> |
| | | <Page auto-content-height><FormModal @success="handleRefresh" /> |
| | | <ProcessModal @success="handleRefresh" /> |
| | | <Page auto-content-height> |
| | | <FormModal @success="handleRefresh" /> |
| | | <AuditModalComp @success="handleRefresh" /> |
| | | |
| | | <Grid table-title="杂项入库单列表"> |
| | | <template #toolbar-tools> |
| | |
| | | type: 'link', |
| | | auth: ['mes:wm:misc-receipt:submit'], |
| | | ifShow: row.status === MesWmMiscReceiptStatusEnum.PREPARE, |
| | | onClick: handleSubmitApproval.bind(null, row), |
| | | // 审核人由审批配置统一指定,提交前仅二次确认,不再弹选流程框 |
| | | popConfirm: { |
| | | title: '确认提交审批?提交后由审批配置中指定的审核人处理。', |
| | | confirm: handleSubmitApproval.bind(null, row), |
| | | }, |
| | | }, |
| | | { |
| | | label: '查看审批', |
| | | label: '审核', |
| | | type: 'link', |
| | | auth: ['mes:wm:misc-receipt:query'], |
| | | ifShow: row.status === MesWmMiscReceiptStatusEnum.APPROVING, |
| | | onClick: handleProcessDetail.bind(null, row), |
| | | icon: ACTION_ICON.AUDIT, |
| | | auth: ['mes:wm:misc-receipt:audit'], |
| | | // 仅「审批中 + 当前登录用户在审批配置的审核人名单内」才显示 |
| | | ifShow: canAudit(row), |
| | | onClick: handleAudit.bind(null, row, true), |
| | | }, |
| | | { |
| | | label: '审核不通过', |
| | | type: 'link', |
| | | danger: true, |
| | | auth: ['mes:wm:misc-receipt:audit'], |
| | | // 同上,与「审核」成对出现 |
| | | ifShow: canAudit(row), |
| | | onClick: handleAudit.bind(null, row, false), |
| | | }, |
| | | { |
| | | label: '执行入库', |