mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 09:49:20 +08:00
fix: 编辑商品内调价后同步刷新表单 SKU 成本展示
This commit is contained in:
+35
-1
@@ -1,5 +1,6 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import type { ProductDTO, ProductVO } from '#/api/ec/product/types';
|
import type { ProductDTO, ProductVO } from '#/api/ec/product/types';
|
||||||
|
import type { ProductSkuVO } from '#/api/ec/product/sku/types';
|
||||||
|
|
||||||
import type { DropdownRender } from 'ant-design-vue/es/vc-select/BaseSelect';
|
import type { DropdownRender } from 'ant-design-vue/es/vc-select/BaseSelect';
|
||||||
import { computed, h, nextTick, onUnmounted, ref } from 'vue';
|
import { computed, h, nextTick, onUnmounted, ref } from 'vue';
|
||||||
@@ -80,6 +81,39 @@ function openCostDrawer() {
|
|||||||
productSkuCostDrawerRef.value?.open(product);
|
productSkuCostDrawerRef.value?.open(product);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 成本抽屉调价/删段后,同步刷新本表单只读成本列 */
|
||||||
|
function applySkuCostFromDrawer(vo: ProductSkuVO.Info) {
|
||||||
|
const skuId = vo.id;
|
||||||
|
if (skuId == null) return;
|
||||||
|
|
||||||
|
const patch = {
|
||||||
|
productCost: Number(vo.productCost ?? 0),
|
||||||
|
shippingCost: Number(vo.shippingCost ?? 0),
|
||||||
|
otherCost: Number(vo.otherCost ?? 0),
|
||||||
|
costEffectiveFrom: vo.costEffectiveFrom,
|
||||||
|
};
|
||||||
|
|
||||||
|
const idx = skus.value.findIndex((s) => s.id === skuId);
|
||||||
|
if (idx >= 0) {
|
||||||
|
skus.value[idx] = { ...skus.value[idx]!, ...patch };
|
||||||
|
}
|
||||||
|
|
||||||
|
const productSkus = currentProductData.value?.skus;
|
||||||
|
if (productSkus) {
|
||||||
|
const pIdx = productSkus.findIndex((s) => s.id === skuId);
|
||||||
|
if (pIdx >= 0) {
|
||||||
|
productSkus[pIdx] = { ...productSkus[pIdx]!, ...patch };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onCostDrawerSuccess(payload?: { sku?: ProductSkuVO.Info }) {
|
||||||
|
if (payload?.sku) {
|
||||||
|
applySkuCostFromDrawer(payload.sku);
|
||||||
|
}
|
||||||
|
emit('success');
|
||||||
|
}
|
||||||
|
|
||||||
// 内部状态管理
|
// 内部状态管理
|
||||||
const isEdit = ref(false);
|
const isEdit = ref(false);
|
||||||
const currentProductData = ref<null | Partial<ProductVO.Info> | ProductVO.Info>(
|
const currentProductData = ref<null | Partial<ProductVO.Info> | ProductVO.Info>(
|
||||||
@@ -1141,7 +1175,7 @@ onUnmounted(() => {
|
|||||||
|
|
||||||
<ProductSkuCostDrawer
|
<ProductSkuCostDrawer
|
||||||
ref="productSkuCostDrawerRef"
|
ref="productSkuCostDrawerRef"
|
||||||
@success="emit('success')"
|
@success="onCostDrawerSuccess"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<ProductSkuMigrateModal
|
<ProductSkuMigrateModal
|
||||||
|
|||||||
+4
-3
@@ -25,7 +25,8 @@ import ProductSkuCostFormModal from './ProductSkuCostFormModal.vue';
|
|||||||
defineOptions({ name: 'ProductSkuCostDrawer' });
|
defineOptions({ name: 'ProductSkuCostDrawer' });
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
success: [];
|
/** 成本变更后通知外层;带上最新 SKU 便于编辑表单就地刷新 */
|
||||||
|
success: [payload?: { sku?: ProductSkuVO.Info }];
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||||
@@ -225,7 +226,7 @@ async function onCostFormSuccess(payload: {
|
|||||||
if (selectedSkuId.value != null) {
|
if (selectedSkuId.value != null) {
|
||||||
await loadHistory(selectedSkuId.value);
|
await loadHistory(selectedSkuId.value);
|
||||||
}
|
}
|
||||||
emit('success');
|
emit('success', { sku: payload.sku });
|
||||||
if (payload.costChanged) {
|
if (payload.costChanged) {
|
||||||
message.info('已标记 BI 待重算,请在工作台查看数据健康度');
|
message.info('已标记 BI 待重算,请在工作台查看数据健康度');
|
||||||
}
|
}
|
||||||
@@ -239,7 +240,7 @@ async function handleDeleteHistory(row: ProductSkuCostVO.History) {
|
|||||||
if (selectedSkuId.value != null) {
|
if (selectedSkuId.value != null) {
|
||||||
await loadHistory(selectedSkuId.value);
|
await loadHistory(selectedSkuId.value);
|
||||||
}
|
}
|
||||||
emit('success');
|
emit('success', { sku: vo ?? undefined });
|
||||||
message.success('已删除成本段,已标记 BI 待重算');
|
message.success('已删除成本段,已标记 BI 待重算');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
|||||||
Reference in New Issue
Block a user