From a90446dff644e9b47611f614f94be7797d5e0b55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=9F=91=E8=9E=82?= Date: Sun, 26 Apr 2026 21:27:12 +0800 Subject: [PATCH] =?UTF-8?q?feat(ecom-dmb):=20=E5=95=86=E5=93=81=E5=8D=A1?= =?UTF-8?q?=E7=89=87=E4=BF=9D=E5=AD=98=E6=97=B6=E6=A3=80=E6=B5=8B=E8=A7=84?= =?UTF-8?q?=E6=A0=BC=E6=88=90=E6=9C=AC=E5=8F=98=E6=9B=B4=EF=BC=8C=E5=BC=B9?= =?UTF-8?q?=E5=87=BA=E5=90=8C=E6=AD=A5=E7=A1=AE=E8=AE=A4=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - updateProductApi 返回 costChangedSpecIds 时弹出成本同步弹窗 - 用户勾选规格并选择时间范围后调用 batchSyncCostsToOrdersApi 同步历史订单 --- .../product/components/ProductCard.vue | 125 +++++++++++++++++- 1 file changed, 121 insertions(+), 4 deletions(-) diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/product/components/ProductCard.vue b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/product/components/ProductCard.vue index 5aa0619d..a0a501ff 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/product/components/ProductCard.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/product/components/ProductCard.vue @@ -4,14 +4,31 @@ import type { ProductDTO, ProductVO } from '#/api/ecommerce/product/types'; import { computed, ref, watch } from 'vue'; import { useRouter } from 'vue-router'; +import { useVbenModal } from '@vben/common-ui'; import { createIconifyIcon } from '@vben/icons'; -import { Button, Card, Image, Input, Popconfirm, TreeSelect, message } from 'ant-design-vue'; +import { + Button, + Card, + DatePicker, + Form, + Image, + Input, + message, + Popconfirm, + TreeSelect, +} from 'ant-design-vue'; +import dayjs from 'dayjs'; import TextArea from 'ant-design-vue/es/input/TextArea'; -import { uploadFileToOss } from '#/utils/oss-upload'; -import { getCategoryTreeApi } from '#/api/ecommerce/category'; import { updateProductApi } from '#/api/ecommerce/product'; +import { + batchSyncCostsToOrdersApi, + getProductSpecsByIdsApi, +} from '#/api/ecommerce/product-spec/apis'; +import type { ProductSpecVO } from '#/api/ecommerce/product-spec/types'; +import { getCategoryTreeApi } from '#/api/ecommerce/category'; +import { uploadFileToOss } from '#/utils/oss-upload'; const props = defineProps(); const emit = defineEmits(); @@ -23,6 +40,59 @@ const ChartIcon = createIconifyIcon('lucide:bar-chart-2'); const ImageOffIcon = createIconifyIcon('lucide:image-off'); const PlusIcon = createIconifyIcon('lucide:plus'); +// 成本同步弹窗 +const [SyncModal, syncModalApi] = useVbenModal({ + title: '成本变更确认', + class: 'w-[500px]', + draggable: true, + contentClass: 'px-5 py-4', + onConfirm: handleSyncConfirm, + onCancel: () => { + syncModalApi.close(); + }, +}); + +const syncFormData = ref<[string, string] | undefined>(undefined); + +async function openSyncModal(costChangedSpecIds: number[]) { + try { + const specs = await getProductSpecsByIdsApi(costChangedSpecIds); + pendingCostChangedSpecs.value = specs ?? []; + selectedSyncSpecIds.value = costChangedSpecIds; + syncFormData.value = [ + dayjs().startOf('day').format('YYYY-MM-DD HH:mm:ss'), + dayjs().endOf('day').format('YYYY-MM-DD HH:mm:ss'), + ]; + syncModalApi.open(); + } catch (error) { + console.error('获取规格详情失败:', error); + message.error('获取规格详情失败,无法进行成本同步'); + } +} + +const pendingCostChangedSpecs = ref([]); +const selectedSyncSpecIds = ref([]); + +async function handleSyncConfirm() { + if (selectedSyncSpecIds.value.length === 0 || !syncFormData.value) return; + try { + syncModalApi.setState?.({ confirmLoading: true }); + const [startDate, endDate] = syncFormData.value; + const totalUpdated = await batchSyncCostsToOrdersApi({ + specIds: selectedSyncSpecIds.value, + startTime: startDate, + endTime: endDate, + }); + message.success(`成本同步完成,共更新 ${totalUpdated ?? 0} 条订单`); + syncModalApi.close?.(); + } catch (error) { + console.error('成本同步失败:', error); + message.error('成本同步失败'); + } finally { + syncModalApi.setState?.({ confirmLoading: false }); + } +} + interface Props { product: ProductVO.Info; } @@ -271,11 +341,15 @@ const saveEdit = async () => { return { id: spec.id, ...base } as ProductDTO.UpdateSpec; }), }; - await updateProductApi(props.product.id, payload); + const result = await updateProductApi(props.product.id, payload); message.success('商品保存成功'); isEditing.value = false; emit('updated'); emit('editing-change', false); + // 如果有规格成本变更,弹出同步确认框 + if (result.costChangedSpecIds?.length > 0) { + openSyncModal(result.costChangedSpecIds); + } } catch (error) { console.error('保存商品失败:', error); } finally { @@ -496,6 +570,49 @@ const saveEdit = async () => { + + +
+

+ 检测到 {{ pendingCostChangedSpecs.length }} 个规格的成本已更新, + 请勾选需要同步的规格: +

+
+
+ +
+
{{ spec.name }}
+
{{ spec.specCode || '无编码' }}
+
+
+
商品成本: {{ spec.productCost }}
+
运费: {{ spec.shippingCost }}
+
其他: {{ spec.otherCost }}
+
+
+
+
+ + + +
+
+