From 0c27ffce47e533c2c6a66f4db4c467e8c456803f Mon Sep 17 00:00:00 2001
From: xiaoyi <908147524@qq.com>
Date: 星期二, 03 十一月 2026 09:45:48 +0800
Subject: [PATCH] feat(mes): 采购入库单 / 销售出库单 前端新增导入入口

---
 src/views/wls/itemreceipt/index.vue    |   27 ++++++
 src/api/mes/wm/itemreceipt/index.ts    |   19 ++++
 src/views/wls/productsales/index.vue   |   30 +++++++
 src/api/mes/wm/productsales/index.ts   |   19 ++++
 src/components/wm-doc-import/index.vue |  133 +++++++++++++++++++++++++++++++++
 5 files changed, 227 insertions(+), 1 deletions(-)

diff --git a/src/api/mes/wm/itemreceipt/index.ts b/src/api/mes/wm/itemreceipt/index.ts
index 63e50cc..7b8e824 100644
--- a/src/api/mes/wm/itemreceipt/index.ts
+++ b/src/api/mes/wm/itemreceipt/index.ts
@@ -26,6 +26,12 @@
     remark?: string; // 澶囨敞
     createTime?: Date; // 鍒涘缓鏃堕棿
   }
+
+  /** 鍗曟嵁瀵煎叆缁撴灉 */
+  export interface WmDocImportResult {
+    createCodes?: string[]; // 鍒涘缓鎴愬姛鐨勫崟鎹紪鐮�
+    failureCodes?: Record<string, string>; // 澶辫触鐨勭紪鐮佸強鍘熷洜
+  }
 }
 
 /** 鏌ヨ閲囪喘鍏ュ簱鍗曞垎椤� */
@@ -85,6 +91,19 @@
   });
 }
 
+/** 涓嬭浇閲囪喘鍏ュ簱鍗曞鍏ユā鏉� */
+export function importItemReceiptTemplate() {
+  return requestClient.download('/mes/wm/item-receipt/get-import-template');
+}
+
+/** 瀵煎叆閲囪喘鍏ュ簱鍗� */
+export function importItemReceipt(file: File) {
+  return requestClient.upload<WmDocImportResult>(
+    '/mes/wm/item-receipt/import',
+    { file },
+  );
+}
+
 /** 鏍规嵁鍒拌揣閫氱煡鍗曠敓鎴愰噰璐叆搴撳崟 */
 export function generateItemReceiptFromArrivalNotice(arrivalNoticeId: number) {
   return requestClient.post<number>(
diff --git a/src/api/mes/wm/productsales/index.ts b/src/api/mes/wm/productsales/index.ts
index af39ac3..016ae72 100644
--- a/src/api/mes/wm/productsales/index.ts
+++ b/src/api/mes/wm/productsales/index.ts
@@ -24,6 +24,12 @@
     remark?: string; // 澶囨敞
     createTime?: Date; // 鍒涘缓鏃堕棿
   }
+
+  /** 鍗曟嵁瀵煎叆缁撴灉 */
+  export interface WmDocImportResult {
+    createCodes?: string[]; // 鍒涘缓鎴愬姛鐨勫崟鎹紪鐮�
+    failureCodes?: Record<string, string>; // 澶辫触鐨勭紪鐮佸強鍘熷洜
+  }
 }
 
 /** 鏌ヨ閿�鍞嚭搴撳崟鍒嗛〉 */
@@ -88,6 +94,19 @@
   );
 }
 
+/** 涓嬭浇閿�鍞嚭搴撳崟瀵煎叆妯℃澘 */
+export function importProductSalesTemplate() {
+  return requestClient.download('/mes/wm/product-sales/get-import-template');
+}
+
+/** 瀵煎叆閿�鍞嚭搴撳崟 */
+export function importProductSales(file: File) {
+  return requestClient.upload<MesWmProductSalesApi.WmDocImportResult>(
+    '/mes/wm/product-sales/import',
+    { file },
+  );
+}
+
 /** 瀵煎嚭閿�鍞嚭搴撳崟 */
 export function exportProductSales(params: any) {
   return requestClient.download('/mes/wm/product-sales/export-excel', {
diff --git a/src/components/wm-doc-import/index.vue b/src/components/wm-doc-import/index.vue
new file mode 100644
index 0000000..057aa3b
--- /dev/null
+++ b/src/components/wm-doc-import/index.vue
@@ -0,0 +1,133 @@
+<script lang="ts" setup>
+import type { FileType } from 'ant-design-vue/es/upload/interface';
+
+import { useVbenModal } from '@vben/common-ui';
+import { downloadFileFromBlobPart } from '@vben/utils';
+
+import { Button, message, Upload } from 'ant-design-vue';
+
+import { useVbenForm } from '#/adapter/form';
+
+defineOptions({ name: 'WmDocImportForm' });
+
+const props = withDefaults(
+  defineProps<{
+    /** 涓嬭浇妯℃澘鎺ュ彛 */
+    templateApi: () => Promise<Blob | BlobPart | any>;
+    /** 瀵煎叆鎺ュ彛 */
+    importApi: (file: File) => Promise<any>;
+    /** 鍗曟嵁鍚嶇О锛岀敤浜庢彁绀轰笌鏂囦欢鍚� */
+    subject: string;
+    /** 涓婁紶妗嗘爣绛� */
+    fileLabel?: string;
+  }>(),
+  {
+    fileLabel: 'Excel 鏁版嵁',
+  },
+);
+
+const emit = defineEmits(['success']);
+
+const [Form, formApi] = useVbenForm({
+  commonConfig: {
+    componentProps: { class: 'w-full' },
+    formItemClass: 'col-span-2',
+    labelWidth: 120,
+  },
+  layout: 'horizontal',
+  schema: [
+    {
+      fieldName: 'file',
+      label: '',
+      component: 'Upload',
+      rules: 'required',
+      help: '浠呭厑璁稿鍏� xls銆亁lsx 鏍煎紡鏂囦欢锛涘悓涓�鍗曟嵁缂栫爜鐨勫琛屼細褰掑苟涓轰竴寮犲崟鎹殑鏄庣粏',
+    },
+  ],
+  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 result = (await props.importApi(data.file as File)) as any;
+      const createCodes: string[] = result?.createCodes ?? [];
+      const failureCodes: Record<string, string> = result?.failureCodes ?? {};
+      const failCount = Object.keys(failureCodes).length;
+
+      await modalApi.close();
+      if (createCodes.length > 0) {
+        emit('success');
+      }
+
+      // 缁撴灉鎻愮ず锛氭垚鍔�/澶辫触鍒嗗埆姹囨�伙紝澶辫触鏄庣粏鏈�澶氬睍绀� 5 鏉�
+      const lines: string[] = [];
+      if (createCodes.length > 0) {
+        lines.push(`鎴愬姛瀵煎叆 ${createCodes.length} 寮�${props.subject}`);
+      }
+      if (failCount > 0) {
+        const detail = Object.entries(failureCodes)
+          .slice(0, 5)
+          .map(([key, reason]) => `${key}锛�${reason}`)
+          .join('锛�');
+        lines.push(
+          `${failCount} 琛�/寮犳湭瀵煎叆鈥斺��${detail}${failCount > 5 ? '锛堝叾浣欑暐锛�' : ''}`,
+        );
+      }
+      if (lines.length === 0) {
+        message.warning('娌℃湁鍙鍏ョ殑鏁版嵁锛岃妫�鏌ユ枃浠跺唴瀹�');
+        return;
+      }
+      if (createCodes.length > 0 && failCount === 0) {
+        message.success(lines[0]);
+      } else if (failCount > 0 && createCodes.length === 0) {
+        message.error(lines.join('锛�'));
+      } else {
+        message.warning(lines.join('锛�'));
+      }
+    } finally {
+      modalApi.unlock();
+    }
+  },
+});
+
+/** 涓婁紶鍓� */
+function beforeUpload(file: FileType) {
+  formApi.setFieldValue('file', file);
+  return false;
+}
+
+/** 涓嬭浇妯$増 */
+async function handleDownload() {
+  const data = await props.templateApi();
+  downloadFileFromBlobPart({
+    fileName: `${props.subject}瀵煎叆妯℃澘.xls`,
+    source: data,
+  });
+}
+</script>
+
+<template>
+  <Modal :title="`瀵煎叆${subject}`" class="w-2/5">
+    <Form class="mx-4">
+      <template #file>
+        <div class="w-full">
+          <Upload :before-upload="beforeUpload" :max-count="1" accept=".xls,.xlsx">
+            <Button type="primary">閫夋嫨 Excel 鏂囦欢</Button>
+          </Upload>
+        </div>
+      </template>
+    </Form>
+    <template #prepend-footer>
+      <div class="flex flex-auto items-center">
+        <Button @click="handleDownload">涓嬭浇瀵煎叆妯℃澘</Button>
+      </div>
+    </template>
+  </Modal>
+</template>
diff --git a/src/views/wls/itemreceipt/index.vue b/src/views/wls/itemreceipt/index.vue
index 552e77a..50cc629 100644
--- a/src/views/wls/itemreceipt/index.vue
+++ b/src/views/wls/itemreceipt/index.vue
@@ -15,8 +15,11 @@
   exportItemReceipt,
   generateItemReceiptFromArrivalNotice,
   getItemReceiptPage,
+  importItemReceipt,
+  importItemReceiptTemplate,
 } from '#/api/mes/wm/itemreceipt';
 import { $t } from '#/locales';
+import WmDocImportForm from '#/components/wm-doc-import/index.vue';
 
 import { useGridColumns, useGridFormSchema } from './data';
 import Form from './modules/form.vue';
@@ -29,6 +32,11 @@
 
 const [AnSelectModal, anSelectModalApi] = useVbenModal({
   connectedComponent: AnSelectDialog,
+  destroyOnClose: true,
+});
+
+const [ImportModal, importModalApi] = useVbenModal({
+  connectedComponent: WmDocImportForm,
   destroyOnClose: true,
 });
 
@@ -106,6 +114,17 @@
   }
 }
 
+/** 瀵煎叆閲囪喘鍏ュ簱鍗� */
+function handleImport() {
+  importModalApi
+    .setData({
+      subject: '閲囪喘鍏ュ簱鍗�',
+      templateApi: importItemReceiptTemplate,
+      importApi: importItemReceipt,
+    })
+    .open();
+}
+
 /** 瀵煎嚭琛ㄦ牸 */
 async function handleExport() {
   const data = await exportItemReceipt(await gridApi.formApi.getValues());
@@ -147,6 +166,7 @@
   <Page auto-content-height>
     <FormModal @success="handleRefresh" />
     <AnSelectModal @selected="handleArrivalNoticeSelected" />
+    <ImportModal @success="handleRefresh" />
 
     <Grid table-title="閲囪喘鍏ュ簱鍗曞垪琛�">
       <template #toolbar-tools>
@@ -167,6 +187,13 @@
               onClick: handleGenerateFromAN,
             },
             {
+              label: '瀵煎叆',
+              type: 'primary',
+              icon: ACTION_ICON.UPLOAD,
+              auth: ['mes:wm-item-receipt:import'],
+              onClick: handleImport,
+            },
+            {
               label: $t('ui.actionTitle.export'),
               type: 'primary',
               icon: ACTION_ICON.DOWNLOAD,
diff --git a/src/views/wls/productsales/index.vue b/src/views/wls/productsales/index.vue
index 1b0dc47..88b92d9 100644
--- a/src/views/wls/productsales/index.vue
+++ b/src/views/wls/productsales/index.vue
@@ -14,14 +14,22 @@
   deleteProductSales,
   exportProductSales,
   getProductSalesPage,
+  importProductSales,
+  importProductSalesTemplate,
 } from '#/api/mes/wm/productsales';
 import { $t } from '#/locales';
+import WmDocImportForm from '#/components/wm-doc-import/index.vue';
 
 import { useGridColumns, useGridFormSchema } from './data';
 import Form from './modules/form.vue';
 
 const [FormModal, formModalApi] = useVbenModal({
   connectedComponent: Form,
+  destroyOnClose: true,
+});
+
+const [ImportModal, importModalApi] = useVbenModal({
+  connectedComponent: WmDocImportForm,
   destroyOnClose: true,
 });
 
@@ -82,6 +90,17 @@
   handleRefresh();
 }
 
+/** 瀵煎叆閿�鍞嚭搴撳崟 */
+function handleImport() {
+  importModalApi
+    .setData({
+      subject: '閿�鍞嚭搴撳崟',
+      templateApi: importProductSalesTemplate,
+      importApi: importProductSales,
+    })
+    .open();
+}
+
 /** 瀵煎嚭琛ㄦ牸 */
 async function handleExport() {
   const data = await exportProductSales(await gridApi.formApi.getValues());
@@ -120,7 +139,9 @@
 </script>
 
 <template>
-  <Page auto-content-height><FormModal @success="handleRefresh" />
+  <Page auto-content-height>
+    <FormModal @success="handleRefresh" />
+    <ImportModal @success="handleRefresh" />
 
     <Grid table-title="閿�鍞嚭搴撳崟鍒楄〃">
       <template #toolbar-tools>
@@ -134,6 +155,13 @@
               onClick: handleCreate,
             },
             {
+              label: '瀵煎叆',
+              type: 'primary',
+              icon: ACTION_ICON.UPLOAD,
+              auth: ['mes:wm-product-sales:import'],
+              onClick: handleImport,
+            },
+            {
               label: $t('ui.actionTitle.export'),
               type: 'primary',
               icon: ACTION_ICON.DOWNLOAD,

--
Gitblit v1.9.3