优化
This commit is contained in:
@@ -5,7 +5,7 @@ import { validateCustomRange } from './state'
|
||||
export const buckets: { code: CoverageBucket; label: string }[] = [
|
||||
{ code: 'DAYS_0_30', label: '0~30天(含30)' }, { code: 'DAYS_30_60', label: '30~60天(含60)' },
|
||||
{ code: 'DAYS_60_90', label: '60~90天(含90)' }, { code: 'DAYS_GT_90', label: '超过90天' },
|
||||
{ code: 'NO_OUTBOUND_30D', label: '近30日无出库' }, { code: 'NO_AVAILABLE', label: '无可售库存' }, { code: 'UNKNOWN', label: '库存或销量待核验' },
|
||||
{ code: 'NO_OUTBOUND_IN_WINDOW', label: '所选时段无出库' }, { code: 'NO_AVAILABLE', label: '无可售库存' }, { code: 'UNKNOWN', label: '库存或销量待核验' },
|
||||
]
|
||||
export const rangeOptions: { value: RangePreset; label: string }[] = [{ 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: '自定义' }]
|
||||
export interface OverviewReturn { rangePreset: RangePreset; startDate?: string; endDate?: string; scroll: number }
|
||||
@@ -81,15 +81,19 @@ export function parseDashboardDrilldown(query: LocationQuery, mode: 'sales' | 'i
|
||||
} else {
|
||||
if (query.drilldownFrom !== undefined && scalar(query, 'drilldownFrom') !== 'DASHBOARD') throw new Error('库存下钻来源枚举无效')
|
||||
if (['analysis', 'rangePreset', 'startDate', 'endDate', 'windowDays'].some(key => query[key] !== undefined)) throw new Error('库存下钻不能携带销量日期条件')
|
||||
result.startDate = context.rangeStartDate ?? ''
|
||||
result.endDate = context.rangeEndDateExclusive ? previousDate(context.rangeEndDateExclusive) : ''
|
||||
if (validateCustomRange(result.startDate, result.endDate, context.anchorDate)) throw new Error('库存下钻缺少有效的原图统计区间')
|
||||
result.rangePreset = 'CUSTOM'
|
||||
const bucket = scalar(query, 'coverageBucket')
|
||||
const rule = scalar(query, 'bucketRuleVersion')
|
||||
const selection = scalar(query, 'coverageSelection')
|
||||
const attention = scalar(query, 'attention') || 'ALL'
|
||||
const sort = scalar(query, 'sortBy') || 'AVAILABLE_DESC'
|
||||
if (!['ALL', 'NO_OUTBOUND_30D'].includes(attention) || !['AVAILABLE_DESC', 'COVERAGE_DAYS_DESC', 'PHYSICAL_DESC', 'OUTBOUND_30D_ASC'].includes(sort)) throw new Error('库存下钻枚举无效')
|
||||
if (!['ALL', 'NO_OUTBOUND_IN_WINDOW'].includes(attention) || !['AVAILABLE_DESC', 'COVERAGE_DAYS_DESC', 'PHYSICAL_DESC', 'OUTBOUND_ASC'].includes(sort)) throw new Error('库存下钻枚举无效')
|
||||
if ((bucket && (!buckets.some(item => item.code === bucket) || rule !== 'COVERAGE_DISTRIBUTION_V1' || selection || attention !== 'ALL')) || (!bucket && rule) || (selection && (selection !== 'FINITE_POSITIVE' || attention !== 'ALL'))) throw new Error('库存分组条件无效或互斥')
|
||||
result.inventory = { attention: attention as 'ALL' | 'NO_OUTBOUND_30D', sortBy: sort as BusinessQuery['sortBy'], coverageBucket: bucket ? bucket as CoverageBucket : undefined, bucketRuleVersion: bucket ? 'COVERAGE_DISTRIBUTION_V1' : undefined, coverageSelection: selection ? 'FINITE_POSITIVE' : undefined, drilldownFrom: 'DASHBOARD' }
|
||||
result.summary += ` · ${buckets.find(item => item.code === bucket)?.label ?? (selection ? '有限正可售天数,从高到低' : attention === 'NO_OUTBOUND_30D' ? '近30日无出库,实物量从高到低' : '库存')}`
|
||||
result.inventory = { attention: attention as 'ALL' | 'NO_OUTBOUND_IN_WINDOW', sortBy: sort as BusinessQuery['sortBy'], coverageBucket: bucket ? bucket as CoverageBucket : undefined, bucketRuleVersion: bucket ? 'COVERAGE_DISTRIBUTION_V1' : undefined, coverageSelection: selection ? 'FINITE_POSITIVE' : undefined, drilldownFrom: 'DASHBOARD' }
|
||||
result.summary += ` · ${result.startDate} 至 ${result.endDate} · ${buckets.find(item => item.code === bucket)?.label ?? (selection ? '有限正可售天数,从高到低' : attention === 'NO_OUTBOUND_IN_WINDOW' ? '所选时段无出库,实物量从高到低' : '库存')}`
|
||||
}
|
||||
if (sku) result.summary += ` · ${customerCode ? `${customerCode} / ` : ''}${sku}`
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user