| | |
| | | import type { VxeTableGridOptions } from '#/adapter/vxe-table'; |
| | | import type { ErpPurchaseRequestApi } from '#/api/erp/purchase/request'; |
| | | |
| | | import { ref } from 'vue'; |
| | | import { onMounted, ref } from 'vue'; |
| | | import { useRouter } from 'vue-router'; |
| | | |
| | | import { confirm, Page, useVbenModal } from '@vben/common-ui'; |
| | | import { Page, useVbenModal } from '@vben/common-ui'; |
| | | import { useUserStore } from '@vben/stores'; |
| | | import { downloadFileFromBlobPart, isEmpty } from '@vben/utils'; |
| | | |
| | | import { message, Tag } from 'ant-design-vue'; |
| | |
| | | import { |
| | | deletePurchaseRequest, |
| | | exportPurchaseRequest, |
| | | getApproveProcessList, |
| | | getPurchaseRequestApproverUserIds, |
| | | getPurchaseRequestPage, |
| | | submitPurchaseRequest, |
| | | } from '#/api/erp/purchase/request'; |
| | | import { $t } from '#/locales'; |
| | | |
| | | import { useGridColumns, useGridFormSchema } from './data'; |
| | | import AuditModal from './modules/audit-modal.vue'; |
| | | import Form from './modules/form.vue'; |
| | | import OrderForm from './modules/order-form.vue'; |
| | | import ProcessSelectModal from './modules/process-select-modal.vue'; |
| | | |
| | | /** ERP 采购申请列表 */ |
| | | defineOptions({ name: 'ErpPurchaseRequest' }); |
| | | |
| | | const router = useRouter(); |
| | | const userStore = useUserStore(); |
| | | |
| | | /** 当前业务类型的审批人编号集合,用于判断是否展示审核按钮 */ |
| | | const approverIds = ref<number[]>([]); |
| | | /** 当前登录用户编号 */ |
| | | const currentUserId = userStore.userInfo?.id; |
| | | |
| | | 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(); |
| | | } |
| | | |
| | | /** 加载当前业务类型的审批人编号集合 */ |
| | | async function loadApproverIds() { |
| | | try { |
| | | approverIds.value = (await getPurchaseRequestApproverUserIds()) ?? []; |
| | | } catch { |
| | | approverIds.value = []; |
| | | } |
| | | } |
| | | |
| | | /** 当前用户是否为该业务类型的审批人,且单据处于审批中 */ |
| | | function canAudit(row: ErpPurchaseRequestApi.PurchaseRequest) { |
| | | return ( |
| | | row.status === 10 && approverIds.value.includes(currentUserId as number) |
| | | ); |
| | | } |
| | | |
| | | /** 导出表格 */ |
| | |
| | | } |
| | | } |
| | | |
| | | /** 提交审批 - 先获取流程列表 */ |
| | | /** 提交审核 - 后端按审批配置校验审批人,无需前端选择流程 */ |
| | | async function handleSubmit(row: ErpPurchaseRequestApi.PurchaseRequest) { |
| | | const hideLoading = message.loading({ |
| | | content: '获取审批流程...', |
| | | content: '正在提交审核...', |
| | | duration: 0, |
| | | }); |
| | | try { |
| | | const processList = await getApproveProcessList(row.id!); |
| | | hideLoading(); |
| | | if (!processList || processList.length === 0) { |
| | | message.warning('暂无可用审批流程,请先配置 BPM 流程'); |
| | | return; |
| | | } |
| | | // 打开流程选择弹窗 |
| | | processModalApi.setData({ id: row.id, processList }).open(); |
| | | } catch { |
| | | await submitPurchaseRequest(row.id!); |
| | | message.success('提交成功,等待审批人审核'); |
| | | handleRefresh(); |
| | | } finally { |
| | | hideLoading(); |
| | | } |
| | | } |
| | | |
| | | /** 审核 - 通过 / 不通过 */ |
| | | function handleAudit(row: ErpPurchaseRequestApi.PurchaseRequest, pass: boolean) { |
| | | auditModalApi.setData({ pass, row }).open(); |
| | | } |
| | | |
| | | /** 生成采购订单 */ |
| | |
| | | formModalApi.setData({ formType: 'detail', id: row.id }).open(); |
| | | } |
| | | |
| | | /** 查看审批详情 */ |
| | | /** 查看审批记录 - 轻量级审批不再跳转 BPM 流程详情 */ |
| | | function handleViewProcess(row: ErpPurchaseRequestApi.PurchaseRequest) { |
| | | if (!row.processInstanceId) { |
| | | message.warning('该申请尚未提交审批'); |
| | | const parts: string[] = []; |
| | | if (row.reviewerName) { |
| | | parts.push(`审核人:${row.reviewerName}`); |
| | | } |
| | | if (row.reviewTime) { |
| | | parts.push(`审核时间:${row.reviewTime}`); |
| | | } |
| | | if (row.reviewRemark) { |
| | | parts.push( |
| | | `${row.status === 30 ? '不通过原因' : '审核意见'}:${row.reviewRemark}`, |
| | | ); |
| | | } |
| | | if (parts.length === 0) { |
| | | message.info('该申请暂无审核记录'); |
| | | return; |
| | | } |
| | | router.push({ name: 'BpmProcessInstanceDetail', query: { id: row.processInstanceId } }); |
| | | message.info(parts.join(' ')); |
| | | } |
| | | |
| | | /** 查看采购订单 */ |
| | |
| | | checkboxChange: handleRowCheckboxChange, |
| | | }, |
| | | }); |
| | | |
| | | onMounted(() => { |
| | | loadApproverIds(); |
| | | }); |
| | | </script> |
| | | |
| | | <template> |
| | | <Page auto-content-height> |
| | | <FormModal @success="handleRefresh" /> |
| | | <OrderFormModal @success="handleRefresh" /> |
| | | <ProcessModal @success="handleRefresh" /> |
| | | <AuditModalComp @success="handleRefresh" /> |
| | | <Grid table-title="采购申请列表"> |
| | | <template #toolbar-tools> |
| | | <TableAction |
| | |
| | | { |
| | | label: '提交', |
| | | type: 'link', |
| | | auth: ['erp:purchase-request:submit'], |
| | | // 未提交与审核不通过均可提交,审核不通过需修改后重新提交 |
| | | ifShow: () => row.status === 0 || row.status === 30, |
| | | onClick: handleSubmit.bind(null, row), |
| | | }, |
| | | { |
| | | label: '审核', |
| | | type: 'link', |
| | | icon: ACTION_ICON.AUDIT, |
| | | auth: ['erp:purchase-request:audit'], |
| | | // 仅「审批中 + 当前登录用户是审批人」才显示,其他人看不到该按钮 |
| | | ifShow: canAudit(row), |
| | | onClick: handleAudit.bind(null, row, true), |
| | | }, |
| | | { |
| | | label: '审核不通过', |
| | | type: 'link', |
| | | danger: true, |
| | | icon: ACTION_ICON.AUDIT, |
| | | auth: ['erp:purchase-request:audit'], |
| | | ifShow: canAudit(row), |
| | | onClick: handleAudit.bind(null, row, false), |
| | | }, |
| | | { |
| | | label: '生成订单', |
| | |
| | | { |
| | | label: '查看审批', |
| | | type: 'link', |
| | | ifShow: () => row.status !== 0, |
| | | ifShow: () => row.status === 20 || row.status === 30, |
| | | onClick: handleViewProcess.bind(null, row), |
| | | }, |
| | | { |