<script lang="ts" setup>
|
import type { FileType } from 'ant-design-vue/es/upload/interface';
|
|
import { h } from 'vue';
|
|
import { useVbenModal } from '@vben/common-ui';
|
import { downloadFileFromBlobPart } from '@vben/utils';
|
|
import { Button, message, notification, Upload } from 'ant-design-vue';
|
|
import { useVbenForm } from '#/adapter/form';
|
import { importItemType, importItemTypeTemplate } from '#/api/mes/md/item/type';
|
import { $t } from '#/locales';
|
|
import { useImportFormSchema } from '../data';
|
|
const emit = defineEmits(['success']);
|
|
const [Form, formApi] = useVbenForm({
|
commonConfig: {
|
formItemClass: 'col-span-2',
|
labelWidth: 120,
|
},
|
layout: 'horizontal',
|
schema: useImportFormSchema(),
|
showDefaultActions: false,
|
});
|
|
const [Modal, modalApi] = useVbenModal({
|
async onConfirm() {
|
const { valid } = await formApi.validate();
|
if (!valid) {
|
return;
|
}
|
modalApi.lock();
|
// 提交表单
|
const data = await formApi.getValues();
|
try {
|
const response = (await importItemType(data.file, data.updateSupport)) as any;
|
// 关闭并提示
|
await modalApi.close();
|
emit('success');
|
|
const resultData = response?.data || response || {};
|
const failureList = resultData.failureList || {};
|
|
if (Object.keys(failureList).length > 0) {
|
const errorNodes = Object.entries(failureList).map(([name, reason]) => {
|
return h('div', `${name}: ${reason}`);
|
});
|
|
notification.warning({
|
message: '导入完成,部分物料分类导入失败',
|
description: () => h('div', errorNodes),
|
duration: null,
|
});
|
} else {
|
message.success($t('ui.actionMessage.operationSuccess'));
|
}
|
} finally {
|
modalApi.unlock();
|
}
|
},
|
});
|
|
/** 上传前 */
|
function beforeUpload(file: FileType) {
|
formApi.setFieldValue('file', file);
|
return false;
|
}
|
|
/** 下载模版 */
|
async function handleDownload() {
|
const data = await importItemTypeTemplate();
|
downloadFileFromBlobPart({ fileName: '物料分类导入模板.xls', source: data });
|
}
|
</script>
|
|
<template>
|
<Modal title="导入物料分类" class="w-1/3">
|
<Form class="mx-4">
|
<template #file>
|
<div class="w-full">
|
<Upload
|
:max-count="1"
|
accept=".xls,.xlsx"
|
:before-upload="beforeUpload"
|
>
|
<Button type="primary"> 选择 Excel 文件 </Button>
|
</Upload>
|
</div>
|
</template>
|
</Form>
|
<div class="mx-4 mt-2 mb-4 text-gray-500 text-xs">
|
提示:模板中的“父分类编码”请填写父分类的编码(如 RAW),顶级分类该列留空即可。
|
<div>“物料/产品标识”填 ITEM(物料)或 PRODUCT(产品)。</div>
|
<div>“状态”填 0(启用)/1(禁用)。</div>
|
</div>
|
<template #prepend-footer>
|
<div class="flex flex-auto items-center">
|
<Button @click="handleDownload"> 下载导入模板 </Button>
|
</div>
|
</template>
|
</Modal>
|
</template>
|