diff --git a/apps/web-antd/src/views/business/order/product-order/index.vue b/apps/web-antd/src/views/business/order/product-order/index.vue index 305b7068..5de5bcb3 100644 --- a/apps/web-antd/src/views/business/order/product-order/index.vue +++ b/apps/web-antd/src/views/business/order/product-order/index.vue @@ -152,7 +152,7 @@ const passApplication = () => { // 新标签跳转到 exportWesternMedicineApi exportOrderApi().then((res) => { // 创建新的URL表示指定的File对象或者Blob对象。 - downloadByData(res.data, '萧康云医-西药导出.xlsx'); + downloadByData(res.data, `萧康云医-商品订单导出${new Date()}.xlsx`); message.success('导出成功!'); }); }; diff --git a/apps/web-antd/src/views/business/product/china-medicine/components/ExcelUpload.vue b/apps/web-antd/src/views/business/product/china-medicine/components/ExcelUpload.vue index 54065b66..37c0d8d4 100644 --- a/apps/web-antd/src/views/business/product/china-medicine/components/ExcelUpload.vue +++ b/apps/web-antd/src/views/business/product/china-medicine/components/ExcelUpload.vue @@ -3,61 +3,97 @@ import { ref } from 'vue'; import { useVbenModal } from '@vben/common-ui'; -import { message, UploadDragger } from 'ant-design-vue'; +import { message, UploadDragger, type UploadFile } from 'ant-design-vue'; import { importChinaMedicineApi } from '../api'; const gridApi = ref(); -const fileList = ref([]); - -const importChinaMedicine = (file) => { - const submitApi = importChinaMedicineApi; - submitApi({ - file: file.file, - }) - .then(() => { - message.success('导入成功'); - gridApi.value?.reload(); - modalApi.close(); - }) - .finally(() => { - }); -}; - +const fileList = ref([]); +const selectedFile = ref(null); // 新增:存储选中的文件 +const isFileSelected = ref(false); // 新增:标记是否有文件被选中 const [Modal, modalApi] = useVbenModal({ fullscreenButton: false, draggable: true, onCancel() { + // 重置文件状态 + selectedFile.value = null; + isFileSelected.value = false; + fileList.value = []; modalApi.close(); }, onConfirm: async () => { + // 检查是否有选中文件 + if (!selectedFile.value) { + message.warning('请先选择要上传的文件'); + return; + } + modalApi.setState({ loading: true, confirmLoading: true }); - const submitApi = importChinaMedicineApi; - submitApi({ - file: fileList.value, - }) - .then(() => { - message.success('导入成功'); - gridApi.value?.reload(); - modalApi.close(); - }) - .finally(() => { - modalApi.setState({ loading: false, confirmLoading: false }); + + try { + await importChinaMedicineApi({ + file: selectedFile.value, }); + + message.success('导入成功'); + gridApi.value?.reload(); + + // 重置文件状态 + selectedFile.value = null; + isFileSelected.value = false; + fileList.value = []; + + modalApi.close(); + } catch (error) { + message.error('导入失败'); + } finally { + modalApi.setState({ loading: false, confirmLoading: false }); + } }, onOpenChange(isOpen: boolean) { gridApi.value = isOpen ? modalApi.getData()?.gridApi : null; + // 重置文件状态 + selectedFile.value = null; + isFileSelected.value = false; + fileList.value = []; }, }); + +// 处理文件选择变化,只存储文件不上传 +const handleChange = (info: { file: UploadFile }) => { + const { file } = info; + + if (file.status === 'removed') { + // 文件被移除 + selectedFile.value = null; + isFileSelected.value = false; + return; + } + + if (file) { + // 存储选中的文件 + selectedFile.value = file; + isFileSelected.value = true; + message.success('文件已选择,请点击确认按钮上传'); + } +}; diff --git a/apps/web-antd/src/views/business/product/western-medicine/components/ExcelUpload.vue b/apps/web-antd/src/views/business/product/western-medicine/components/ExcelUpload.vue index 79597eea..0b6a8379 100644 --- a/apps/web-antd/src/views/business/product/western-medicine/components/ExcelUpload.vue +++ b/apps/web-antd/src/views/business/product/western-medicine/components/ExcelUpload.vue @@ -3,60 +3,101 @@ import { ref } from 'vue'; import { useVbenModal } from '@vben/common-ui'; -import { message, UploadDragger } from 'ant-design-vue'; +import { message, UploadDragger, type UploadFile } from 'ant-design-vue'; import { importWesternMedicineApi } from '../api'; const gridApi = ref(); -const fileList = ref([]); - -const importWesternMedicine = (file) => { - const submitApi = importWesternMedicineApi; - submitApi({ - file: file.file, - }) - .then(() => { - message.success('导入成功'); - gridApi.value?.reload(); - modalApi.close(); - }) - .finally(() => { - }); -}; - +const fileList = ref([]); +const selectedFile = ref(null); // 新增:存储选中的文件 +const isFileSelected = ref(false); // 新增:标记是否有文件被选中 const [Modal, modalApi] = useVbenModal({ fullscreenButton: false, draggable: true, onCancel() { + // 重置文件状态 + selectedFile.value = null; + isFileSelected.value = false; + fileList.value = []; modalApi.close(); }, onConfirm: async () => { + // 检查是否有选中文件 + if (!selectedFile.value) { + message.warning('请先选择要上传的文件'); + return; + } + modalApi.setState({ loading: true, confirmLoading: true }); - const submitApi = importWesternMedicineApi; - submitApi({ - file: fileList.value, - }) - .then(() => { - message.success('导入成功'); - gridApi.value?.reload(); - modalApi.close(); - }) - .finally(() => { - modalApi.setState({ loading: false, confirmLoading: false }); + + try { + await importWesternMedicineApi({ + file: selectedFile.value, }); + + message.success('导入成功'); + gridApi.value?.reload(); + + // 重置文件状态 + selectedFile.value = null; + isFileSelected.value = false; + fileList.value = []; + + modalApi.close(); + } catch { + message.error('导入失败'); + } finally { + modalApi.setState({ loading: false, confirmLoading: false }); + } }, onOpenChange(isOpen: boolean) { gridApi.value = isOpen ? modalApi.getData()?.gridApi : null; + // 重置文件状态 + selectedFile.value = null; + isFileSelected.value = false; + fileList.value = []; }, }); + +// 处理文件选择变化,只存储文件不上传 +const handleChange = (info: { file: UploadFile }) => { + const { file } = info; + + if (file.status === 'removed') { + // 文件被移除 + selectedFile.value = null; + isFileSelected.value = false; + return; + } + + if (file) { + // 存储选中的文件 + selectedFile.value = file; + isFileSelected.value = true; + message.success('文件已选择,请点击确认按钮上传'); + } +}; diff --git a/apps/web-antd/src/views/business/warehouse-drug-management/admin/components/ExcelUpload.vue b/apps/web-antd/src/views/business/warehouse-drug-management/admin/components/ExcelUpload.vue index 1f3aaeef..d167cc52 100644 --- a/apps/web-antd/src/views/business/warehouse-drug-management/admin/components/ExcelUpload.vue +++ b/apps/web-antd/src/views/business/warehouse-drug-management/admin/components/ExcelUpload.vue @@ -8,6 +8,7 @@ import { message, type UploadChangeParam, UploadDragger, + type UploadFile, } from 'ant-design-vue'; import { downloadByData } from '#/util/tool'; @@ -20,62 +21,108 @@ import { const gridApi = ref(); const passApplication = ref(); +const titles = ref('批量修改药品价格'); const importType = ref(1); -const fileList = ref([]); +const uploadType = ref(1); +const fileList = ref([]); +const selectedFile = ref(null); // 新增:存储选中的文件 +const isFileSelected = ref(false); // 新增:标记是否有文件被选中 const [Modal, modalApi] = useVbenModal({ fullscreenButton: false, draggable: true, onCancel() { + // 重置文件状态 + selectedFile.value = null; + isFileSelected.value = false; + fileList.value = []; modalApi.close(); }, onConfirm: async () => { - // modalApi.setState({ loading: true, confirmLoading: true }); - gridApi.value?.reload(); - modalApi.close(); + // 检查是否有选中文件 + if (!selectedFile.value) { + message.warning('请先选择要上传的文件'); + return; + } + + modalApi.setState({ loading: true, confirmLoading: true }); + + try { + const submitApi = + importType.value === 1 + ? importWarehouseDrugManagementApi + : importUpdatePriceApi; + + await submitApi({ + file: selectedFile.value, + upload_type: uploadType.value, + }); + + message.success('上传成功'); + gridApi.value?.reload(); + + // 重置文件状态 + selectedFile.value = null; + isFileSelected.value = false; + fileList.value = []; + + modalApi.close(); + } catch { + message.error('上传失败'); + } finally { + modalApi.setState({ loading: false, confirmLoading: false }); + } }, onOpenChange(isOpen: boolean) { gridApi.value = isOpen ? modalApi.getData()?.gridApi : null; passApplication.value = isOpen ? modalApi.getData()?.passApplication : null; importType.value = isOpen ? modalApi.getData()?.type : 1; + uploadType.value = isOpen ? modalApi.getData()?.uploadType : 1; fileList.value = []; + selectedFile.value = null; // 重置选中的文件 + isFileSelected.value = false; // 重置文件选择状态 + + switch (uploadType.value) { + case 1: { + titles.value = '批量修改中药价格(库里不存在的自动添加)'; + break; + } + case 2: { + titles.value = '批量修改西(中成)药价格(库里不存在的自动添加)'; + break; + } + case 5: { + titles.value = '批量修产品服务包药价格(库里不存在的自动添加)'; + break; + } + // No default + } }, }); -const importWarehouseDrugManagement = ({ file, onSuccess }) => { - modalApi.setState({ loading: true, confirmLoading: true }); - const submitApi = - importType.value === 1 - ? importWarehouseDrugManagementApi - : importUpdatePriceApi; - submitApi({ - file, - }) - .then(() => { - onSuccess('ok', { status: 'done' }); - }) - .catch(() => { - onSuccess('error', { status: 'error' }); - }) - .finally(() => { - modalApi.setState({ loading: false, confirmLoading: false }); - }); -}; +// 修改:处理文件选择变化,只存储文件不上传 const handleChange = (info: UploadChangeParam) => { - if (info.file.status === 'uploading') { + const { file } = info; + + if (file.status === 'removed') { + // 文件被移除 + selectedFile.value = null; + isFileSelected.value = false; return; } - if (info.file.status === 'done') { - message.success('上传成功'); - } - if (info.file.status === 'error') { - message.error('upload error'); + + if (file) { + // 存储选中的文件 + selectedFile.value = file; + isFileSelected.value = true; + message.success('文件已选择,请点击确认按钮上传'); } }; +// 修改:移除原来的上传函数,因为现在在onConfirm中处理上传 + const exportWarehouseDrugManagementTemplate = () => { exportWarehouseDrugManagementTemplateApi().then((res) => { - // 创建新的URL表示指定的File对象或者Blob对象。 downloadByData( res.data, '萧康云医-仓库商品导入模板结果导出(只包含未导入的药品).xlsx', @@ -85,19 +132,36 @@ const exportWarehouseDrugManagementTemplate = () => { }; diff --git a/apps/web-antd/src/views/business/warehouse-drug-management/admin/index.vue b/apps/web-antd/src/views/business/warehouse-drug-management/admin/index.vue index 1cd8e97c..7700e74b 100644 --- a/apps/web-antd/src/views/business/warehouse-drug-management/admin/index.vue +++ b/apps/web-antd/src/views/business/warehouse-drug-management/admin/index.vue @@ -85,9 +85,12 @@ const passApplication = () => { }; const openExcelUploadModal = (type = 1) => { + const uploadType = gridApi.formApi.latestSubmissionValues.type; + ExcelUploadModalApi.setData({ gridApi, type, + uploadType, passApplication, }); ExcelUploadModalApi.open(); @@ -150,6 +153,7 @@ const updateStatus = (id: number) => { }, }, ]" + :flex="false" >