<script lang="ts" setup>
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
import type { MesPdTechConfirmApi } from '#/api/mes/pd/tech-confirm';
|
|
import { Page, useVbenModal } from '@vben/common-ui';
|
import { $t } from '@vben/locales';
|
import { downloadFileFromBlobPart } from '@vben/utils';
|
|
import { ref } from 'vue';
|
|
import { MesPdTechConfirmStatusEnum } from '#/packages/constants/src';
|
|
import { Button, message } from 'ant-design-vue';
|
|
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
import {
|
deleteTechConfirm,
|
exportTechConfirm,
|
getTechConfirmApproverIds,
|
getTechConfirmPage,
|
submitTechConfirmAudit,
|
} from '#/api/mes/pd/tech-confirm';
|
import { useUserStore } from '@vben/stores';
|
|
import { useGridColumns, useGridFormSchema } from './data';
|
import AuditModal from './modules/audit-modal.vue';
|
import CustomerConfirmModal from './modules/customer-confirm-modal.vue';
|
import Form from './modules/form.vue';
|
|
const userStore = useUserStore();
|
const currentUserId = userStore.userInfo?.id; // 当前登录用户 ID,用于审核人权限判断
|
|
/** 审批配置中该业务的审核人编号集合,决定「审核 / 审核不通过」按钮是否展示 */
|
const approverIds = ref<number[]>([]);
|
|
/** 拉取审核人集合;失败时保持为空(按钮不展示),不阻断列表加载 */
|
async function loadApproverIds() {
|
try {
|
approverIds.value = (await getTechConfirmApproverIds()) ?? [];
|
} catch {
|
approverIds.value = [];
|
}
|
}
|
|
/** 当前登录用户是否为该业务的审核人,且单据处于待审核状态 */
|
function canAudit(row: MesPdTechConfirmApi.TechConfirm) {
|
return (
|
row.status === MesPdTechConfirmStatusEnum.PENDING_AUDIT &&
|
!!currentUserId &&
|
approverIds.value.includes(currentUserId)
|
);
|
}
|
|
const [FormModal, formModalApi] = useVbenModal({
|
connectedComponent: Form,
|
destroyOnClose: true,
|
});
|
|
const [AuditModalComp, auditModalApi] = useVbenModal({
|
connectedComponent: AuditModal,
|
destroyOnClose: true,
|
});
|
|
const [CustomerConfirm, customerConfirmApi] = useVbenModal({
|
connectedComponent: CustomerConfirmModal,
|
destroyOnClose: true,
|
});
|
|
/** 刷新表格与审核人集合 */
|
function handleRefresh() {
|
gridApi.query();
|
loadApproverIds();
|
}
|
|
/** 新增 */
|
function handleCreate() {
|
formModalApi.setData({ formType: 'create' }).open();
|
}
|
|
/** 查看 */
|
function handleDetail(row: MesPdTechConfirmApi.TechConfirm) {
|
formModalApi.setData({ id: row.id, formType: 'detail' }).open();
|
}
|
|
/** 编辑 */
|
function handleEdit(row: MesPdTechConfirmApi.TechConfirm) {
|
formModalApi.setData({ id: row.id, formType: 'update' }).open();
|
}
|
|
/** 删除 */
|
async function handleDelete(row: MesPdTechConfirmApi.TechConfirm) {
|
const hideLoading = message.loading({
|
content: $t('ui.actionMessage.deleting', [row.confirmNo ?? '']),
|
duration: 0,
|
});
|
try {
|
await deleteTechConfirm(row.id!);
|
message.success($t('ui.actionMessage.deleteSuccess', [row.confirmNo ?? '']));
|
handleRefresh();
|
} finally {
|
hideLoading();
|
}
|
}
|
|
/** 提交审核 - 审核人由「系统管理 - 审批配置」统一指定,此处无需选择 */
|
async function handleSubmitAudit(row: MesPdTechConfirmApi.TechConfirm) {
|
const hideLoading = message.loading({
|
content: '正在提交审核...',
|
duration: 0,
|
});
|
try {
|
await submitTechConfirmAudit(row.id!);
|
message.success('提交审核成功');
|
handleRefresh();
|
} finally {
|
hideLoading();
|
}
|
}
|
|
/** 审核 - 通过 / 不通过 */
|
function handleAudit(row: MesPdTechConfirmApi.TechConfirm, pass: boolean) {
|
auditModalApi.setData({ pass, row }).open();
|
}
|
|
/** 客户确认 - 记录客户确认人,由后端写入确认时间 */
|
function handleCustomerConfirm(row: MesPdTechConfirmApi.TechConfirm) {
|
customerConfirmApi
|
.setData({
|
id: row.id,
|
confirmNo: row.confirmNo,
|
customerName: row.customerName,
|
})
|
.open();
|
}
|
|
/** 导出 */
|
async function handleExport() {
|
const data = await exportTechConfirm(await gridApi.formApi.getValues());
|
downloadFileFromBlobPart({ fileName: '产品技术确认函.xls', source: data });
|
}
|
|
const [Grid, gridApi] = useVbenVxeGrid({
|
formOptions: {
|
schema: useGridFormSchema(),
|
},
|
gridOptions: {
|
columns: useGridColumns(),
|
height: 'auto',
|
keepSource: true,
|
proxyConfig: {
|
ajax: {
|
query: async ({ page }, formValues) =>
|
await getTechConfirmPage({
|
pageNo: page.currentPage,
|
pageSize: page.pageSize,
|
...formValues,
|
}),
|
},
|
},
|
rowConfig: {
|
keyField: 'id',
|
isHover: true,
|
},
|
toolbarConfig: {
|
refresh: true,
|
search: true,
|
},
|
} as VxeTableGridOptions<MesPdTechConfirmApi.TechConfirm>,
|
});
|
|
// 进入页面即拉取审核人集合,用于控制审核按钮显隐
|
loadApproverIds();
|
</script>
|
|
<template>
|
<Page auto-content-height>
|
<FormModal @success="handleRefresh" />
|
<AuditModalComp @success="handleRefresh" />
|
<CustomerConfirm @success="handleRefresh" />
|
<Grid table-title="产品技术确认函列表">
|
<template #toolbar-tools>
|
<TableAction
|
:actions="[
|
{
|
label: $t('ui.actionTitle.create', ['技术确认函']),
|
type: 'primary',
|
icon: ACTION_ICON.ADD,
|
auth: ['mes:pd-tech-confirm:create'],
|
onClick: handleCreate,
|
},
|
{
|
label: $t('ui.actionTitle.export'),
|
type: 'primary',
|
icon: ACTION_ICON.DOWNLOAD,
|
auth: ['mes:pd-tech-confirm:export'],
|
onClick: handleExport,
|
},
|
]"
|
/>
|
</template>
|
<template #confirmNo="{ row }">
|
<Button type="link" @click="handleDetail(row)">
|
{{ row.confirmNo }}
|
</Button>
|
</template>
|
<template #actions="{ row }">
|
<TableAction
|
:actions="[
|
{
|
label: '提交审核',
|
type: 'link',
|
icon: ACTION_ICON.AUDIT,
|
auth: ['mes:pd-tech-confirm:update'],
|
// 草稿与审核不通过均可提交,审核不通过需修改后重新提交
|
ifShow:
|
row.status === MesPdTechConfirmStatusEnum.DRAFT ||
|
row.status === MesPdTechConfirmStatusEnum.REJECTED,
|
// 审核人由审批配置统一指定,提交前仅二次确认,不再弹选人框
|
popConfirm: {
|
title: '确认提交审核?提交后由审批配置中指定的审核人处理。',
|
confirm: handleSubmitAudit.bind(null, row),
|
},
|
},
|
{
|
label: '审核',
|
type: 'link',
|
icon: ACTION_ICON.AUDIT,
|
auth: ['mes:pd-tech-confirm:audit'],
|
// 仅「待审核 + 当前登录用户在审批配置的审核人名单内」才显示
|
ifShow: canAudit(row),
|
onClick: handleAudit.bind(null, row, true),
|
},
|
{
|
label: '审核不通过',
|
type: 'link',
|
danger: true,
|
auth: ['mes:pd-tech-confirm:audit'],
|
// 同上,与「审核」成对出现
|
ifShow: canAudit(row),
|
onClick: handleAudit.bind(null, row, false),
|
},
|
{
|
label: '客户确认',
|
type: 'link',
|
icon: ACTION_ICON.AUDIT,
|
auth: ['mes:pd-tech-confirm:update'],
|
ifShow: row.status === MesPdTechConfirmStatusEnum.AUDITED,
|
onClick: handleCustomerConfirm.bind(null, row),
|
},
|
{
|
label: $t('common.edit'),
|
type: 'link',
|
icon: ACTION_ICON.EDIT,
|
auth: ['mes:pd-tech-confirm:update'],
|
// 仅草稿与审核不通过可修改,其余状态单据已锁定
|
ifShow:
|
row.status === MesPdTechConfirmStatusEnum.DRAFT ||
|
row.status === MesPdTechConfirmStatusEnum.REJECTED,
|
onClick: handleEdit.bind(null, row),
|
},
|
{
|
label: $t('common.delete'),
|
type: 'link',
|
danger: true,
|
icon: ACTION_ICON.DELETE,
|
auth: ['mes:pd-tech-confirm:delete'],
|
// 仅草稿与审核不通过可删除
|
ifShow:
|
row.status === MesPdTechConfirmStatusEnum.DRAFT ||
|
row.status === MesPdTechConfirmStatusEnum.REJECTED,
|
popConfirm: {
|
title: $t('ui.actionMessage.deleteConfirm', [row.confirmNo ?? '']),
|
confirm: handleDelete.bind(null, row),
|
},
|
},
|
{
|
label: $t('common.detail'),
|
type: 'link',
|
icon: ACTION_ICON.VIEW,
|
auth: ['mes:pd-tech-confirm:query'],
|
onClick: handleDetail.bind(null, row),
|
},
|
]"
|
/>
|
</template>
|
</Grid>
|
</Page>
|
</template>
|