mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 23:49:19 +08:00
refactor: BI 脏日账本与 as-of 成本重算管线落地,退役 COST_SYNC 并重构工作台健康度 UI
This commit is contained in:
@@ -13,7 +13,7 @@ export namespace BiOrderStatCalcVO {
|
||||
export interface FullTask {
|
||||
id: number;
|
||||
shopId: number;
|
||||
/** MANUAL / CONVERT / COST_SYNC / SKU_MIGRATE */
|
||||
/** MANUAL / CONVERT / DIRTY_DAY(历史:COST_SYNC / SKU_MIGRATE) */
|
||||
triggerSource?: string;
|
||||
/** 上游任务 id;含义由 triggerSource 决定 */
|
||||
upstreamTaskId?: number;
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import type { BiOrderStatDirtyVO } from './types';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
/** BI 脏日健康度摘要 */
|
||||
export async function getBiOrderStatDirtyHealthApi() {
|
||||
return requestClient.get<BiOrderStatDirtyVO.HealthSummary>(
|
||||
'/bi/order-stat/dirty/health',
|
||||
);
|
||||
}
|
||||
|
||||
/** 待重算脏日列表 */
|
||||
export async function listBiOrderStatDirtyPendingApi(limit = 200) {
|
||||
return requestClient.get<BiOrderStatDirtyVO.PendingRow[]>(
|
||||
'/bi/order-stat/dirty/pending',
|
||||
{ params: { limit } },
|
||||
);
|
||||
}
|
||||
|
||||
/** 一键重算全部待处理脏日 */
|
||||
export async function applyBiOrderStatDirtyPendingApi() {
|
||||
return requestClient.post<BiOrderStatDirtyVO.ApplyResult>(
|
||||
'/bi/order-stat/dirty/apply-pending',
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './apis';
|
||||
export * from './types';
|
||||
@@ -0,0 +1 @@
|
||||
export * from './types.vo';
|
||||
@@ -0,0 +1,34 @@
|
||||
export namespace BiOrderStatDirtyVO {
|
||||
export interface HealthSummary {
|
||||
pendingDayCount: number;
|
||||
pendingShopCount: number;
|
||||
oldestPendingDate?: string;
|
||||
hasRunning: boolean;
|
||||
}
|
||||
|
||||
export interface PendingRow {
|
||||
id: number;
|
||||
shopId: number;
|
||||
shopName?: string;
|
||||
statDate: string;
|
||||
reasons: string[];
|
||||
status: string;
|
||||
updateTime?: string;
|
||||
}
|
||||
|
||||
export interface TaskBrief {
|
||||
biCalcTaskId?: number;
|
||||
shopId: number;
|
||||
dateFrom: string;
|
||||
dateTo: string;
|
||||
totalDays: number;
|
||||
status: string;
|
||||
}
|
||||
|
||||
export interface ApplyResult {
|
||||
applyBatchId: string;
|
||||
dirtyDayCount: number;
|
||||
taskCount: number;
|
||||
tasks: TaskBrief[];
|
||||
}
|
||||
}
|
||||
@@ -3,49 +3,14 @@ import type { ProductSkuVO } from '#/api/ec/product/sku/types';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
/**
|
||||
* 同步 SKU 成本到历史订单(单个 SKU)
|
||||
*/
|
||||
export async function syncCostsToOrdersApi(data: ProductSkuCostDTO.SyncCost) {
|
||||
return requestClient.post<number>('/ec/product/sku/cost/sync-to-orders', data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量同步 SKU 当前生效成本到历史订单
|
||||
*/
|
||||
export async function batchSyncCostsToOrdersApi(
|
||||
data: ProductSkuCostDTO.BatchSyncCost,
|
||||
) {
|
||||
return requestClient.post<number>(
|
||||
'/ec/product/sku/cost/batch-sync-to-orders',
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计指定 SKU 与时间范围内将参与成本同步的订单数量
|
||||
*/
|
||||
export async function countOrdersForCostSyncApi(
|
||||
data: ProductSkuCostDTO.BatchSyncCost,
|
||||
) {
|
||||
return requestClient.post<number>(
|
||||
'/ec/product/sku/cost/count-orders-for-sync',
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询 SKU 成本历史
|
||||
*/
|
||||
/** 查询 SKU 成本历史 */
|
||||
export async function listSkuCostsApi(skuId: number) {
|
||||
return requestClient.get<ProductSkuCostVO.History[]>(
|
||||
`/ec/product/sku/cost/${skuId}`,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* SKU 调价(按生效日追加 / 同日纠错)
|
||||
*/
|
||||
/** SKU 调价(按生效日追加 / 同日纠错) */
|
||||
export async function adjustSkuCostApi(
|
||||
skuId: number,
|
||||
data: ProductSkuCostDTO.AdjustCost,
|
||||
@@ -56,9 +21,7 @@ export async function adjustSkuCostApi(
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除成本历史段,并记入待同步影响面
|
||||
*/
|
||||
/** 删除成本历史段,并标记 BI 待重算 */
|
||||
export async function deleteSkuCostRecordApi(costId: number) {
|
||||
return requestClient.delete<ProductSkuVO.Info>(
|
||||
`/ec/product/sku/cost/record/${costId}`,
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
export namespace CostSyncVO {
|
||||
export interface Impact {
|
||||
id: number;
|
||||
productId: number;
|
||||
skuId: number;
|
||||
dateFrom: string;
|
||||
dateTo: string;
|
||||
status: string;
|
||||
lastProductCost?: number;
|
||||
lastShippingCost?: number;
|
||||
lastOtherCost?: number;
|
||||
createTime?: string;
|
||||
appliedTime?: string;
|
||||
applyBatchId?: string;
|
||||
}
|
||||
|
||||
export interface ApplyTaskBrief {
|
||||
costSyncTaskId: number;
|
||||
shopId: number;
|
||||
biCalcTaskId?: number;
|
||||
dateFrom: string;
|
||||
dateTo: string;
|
||||
totalDays: number;
|
||||
status: string;
|
||||
createTime?: string;
|
||||
}
|
||||
|
||||
export interface ApplyResult {
|
||||
applyBatchId: string;
|
||||
impactCount: number;
|
||||
taskCount: number;
|
||||
tasks: ApplyTaskBrief[];
|
||||
}
|
||||
}
|
||||
|
||||
/** 待同步成本影响面 */
|
||||
export async function listPendingCostImpactsApi() {
|
||||
return requestClient.get<CostSyncVO.Impact[]>('/ec/product/sku/cost/sync/impacts/pending');
|
||||
}
|
||||
|
||||
/** 一键同步全部 PENDING → 成本任务 + BI 全量 */
|
||||
export async function applyPendingCostImpactsApi() {
|
||||
return requestClient.post<CostSyncVO.ApplyResult>(
|
||||
'/ec/product/sku/cost/sync/apply-pending',
|
||||
);
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
export * from './apis';
|
||||
@@ -2,23 +2,6 @@
|
||||
* SKU 成本相关 DTO
|
||||
*/
|
||||
export namespace ProductSkuCostDTO {
|
||||
/** 同步 SKU 成本到订单(单个 SKU) */
|
||||
export interface SyncCost {
|
||||
skuId: number;
|
||||
productCost: number;
|
||||
shippingCost?: number;
|
||||
otherCost?: number;
|
||||
startTime: string;
|
||||
endTime: string;
|
||||
}
|
||||
|
||||
/** 批量同步 SKU 成本到订单 */
|
||||
export interface BatchSyncCost {
|
||||
skuIds: number[];
|
||||
startTime: string;
|
||||
endTime: string;
|
||||
}
|
||||
|
||||
/** SKU 调价(按生效日) */
|
||||
export interface AdjustCost {
|
||||
/** 生效起始日 yyyy-MM-dd */
|
||||
|
||||
@@ -1,48 +1 @@
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
export namespace SkuMigrateVO {
|
||||
export interface Impact {
|
||||
id: number;
|
||||
skuId: number;
|
||||
fromProductId: number;
|
||||
toProductId: number;
|
||||
dateFrom: string;
|
||||
dateTo: string;
|
||||
status: string;
|
||||
createTime?: string;
|
||||
appliedTime?: string;
|
||||
applyBatchId?: string;
|
||||
}
|
||||
|
||||
export interface ApplyTaskBrief {
|
||||
applyTaskId: number;
|
||||
shopId: number;
|
||||
biCalcTaskId?: number;
|
||||
dateFrom: string;
|
||||
dateTo: string;
|
||||
totalDays: number;
|
||||
status: string;
|
||||
createTime?: string;
|
||||
}
|
||||
|
||||
export interface ApplyResult {
|
||||
applyBatchId: string;
|
||||
impactCount: number;
|
||||
taskCount: number;
|
||||
tasks: ApplyTaskBrief[];
|
||||
}
|
||||
}
|
||||
|
||||
/** 待重算迁品影响面 */
|
||||
export async function listPendingSkuMigrateImpactsApi() {
|
||||
return requestClient.get<SkuMigrateVO.Impact[]>(
|
||||
'/ec/product/sku/migrate/impacts/pending',
|
||||
);
|
||||
}
|
||||
|
||||
/** 一键创建 BI 全量重算任务 */
|
||||
export async function applyPendingSkuMigrateImpactsApi() {
|
||||
return requestClient.post<SkuMigrateVO.ApplyResult>(
|
||||
'/ec/product/sku/migrate/apply-pending',
|
||||
);
|
||||
}
|
||||
/** 迁品 API 已合并至商品控制器;BI 重算请在工作台查看数据健康度。 */
|
||||
|
||||
+350
@@ -0,0 +1,350 @@
|
||||
<script lang="ts" setup>
|
||||
import type { BiOrderStatDirtyVO } from '#/api/bi/order-stat/dirty';
|
||||
|
||||
import { computed, ref, watch } from 'vue';
|
||||
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import { Popover, Spin, message } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
applyBiOrderStatDirtyPendingApi,
|
||||
getBiOrderStatDirtyHealthApi,
|
||||
listBiOrderStatDirtyPendingApi,
|
||||
} from '#/api/bi/order-stat/dirty';
|
||||
|
||||
import BiHealthDimensionCard from './BiHealthDimensionCard.vue';
|
||||
import BiDirtyDayModal from './BiDirtyDayModal.vue';
|
||||
|
||||
defineOptions({ name: 'BiDataHealthToolbarButton' });
|
||||
|
||||
const props = defineProps<{
|
||||
open: boolean;
|
||||
/** 与工作台全局刷新联动,展示加载态 */
|
||||
syncRefreshing?: boolean;
|
||||
toolbarPanelClass: string;
|
||||
toolbarShellClass: string;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:open': [open: boolean];
|
||||
}>();
|
||||
|
||||
const HeartPulseIcon = createIconifyIcon('lucide:heart-pulse');
|
||||
const RefreshCwIcon = createIconifyIcon('lucide:refresh-cw');
|
||||
|
||||
const health = ref<BiOrderStatDirtyVO.HealthSummary | null>(null);
|
||||
const previewRows = ref<BiOrderStatDirtyVO.PendingRow[]>([]);
|
||||
const loading = ref(false);
|
||||
const previewLoading = ref(false);
|
||||
const applying = ref(false);
|
||||
const dirtyModalRef = ref<InstanceType<typeof BiDirtyDayModal> | null>(null);
|
||||
|
||||
const showLoading = computed(() => loading.value || !!props.syncRefreshing);
|
||||
|
||||
const dirtyStatus = computed<'ok' | 'pending' | 'running' | 'loading'>(() => {
|
||||
if (showLoading.value && !health.value) return 'loading';
|
||||
const h = health.value;
|
||||
if (!h || h.pendingDayCount <= 0) return 'ok';
|
||||
if (h.hasRunning) return 'running';
|
||||
return 'pending';
|
||||
});
|
||||
|
||||
const overallAttention = computed(() => dirtyStatus.value !== 'ok');
|
||||
|
||||
const triggerDotClass = computed(() => {
|
||||
switch (dirtyStatus.value) {
|
||||
case 'pending': {
|
||||
return 'bg-amber-500';
|
||||
}
|
||||
case 'running': {
|
||||
return 'bg-blue-500 animate-pulse';
|
||||
}
|
||||
case 'ok': {
|
||||
return 'bg-emerald-500';
|
||||
}
|
||||
default: {
|
||||
return 'bg-slate-300';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const triggerLabel = computed(() => {
|
||||
const h = health.value;
|
||||
if (showLoading.value && !h) return 'BI健康';
|
||||
if (!h || h.pendingDayCount <= 0) return 'BI健康';
|
||||
if (h.hasRunning) return `重算中·${h.pendingDayCount}`;
|
||||
return `待重算·${h.pendingDayCount}`;
|
||||
});
|
||||
|
||||
const dirtyMetrics = computed(() => {
|
||||
const h = health.value;
|
||||
if (!h || h.pendingDayCount <= 0) {
|
||||
return [{ label: '状态', value: '统计与报表一致' }];
|
||||
}
|
||||
const rows: { label: string; value: string }[] = [
|
||||
{ label: '未完成', value: `${h.pendingDayCount} 个统计日` },
|
||||
{ label: '涉及店铺', value: `${h.pendingShopCount} 家` },
|
||||
];
|
||||
if (h.oldestPendingDate) {
|
||||
rows.push({ label: '最早日期', value: h.oldestPendingDate });
|
||||
}
|
||||
return rows;
|
||||
});
|
||||
|
||||
const previewPending = computed(
|
||||
() => previewRows.value.filter((r) => r.status === 'PENDING').length,
|
||||
);
|
||||
const previewRunning = computed(
|
||||
() => previewRows.value.filter((r) => r.status === 'RUNNING').length,
|
||||
);
|
||||
|
||||
const primaryActionLabel = computed(() =>
|
||||
previewPending.value > 0 ? '一键重算' : '补投卡住任务',
|
||||
);
|
||||
const primaryDisabled = computed(
|
||||
() => !health.value || health.value.pendingDayCount <= 0,
|
||||
);
|
||||
|
||||
const reasonLabels: Record<string, string> = {
|
||||
COST: '成本',
|
||||
PRODUCT_DIM: '迁品',
|
||||
};
|
||||
|
||||
async function refreshHealth() {
|
||||
loading.value = true;
|
||||
try {
|
||||
health.value = (await getBiOrderStatDirtyHealthApi()) ?? null;
|
||||
} catch {
|
||||
health.value = null;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function loadPreview() {
|
||||
previewLoading.value = true;
|
||||
try {
|
||||
previewRows.value = (await listBiOrderStatDirtyPendingApi(8)) ?? [];
|
||||
} catch {
|
||||
previewRows.value = [];
|
||||
} finally {
|
||||
previewLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshAll() {
|
||||
await Promise.all([refreshHealth(), loadPreview()]);
|
||||
}
|
||||
|
||||
/** 工作台统一刷新:仅摘要,不拉预览列表 */
|
||||
async function refreshSummary() {
|
||||
await refreshHealth();
|
||||
}
|
||||
|
||||
function handlePopoverOpen(open: boolean) {
|
||||
emit('update:open', open);
|
||||
if (open) {
|
||||
void refreshAll();
|
||||
}
|
||||
}
|
||||
|
||||
function openDetailModal() {
|
||||
emit('update:open', false);
|
||||
void dirtyModalRef.value?.open();
|
||||
}
|
||||
|
||||
async function handleQuickApply() {
|
||||
if (primaryDisabled.value) {
|
||||
message.info('当前没有待处理的脏日');
|
||||
return;
|
||||
}
|
||||
applying.value = true;
|
||||
try {
|
||||
const result = await applyBiOrderStatDirtyPendingApi();
|
||||
if (result?.applyBatchId === 'recover') {
|
||||
message.success(`已补投 ${result.taskCount ?? 0} 个卡住任务`);
|
||||
} else {
|
||||
message.success(`已创建 ${result?.taskCount ?? 0} 个重算任务`);
|
||||
}
|
||||
await refreshAll();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
} finally {
|
||||
applying.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function onModalApplied() {
|
||||
void refreshAll();
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.open,
|
||||
(open) => {
|
||||
if (open) void refreshAll();
|
||||
},
|
||||
);
|
||||
|
||||
defineExpose({ refresh: refreshSummary, refreshAll });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Popover
|
||||
trigger="click"
|
||||
placement="bottomRight"
|
||||
:open="open"
|
||||
overlay-class-name="bi-health-popover"
|
||||
@update:open="handlePopoverOpen"
|
||||
>
|
||||
<template #content>
|
||||
<div class="w-[min(22rem,calc(100vw-2rem))] py-1">
|
||||
<div class="mb-3 flex items-center justify-between gap-2 px-0.5">
|
||||
<div>
|
||||
<div class="text-sm font-bold text-slate-900 dark:text-slate-100">
|
||||
BI 数据健康度
|
||||
</div>
|
||||
<div class="text-xs text-slate-500 dark:text-slate-400">
|
||||
多维度监测;当前已接入统计重算
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex h-7 w-7 items-center justify-center rounded-lg text-slate-500 transition hover:bg-slate-100 hover:text-slate-700 dark:hover:bg-[hsl(240deg_3.7%_18%)]"
|
||||
title="刷新"
|
||||
@click="refreshAll"
|
||||
>
|
||||
<RefreshCwIcon
|
||||
class="h-3.5 w-3.5"
|
||||
:class="showLoading ? 'animate-spin' : ''"
|
||||
/>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-2.5">
|
||||
<BiHealthDimensionCard
|
||||
title="订单日统计重算"
|
||||
icon="lucide:bar-chart-3"
|
||||
:status="dirtyStatus"
|
||||
description="成本调价、SKU 迁品后,需 FULL 重算以保证报表准确。"
|
||||
:metrics="dirtyMetrics"
|
||||
:primary-action-label="primaryActionLabel"
|
||||
secondary-action-label="查看明细"
|
||||
:primary-loading="applying"
|
||||
:primary-disabled="primaryDisabled"
|
||||
@primary="handleQuickApply"
|
||||
@secondary="openDetailModal"
|
||||
>
|
||||
<div
|
||||
v-if="health && health.pendingDayCount > 0"
|
||||
class="mt-2 rounded-lg bg-slate-50 px-2.5 py-2 dark:bg-[hsl(240deg_3.7%_12%)]"
|
||||
>
|
||||
<div
|
||||
class="mb-1.5 flex items-center justify-between text-[11px] text-slate-500 dark:text-slate-400"
|
||||
>
|
||||
<span>最近脏日</span>
|
||||
<span v-if="previewPending + previewRunning > 0">
|
||||
待 {{ previewPending }} · 算 {{ previewRunning }}
|
||||
</span>
|
||||
</div>
|
||||
<Spin :spinning="previewLoading" size="small">
|
||||
<ul v-if="previewRows.length > 0" class="space-y-1">
|
||||
<li
|
||||
v-for="row in previewRows"
|
||||
:key="row.id"
|
||||
class="flex items-center justify-between gap-2 text-xs"
|
||||
>
|
||||
<span class="truncate text-slate-700 dark:text-slate-300">
|
||||
{{ row.statDate }}
|
||||
<span class="text-slate-400">
|
||||
· {{ row.shopName || `#${row.shopId}` }}
|
||||
</span>
|
||||
</span>
|
||||
<span
|
||||
class="shrink-0 rounded px-1.5 py-0.5 text-[10px] font-medium"
|
||||
:class="
|
||||
row.status === 'RUNNING'
|
||||
? 'bg-blue-100 text-blue-700 dark:bg-blue-950 dark:text-blue-300'
|
||||
: 'bg-amber-100 text-amber-700 dark:bg-amber-950 dark:text-amber-300'
|
||||
"
|
||||
>
|
||||
{{
|
||||
(row.reasons ?? [])
|
||||
.map((r) => reasonLabels[r] ?? r)
|
||||
.join('/') || (row.status === 'RUNNING' ? '重算' : '待算')
|
||||
}}
|
||||
</span>
|
||||
</li>
|
||||
</ul>
|
||||
<div
|
||||
v-else-if="!previewLoading"
|
||||
class="text-xs text-slate-400"
|
||||
>
|
||||
暂无明细
|
||||
</div>
|
||||
</Spin>
|
||||
</div>
|
||||
</BiHealthDimensionCard>
|
||||
|
||||
<BiHealthDimensionCard
|
||||
title="增量同步"
|
||||
icon="lucide:radio"
|
||||
status="soon"
|
||||
coming-soon
|
||||
description="监测订单增量、广告费转换等管线是否滞后或暂停。"
|
||||
/>
|
||||
|
||||
<BiHealthDimensionCard
|
||||
title="数据新鲜度"
|
||||
icon="lucide:clock-3"
|
||||
status="soon"
|
||||
coming-soon
|
||||
description="各店铺最新统计日落库时间与工作台查询范围的差距。"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div
|
||||
:class="[
|
||||
toolbarShellClass,
|
||||
'cursor-pointer',
|
||||
syncRefreshing ? 'cursor-wait opacity-70' : '',
|
||||
]"
|
||||
>
|
||||
<div
|
||||
:class="[
|
||||
toolbarPanelClass,
|
||||
'flex items-center gap-1.5 px-2 py-1',
|
||||
overallAttention
|
||||
? 'ring-1 ring-inset ring-amber-300/60 dark:ring-amber-600/40'
|
||||
: '',
|
||||
]"
|
||||
>
|
||||
<span class="relative flex h-4 w-4 shrink-0 items-center justify-center">
|
||||
<HeartPulseIcon
|
||||
class="h-4 w-4 text-slate-600 dark:text-slate-300"
|
||||
:class="syncRefreshing ? 'animate-pulse' : ''"
|
||||
/>
|
||||
<span
|
||||
class="absolute -right-0.5 -top-0.5 h-2 w-2 rounded-full ring-2 ring-white dark:ring-[hsl(222.34deg_10.43%_14%)]"
|
||||
:class="triggerDotClass"
|
||||
/>
|
||||
</span>
|
||||
<span
|
||||
class="whitespace-nowrap text-xs font-bold text-slate-700 dark:text-slate-300"
|
||||
>
|
||||
{{ triggerLabel }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</Popover>
|
||||
|
||||
<BiDirtyDayModal ref="dirtyModalRef" @applied="onModalApplied" />
|
||||
</template>
|
||||
|
||||
<style>
|
||||
.bi-health-popover .ant-popover-inner {
|
||||
padding: 12px 14px;
|
||||
}
|
||||
</style>
|
||||
+181
@@ -0,0 +1,181 @@
|
||||
<script lang="ts" setup>
|
||||
import type { BiOrderStatDirtyVO } from '#/api/bi/order-stat/dirty';
|
||||
|
||||
import { computed, h, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { Alert, Button, Table, Tag, message } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
applyBiOrderStatDirtyPendingApi,
|
||||
listBiOrderStatDirtyPendingApi,
|
||||
} from '#/api/bi/order-stat/dirty';
|
||||
|
||||
defineOptions({ name: 'BiDirtyDayModal' });
|
||||
|
||||
const emit = defineEmits<{
|
||||
applied: [];
|
||||
}>();
|
||||
|
||||
const [DirtyModal, dirtyModalApi] = useVbenModal({
|
||||
title: 'BI 数据待重算',
|
||||
class: 'w-[860px] max-w-[calc(100vw-2rem)]',
|
||||
draggable: true,
|
||||
contentClass: 'px-5 py-4 min-h-[360px]',
|
||||
showCancelButton: true,
|
||||
cancelText: '关闭',
|
||||
showConfirmButton: false,
|
||||
});
|
||||
|
||||
const loading = ref(false);
|
||||
const applying = ref(false);
|
||||
const pending = ref<BiOrderStatDirtyVO.PendingRow[]>([]);
|
||||
const lastResult = ref<BiOrderStatDirtyVO.ApplyResult | null>(null);
|
||||
|
||||
const reasonLabels: Record<string, string> = {
|
||||
COST: '成本变更',
|
||||
PRODUCT_DIM: '商品维变更',
|
||||
};
|
||||
|
||||
const pendingOnlyCount = computed(() =>
|
||||
pending.value.filter((r) => r.status === 'PENDING').length,
|
||||
);
|
||||
|
||||
const runningCount = computed(() =>
|
||||
pending.value.filter((r) => r.status === 'RUNNING').length,
|
||||
);
|
||||
|
||||
const columns = [
|
||||
{
|
||||
title: '统计日',
|
||||
dataIndex: 'statDate',
|
||||
key: 'statDate',
|
||||
width: 110,
|
||||
},
|
||||
{
|
||||
title: '店铺',
|
||||
dataIndex: 'shopName',
|
||||
key: 'shopName',
|
||||
width: 140,
|
||||
customRender: ({ record }: { record: BiOrderStatDirtyVO.PendingRow }) =>
|
||||
record.shopName || `#${record.shopId}`,
|
||||
},
|
||||
{
|
||||
title: '原因',
|
||||
key: 'reasons',
|
||||
customRender: ({ record }: { record: BiOrderStatDirtyVO.PendingRow }) =>
|
||||
(record.reasons ?? []).map((r) => reasonLabels[r] ?? r).join('、') || '—',
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
key: 'status',
|
||||
width: 90,
|
||||
customRender: ({ text }: { text?: string }) => {
|
||||
const color =
|
||||
text === 'RUNNING' ? 'processing' : text === 'PENDING' ? 'warning' : 'default';
|
||||
const label =
|
||||
text === 'RUNNING' ? '重算中' : text === 'PENDING' ? '待重算' : text ?? '—';
|
||||
return h(Tag, { color }, () => label);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
async function reload() {
|
||||
loading.value = true;
|
||||
lastResult.value = null;
|
||||
try {
|
||||
pending.value = (await listBiOrderStatDirtyPendingApi()) ?? [];
|
||||
} catch {
|
||||
pending.value = [];
|
||||
message.error('加载待重算列表失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function open() {
|
||||
dirtyModalApi.open();
|
||||
await reload();
|
||||
}
|
||||
|
||||
async function handleApply() {
|
||||
if (pending.value.length === 0) {
|
||||
message.info('没有待处理的脏日');
|
||||
return;
|
||||
}
|
||||
applying.value = true;
|
||||
try {
|
||||
const result = await applyBiOrderStatDirtyPendingApi();
|
||||
lastResult.value = result ?? null;
|
||||
if (result?.applyBatchId === 'recover') {
|
||||
message.success(
|
||||
`已补投 ${result.taskCount ?? 0} 个卡住的重算任务(重算中脏日 ${result.dirtyDayCount ?? 0} 个)`,
|
||||
);
|
||||
} else {
|
||||
message.success(
|
||||
`已创建 ${result?.taskCount ?? 0} 个 BI 重算任务(脏日 ${result?.dirtyDayCount ?? 0} 个)`,
|
||||
);
|
||||
}
|
||||
emit('applied');
|
||||
await reload();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
} finally {
|
||||
applying.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
defineExpose({ open, reload });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<DirtyModal>
|
||||
<Alert
|
||||
type="info"
|
||||
show-icon
|
||||
class="mb-4"
|
||||
message="成本调价或 SKU 迁品后,相关店铺日统计需 FULL 重算。列表含「待重算」与「重算中」;若任务卡在等待,可点一键重算补投 MQ。"
|
||||
/>
|
||||
|
||||
<div class="mb-3 flex items-center justify-between gap-2">
|
||||
<span class="text-sm text-slate-600 dark:text-slate-300">
|
||||
未完成 {{ pending.length }} 条
|
||||
<template v-if="runningCount > 0">
|
||||
(重算中 {{ runningCount }})
|
||||
</template>
|
||||
</span>
|
||||
<Button
|
||||
type="primary"
|
||||
:loading="applying"
|
||||
:disabled="pending.length === 0"
|
||||
@click="handleApply"
|
||||
>
|
||||
{{ pendingOnlyCount > 0 ? '一键重算' : '补投卡住任务' }}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<Table
|
||||
size="small"
|
||||
:loading="loading"
|
||||
:columns="columns"
|
||||
:data-source="pending"
|
||||
:pagination="{ pageSize: 10, showSizeChanger: false }"
|
||||
row-key="id"
|
||||
:scroll="{ y: 320 }"
|
||||
/>
|
||||
|
||||
<Alert
|
||||
v-if="lastResult"
|
||||
type="success"
|
||||
show-icon
|
||||
class="mt-4"
|
||||
:message="
|
||||
lastResult.applyBatchId === 'recover'
|
||||
? `已补投 ${lastResult.taskCount} 个卡住的全量任务(涉及 ${lastResult.dirtyDayCount} 个脏日)`
|
||||
: `批次 ${lastResult.applyBatchId}:${lastResult.taskCount} 个任务已入队`
|
||||
"
|
||||
/>
|
||||
</DirtyModal>
|
||||
</template>
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
<script lang="ts" setup>
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import { Button, Tag } from 'ant-design-vue';
|
||||
|
||||
/** 单维健康度卡片;后续增量同步等维度复用此结构。 */
|
||||
export interface HealthMetric {
|
||||
label: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
export interface HealthDimensionCardProps {
|
||||
title: string;
|
||||
icon: string;
|
||||
status?: 'ok' | 'pending' | 'running' | 'loading' | 'soon';
|
||||
statusLabel?: string;
|
||||
description?: string;
|
||||
metrics?: HealthMetric[];
|
||||
comingSoon?: boolean;
|
||||
primaryActionLabel?: string;
|
||||
secondaryActionLabel?: string;
|
||||
primaryLoading?: boolean;
|
||||
primaryDisabled?: boolean;
|
||||
}
|
||||
|
||||
defineOptions({ name: 'BiHealthDimensionCard' });
|
||||
|
||||
const props = withDefaults(defineProps<HealthDimensionCardProps>(), {
|
||||
status: 'ok',
|
||||
metrics: () => [],
|
||||
comingSoon: false,
|
||||
primaryLoading: false,
|
||||
primaryDisabled: false,
|
||||
});
|
||||
|
||||
const emit = defineEmits<{
|
||||
primary: [];
|
||||
secondary: [];
|
||||
}>();
|
||||
|
||||
const IconComponent = computed(() => createIconifyIcon(props.icon));
|
||||
|
||||
const statusColor = {
|
||||
ok: 'success',
|
||||
pending: 'warning',
|
||||
running: 'processing',
|
||||
loading: 'default',
|
||||
soon: 'default',
|
||||
} as const;
|
||||
|
||||
const statusText = {
|
||||
ok: '正常',
|
||||
pending: '需重算',
|
||||
running: '重算中',
|
||||
loading: '加载中',
|
||||
soon: '即将推出',
|
||||
} as const;
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
class="rounded-xl border border-slate-200/80 bg-white p-3 dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(222.34deg_10.43%_14%)]"
|
||||
:class="comingSoon ? 'opacity-70' : ''"
|
||||
>
|
||||
<div class="mb-2 flex items-start justify-between gap-2">
|
||||
<div class="flex min-w-0 items-center gap-2">
|
||||
<component
|
||||
:is="IconComponent"
|
||||
class="h-4 w-4 shrink-0 text-slate-500 dark:text-slate-400"
|
||||
/>
|
||||
<span class="truncate text-sm font-semibold text-slate-800 dark:text-slate-100">
|
||||
{{ title }}
|
||||
</span>
|
||||
</div>
|
||||
<Tag
|
||||
:color="statusColor[status]"
|
||||
class="!m-0 shrink-0 border-0 text-[11px] leading-5"
|
||||
>
|
||||
{{ statusLabel ?? statusText[status] }}
|
||||
</Tag>
|
||||
</div>
|
||||
|
||||
<p
|
||||
v-if="description"
|
||||
class="mb-2 text-xs leading-relaxed text-slate-500 dark:text-slate-400"
|
||||
>
|
||||
{{ description }}
|
||||
</p>
|
||||
|
||||
<dl
|
||||
v-if="metrics.length > 0"
|
||||
class="mb-2 grid grid-cols-2 gap-x-3 gap-y-1.5 text-xs"
|
||||
>
|
||||
<template v-for="item in metrics" :key="item.label">
|
||||
<dt class="text-slate-500 dark:text-slate-400">{{ item.label }}</dt>
|
||||
<dd class="font-medium text-slate-800 dark:text-slate-200">
|
||||
{{ item.value }}
|
||||
</dd>
|
||||
</template>
|
||||
</dl>
|
||||
|
||||
<slot />
|
||||
|
||||
<div
|
||||
v-if="!comingSoon && (primaryActionLabel || secondaryActionLabel)"
|
||||
class="mt-3 flex flex-wrap gap-2"
|
||||
>
|
||||
<Button
|
||||
v-if="secondaryActionLabel"
|
||||
size="small"
|
||||
@click="emit('secondary')"
|
||||
>
|
||||
{{ secondaryActionLabel }}
|
||||
</Button>
|
||||
<Button
|
||||
v-if="primaryActionLabel"
|
||||
type="primary"
|
||||
size="small"
|
||||
:loading="primaryLoading"
|
||||
:disabled="primaryDisabled"
|
||||
@click="emit('primary')"
|
||||
>
|
||||
{{ primaryActionLabel }}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -46,6 +46,7 @@ import WorkbenchFinanceTab from './tabs/finance/index.vue';
|
||||
import WorkbenchMultiTab from './tabs/multi/index.vue';
|
||||
import WorkbenchPeriodCompareTab from './tabs/compare/index.vue';
|
||||
import WorkbenchSalesRankTab from './tabs/sales-rank/index.vue';
|
||||
import BiDataHealthToolbarButton from './components/BiDataHealthToolbarButton.vue';
|
||||
|
||||
defineOptions({ name: 'Workbench' });
|
||||
|
||||
@@ -558,16 +559,29 @@ async function loadTabData(tab: DataTabKey, opts?: { force?: boolean }) {
|
||||
}
|
||||
}
|
||||
|
||||
/** 强制刷新当前 Tab,并将其余数据 Tab 标脏 */
|
||||
/** 强制刷新当前 Tab,并将其余数据 Tab 标脏;同步刷新 BI 健康度 */
|
||||
async function softRefreshActiveTab() {
|
||||
if (activeTab.value === 'periodCompare') {
|
||||
await periodCompareTabRef.value?.refresh?.({ silent: true });
|
||||
softInvalidateDataTabs();
|
||||
return;
|
||||
}
|
||||
const tab = activeTab.value as DataTabKey;
|
||||
await loadTabData(tab, { force: true });
|
||||
softInvalidateDataTabs(tab);
|
||||
const dataPromise =
|
||||
activeTab.value === 'periodCompare'
|
||||
? (async () => {
|
||||
await periodCompareTabRef.value?.refresh?.({ silent: true });
|
||||
softInvalidateDataTabs();
|
||||
})()
|
||||
: (async () => {
|
||||
const tab = activeTab.value as DataTabKey;
|
||||
await loadTabData(tab, { force: true });
|
||||
softInvalidateDataTabs(tab);
|
||||
})();
|
||||
await Promise.all([dataPromise, refreshBiHealth()]);
|
||||
}
|
||||
|
||||
const biHealthRef = ref<InstanceType<typeof BiDataHealthToolbarButton> | null>(
|
||||
null,
|
||||
);
|
||||
|
||||
/** 与工作台刷新统一:健康摘要 +(Popover 打开时)脏日预览 */
|
||||
async function refreshBiHealth() {
|
||||
await biHealthRef.value?.refresh?.();
|
||||
}
|
||||
|
||||
async function refreshActiveDataTab(opts?: { force?: boolean }) {
|
||||
@@ -715,6 +729,7 @@ watch(activeTab, (tab) => {
|
||||
if (tab !== 'periodCompare') {
|
||||
void loadTabData(tab as DataTabKey);
|
||||
}
|
||||
void refreshBiHealth();
|
||||
setTimeout(() => {
|
||||
void redrawActiveTabCharts();
|
||||
}, 80);
|
||||
@@ -733,7 +748,7 @@ let darkObserver: MutationObserver | null = null;
|
||||
|
||||
onMounted(async () => {
|
||||
document.addEventListener('visibilitychange', onDocumentVisibilityChange);
|
||||
await loadTabData('finance');
|
||||
await Promise.all([loadTabData('finance'), refreshBiHealth()]);
|
||||
setTimeout(() => {
|
||||
void redrawActiveTabCharts();
|
||||
}, 120);
|
||||
@@ -787,6 +802,15 @@ onUnmounted(() => {
|
||||
<div
|
||||
class="workbench-header-extra flex w-full max-w-full flex-col gap-2 sm:w-auto sm:flex-row sm:items-center sm:gap-2"
|
||||
>
|
||||
<BiDataHealthToolbarButton
|
||||
ref="biHealthRef"
|
||||
:open="openPopover === 'biHealth'"
|
||||
:sync-refreshing="refreshing"
|
||||
:toolbar-shell-class="toolbarShellClass"
|
||||
:toolbar-panel-class="toolbarPanelClass"
|
||||
@update:open="(val: boolean) => handlePopoverOpen('biHealth', val)"
|
||||
/>
|
||||
|
||||
<Popover
|
||||
trigger="click"
|
||||
:open="openPopover === 'taxRate'"
|
||||
@@ -951,7 +975,7 @@ onUnmounted(() => {
|
||||
refreshing ? 'cursor-wait opacity-70' : 'cursor-pointer',
|
||||
]"
|
||||
role="button"
|
||||
:title="refreshDone ? '已刷新' : '刷新当前页数据'"
|
||||
:title="refreshDone ? '已刷新' : '刷新当前页数据与 BI 健康度'"
|
||||
@click="handleManualRefresh"
|
||||
>
|
||||
<div
|
||||
|
||||
@@ -44,9 +44,6 @@ const itemColumns = [
|
||||
{ title: '数量', dataIndex: 'quantity', key: 'quantity', width: 70 },
|
||||
{ title: '单价', key: 'unitPrice', width: 100 },
|
||||
{ title: '行金额', key: 'lineAmount', width: 100 },
|
||||
{ title: '商品成本', key: 'productCost', width: 100 },
|
||||
{ title: '运费成本', key: 'shippingCost', width: 100 },
|
||||
{ title: '其他成本', key: 'otherCost', width: 100 },
|
||||
{
|
||||
title: 'SKU编码',
|
||||
dataIndex: 'skuCode',
|
||||
@@ -227,15 +224,6 @@ defineExpose({ open, close });
|
||||
<template v-else-if="column.key === 'lineAmount'">
|
||||
{{ money(record.lineAmount) }}
|
||||
</template>
|
||||
<template v-else-if="column.key === 'productCost'">
|
||||
{{ money(record.productCost) }}
|
||||
</template>
|
||||
<template v-else-if="column.key === 'shippingCost'">
|
||||
{{ money(record.shippingCost) }}
|
||||
</template>
|
||||
<template v-else-if="column.key === 'otherCost'">
|
||||
{{ money(record.otherCost) }}
|
||||
</template>
|
||||
</template>
|
||||
</Table>
|
||||
</template>
|
||||
|
||||
@@ -61,9 +61,6 @@ interface FormItemRow {
|
||||
linkSkuName: string;
|
||||
quantity: number;
|
||||
unitPrice: number;
|
||||
productCost: number;
|
||||
shippingCost: number;
|
||||
otherCost: number;
|
||||
}
|
||||
|
||||
interface HeaderForm {
|
||||
@@ -165,9 +162,6 @@ function emptyItem(): FormItemRow {
|
||||
linkSkuName: '',
|
||||
quantity: 1,
|
||||
unitPrice: 0,
|
||||
productCost: 0,
|
||||
shippingCost: 0,
|
||||
otherCost: 0,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -181,9 +175,6 @@ function toFormItem(item: NonNullable<OrderVO.Info['items']>[number]): FormItemR
|
||||
linkSkuName: item.linkSkuName || '',
|
||||
quantity: item.quantity ?? 1,
|
||||
unitPrice: Number(item.unitPrice ?? 0),
|
||||
productCost: Number(item.productCost ?? 0),
|
||||
shippingCost: Number(item.shippingCost ?? 0),
|
||||
otherCost: Number(item.otherCost ?? 0),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -391,9 +382,6 @@ function ensureSkuOption(item: FormItemRow) {
|
||||
id: item.productSkuId,
|
||||
name: item.linkSkuName || '',
|
||||
skuCode: item.skuCode,
|
||||
productCost: item.productCost,
|
||||
shippingCost: item.shippingCost,
|
||||
otherCost: item.otherCost,
|
||||
} as ProductSkuVO.Info,
|
||||
});
|
||||
}
|
||||
@@ -404,9 +392,6 @@ function handleProductChange(index: number, productId: number | undefined) {
|
||||
item.productSkuId = undefined;
|
||||
item.skuCode = undefined;
|
||||
item.linkSkuName = '';
|
||||
item.productCost = 0;
|
||||
item.shippingCost = 0;
|
||||
item.otherCost = 0;
|
||||
if (productId) {
|
||||
const selected = productOptions.value.find((opt) => opt.value === productId);
|
||||
item.linkProductName = selected?.product.name || item.linkProductName;
|
||||
@@ -430,16 +415,10 @@ function handleProductSkuChange(index: number, skuId: number | undefined) {
|
||||
if (selected) {
|
||||
item.linkSkuName = selected.sku.name;
|
||||
item.skuCode = selected.sku.skuCode;
|
||||
item.productCost = selected.sku.productCost;
|
||||
item.shippingCost = selected.sku.shippingCost || 0;
|
||||
item.otherCost = selected.sku.otherCost || 0;
|
||||
}
|
||||
} else {
|
||||
item.linkSkuName = '';
|
||||
item.skuCode = undefined;
|
||||
item.productCost = 0;
|
||||
item.shippingCost = 0;
|
||||
item.otherCost = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -471,9 +450,6 @@ function buildItemPayload(item: FormItemRow): OrderItemDTO.Create {
|
||||
linkSkuName: item.linkSkuName?.trim() || skuOpt?.sku.name || undefined,
|
||||
quantity: item.quantity,
|
||||
unitPrice: item.unitPrice,
|
||||
productCost: item.productCost,
|
||||
shippingCost: item.shippingCost,
|
||||
otherCost: item.otherCost,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -787,7 +763,7 @@ defineExpose({
|
||||
</Form.Item>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-5 gap-3">
|
||||
<div class="grid grid-cols-2 gap-3">
|
||||
<Form.Item
|
||||
:name="['items', index, 'quantity']"
|
||||
:rules="[{ required: true, message: '请输入数量', trigger: 'blur' }]"
|
||||
@@ -813,42 +789,6 @@ defineExpose({
|
||||
style="width: 100%"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
:name="['items', index, 'productCost']"
|
||||
class="mb-0"
|
||||
label="商品成本"
|
||||
>
|
||||
<InputNumber
|
||||
v-model:value="item.productCost"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
:name="['items', index, 'shippingCost']"
|
||||
class="mb-0"
|
||||
label="运费成本"
|
||||
>
|
||||
<InputNumber
|
||||
v-model:value="item.shippingCost"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
:name="['items', index, 'otherCost']"
|
||||
class="mb-0"
|
||||
label="其他成本"
|
||||
>
|
||||
<InputNumber
|
||||
v-model:value="item.otherCost"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</Form.Item>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
-138
@@ -1,138 +0,0 @@
|
||||
<script lang="ts" setup>
|
||||
import type { CostSyncVO } from '#/api/ec/product/sku/cost/sync';
|
||||
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { Alert, Button, Table, message } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
applyPendingCostImpactsApi,
|
||||
listPendingCostImpactsApi,
|
||||
} from '#/api/ec/product/sku/cost/sync';
|
||||
|
||||
defineOptions({ name: 'ProductCostSyncToOrdersModal' });
|
||||
|
||||
const [SyncModal, syncModalApi] = useVbenModal({
|
||||
title: '成本待同步',
|
||||
class: 'w-[800px] max-w-[calc(100vw-2rem)]',
|
||||
draggable: true,
|
||||
contentClass: 'px-5 py-4 min-h-[360px]',
|
||||
showCancelButton: true,
|
||||
cancelText: '关闭',
|
||||
showConfirmButton: false,
|
||||
});
|
||||
|
||||
const loading = ref(false);
|
||||
const applying = ref(false);
|
||||
const pending = ref<CostSyncVO.Impact[]>([]);
|
||||
const lastResult = ref<CostSyncVO.ApplyResult | null>(null);
|
||||
|
||||
const columns = [
|
||||
{ title: 'SKU ID', dataIndex: 'skuId', key: 'skuId', width: 100 },
|
||||
{ title: '商品 ID', dataIndex: 'productId', key: 'productId', width: 100 },
|
||||
{
|
||||
title: '影响区间',
|
||||
key: 'range',
|
||||
customRender: ({ record }: { record: CostSyncVO.Impact }) =>
|
||||
`${record.dateFrom} ~ ${record.dateTo}`,
|
||||
},
|
||||
{
|
||||
title: '成本快照',
|
||||
key: 'cost',
|
||||
customRender: ({ record }: { record: CostSyncVO.Impact }) =>
|
||||
`¥${Number(record.lastProductCost ?? 0).toFixed(2)} / ¥${Number(record.lastShippingCost ?? 0).toFixed(2)} / ¥${Number(record.lastOtherCost ?? 0).toFixed(2)}`,
|
||||
},
|
||||
];
|
||||
|
||||
async function reload() {
|
||||
loading.value = true;
|
||||
lastResult.value = null;
|
||||
try {
|
||||
pending.value = (await listPendingCostImpactsApi()) ?? [];
|
||||
} catch {
|
||||
pending.value = [];
|
||||
message.error('加载待同步影响面失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开账本一键回刷(skuIds 保留兼容旧调用,实际按公司全部 PENDING)。
|
||||
*/
|
||||
async function open(_skuIds?: number[], _options?: { entry?: string }) {
|
||||
syncModalApi.open();
|
||||
await reload();
|
||||
}
|
||||
|
||||
async function handleApply() {
|
||||
if (pending.value.length === 0) {
|
||||
message.info('没有待同步的影响面');
|
||||
return;
|
||||
}
|
||||
applying.value = true;
|
||||
try {
|
||||
const result = await applyPendingCostImpactsApi();
|
||||
lastResult.value = result ?? null;
|
||||
message.success(
|
||||
`已创建 ${result?.taskCount ?? 0} 个店铺成本同步任务(影响面 ${result?.impactCount ?? 0} 条)`,
|
||||
);
|
||||
await reload();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
} finally {
|
||||
applying.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
defineExpose({ open });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<SyncModal>
|
||||
<Alert
|
||||
type="info"
|
||||
show-icon
|
||||
class="mb-4"
|
||||
message="调价后会记入待同步影响面。确认不再改价后,一键按店创建成本同步任务,并预建下游 BI 全量重算(按日先改订单明细再投计算)。"
|
||||
/>
|
||||
<div class="mb-3 flex items-center justify-between gap-2">
|
||||
<span class="text-muted-foreground text-sm">
|
||||
待同步 {{ pending.length }} 条
|
||||
</span>
|
||||
<div class="flex gap-2">
|
||||
<Button :loading="loading" @click="reload">刷新</Button>
|
||||
<Button
|
||||
type="primary"
|
||||
:loading="applying"
|
||||
:disabled="pending.length === 0"
|
||||
@click="handleApply"
|
||||
>
|
||||
一键同步并重算
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<Table
|
||||
size="small"
|
||||
row-key="id"
|
||||
:loading="loading"
|
||||
:columns="columns"
|
||||
:data-source="pending"
|
||||
:pagination="false"
|
||||
/>
|
||||
<div v-if="lastResult" class="text-muted-foreground mt-4 text-sm">
|
||||
批次 {{ lastResult.applyBatchId }} · 任务
|
||||
{{ lastResult.taskCount }} 个
|
||||
<ul v-if="lastResult.tasks?.length" class="mt-1 list-disc pl-5">
|
||||
<li v-for="t in lastResult.tasks" :key="t.costSyncTaskId">
|
||||
店 #{{ t.shopId }} 成本任务 #{{ t.costSyncTaskId }} → BI #{{
|
||||
t.biCalcTaskId ?? '-'
|
||||
}}
|
||||
({{ t.dateFrom }}~{{ t.dateTo }},{{ t.totalDays }} 天)
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</SyncModal>
|
||||
</template>
|
||||
+6
-37
@@ -17,16 +17,13 @@ import {
|
||||
Table,
|
||||
TreeSelect,
|
||||
} from 'ant-design-vue';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import { getCategoryTreeApi } from '#/api/ec/product/category';
|
||||
import { createProductApi, updateProductApi } from '#/api/ec/product';
|
||||
import { uploadFile } from '#/utils/upload-file';
|
||||
import CategoryFormModal from '#/views/ec/product/category/components/CategoryFormModal.vue';
|
||||
import ProductCostSyncToOrdersModal from './ProductCostSyncToOrdersModal.vue';
|
||||
import ProductSkuCostDrawer from './ProductSkuCostDrawer.vue';
|
||||
import ProductSkuDeleteConfirmModal from './ProductSkuDeleteConfirmModal.vue';
|
||||
import ProductSkuMigrateImpactModal from './ProductSkuMigrateImpactModal.vue';
|
||||
import ProductSkuMigrateModal from './ProductSkuMigrateModal.vue';
|
||||
|
||||
interface Emits {
|
||||
@@ -62,34 +59,18 @@ const DownIcon = createIconifyIcon('lucide:chevron-down');
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
const TrashIcon = createIconifyIcon('lucide:trash-2');
|
||||
|
||||
const productCostSyncModalRef = ref<InstanceType<
|
||||
typeof ProductCostSyncToOrdersModal
|
||||
> | null>(null);
|
||||
const productSkuCostDrawerRef = ref<InstanceType<
|
||||
typeof ProductSkuCostDrawer
|
||||
> | null>(null);
|
||||
const productSkuMigrateModalRef = ref<InstanceType<
|
||||
typeof ProductSkuMigrateModal
|
||||
> | null>(null);
|
||||
const productSkuMigrateImpactModalRef = ref<InstanceType<
|
||||
typeof ProductSkuMigrateImpactModal
|
||||
> | null>(null);
|
||||
const productSkuDeleteModalRef = ref<InstanceType<
|
||||
typeof ProductSkuDeleteConfirmModal
|
||||
> | null>(null);
|
||||
/** SKU 列表滚动容器:新增行后滚到底 */
|
||||
const skuListScrollRef = ref<HTMLElement | null>(null);
|
||||
|
||||
async function openSyncModal(skuIds: number[]) {
|
||||
await productCostSyncModalRef.value?.open(skuIds, {
|
||||
entry: 'after-save',
|
||||
initialDateRange: [
|
||||
dayjs().startOf('day').format('YYYY-MM-DD'),
|
||||
dayjs().endOf('day').format('YYYY-MM-DD'),
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
function openCostDrawer() {
|
||||
const product = currentProductData.value as ProductVO.Info | null;
|
||||
if (!product?.id) {
|
||||
@@ -347,11 +328,10 @@ async function handleSubmit() {
|
||||
skus: skusPayload,
|
||||
};
|
||||
const result = await updateProductApi(currentProductData.value.id, updateData);
|
||||
if (skus.value.length > 0 && result.skuIdsCostChangedWithLinkedOrders?.length > 0) {
|
||||
message.success('商品和 SKU更新成功');
|
||||
openSyncModal(result.skuIdsCostChangedWithLinkedOrders);
|
||||
if (result.skuIdsCostChangedWithLinkedOrders?.length > 0) {
|
||||
message.success('商品和 SKU 更新成功,已标记 BI 待重算(请在工作台查看)');
|
||||
} else {
|
||||
message.success('商品和 SKU更新成功');
|
||||
message.success('商品和 SKU 更新成功');
|
||||
}
|
||||
} else {
|
||||
// 创建模式:统一使用创建接口,规格信息作为可选字段
|
||||
@@ -375,9 +355,10 @@ async function handleSubmit() {
|
||||
};
|
||||
const createResult = await createProductApi(createData);
|
||||
if (skus.value.length > 0) {
|
||||
message.success('商品和 SKU创建成功');
|
||||
if (createResult.skuIdsCostChangedWithLinkedOrders?.length > 0) {
|
||||
void openSyncModal(createResult.skuIdsCostChangedWithLinkedOrders);
|
||||
message.success('商品和 SKU 创建成功,已标记 BI 待重算(请在工作台查看)');
|
||||
} else {
|
||||
message.success('商品和 SKU 创建成功');
|
||||
}
|
||||
} else {
|
||||
message.success('创建成功');
|
||||
@@ -593,10 +574,6 @@ function openMigrateModal() {
|
||||
);
|
||||
}
|
||||
|
||||
function openMigrateImpactModal() {
|
||||
productSkuMigrateImpactModalRef.value?.open();
|
||||
}
|
||||
|
||||
function onMigrateSuccess(product: ProductVO.Info) {
|
||||
applySkusFromProduct(product);
|
||||
emit('success');
|
||||
@@ -1123,12 +1100,6 @@ onUnmounted(() => {
|
||||
>
|
||||
迁入他品 SKU
|
||||
</Button>
|
||||
<Button
|
||||
v-if="isEdit && currentProductData?.id"
|
||||
@click="openMigrateImpactModal"
|
||||
>
|
||||
迁品待重算
|
||||
</Button>
|
||||
<Button type="primary" @click="addSku">
|
||||
<template #icon>
|
||||
<PlusIcon class="h-4 w-4" />
|
||||
@@ -1168,7 +1139,6 @@ onUnmounted(() => {
|
||||
</Form>
|
||||
</Modal>
|
||||
|
||||
<ProductCostSyncToOrdersModal ref="productCostSyncModalRef" />
|
||||
<ProductSkuCostDrawer
|
||||
ref="productSkuCostDrawerRef"
|
||||
@success="emit('success')"
|
||||
@@ -1178,7 +1148,6 @@ onUnmounted(() => {
|
||||
ref="productSkuMigrateModalRef"
|
||||
@success="onMigrateSuccess"
|
||||
/>
|
||||
<ProductSkuMigrateImpactModal ref="productSkuMigrateImpactModalRef" />
|
||||
<ProductSkuDeleteConfirmModal ref="productSkuDeleteModalRef" />
|
||||
<CategoryFormModal ref="categoryFormModalRef" @success="reloadCategoryTree" />
|
||||
</template>
|
||||
|
||||
+6
-12
@@ -20,7 +20,6 @@ import {
|
||||
|
||||
import { deleteSkuCostRecordApi, listSkuCostsApi } from '#/api/ec/product/sku/cost';
|
||||
|
||||
import ProductCostSyncToOrdersModal from './ProductCostSyncToOrdersModal.vue';
|
||||
import ProductSkuCostFormModal from './ProductSkuCostFormModal.vue';
|
||||
|
||||
defineOptions({ name: 'ProductSkuCostDrawer' });
|
||||
@@ -41,9 +40,6 @@ const history = ref<ProductSkuCostVO.History[]>([]);
|
||||
const historyLoading = ref(false);
|
||||
const deletingId = ref<number | null>(null);
|
||||
|
||||
const costSyncModalRef = ref<InstanceType<
|
||||
typeof ProductCostSyncToOrdersModal
|
||||
> | null>(null);
|
||||
const costFormModalRef = ref<InstanceType<
|
||||
typeof ProductSkuCostFormModal
|
||||
> | null>(null);
|
||||
@@ -117,7 +113,7 @@ const historyColumns = [
|
||||
Popconfirm,
|
||||
{
|
||||
title:
|
||||
'删除该成本段后将回落到前一段,并记入待同步影响面。确定删除?',
|
||||
'删除该成本段后将回落到前一段,并标记 BI 待重算。确定删除?',
|
||||
okText: '删除',
|
||||
okType: 'danger',
|
||||
cancelText: '取消',
|
||||
@@ -231,7 +227,7 @@ async function onCostFormSuccess(payload: {
|
||||
}
|
||||
emit('success');
|
||||
if (payload.costChanged) {
|
||||
void costSyncModalRef.value?.open();
|
||||
message.info('已标记 BI 待重算,请在工作台查看数据健康度');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,8 +240,7 @@ async function handleDeleteHistory(row: ProductSkuCostVO.History) {
|
||||
await loadHistory(selectedSkuId.value);
|
||||
}
|
||||
emit('success');
|
||||
message.success('已删除成本段,已记入待同步影响面');
|
||||
void costSyncModalRef.value?.open();
|
||||
message.success('已删除成本段,已标记 BI 待重算');
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
} finally {
|
||||
@@ -254,7 +249,7 @@ async function handleDeleteHistory(row: ProductSkuCostVO.History) {
|
||||
}
|
||||
|
||||
function handleSyncCurrent() {
|
||||
void costSyncModalRef.value?.open();
|
||||
message.info('订单成本已改为按订单日自动读取 SKU 成本,请在工作台查看 BI 数据健康度');
|
||||
}
|
||||
|
||||
defineExpose({ open });
|
||||
@@ -272,7 +267,7 @@ defineExpose({ open });
|
||||
type="info"
|
||||
show-icon
|
||||
class="mb-4"
|
||||
message="取某日成本 = effective_from ≤ 业务日且最大的一条。添加可指定生效日;编辑仅改金额(生效日锁定);删除后回落前一段。变更会记入待同步影响面(回刷订单 + BI)。"
|
||||
message="取某日成本 = effective_from ≤ 业务日且最大的一条。添加可指定生效日;编辑仅改金额(生效日锁定);删除后回落前一段。变更会自动标记 BI 待重算。"
|
||||
/>
|
||||
|
||||
<div v-if="skus.length === 0" class="py-10 text-center text-slate-400">
|
||||
@@ -320,7 +315,7 @@ defineExpose({ open });
|
||||
</template>
|
||||
添加成本段
|
||||
</Button>
|
||||
<Button @click="handleSyncCurrent">同步到订单</Button>
|
||||
<Button @click="handleSyncCurrent">BI 重算说明</Button>
|
||||
</Space>
|
||||
</div>
|
||||
|
||||
@@ -339,6 +334,5 @@ defineExpose({ open });
|
||||
ref="costFormModalRef"
|
||||
@success="onCostFormSuccess"
|
||||
/>
|
||||
<ProductCostSyncToOrdersModal ref="costSyncModalRef" />
|
||||
</Drawer>
|
||||
</template>
|
||||
|
||||
-131
@@ -1,131 +0,0 @@
|
||||
<script lang="ts" setup>
|
||||
import type { SkuMigrateVO } from '#/api/ec/product/sku/migrate';
|
||||
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { Alert, Button, Table, message } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
applyPendingSkuMigrateImpactsApi,
|
||||
listPendingSkuMigrateImpactsApi,
|
||||
} from '#/api/ec/product/sku/migrate';
|
||||
|
||||
defineOptions({ name: 'ProductSkuMigrateImpactModal' });
|
||||
|
||||
const [SyncModal, syncModalApi] = useVbenModal({
|
||||
title: '迁品待重算',
|
||||
class: 'w-[800px] max-w-[calc(100vw-2rem)]',
|
||||
draggable: true,
|
||||
contentClass: 'px-5 py-4 min-h-[360px]',
|
||||
showCancelButton: true,
|
||||
cancelText: '关闭',
|
||||
showConfirmButton: false,
|
||||
});
|
||||
|
||||
const loading = ref(false);
|
||||
const applying = ref(false);
|
||||
const pending = ref<SkuMigrateVO.Impact[]>([]);
|
||||
const lastResult = ref<SkuMigrateVO.ApplyResult | null>(null);
|
||||
|
||||
const columns = [
|
||||
{ title: 'SKU ID', dataIndex: 'skuId', key: 'skuId', width: 90 },
|
||||
{
|
||||
title: '迁出商品',
|
||||
dataIndex: 'fromProductId',
|
||||
key: 'fromProductId',
|
||||
width: 100,
|
||||
},
|
||||
{
|
||||
title: '迁入商品',
|
||||
dataIndex: 'toProductId',
|
||||
key: 'toProductId',
|
||||
width: 100,
|
||||
},
|
||||
{
|
||||
title: '影响区间',
|
||||
key: 'range',
|
||||
customRender: ({ record }: { record: SkuMigrateVO.Impact }) =>
|
||||
`${record.dateFrom} ~ ${record.dateTo}`,
|
||||
},
|
||||
];
|
||||
|
||||
async function reload() {
|
||||
loading.value = true;
|
||||
lastResult.value = null;
|
||||
try {
|
||||
pending.value = (await listPendingSkuMigrateImpactsApi()) ?? [];
|
||||
} catch {
|
||||
pending.value = [];
|
||||
message.error('加载迁品影响面失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function open() {
|
||||
syncModalApi.open();
|
||||
await reload();
|
||||
}
|
||||
|
||||
async function handleApply() {
|
||||
if (pending.value.length === 0) {
|
||||
message.info('没有待重算的影响面');
|
||||
return;
|
||||
}
|
||||
applying.value = true;
|
||||
try {
|
||||
const result = await applyPendingSkuMigrateImpactsApi();
|
||||
lastResult.value = result ?? null;
|
||||
message.success(
|
||||
`已创建 ${result?.taskCount ?? 0} 个店铺 BI 重算任务(影响面 ${result?.impactCount ?? 0} 条)`,
|
||||
);
|
||||
await reload();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
} finally {
|
||||
applying.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
defineExpose({ open });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<SyncModal>
|
||||
<Alert
|
||||
type="info"
|
||||
show-icon
|
||||
class="mb-4"
|
||||
message="迁品后会记入待重算影响面。确认归属无误后一键按店创建 BI 全量任务,按日 FULL 纠正商品维统计(不改订单明细)。"
|
||||
/>
|
||||
<div class="mb-3 flex items-center justify-between gap-2">
|
||||
<span class="text-muted-foreground text-sm">
|
||||
待重算 {{ pending.length }} 条
|
||||
</span>
|
||||
<div class="flex gap-2">
|
||||
<Button :loading="loading" @click="reload">刷新</Button>
|
||||
<Button
|
||||
type="primary"
|
||||
:loading="applying"
|
||||
:disabled="pending.length === 0"
|
||||
@click="handleApply"
|
||||
>
|
||||
一键重算 BI
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<Table
|
||||
size="small"
|
||||
row-key="id"
|
||||
:loading="loading"
|
||||
:columns="columns"
|
||||
:data-source="pending"
|
||||
:pagination="false"
|
||||
/>
|
||||
<div v-if="lastResult" class="text-muted-foreground mt-3 text-sm">
|
||||
批次 {{ lastResult.applyBatchId }} · 任务 {{ lastResult.taskCount }} 个
|
||||
</div>
|
||||
</SyncModal>
|
||||
</template>
|
||||
+7
@@ -190,6 +190,13 @@ function taskOriginTag(
|
||||
upstreamTaskId?: null | number,
|
||||
) {
|
||||
const source = triggerSource?.toUpperCase();
|
||||
if (source === 'DIRTY_DAY') {
|
||||
return {
|
||||
color: 'orange' as const,
|
||||
text: '脏日重算',
|
||||
tip: '成本/商品维变更触发的 BI 重算',
|
||||
};
|
||||
}
|
||||
if (source === 'COST_SYNC') {
|
||||
return {
|
||||
color: 'purple' as const,
|
||||
|
||||
Reference in New Issue
Block a user