2026-10-12 20:33:39 +08:00
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
|
import '@/styles/adminDensity.css'
|
|
|
|
|
|
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
|
|
|
|
|
|
import { useRoute, useRouter } from 'vue-router'
|
|
|
|
|
|
import AdminPage from '@/shared/components/AdminPage.vue'
|
|
|
|
|
|
import ListPageLayout from '@/shared/components/ListPageLayout.vue'
|
|
|
|
|
|
import QueryToolbar, { type QueryField, type QueryModel } from '@/shared/components/QueryToolbar.vue'
|
|
|
|
|
|
import DataTable, { type DataTableColumn } from '@/shared/components/DataTable.vue'
|
|
|
|
|
|
import LoadErrorState from '@/shared/components/LoadErrorState.vue'
|
|
|
|
|
|
import ApiErrorMeta from '@/shared/components/ApiErrorMeta.vue'
|
2026-10-12 22:06:45 +08:00
|
|
|
|
import AppDialog from '@/shared/components/AppDialog.vue'
|
2026-10-12 20:33:39 +08:00
|
|
|
|
import { useAccessPreviewStore } from '@/core/access/accessPreview'
|
|
|
|
|
|
import { getApiErrorMessage, getApiErrorDetails, type ApiErrorDetails } from '@/shared/api/http'
|
|
|
|
|
|
import { analyticsApi } from '../api/analytics'
|
2026-10-12 21:36:24 +08:00
|
|
|
|
import type { BusinessQuery, DailyResponse, InventoryAttention, InventorySort, Metric, Overview, QueryContext, RangePreset, SalesSummary } from '../types'
|
2026-10-12 20:33:39 +08:00
|
|
|
|
import { RequestFence, RuntimePoller, contextParams, hasActiveTask, label, beijingTime, reasonsText, quantityText, sameContext, shownQuantity, validateCustomRange } from '../state'
|
|
|
|
|
|
import SkuTrend from './SkuTrend.vue'
|
|
|
|
|
|
|
|
|
|
|
|
const props = defineProps<{ mode: 'sales' | 'inventory' }>()
|
|
|
|
|
|
const route = useRoute()
|
|
|
|
|
|
const router = useRouter()
|
|
|
|
|
|
const access = useAccessPreviewStore()
|
|
|
|
|
|
const permitted = computed(() => access.can('platform:self-operated-analytics:list'))
|
2026-10-12 21:36:24 +08:00
|
|
|
|
function initialFilters(): QueryModel { return { warehouseCode: typeof route.query.warehouseCode === 'string' ? route.query.warehouseCode : '', sku: typeof route.query.sku === 'string' ? route.query.sku : '', analysis: 'summary', rangePreset: 'TODAY', windowDays: 30, attention: 'ALL', sortBy: 'AVAILABLE_DESC', threshold: '', customStart: '', customEnd: '' } }
|
|
|
|
|
|
const filters = ref<QueryModel>(initialFilters())
|
|
|
|
|
|
const applied = ref({ sku: String(filters.value.sku) })
|
2026-10-12 20:33:39 +08:00
|
|
|
|
const overview = ref<Overview | null>(null)
|
|
|
|
|
|
const context = ref<QueryContext | null>(null)
|
|
|
|
|
|
const rows = ref<(SalesSummary | Metric)[]>([])
|
|
|
|
|
|
const daily = ref<DailyResponse | null>(null)
|
2026-10-12 22:06:45 +08:00
|
|
|
|
const trendOpen = ref(false)
|
|
|
|
|
|
const trendLoading = ref(false)
|
|
|
|
|
|
const trendError = ref('')
|
|
|
|
|
|
const trendErrorDetails = ref<ApiErrorDetails | null>(null)
|
2026-10-12 21:36:24 +08:00
|
|
|
|
const attention = computed(() => (filters.value.attention || 'ALL') as InventoryAttention)
|
|
|
|
|
|
const sortBy = computed(() => (filters.value.sortBy || 'AVAILABLE_DESC') as InventorySort)
|
|
|
|
|
|
const thresholdInput = computed(() => String(filters.value.threshold ?? ''))
|
2026-10-12 20:33:39 +08:00
|
|
|
|
const appliedInventory = ref<{ attention: InventoryAttention; sortBy: InventorySort; coverageDaysThreshold?: number }>({ attention: 'ALL', sortBy: 'AVAILABLE_DESC' })
|
|
|
|
|
|
const loading = ref(false)
|
|
|
|
|
|
const error = ref('')
|
|
|
|
|
|
const errorDetails = ref<ApiErrorDetails | null>(null)
|
|
|
|
|
|
const runtimeError = ref('')
|
|
|
|
|
|
const newData = ref(false)
|
|
|
|
|
|
const newDay = ref(false)
|
|
|
|
|
|
const current = ref(1)
|
|
|
|
|
|
const size = ref(20)
|
|
|
|
|
|
const total = ref(0)
|
2026-10-12 21:36:24 +08:00
|
|
|
|
const preset = computed(() => (filters.value.rangePreset || 'TODAY') as RangePreset)
|
|
|
|
|
|
const customStart = computed(() => String(filters.value.customStart ?? ''))
|
|
|
|
|
|
const customEnd = computed(() => String(filters.value.customEnd ?? ''))
|
|
|
|
|
|
const tab = computed(() => (filters.value.analysis || 'summary') as 'summary' | 'hot' | 'slow')
|
|
|
|
|
|
const windowDays = computed(() => Number(filters.value.windowDays || 30) as 7 | 30)
|
2026-10-12 20:33:39 +08:00
|
|
|
|
const sourceAccount = 'lingxing-primary'
|
|
|
|
|
|
const warehouseCode = computed(() => String(filters.value.warehouseCode ?? ''))
|
2026-10-12 21:36:24 +08:00
|
|
|
|
const fields = computed<QueryField[]>(() => {
|
|
|
|
|
|
const result: QueryField[] = [
|
|
|
|
|
|
{ key: 'warehouseCode', type: 'select', label: '仓库', width: 210, placeholder: '请选择仓库(必选)', options: [...new Map((overview.value?.warehouses ?? []).map(row => [row.warehouseCode, { value: row.warehouseCode, label: row.warehouseName || row.warehouseCode }])).values()] },
|
|
|
|
|
|
{ key: 'sku', type: 'input', label: 'SKU', width: 230, placeholder: '输入SKU编码(精确查询)' },
|
|
|
|
|
|
]
|
|
|
|
|
|
if (props.mode === 'inventory') result.push(
|
|
|
|
|
|
{ key: 'attention', type: 'select', label: '库存关注', width: 200, props: { 'aria-label': '库存关注' }, options: [{ value: 'ALL', label: '全部库存关注' }, { value: 'NO_OUTBOUND_30D', label: '近30天无出库' }, { value: 'COVERAGE_GT_THRESHOLD', label: '可售天数超过阈值' }, { value: 'FROZEN_STOCK', label: '冻结库存' }, { value: 'DEFECTIVE_STOCK', label: '次品库存' }, { value: 'UNASSESSABLE', label: '数据不足/待观察' }] },
|
|
|
|
|
|
{ key: 'threshold', type: 'input', label: '可售天数阈值', width: 160, placeholder: '可售天数阈值(天)', props: { 'aria-label': '可售天数阈值', inputmode: 'numeric' } },
|
|
|
|
|
|
{ key: 'sortBy', type: 'select', label: '库存排序', width: 210, options: [{ value: 'AVAILABLE_DESC', label: '正品可售量从高到低' }, { value: 'COVERAGE_DAYS_DESC', label: '可售天数从高到低' }, { value: 'PHYSICAL_DESC', label: '全品质实物从高到低' }, { value: 'OUTBOUND_30D_ASC', label: '近30天出库从低到高' }] },
|
|
|
|
|
|
)
|
|
|
|
|
|
else {
|
|
|
|
|
|
result.push({ key: 'analysis', type: 'select', label: '销量类别', width: 170, props: { clearable: false }, options: [{ value: 'summary', label: 'SKU销量' }, { value: 'hot', label: '热销Top100' }, { value: 'slow', label: '滞销Top100' }] })
|
|
|
|
|
|
if (tab.value === 'summary') {
|
|
|
|
|
|
result.push({ key: 'rangePreset', type: 'select', label: '销量日期', width: 150, props: { clearable: false }, options: [{ value: 'TODAY', label: '今日' }, { value: 'LAST_3_DAYS', label: '近3天' }, { value: 'THIS_WEEK', label: '本周' }, { value: 'LAST_15_DAYS', label: '近15天' }, { value: 'THIS_MONTH', label: '本月' }, { value: 'CUSTOM', label: '自定义' }] })
|
|
|
|
|
|
if (preset.value === 'CUSTOM') result.push({ key: 'customStart', type: 'date', label: '开始日期', width: 160 }, { key: 'customEnd', type: 'date', label: '结束日期', width: 160 })
|
|
|
|
|
|
} else if (tab.value === 'hot') result.push({ key: 'windowDays', type: 'select', label: '热销窗口', width: 180, props: { clearable: false }, options: [{ value: 7, label: '近7个完整自然日' }, { value: 30, label: '近30个完整自然日' }] })
|
|
|
|
|
|
}
|
|
|
|
|
|
return result
|
|
|
|
|
|
})
|
2026-10-12 20:33:39 +08:00
|
|
|
|
const summaryMode = computed(() => props.mode === 'sales' && tab.value === 'summary')
|
|
|
|
|
|
const columns = computed<DataTableColumn[]>(() => [
|
|
|
|
|
|
...(summaryMode.value ? [{ key: 'actions', label: '操作', width: 110, slotName: 'actions', fixed: 'left' }] : []),
|
|
|
|
|
|
{ prop: 'sku', label: 'SKU', minWidth: 170, ...(props.mode === 'inventory' ? { slotName: 'sku' } : {}) },
|
2026-10-12 21:36:24 +08:00
|
|
|
|
{ prop: 'productName', label: '商品名称', minWidth: 190 },
|
|
|
|
|
|
{ key: 'owner', label: '所属货主', minWidth: 140, slotName: 'owner' },
|
|
|
|
|
|
{ key: 'unit', label: '单位', width: 70, slotName: 'unit' },
|
2026-10-12 20:33:39 +08:00
|
|
|
|
...(props.mode === 'inventory' ? [
|
|
|
|
|
|
{ key: 'physicalQuantity', label: '全品质实物', width: 110, slotName: 'physicalQuantity' },
|
|
|
|
|
|
{ key: 'availableQuantity', label: '正品可售', width: 110, slotName: 'availableQuantity' },
|
|
|
|
|
|
{ key: 'frozenQuantity', label: '全品质冻结', width: 110, slotName: 'frozenQuantity' },
|
|
|
|
|
|
{ key: 'defectivePhysicalQuantity', label: '次品实物', width: 110, slotName: 'defectivePhysicalQuantity' },
|
|
|
|
|
|
{ key: 'transitQuantity', label: '在途', width: 110, slotName: 'transitQuantity' },
|
|
|
|
|
|
{ key: 'outboundQuantity30d', label: '近30天出库', width: 120, slotName: 'outboundQuantity30d' },
|
|
|
|
|
|
{ key: 'averageDailyOutboundQuantity', label: '30天日均出库', width: 140, slotName: 'averageDailyOutboundQuantity' },
|
|
|
|
|
|
{ key: 'inventoryCoverageDays', label: '可售天数', width: 110, slotName: 'inventoryCoverageDays' },
|
|
|
|
|
|
{ key: 'lastOutbound', label: '最近已观测出库', minWidth: 220, slotName: 'lastOutbound' },
|
|
|
|
|
|
{ key: 'attention', label: '关注原因', minWidth: 160, slotName: 'attention' },
|
|
|
|
|
|
] : [{ key: 'quantity', label: summaryMode.value ? '区间出库量 / 已采集量' : '完整窗口出库量', width: 200, slotName: 'quantity' }]),
|
|
|
|
|
|
{ key: 'status', label: '数据状态', minWidth: 130, slotName: 'status' },
|
|
|
|
|
|
{ key: 'reason', label: '说明', minWidth: 220, slotName: 'reason' },
|
2026-10-12 21:36:24 +08:00
|
|
|
|
].map(column => ['quantity', 'physicalQuantity', 'availableQuantity', 'frozenQuantity', 'defectivePhysicalQuantity', 'transitQuantity', 'outboundQuantity30d', 'averageDailyOutboundQuantity', 'inventoryCoverageDays'].includes(String(column.key)) ? { ...column, align: 'right' } : column))
|
2026-10-12 20:33:39 +08:00
|
|
|
|
const dataFence = new RequestFence()
|
|
|
|
|
|
const dailyFence = new RequestFence()
|
|
|
|
|
|
const runtimeFence = new RequestFence()
|
|
|
|
|
|
function asSummary(row: unknown) { return row as SalesSummary }
|
|
|
|
|
|
function asMetric(row: unknown) { return row as Metric }
|
|
|
|
|
|
function query(): BusinessQuery {
|
2026-10-12 21:36:24 +08:00
|
|
|
|
const result: BusinessQuery = { sourceAccount, warehouseCode: warehouseCode.value, sku: applied.value.sku || undefined, current: current.value, size: size.value, ...contextParams(context.value) }
|
2026-10-12 20:33:39 +08:00
|
|
|
|
if (summaryMode.value) {
|
|
|
|
|
|
result.rangePreset = preset.value
|
|
|
|
|
|
if (preset.value === 'CUSTOM') { result.startDate = customStart.value; result.endDate = customEnd.value }
|
|
|
|
|
|
} else if (props.mode === 'sales' && tab.value === 'hot') result.windowDays = windowDays.value
|
|
|
|
|
|
if (props.mode === 'inventory') Object.assign(result, appliedInventory.value)
|
|
|
|
|
|
return result
|
|
|
|
|
|
}
|
|
|
|
|
|
async function load(reset = false) {
|
|
|
|
|
|
if (!permitted.value || !warehouseCode.value) return
|
|
|
|
|
|
if (summaryMode.value && preset.value === 'CUSTOM') {
|
|
|
|
|
|
const problem = validateCustomRange(customStart.value, customEnd.value, context.value?.anchorDate)
|
|
|
|
|
|
if (problem) { error.value = problem; return }
|
|
|
|
|
|
}
|
2026-10-12 21:36:24 +08:00
|
|
|
|
if (reset) { context.value = null; daily.value = null; rows.value = []; total.value = 0; newData.value = false; current.value = 1 }
|
2026-10-12 22:06:45 +08:00
|
|
|
|
trendOpen.value = false
|
2026-10-12 20:33:39 +08:00
|
|
|
|
dailyFence.cancel()
|
|
|
|
|
|
const request = dataFence.begin()
|
|
|
|
|
|
loading.value = true
|
|
|
|
|
|
error.value = ''
|
|
|
|
|
|
errorDetails.value = null
|
|
|
|
|
|
try {
|
|
|
|
|
|
const params = query()
|
|
|
|
|
|
const result = props.mode === 'inventory' ? await analyticsApi.inventory(params, request.signal)
|
|
|
|
|
|
: tab.value === 'hot' ? await analyticsApi.hot(params, request.signal)
|
|
|
|
|
|
: tab.value === 'slow' ? await analyticsApi.slow(params, request.signal) : await analyticsApi.summary(params, request.signal)
|
|
|
|
|
|
if (!request.current()) return
|
2026-10-12 21:36:24 +08:00
|
|
|
|
if (context.value && !sameContext(context.value, result.context)) throw new Error('查询版本已变化,请重新查询')
|
2026-10-12 20:33:39 +08:00
|
|
|
|
context.value = result.context
|
|
|
|
|
|
rows.value = result.records
|
|
|
|
|
|
total.value = result.total
|
|
|
|
|
|
daily.value = null
|
2026-10-12 21:36:24 +08:00
|
|
|
|
} catch (cause) { if (request.current()) { errorDetails.value = getApiErrorDetails(cause, '查询失败,请重新查询'); error.value = errorDetails.value.message } }
|
2026-10-12 20:33:39 +08:00
|
|
|
|
finally { if (request.current()) loading.value = false }
|
|
|
|
|
|
}
|
|
|
|
|
|
async function showTrend(row: SalesSummary | Metric) {
|
2026-10-12 22:06:45 +08:00
|
|
|
|
trendOpen.value = true
|
|
|
|
|
|
trendLoading.value = true
|
|
|
|
|
|
daily.value = null
|
|
|
|
|
|
trendError.value = ''
|
|
|
|
|
|
trendErrorDetails.value = null
|
2026-10-12 20:33:39 +08:00
|
|
|
|
const request = dailyFence.begin()
|
|
|
|
|
|
try {
|
|
|
|
|
|
const params: BusinessQuery = { sourceAccount, warehouseCode: warehouseCode.value, customerCode: row.customerCode, sku: row.sku, current: 1, size: 20, ...contextParams(context.value), rangePreset: props.mode === 'inventory' ? 'CUSTOM' : preset.value }
|
|
|
|
|
|
if (props.mode === 'inventory' && context.value?.rangeStartDate && context.value.rangeEndDateExclusive) {
|
|
|
|
|
|
params.startDate = context.value.rangeStartDate
|
|
|
|
|
|
params.endDate = new Date(Date.parse(`${context.value.rangeEndDateExclusive}T00:00:00Z`) - 86400000).toISOString().slice(0, 10)
|
|
|
|
|
|
} else if (params.rangePreset === 'CUSTOM') { params.startDate = customStart.value; params.endDate = customEnd.value }
|
|
|
|
|
|
const result = await analyticsApi.daily(params, request.signal)
|
|
|
|
|
|
if (!request.current()) return
|
2026-10-12 21:36:24 +08:00
|
|
|
|
if (!context.value || !sameContext(context.value, result.context)) throw new Error('趋势版本与列表不一致,请重新查询')
|
2026-10-12 20:33:39 +08:00
|
|
|
|
daily.value = result
|
2026-10-12 22:06:45 +08:00
|
|
|
|
} catch (cause) { if (request.current()) { trendErrorDetails.value = getApiErrorDetails(cause, 'SKU趋势读取失败'); trendError.value = trendErrorDetails.value.message } }
|
|
|
|
|
|
finally { if (request.current()) trendLoading.value = false }
|
2026-10-12 20:33:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
async function readRuntime() {
|
|
|
|
|
|
if (!permitted.value) return false
|
|
|
|
|
|
const request = runtimeFence.begin()
|
|
|
|
|
|
try {
|
|
|
|
|
|
const result = await analyticsApi.overview(sourceAccount, undefined, request.signal)
|
|
|
|
|
|
if (!request.current()) return false
|
|
|
|
|
|
overview.value = result
|
|
|
|
|
|
runtimeError.value = ''
|
|
|
|
|
|
const today = new Intl.DateTimeFormat('en-CA', { timeZone: 'Asia/Shanghai', year: 'numeric', month: '2-digit', day: '2-digit' }).format(new Date())
|
|
|
|
|
|
newDay.value = Boolean(context.value && context.value.anchorDate !== today)
|
|
|
|
|
|
const warehouse = result.warehouses.filter(row => row.warehouseCode === warehouseCode.value)
|
|
|
|
|
|
if (context.value && warehouse.some(row => row.lastPublishedAt && Date.parse(row.lastPublishedAt) > Date.parse(context.value!.queryAsOf))) newData.value = true
|
|
|
|
|
|
return hasActiveTask(result.warehouses.flatMap(row => [row.currentTask, row.sharedUpstream].filter((task): task is NonNullable<typeof task> => Boolean(task))))
|
|
|
|
|
|
} catch (cause) { if (request.current()) runtimeError.value = getApiErrorMessage(cause, '状态更新失败,保留上次观测结果'); return false }
|
|
|
|
|
|
}
|
|
|
|
|
|
const poller = new RuntimePoller(readRuntime, () => runtimeFence.cancel())
|
2026-10-12 22:06:45 +08:00
|
|
|
|
watch(trendOpen, open => { if (!open) { dailyFence.cancel(); daily.value = null; trendLoading.value = false; trendError.value = ''; trendErrorDetails.value = null } })
|
2026-10-12 20:33:39 +08:00
|
|
|
|
function visibility() { poller.setVisible(!document.hidden) }
|
|
|
|
|
|
function search() {
|
|
|
|
|
|
const rawThreshold = thresholdInput.value.trim()
|
|
|
|
|
|
if (props.mode === 'inventory' && ((rawThreshold && (!/^\d+$/.test(rawThreshold) || !Number.isSafeInteger(Number(rawThreshold)) || Number(rawThreshold) <= 0)) || (attention.value === 'COVERAGE_GT_THRESHOLD' && !rawThreshold))) {
|
|
|
|
|
|
error.value = '可售天数阈值须为正整数;选择超过阈值关注时必须填写'
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
appliedInventory.value = { attention: attention.value, sortBy: sortBy.value, coverageDaysThreshold: rawThreshold ? Number(rawThreshold) : undefined }
|
2026-10-12 21:36:24 +08:00
|
|
|
|
applied.value = { sku: String(filters.value.sku ?? '').trim() }
|
2026-10-12 20:33:39 +08:00
|
|
|
|
current.value = 1
|
2026-10-12 21:36:24 +08:00
|
|
|
|
void load(true)
|
2026-10-12 20:33:39 +08:00
|
|
|
|
}
|
2026-10-12 21:36:24 +08:00
|
|
|
|
function reset() { filters.value = { ...initialFilters(), warehouseCode: '', sku: '' }; applied.value = { sku: '' }; appliedInventory.value = { attention: 'ALL', sortBy: 'AVAILABLE_DESC' } }
|
|
|
|
|
|
function link(path: string) { void router.push({ path, query: { warehouseCode: warehouseCode.value, sku: applied.value.sku } }) }
|
2026-10-12 22:06:45 +08:00
|
|
|
|
watch(warehouseCode, () => { trendOpen.value = false; dataFence.cancel(); dailyFence.cancel(); rows.value = []; total.value = 0; context.value = null; daily.value = null; error.value = ''; current.value = 1; void load(true) })
|
2026-10-12 21:36:24 +08:00
|
|
|
|
watch([preset, tab, windowDays], () => { current.value = 1; if (!summaryMode.value || preset.value !== 'CUSTOM' || customStart.value && customEnd.value) void load() })
|
2026-10-12 20:33:39 +08:00
|
|
|
|
watch([current, size], () => { void load() })
|
|
|
|
|
|
onMounted(() => { visibility(); poller.start(); document.addEventListener('visibilitychange', visibility); void load() })
|
|
|
|
|
|
onUnmounted(() => { poller.stop(); dataFence.cancel(); dailyFence.cancel(); document.removeEventListener('visibilitychange', visibility) })
|
|
|
|
|
|
</script>
|
|
|
|
|
|
<template>
|
|
|
|
|
|
<AdminPage class="admin-density">
|
|
|
|
|
|
<p v-if="!permitted" role="alert">没有自营经营数据查看权限。</p>
|
|
|
|
|
|
<ListPageLayout v-else>
|
2026-10-12 22:06:45 +08:00
|
|
|
|
<DataTable appearance="integrated" v-model:page="current" v-model:page-size="size" :data="rows" :columns="columns" :loading="loading" :total="total" :empty-text="!warehouseCode ? '请选择仓库后查询SKU' : error ? '查询失败,请重试' : '暂无符合条件的SKU数据'">
|
|
|
|
|
|
<template #filters><QueryToolbar v-model="filters" :fields="fields" ariaLabel="自营SKU筛选" :preference-key="`self-operated-${mode}-query`" :loading="loading" :search-on-reset="false" @search="search" @reset="reset" /></template>
|
|
|
|
|
|
<template #notices>
|
2026-10-12 21:36:24 +08:00
|
|
|
|
<p v-if="runtimeError" class="analytics-note" role="status">{{ runtimeError }};最近观测:{{ beijingTime(overview?.observedAt) }}</p>
|
2026-10-12 20:33:39 +08:00
|
|
|
|
<LoadErrorState v-if="error" title="查询未完成" :message="error" :loading="loading" compact @retry="load(true)"><template #details><ApiErrorMeta v-if="errorDetails" :details="errorDetails" /></template></LoadErrorState>
|
2026-10-12 21:36:24 +08:00
|
|
|
|
<p v-if="newData || newDay" class="analytics-note" role="status">{{ newDay ? '北京时间已跨日。' : '有新数据。' }}点击查询更新数据。</p>
|
2026-10-13 00:10:54 +08:00
|
|
|
|
<p v-if="mode === 'inventory' && context" class="analytics-note" data-testid="inventory-observation">本仓库存采集时间(北京时间):{{ beijingTime(context.inventoryObservedFrom) }} 至 {{ beijingTime(context.inventoryObservedUntil) }}。{{ context.inventoryObservedFrom && context.inventoryObservedUntil ? '当前列表来自本仓一轮完整分页观测,各页在该时段内采集,不代表同一瞬间的库存。' : '尚无完整库存观测时段,缺失时间不以发布时间代替。' }}</p>
|
2026-10-12 21:36:24 +08:00
|
|
|
|
<details class="analytics-rules">
|
|
|
|
|
|
<summary>统计说明 · 北京时间/件</summary>
|
|
|
|
|
|
<p>{{ summaryMode ? '今日显示已采集量,完整日期显示出库量;未知数据不按零计算。' : '使用截至昨日的完整自然日;日均和可售天数由已采集数据计算。' }}同一SKU属于不同货主时分别展示。</p>
|
|
|
|
|
|
<p v-if="mode === 'inventory'">实物含全品质,可售仅正品;冻结、次品不重复计入实物,在途不计当前占仓。可售天数阈值只用于本次查询。</p>
|
|
|
|
|
|
<p v-if="context">查询时间:{{ beijingTime(context.queryAsOf) }};有效至 {{ beijingTime(context.queryExpiresAt) }}。销量覆盖截至 {{ context.salesCoveredUntil ? beijingTime(context.salesCoveredUntil) : '尚无可用数据' }}。{{ context.rebuildRequired ? '数据修订待重建。' : '' }}</p>
|
|
|
|
|
|
<p v-if="context">实际计算区间:{{ context.rangeStartDate ?? '—' }} 至 {{ context.rangeEndDateExclusive ?? '—' }}(截止日不含)<template v-if="context.calculationWindowDays != null">;{{ context.calculationWindowDays }} 天</template>。</p>
|
|
|
|
|
|
<p v-for="state in (overview?.warehouses ?? []).filter(item => item.warehouseCode === warehouseCode)" :key="state.dataFamily">{{ state.dataFamily === 'INVENTORY' ? '库存' : '销量' }}数据:{{ label(state.dataFreshness) }};最近发布时间 {{ beijingTime(state.lastPublishedAt) }}。</p>
|
|
|
|
|
|
</details>
|
2026-10-12 22:06:45 +08:00
|
|
|
|
</template>
|
2026-10-12 21:36:24 +08:00
|
|
|
|
<template #toolbar-actions><el-button :disabled="!warehouseCode" @click="link('/self-operated/collection')">查看采集状态</el-button><el-button :disabled="!warehouseCode" @click="link(mode === 'sales' ? '/self-operated/inventory' : '/self-operated/sales')">{{ mode === 'sales' ? '查看库存' : '查看销量' }}</el-button></template>
|
|
|
|
|
|
<template #actions="{ row }"><el-button class="density-action" @click="showTrend(asSummary(row))">每日趋势</el-button></template>
|
|
|
|
|
|
<template #sku="{ row }"><el-button class="density-action" :aria-label="`查看 ${asMetric(row).customerCode} ${asMetric(row).sku} 每日趋势`" @click="showTrend(asMetric(row))">{{ asMetric(row).sku }}</el-button></template>
|
|
|
|
|
|
<template #owner="{ row }"><span>{{ asMetric(row).customerName || asMetric(row).customerCode || '—' }}</span><small v-if="asMetric(row).customerName && asMetric(row).customerCode" class="analytics-owner-code">{{ asMetric(row).customerCode }}</small></template>
|
|
|
|
|
|
<template #unit="{ row }">{{ asMetric(row).quantityUnit === 'PCS' ? '件' : asMetric(row).quantityUnit || '—' }}</template>
|
2026-10-12 20:33:39 +08:00
|
|
|
|
<template #lastOutbound="{ row }">{{ asMetric(row).lastObservedOutboundDate ?? '已采集历史内未见出库' }}<br />历史覆盖起点:{{ asMetric(row).observedHistoryStartDate ?? '—' }}</template>
|
|
|
|
|
|
<template #attention="{ row }">{{ reasonsText(asMetric(row).attentionReasons) }}</template>
|
|
|
|
|
|
<template #quantity="{ row }">{{ quantityText(summaryMode ? shownQuantity(asSummary(row)) : asMetric(row).outboundQuantity) }} {{ summaryMode && asSummary(row).dataStatus !== 'COMPLETE' ? '(已采集,未完整)' : '' }}</template>
|
|
|
|
|
|
<template #status="{ row }">{{ label(summaryMode ? asSummary(row).dataStatus : asMetric(row).status) }}</template>
|
|
|
|
|
|
<template #reason="{ row }">{{ reasonsText(summaryMode ? asSummary(row).reasonCodes : asMetric(row).reasonCodes) }}</template>
|
|
|
|
|
|
<template v-for="key in ['physicalQuantity', 'availableQuantity', 'frozenQuantity', 'defectivePhysicalQuantity', 'transitQuantity', 'outboundQuantity30d', 'averageDailyOutboundQuantity', 'inventoryCoverageDays'] as const" :key="key" #[key]="{ row }">{{ quantityText(asMetric(row)[key]) }}<span v-if="asMetric(row).quantityStatuses?.[key] && asMetric(row).quantityStatuses?.[key] !== 'VALID'">({{ label(asMetric(row).quantityStatuses?.[key]) }})</span></template>
|
|
|
|
|
|
</DataTable>
|
|
|
|
|
|
</ListPageLayout>
|
2026-10-12 22:06:45 +08:00
|
|
|
|
<AppDialog v-model="trendOpen" class="admin-density-dialog" title="SKU每日出库趋势" width="1120px" :loading="trendLoading" :show-confirm="false" cancel-text="关闭" fullscreenable>
|
|
|
|
|
|
<div class="admin-density">
|
|
|
|
|
|
<LoadErrorState v-if="trendError" title="趋势读取失败" :message="trendError" compact><template #details><ApiErrorMeta v-if="trendErrorDetails" :details="trendErrorDetails" /></template></LoadErrorState>
|
|
|
|
|
|
<template v-if="daily">
|
|
|
|
|
|
<SkuTrend :data="daily" />
|
|
|
|
|
|
<el-button @click="router.push({ path: mode === 'inventory' ? '/self-operated/sales' : '/self-operated/inventory', query: { warehouseCode, sku: daily.summary.sku } })">{{ mode === 'inventory' ? '在销量页查看该SKU(全部货主)' : '在库存页查看该SKU(全部货主)' }}</el-button>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</AppDialog>
|
2026-10-12 20:33:39 +08:00
|
|
|
|
</AdminPage>
|
|
|
|
|
|
</template>
|
2026-10-12 21:36:24 +08:00
|
|
|
|
<style scoped>
|
|
|
|
|
|
.analytics-note, .analytics-rules { margin: 0; font-size: var(--admin-font-caption); }
|
|
|
|
|
|
.analytics-rules summary { cursor: pointer; }
|
|
|
|
|
|
.analytics-rules p { margin: var(--admin-space-2) 0; }
|
|
|
|
|
|
.analytics-owner-code { display: block; font-size: var(--admin-font-caption); color: var(--el-text-color-secondary); }
|
|
|
|
|
|
</style>
|