<script lang="ts" setup>
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
import type { MesWmStockTakingTaskApi } from '#/api/mes/wm/stocktaking/task';
|
|
import { ref } from 'vue';
|
|
import { Page, useVbenModal } from '@vben/common-ui';
|
import { MesWmStockTakingTaskStatusEnum } from '@vben/constants';
|
import { downloadFileFromBlobPart } from '@vben/utils';
|
|
import { Button, message } from 'ant-design-vue';
|
|
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
import {
|
cancelStockTaking,
|
deleteStockTaking,
|
exportStockTaking,
|
getStockTakingPage,
|
} from '#/api/mes/wm/stocktaking/task';
|
import {
|
importStockTakingQuantity,
|
importStockTakingQuantityTemplate,
|
} from '#/api/wls/stocktaking/task/line';
|
import { $t } from '#/locales';
|
|
import { useGridColumns, useGridFormSchema } from './data';
|
import Form from './modules/form.vue';
|
|
const [FormModal, formModalApi] = useVbenModal({
|
connectedComponent: Form,
|
destroyOnClose: true,
|
});
|
|
/** 刷新表格 */
|
function handleRefresh() {
|
gridApi.query();
|
}
|
|
/** 创建盘点任务 */
|
function handleCreate() {
|
formModalApi.setData({ formType: 'create' }).open();
|
}
|
|
/** 查看盘点任务 */
|
function handleDetail(row: MesWmStockTakingTaskApi.StockTakingTask) {
|
formModalApi.setData({ formType: 'detail', id: row.id }).open();
|
}
|
|
/** 编辑盘点任务 */
|
function handleEdit(row: MesWmStockTakingTaskApi.StockTakingTask) {
|
formModalApi.setData({ formType: 'update', id: row.id }).open();
|
}
|
|
/** 提交盘点任务 */
|
function handleSubmit(row: MesWmStockTakingTaskApi.StockTakingTask) {
|
formModalApi.setData({ formType: 'submit', id: row.id }).open();
|
}
|
|
/** 执行盘点 */
|
function handleExecute(row: MesWmStockTakingTaskApi.StockTakingTask) {
|
formModalApi.setData({ formType: 'execute', id: row.id }).open();
|
}
|
|
/** 取消盘点任务 */
|
async function handleCancel(row: MesWmStockTakingTaskApi.StockTakingTask) {
|
await cancelStockTaking(row.id!);
|
message.success('取消成功');
|
handleRefresh();
|
}
|
|
/** 删除盘点任务 */
|
async function handleDelete(row: MesWmStockTakingTaskApi.StockTakingTask) {
|
const hideLoading = message.loading({
|
content: $t('ui.actionMessage.deleting', [row.code]),
|
duration: 0,
|
});
|
try {
|
await deleteStockTaking(row.id!);
|
message.success($t('ui.actionMessage.deleteSuccess', [row.code]));
|
handleRefresh();
|
} finally {
|
hideLoading();
|
}
|
}
|
|
/** 导出表格 */
|
async function handleExport() {
|
const data = await exportStockTaking(await gridApi.formApi.getValues());
|
downloadFileFromBlobPart({ fileName: '盘点任务.xls', source: data });
|
}
|
|
/** 下载盘点导入模板 */
|
async function handleImportTemplate() {
|
const data = await importStockTakingQuantityTemplate();
|
downloadFileFromBlobPart({ fileName: '盘点实盘数导入模板.xls', source: data });
|
}
|
|
const importFileRef = ref<HTMLInputElement>();
|
const importTaskId = ref<number>();
|
|
/** 触发导入文件选择 */
|
function handleImport(row: MesWmStockTakingTaskApi.StockTakingTask) {
|
importTaskId.value = row.id!;
|
importFileRef.value?.click();
|
}
|
|
/** 导入实盘数文件选择后上传 */
|
async function handleImportFileChange(event: Event) {
|
const file = (event.target as HTMLInputElement).files?.[0];
|
if (!file || !importTaskId.value) {
|
return;
|
}
|
const hideLoading = message.loading({ content: '正在导入实盘数...', duration: 0 });
|
try {
|
const result = await importStockTakingQuantity(importTaskId.value, file);
|
message.success(`导入完成:成功 ${result.successCount ?? 0} 条,失败 ${result.failureCount ?? 0} 条`);
|
if (result.failureMessages?.length) {
|
message.warning(result.failureMessages.slice(0, 5).join(';'));
|
}
|
handleRefresh();
|
} finally {
|
(event.target as HTMLInputElement).value = '';
|
hideLoading();
|
}
|
}
|
|
const [Grid, gridApi] = useVbenVxeGrid({
|
formOptions: {
|
schema: useGridFormSchema(),
|
},
|
gridOptions: {
|
columns: useGridColumns(),
|
height: 'auto',
|
keepSource: true,
|
proxyConfig: {
|
ajax: {
|
query: async ({ page }, formValues) => {
|
return await getStockTakingPage({
|
pageNo: page.currentPage,
|
pageSize: page.pageSize,
|
...formValues,
|
});
|
},
|
},
|
},
|
rowConfig: {
|
keyField: 'id',
|
isHover: true,
|
},
|
toolbarConfig: {
|
refresh: true,
|
search: true,
|
},
|
} as VxeTableGridOptions<MesWmStockTakingTaskApi.StockTakingTask>,
|
});
|
|
const StatusEnum = MesWmStockTakingTaskStatusEnum;
|
</script>
|
|
<template>
|
<Page auto-content-height><FormModal @success="handleRefresh" />
|
|
<Grid table-title="盘点任务列表">
|
<template #toolbar-tools>
|
<TableAction
|
:actions="[
|
{
|
label: $t('ui.actionTitle.create', ['盘点任务']),
|
type: 'primary',
|
icon: ACTION_ICON.ADD,
|
auth: ['mes:wm-stock-taking-task:create'],
|
onClick: handleCreate,
|
},
|
{
|
label: $t('ui.actionTitle.export'),
|
type: 'primary',
|
icon: ACTION_ICON.DOWNLOAD,
|
auth: ['mes:wm-stock-taking-task:export'],
|
onClick: handleExport,
|
},
|
{
|
label: '导入模板',
|
type: 'primary',
|
icon: ACTION_ICON.DOWNLOAD,
|
auth: ['mes:wm-stock-taking-task:query'],
|
onClick: handleImportTemplate,
|
},
|
]"
|
/>
|
</template>
|
<template #code="{ row }">
|
<Button type="link" @click="handleDetail(row)">
|
{{ row.code }}
|
</Button>
|
</template>
|
<template #actions="{ row }">
|
<TableAction
|
:actions="[
|
{
|
label: $t('common.edit'),
|
type: 'link',
|
icon: ACTION_ICON.EDIT,
|
auth: ['mes:wm-stock-taking-task:update'],
|
ifShow: row.status === StatusEnum.PREPARE,
|
onClick: handleEdit.bind(null, row),
|
},
|
{
|
label: '提交',
|
type: 'link',
|
auth: ['mes:wm-stock-taking-task:update'],
|
ifShow: row.status === StatusEnum.PREPARE,
|
onClick: handleSubmit.bind(null, row),
|
},
|
{
|
label: $t('common.delete'),
|
type: 'link',
|
danger: true,
|
icon: ACTION_ICON.DELETE,
|
auth: ['mes:wm-stock-taking-task:delete'],
|
ifShow: row.status === StatusEnum.PREPARE,
|
popConfirm: {
|
title: $t('ui.actionMessage.deleteConfirm', [row.code]),
|
confirm: handleDelete.bind(null, row),
|
},
|
},
|
{
|
label: '执行盘点',
|
type: 'link',
|
auth: ['mes:wm-stock-taking-task:update'],
|
ifShow: row.status === StatusEnum.APPROVING,
|
onClick: handleExecute.bind(null, row),
|
},
|
{
|
label: '导入实盘数',
|
type: 'link',
|
icon: ACTION_ICON.UPLOAD,
|
auth: ['mes:wm-stock-taking-task:update'],
|
ifShow: row.status === StatusEnum.APPROVING,
|
onClick: handleImport.bind(null, row),
|
},
|
{
|
label: '取消',
|
type: 'link',
|
danger: true,
|
auth: ['mes:wm-stock-taking-task:update'],
|
ifShow: row.status === StatusEnum.APPROVING,
|
popConfirm: {
|
title: '确认取消该盘点任务?取消后不可恢复。',
|
confirm: handleCancel.bind(null, row),
|
},
|
},
|
]"
|
/>
|
</template>
|
</Grid>
|
<input
|
ref="importFileRef"
|
class="hidden"
|
type="file"
|
accept=".xls,.xlsx"
|
@change="handleImportFileChange"
|
/>
|
</Page>
|
</template>
|