<script lang="ts" setup>
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
import type { ErpPurchaseRequestApi } from '#/api/erp/purchase/request';
|
|
import { ref } from 'vue';
|
|
import { confirm, Page, useVbenModal } from '@vben/common-ui';
|
import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
|
|
import { message, Tag } from 'ant-design-vue';
|
|
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
import {
|
deletePurchaseRequest,
|
exportPurchaseRequest,
|
getApproveProcessList,
|
getPurchaseRequestPage,
|
submitPurchaseRequest,
|
} from '#/api/erp/purchase/request';
|
import { $t } from '#/locales';
|
|
import { useGridColumns, useGridFormSchema } from './data';
|
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 [FormModal, formModalApi] = useVbenModal({
|
connectedComponent: Form,
|
destroyOnClose: true,
|
});
|
|
const [OrderFormModal, orderFormModalApi] = useVbenModal({
|
connectedComponent: OrderForm,
|
destroyOnClose: true,
|
});
|
|
const [ProcessModal, processModalApi] = useVbenModal({
|
connectedComponent: ProcessSelectModal,
|
destroyOnClose: true,
|
});
|
|
/** 刷新表格 */
|
function handleRefresh() {
|
gridApi.query();
|
}
|
|
/** 导出表格 */
|
async function handleExport() {
|
const data = await exportPurchaseRequest(await gridApi.formApi.getValues());
|
downloadFileFromBlobPart({ fileName: '采购申请.xls', source: data });
|
}
|
|
/** 新增采购申请 */
|
function handleCreate() {
|
formModalApi.setData({ formType: 'create' }).open();
|
}
|
|
/** 编辑采购申请 */
|
function handleEdit(row: ErpPurchaseRequestApi.PurchaseRequest) {
|
formModalApi.setData({ formType: 'edit', id: row.id }).open();
|
}
|
|
/** 删除采购申请 */
|
async function handleDelete(ids: number[]) {
|
const hideLoading = message.loading({
|
content: $t('ui.actionMessage.deleting'),
|
duration: 0,
|
});
|
try {
|
await deletePurchaseRequest(ids);
|
message.success($t('ui.actionMessage.deleteSuccess'));
|
handleRefresh();
|
} finally {
|
hideLoading();
|
}
|
}
|
|
/** 提交审批 - 先获取流程列表 */
|
async function handleSubmit(row: ErpPurchaseRequestApi.PurchaseRequest) {
|
const hideLoading = message.loading({
|
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 {
|
hideLoading();
|
}
|
}
|
|
/** 生成采购订单 */
|
function handleGenerateOrder(row: ErpPurchaseRequestApi.PurchaseRequest) {
|
orderFormModalApi.setData({ id: row.id, supplierId: row.supplierId }).open();
|
}
|
|
const checkedIds = ref<number[]>([]);
|
function handleRowCheckboxChange({
|
records,
|
}: {
|
records: ErpPurchaseRequestApi.PurchaseRequest[];
|
}) {
|
checkedIds.value = records.map((item) => item.id!);
|
}
|
|
/** 查看详情 */
|
function handleDetail(row: ErpPurchaseRequestApi.PurchaseRequest) {
|
formModalApi.setData({ formType: 'detail', id: row.id }).open();
|
}
|
|
const [Grid, gridApi] = useVbenVxeGrid({
|
formOptions: {
|
schema: useGridFormSchema(),
|
},
|
gridOptions: {
|
columns: useGridColumns(),
|
height: 'auto',
|
keepSource: true,
|
proxyConfig: {
|
ajax: {
|
query: async ({ page }, formValues) => {
|
return await getPurchaseRequestPage({
|
pageNo: page.currentPage,
|
pageSize: page.pageSize,
|
...formValues,
|
});
|
},
|
},
|
},
|
rowConfig: {
|
keyField: 'id',
|
isHover: true,
|
},
|
toolbarConfig: {
|
refresh: true,
|
search: true,
|
},
|
} as VxeTableGridOptions<ErpPurchaseRequestApi.PurchaseRequest>,
|
gridEvents: {
|
checkboxAll: handleRowCheckboxChange,
|
checkboxChange: handleRowCheckboxChange,
|
},
|
});
|
</script>
|
|
<template>
|
<Page auto-content-height>
|
<FormModal @success="handleRefresh" />
|
<OrderFormModal @success="handleRefresh" />
|
<ProcessModal @success="handleRefresh" />
|
<Grid table-title="采购申请列表">
|
<template #toolbar-tools>
|
<TableAction
|
:actions="[
|
{
|
label: $t('ui.actionTitle.create', ['采购申请']),
|
type: 'primary',
|
icon: ACTION_ICON.ADD,
|
auth: ['erp:purchase-request:create'],
|
onClick: handleCreate,
|
},
|
{
|
label: $t('ui.actionTitle.export'),
|
type: 'primary',
|
icon: ACTION_ICON.DOWNLOAD,
|
auth: ['erp:purchase-request:export'],
|
onClick: handleExport,
|
},
|
{
|
label: '批量删除',
|
type: 'primary',
|
danger: true,
|
disabled: isEmpty(checkedIds),
|
icon: ACTION_ICON.DELETE,
|
auth: ['erp:purchase-request:delete'],
|
popConfirm: {
|
title: `是否删除所选中数据?`,
|
confirm: handleDelete.bind(null, checkedIds),
|
},
|
},
|
]"
|
/>
|
</template>
|
<template #status="{ row }">
|
<Tag v-if="row.status === 0" color="default">未提交</Tag>
|
<Tag v-else-if="row.status === 10" color="processing">审批中</Tag>
|
<Tag v-else-if="row.status === 20" color="success">审核通过</Tag>
|
<Tag v-else-if="row.status === 30" color="error">审核不通过</Tag>
|
<Tag v-else-if="row.status === 40" color="warning">已取消</Tag>
|
</template>
|
<template #inStatus="{ row }">
|
<Tag v-if="row.inStatus === 0" color="default">未入库</Tag>
|
<Tag v-else-if="row.inStatus === 1" color="warning">部分入库</Tag>
|
<Tag v-else-if="row.inStatus === 2" color="success">全部入库</Tag>
|
</template>
|
<template #actions="{ row }">
|
<TableAction
|
:actions="[
|
{
|
label: $t('common.detail'),
|
type: 'link',
|
icon: ACTION_ICON.VIEW,
|
auth: ['erp:purchase-request:query'],
|
onClick: handleDetail.bind(null, row),
|
},
|
{
|
label: $t('common.edit'),
|
type: 'link',
|
icon: ACTION_ICON.EDIT,
|
auth: ['erp:purchase-request:update'],
|
ifShow: () => row.status === 0,
|
onClick: handleEdit.bind(null, row),
|
},
|
{
|
label: '提交',
|
type: 'link',
|
ifShow: () => row.status === 0 || row.status === 30,
|
onClick: handleSubmit.bind(null, row),
|
},
|
{
|
label: '生成订单',
|
type: 'link',
|
auth: ['erp:purchase-request:generate-order'],
|
ifShow: () => row.status === 20 && !row.orderId,
|
onClick: handleGenerateOrder.bind(null, row),
|
},
|
{
|
label: $t('common.delete'),
|
type: 'link',
|
danger: true,
|
icon: ACTION_ICON.DELETE,
|
auth: ['erp:purchase-request:delete'],
|
ifShow: () => row.status === 0,
|
popConfirm: {
|
title: $t('ui.actionMessage.deleteConfirm', [row.no]),
|
confirm: handleDelete.bind(null, [row.id!]),
|
},
|
},
|
]"
|
/>
|
</template>
|
</Grid>
|
</Page>
|
</template>
|