From 6535d8f34b4b1ed0d9551608847b4041c2e9e701 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期四, 03 九月 2026 17:27:42 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev_pro2.0' into dev_pro2.0

---
 src/views/srm/supplier/modules/import-form.vue |  100 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 100 insertions(+), 0 deletions(-)

diff --git a/src/views/srm/supplier/modules/import-form.vue b/src/views/srm/supplier/modules/import-form.vue
new file mode 100644
index 0000000..3ca2f54
--- /dev/null
+++ b/src/views/srm/supplier/modules/import-form.vue
@@ -0,0 +1,100 @@
+<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';
+import {
+  getSupplierImportTemplate,
+  importSupplierExcel,
+} from '#/api/srm/supplier';
+
+import { useImportFormSchema } from '../data';
+
+const emit = defineEmits(['success']);
+
+const [Form, formApi] = useVbenForm({
+  commonConfig: {
+    formItemClass: 'col-span-2',
+    labelWidth: 110,
+  },
+  layout: 'horizontal',
+  schema: useImportFormSchema(),
+  showDefaultActions: false,
+});
+
+const [Modal, modalApi] = useVbenModal({
+  async onConfirm() {
+    const { valid } = await formApi.validate();
+    if (!valid) {
+      return;
+    }
+    const data = await formApi.getValues();
+    modalApi.lock();
+    try {
+      const res = (await importSupplierExcel({
+        file: data.file,
+        updateSupport: data.updateSupport,
+      })) as any;
+      // 鍏煎鍝嶅簲缁撴瀯锛氫笟鍔℃暟鎹洿鎺ヨ繑鍥炴垨鍖呭湪 { code, data } 涓�
+      const result = res?.data ?? res ?? {};
+      const createList = result.createList ?? [];
+      const updateList = result.updateList ?? [];
+      const failureList = result.failureList ?? {};
+      const failureCount = Object.keys(failureList).length;
+      let tip = `瀵煎叆瀹屾垚锛氭柊澧� ${createList.length} 鏉°�佹洿鏂� ${updateList.length} 鏉°�佸け璐� ${failureCount} 鏉°�俙;
+      if (failureCount > 0) {
+        const sample = Object.entries(failureList)
+          .slice(0, 5)
+          .map(([name, reason]) => `${name}锛�${reason}`)
+          .join('锛�');
+        tip += `澶辫触鍘熷洜绀轰緥锛�${sample}`;
+      }
+      if (failureCount > 0) {
+        message.warning(tip);
+      } else {
+        message.success(tip);
+      }
+      // 鍏抽棴骞跺埛鏂�
+      await modalApi.close();
+      emit('success');
+    } finally {
+      modalApi.unlock();
+    }
+  },
+});
+
+/** 涓婁紶鍓� */
+function beforeUpload(file: FileType) {
+  formApi.setFieldValue('file', file);
+  return false;
+}
+
+/** 涓嬭浇妯℃澘 */
+async function handleDownload() {
+  const data = await getSupplierImportTemplate();
+  downloadFileFromBlobPart({ fileName: '渚涘簲鍟嗗鍏ユā鏉�.xlsx', 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>
+    <template #prepend-footer>
+      <div class="flex flex-auto items-center">
+        <Button @click="handleDownload"> 涓嬭浇瀵煎叆妯℃澘 </Button>
+      </div>
+    </template>
+  </Modal>
+</template>

--
Gitblit v1.9.3