dsh-data-dashboard 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -30,7 +30,7 @@ export function createV10Overview({ T, g, model, Pn }) {
30
30
  el('em', { className: available(item) ? item.value > 0 ? 'is-up' : item.value < 0 ? 'is-down' : 'is-flat' : 'is-pending' }, text), label && el('span', {}, label));
31
31
  }
32
32
  function Comparison({ item, opening = false }) {
33
- return el('span', { className: `ov-comparison${opening ? ' ov-comparison-inline' : ''}` },
33
+ return el('span', { className: `ov-comparison ov-refresh${opening ? ' ov-comparison-inline' : ''}` },
34
34
  el(Growth, { item, label: '同比' }), el('span', { className: 'ov-previous', title: reason(item) }, opening ? '去年同期 ' : '去年同期 ',
35
35
  el(Value, { item: item?.previous, digits: opening ? 0 : 2, unit: opening ? '瓶' : '万' })));
36
36
  }
@@ -62,23 +62,81 @@ export function createV10Overview({ T, g, model, Pn }) {
62
62
  current && deduction && el('b', { className: 'ov-negative-label' }, number(item.negative / 10000))),
63
63
  !available(item) && !available(previous) && el('span', { className: 'ov-missing', 'data-state': item.state }, '—')),
64
64
  el('span', { className: 'ov-month-label' }, `${month}月`));
65
- })), el('span', { className: 'ov-chart-note' }, '底部斜纹为负金额 · 独立刻度'));
65
+ })));
66
+ }
67
+ const pct = (value, digits = 1) => `${number(value, digits)}%`;
68
+ const scopeKeyOf = filters => JSON.stringify([filters.month, filters.period, filters.start, filters.end, filters.region, filters.office, filters.unit, filters.product]);
69
+ // 卡片标题旁的期间小标:让人一眼看出当前月份或区间,以及来源截止到哪天。
70
+ function scopeLabel(kind, filters) {
71
+ const p = model.periodOf(filters), end = model.payload.coverage?.[kind]?.end;
72
+ const day = date => `${Number(date.slice(5, 7))}/${Number(date.slice(8))}`;
73
+ if (p.mode === 'range') return `${day(p.start)}–${day(p.end)} · ${p.days} 天`;
74
+ if (p.mode !== 'month') return p.label;
75
+ const month = `${Number(filters.month.slice(5))} 月`;
76
+ if (typeof end === 'string' && end < p.start) return `${month} · 来源截至 ${day(end)}`;
77
+ return typeof end === 'string' && end < p.end ? `${month} · 截至 ${day(end)}` : month;
78
+ }
79
+ // 达成进度条:只表示达成率(公司按季度销售,销量集中在季末,不与时间进度对比)。
80
+ function Progress({ item }) {
81
+ const ok = available(item), v = ok ? Math.max(0, Math.min(item.value, 100)) : 0;
82
+ return el('span', { className: `ov-progress${ok && item.value >= 100 ? ' is-done' : ''}`, 'aria-hidden': true }, ok && v > 0 && el('i', { style: { width: `${v}%` } }));
83
+ }
84
+ const targetText = target => available(target) ? `目标 ${number(target.value / 10000, 2)} 万` : '';
85
+ // 季度达成:主数字下的整行进度条。
86
+ function QuarterTarget({ t }) {
87
+ const item = t.attainment, ok = available(item);
88
+ const title = [ok ? `季度达成 ${pct(item.value)} = 季度累计 ÷ 全季目标` : `季度达成:${reason(item) || '待确认'}`, available(t.target) && t.target.note].filter(Boolean).join(';');
89
+ return el('div', { className: 'ov-month-target', title },
90
+ el('span', { className: 'ov-mt-label' }, '季度达成', el('b', {}, ok ? pct(item.value) : '—')),
91
+ el(Progress, { item }),
92
+ ok ? el('span', { className: 'ov-mt-meta' }, targetText(t.target)) : el('span', { className: 'ov-mt-meta ov-period-reason' }, reason(item) || '待确认'));
93
+ }
94
+ // 次要期间块:当月(区间)与财年。
95
+ function PeriodTile({ kind, head, sub, actual, growth, attainment, target, hasTargets, title, scopeKey }) {
96
+ const ok = hasTargets && available(attainment);
97
+ return el('div', { className: `ov-period ov-period-${kind}`, title },
98
+ el('span', { className: 'ov-period-head' }, el('span', {}, head), el('small', {}, sub),
99
+ hasTargets && available(target) && el('span', { className: 'ov-period-target' }, targetText(target))),
100
+ el('span', { className: 'ov-period-line' },
101
+ el('span', { key: `a${scopeKey}`, className: 'ov-period-value ov-refresh' }, el(Value, { item: actual, digits: 2, unit: '万' })),
102
+ growth && el(Growth, { item: growth, label: '同比' })),
103
+ hasTargets && el(Progress, { item: attainment }),
104
+ el('span', { className: 'ov-period-foot' },
105
+ ok ? el('span', {}, '达成 ', el('b', {}, pct(attainment.value)))
106
+ : el('span', { className: 'ov-period-reason' }, hasTargets ? reason(attainment) || '目标待确认' : '未上传经营目标')));
66
107
  }
67
108
  function Hero({ kind, data, comparison, filters, open, drill }) {
68
- const module = data.modules[kind], view = presentation.describe(kind, data, filters), movement = kind === 'movement';
69
- const ytdRatio = cross(module, 'invoiceMovementYtdRatio');
109
+ const module = data.modules[kind], movement = kind === 'movement', view = movement ? presentation.describe(kind, data, filters) : null;
110
+ const ytdRatio = cross(module, 'invoiceMovementYtdRatio'), targets = module.targets || {}, hasTargets = Boolean(targets.available);
70
111
  const ytd = extra(module, '当年截至所选月来源金额'), negativeAmount = extra(module, '负金额合计');
112
+ const scopeKey = scopeKeyOf(filters), p = model.periodOf(filters), range = p.mode === 'range', quarter = targets.quarter, fiscal = targets.fiscal;
113
+ const cover = model.payload.coverage?.[kind]?.end, day = date => `${Number(date.slice(5, 7))}/${Number(date.slice(8))}`;
114
+ // 主角:季度累计;没有可定位的季度时退回当月(区间)。
115
+ const primary = quarter ? quarter.actual : module.main, primaryYoY = quarter ? comparison.quarterYoY : comparison.yoy;
116
+ const primaryLabel = quarter ? module.main.label.replace(/^(当月|区间)/, '季度') : module.main.label;
117
+ const through = quarter && typeof cover === 'string' ? [quarter.end, cover].sort()[0] : quarter?.end;
118
+ const primaryScope = !quarter ? scopeLabel(kind, filters) : typeof cover === 'string' && cover < quarter.start ? `${quarter.label} · 来源截至 ${day(cover)}`
119
+ : through < quarter.periodEnd ? `${quarter.label} · 截至 ${day(through)}` : quarter.label;
120
+ const monthName = range ? '区间' : '当月', monthSub = scopeLabel(kind, filters);
121
+ const monthTitle = [`${monthName}:${monthSub}`, hasTargets && (available(targets.attainment) ? `${monthName}达成 ${pct(targets.attainment.value)};${targets.attainment.note || ''}` : `达成:${reason(targets.attainment)}`), range && '区间目标按天数折算'].filter(Boolean).join(';');
122
+ const fiscalTitle = fiscal ? [`财年:${fiscal.detail}`, fiscal.actual.range && `累计 ${fiscal.actual.range.start} 至 ${fiscal.actual.range.end}`, !available(fiscal.actual) && reason(fiscal.actual),
123
+ hasTargets && (available(fiscal.target) ? `全年目标 ${number(fiscal.target.value / 10000, 2)} 万元;${fiscal.target.note || ''}` : `目标:${reason(fiscal.target)}`)].filter(Boolean).join(';') : '';
71
124
  return el('article', { className: `overview-card ov-${kind} ov-hero`, style: { '--hero-accent': module.color }, role: 'button', tabIndex: 0, 'aria-label': `查看${module.title}详情`,
72
125
  onClick: () => open(kind), onKeyDown: event => { if (event.target === event.currentTarget && ['Enter', ' '].includes(event.key)) { event.preventDefault(); open(kind); } } },
73
126
  el('div', { className: 'ov-heading' }, el('i', { className: 'ov-dot', 'aria-hidden': true }), el('h2', {}, module.title), el('span', { className: 'ov-action' }, '详情 →')),
74
- el('p', { className: 'ov-label' }, module.main.label),
75
- el('div', { className: 'ov-hero-values' }, el('div', { className: 'ov-value', 'data-metric': kind }, el(Value, { item: module.main, digits: 2 })), el(Comparison, { item: comparison.yoy })),
127
+ el('p', { className: 'ov-label', title: quarter ? `${quarter.detail};累计到所选期间末日` : undefined }, el('span', {}, primaryLabel), el('span', { className: 'ov-scope-chip' }, primaryScope),
128
+ kind === 'invoice' && model.payload.platforms && Object.keys(model.payload.platforms).length > 0 && el('span', { className: 'ov-scope-chip is-soft', title: '发票合计含公司发票与已上传的平台订单,构成见发票详情' },
129
+ `含${Object.keys(model.payload.platforms).map(id => ({ zang10: '藏10', tunzhihu: '吞之乎' })[id]).join('、')}平台`)),
130
+ el('div', { className: 'ov-hero-values' }, el('div', { key: `v${scopeKey}`, className: 'ov-value ov-refresh', 'data-metric': kind }, el(Value, { item: primary, digits: 2 })), el(Comparison, { key: `c${scopeKey}`, item: primaryYoY })),
131
+ hasTargets && quarter && el(QuarterTarget, { t: quarter }),
132
+ el('div', { className: 'ov-periods' },
133
+ el(PeriodTile, { kind: 'month', head: monthName, sub: monthSub, actual: module.main, growth: comparison.yoy, attainment: targets.attainment, target: targets.month, hasTargets, title: monthTitle, scopeKey }),
134
+ fiscal && el(PeriodTile, { kind: 'fiscal', head: '财年', sub: `${fiscal.label.replace(' 财年', '')} · 7月起`, actual: fiscal.actual, attainment: fiscal.attainment, target: fiscal.target, hasTargets, title: fiscalTitle, scopeKey })),
76
135
  el('div', { className: 'ov-stats' },
77
- el(Stat, { label: '年累计', name: 'ytd', item: ytd, digits: 2, unit: '万', growth: comparison.ytdYoY }),
78
- el(Stat, { label: model.periodOf(filters).mode === 'range' ? '区间负金额' : '当月负金额', name: 'negative', item: negativeAmount, digits: 2, unit: '万' }),
79
- el(Stat, { label: movement ? '扫码终端' : '经销商', name: 'count', item: view.kpis[4], unit: '家' }),
80
- movement ? el(Stat, { label: '累计动销比', name: 'ratio', item: ytdRatio, digits: 1, unit: '%' })
81
- : el(Stat, { label: '达成率', name: 'attainment', item: view.kpis[5], digits: 1 })),
136
+ el(Stat, { label: '年累计 · 1月起', name: 'ytd', item: ytd, digits: 2, unit: '万', growth: comparison.ytdYoY }),
137
+ el(Stat, { label: range ? '区间负金额' : '当月负金额', name: 'negative', item: negativeAmount, digits: 2, unit: '万' }),
138
+ movement && el(Stat, { label: '扫码终端', name: 'count', item: view.kpis[4], unit: '家' }),
139
+ movement && el(Stat, { label: '累计动销比', name: 'ratio', item: ytdRatio, digits: 1, unit: '%' })),
82
140
  el(MonthlyChart, { points: comparison.monthly, kind, filters, drill }));
83
141
  }
84
142
  function Auxiliary({ label, item, digits = 0, unit = '' }) {
@@ -93,10 +151,7 @@ export function createV10Overview({ T, g, model, Pn }) {
93
151
  const inventoryDifference = { label: '盘点减系统金额差额', unit: '元', value: null,
94
152
  state: inventory.state === 'unavailable' ? 'missing' : 'pending',
95
153
  reason: inventory.state === 'unavailable' ? '未接入有效库存来源' : '两类库存金额的计价与估值基础尚未确认,暂不计算金额差额' };
96
- const cover = model.payload.coverage.banquet;
97
- const fixedPeriod = cover?.start && cover?.end ? cover.start.slice(0, 4) === cover.end.slice(0, 4)
98
- ? `${Number(cover.start.slice(5, 7))}–${Number(cover.end.slice(5, 7))} 月固定`
99
- : `${cover.start.slice(0, 7)} 至 ${cover.end.slice(0, 7)} 固定` : '固定期间待确认';
154
+ const banquetMonth = banquet.period.split(';')[0];
100
155
  const entries = [
101
156
  { module: terminal, auxiliary: el(g.Fragment, {}, el(Auxiliary, { label: '有效终端', item: terminalEffective }),
102
157
  el('span', { className: 'ov-tag', title: reason(terminalRate) }, '有效率 ', el(Value, { item: terminalRate, digits: 1, unit: '%' }))), note: `${number(totals.agreements)} 份协议;不随产品筛选` },
@@ -107,24 +162,15 @@ export function createV10Overview({ T, g, model, Pn }) {
107
162
  : { module: inventory, main: extra(inventory, '所选记录盘点金额合计'), digits: 2,
108
163
  auxiliary: el(g.Fragment, {}, el(Auxiliary, { label: '系统', item: extra(inventory, '所选记录系统金额合计'), digits: 2, unit: '万' }),
109
164
  el(Auxiliary, { label: '差额', item: inventoryDifference }), el(Auxiliary, { label: '可销', item: cross(inventory, 'inventorySellableMonths'), digits: 1, unit: '月' })), note: `${inventory.period};盘点金额与系统金额按来源分别展示,单位万元` },
110
- { module: banquet, auxiliary: el(g.Fragment, {}, el(Auxiliary, { label: '开瓶', item: extra(banquet, '固定期间宴席开瓶') }),
111
- el(Auxiliary, { label: '场均', item: extra(banquet, '场均开瓶'), digits: 1, unit: '瓶' }), el('span', { title: banquet.period }, fixedPeriod)), note: banquet.period },
165
+ { module: banquet, auxiliary: el(g.Fragment, {}, el(Auxiliary, { label: '开瓶', item: extra(banquet, '宴席开瓶'), unit: '瓶' }),
166
+ el(Auxiliary, { label: '场均', item: extra(banquet, '场均开瓶'), digits: 1, unit: '瓶' }), el('span', { title: banquet.period }, banquetMonth)), note: banquet.period },
112
167
  ];
113
168
  return el('section', { className: 'overview-card ov-operations', 'aria-label': '签约、库存与宴席' },
114
169
  ...entries.map(({ module, main = module.main, digits = 0, auxiliary, note }) => el('button', { key: module.id, type: 'button', className: `ov-operation ov-${module.id}`, onClick: () => open(module.id), 'aria-label': `查看${module.title}详情`, title: note },
115
170
  el('span', { className: 'ov-operation-heading' }, el('i', { className: 'ov-dot', style: { background: module.color } }), module.title, el('span', { className: 'ov-action' }, '→')),
116
171
  el('span', { className: 'ov-secondary-value', 'data-metric': module.id }, el(Value, { item: main, digits })), el('span', { className: 'ov-kv' }, auxiliary))));
117
172
  }
118
- function DayChange({ item }) {
119
- const day = date => date ? `${Number(date.slice(5, 7))}/${Number(date.slice(8))}` : '—';
120
- const bottles = value => finite(value) ? `${number(value)} 瓶` : '—';
121
- const diff = finite(item?.difference) ? `${item.difference > 0 ? '+' : ''}${number(item.difference)} 瓶` : '';
122
- const label = `${day(item?.date)} 较 ${day(item?.previousDate)}`;
123
- const detail = [`${item?.date || '末日'}:${bottles(item?.current)}`, `${item?.previousDate || '昨日'}:${bottles(item?.previous)}`, diff && `变化 ${diff}`, reason(item)].filter(Boolean).join(';');
124
- return el('span', { className: 'ov-day-change', 'data-state': item?.state, title: detail, 'aria-label': `较昨日开瓶 ${detail}` },
125
- el(Growth, { item, label }), el('span', { className: 'ov-day-values' }, bottles(item?.current), el('small', {}, ` / 昨日 ${bottles(item?.previous)}`)));
126
- }
127
- function Opening({ data, description, open }) {
173
+ function Opening({ data, description, filters, open }) {
128
174
  const module = data.modules.opening, points = description.openingDaily, previous = description.openingPreviousDaily;
129
175
  const valid = [...points, ...previous].filter(available), max = Math.max(0, ...valid.map(item => item.value)), min = Math.min(0, ...valid.map(item => item.value)), range = max - min || 1;
130
176
  const x = index => 3 + index * 394 / Math.max(points.length - 1, 1), y = value => 74 - (value - min) / range * 68, baseline = y(0);
@@ -143,28 +189,43 @@ export function createV10Overview({ T, g, model, Pn }) {
143
189
  const first = points[0]?.date, last = points.at(-1)?.date, year = first?.slice(0, 4);
144
190
  const ticks = [...new Set([first && Number(first.slice(8)), 10, 20, last && Number(last.slice(8))])].filter(day => first && day >= Number(first.slice(8)) && day <= Number(last.slice(8))).sort((a, b) => a - b);
145
191
  return el('button', { type: 'button', className: 'overview-card ov-opening', 'aria-label': '查看消费者开瓶详情', onClick: () => open('opening') },
146
- el('span', { className: 'ov-heading' }, el('i', { className: 'ov-dot' }), el('span', {}, module.title), el('span', { className: 'ov-action' }, '→')),
147
- el('span', { className: 'ov-opening-value' }, el('span', { className: 'ov-secondary-value', 'data-metric': 'opening' }, el(Value, { item: module.main }))),
148
- el(Comparison, { item: description.openingYoY, opening: true }),
149
- el(DayChange, { item: description.openingGrowth }),
150
- valid.length ? el('svg', { className: 'ov-sparkline', viewBox: '0 0 400 80', preserveAspectRatio: 'none', role: 'img', 'aria-label': `${description.openingPeriod}每日开瓶;两年按相同日期比较,缺日断开` },
192
+ el('span', { className: 'ov-heading' }, el('i', { className: 'ov-dot' }), el('span', {}, module.title), el('span', { className: 'ov-scope-chip' }, scopeLabel('opening', filters)), el('span', { className: 'ov-action' }, '→')),
193
+ // 2026-11-27:开瓶以开瓶金额(万元)为主,配同比、环比;开瓶瓶数为次要数字;去掉“较昨日”。
194
+ el('span', { className: 'ov-opening-value' }, el('span', { key: `o${scopeKeyOf(filters)}`, className: 'ov-secondary-value ov-refresh', 'data-metric': 'opening' }, el(Value, { item: extra(module, '开瓶金额'), digits: 2 })),
195
+ el('span', { className: 'ov-opening-bottles', title: reason(module.main) }, '开瓶 ', el(Value, { item: module.main, unit: '瓶' }))),
196
+ el('span', { className: 'ov-opening-compare' },
197
+ el('span', { title: (description.openingAmountYoY?.notes || []).join(';') || reason(description.openingAmountYoY) }, el(Growth, { item: description.openingAmountYoY, label: '同比' }),
198
+ el('small', {}, '去年同期 ', el(Value, { item: description.openingAmountYoY?.previous, digits: 2, unit: '万' }))),
199
+ el('span', { title: (description.openingAmountMoM?.notes || []).join(';') || reason(description.openingAmountMoM) }, el(Growth, { item: description.openingAmountMoM, label: '环比' }),
200
+ el('small', {}, '上月同期 ', el(Value, { item: description.openingAmountMoM?.previous, digits: 2, unit: '万' })))),
201
+ valid.length ? el('svg', { className: 'ov-sparkline', viewBox: '0 0 400 80', preserveAspectRatio: 'none', role: 'img', 'aria-label': `${description.openingPeriod}每日开瓶金额;两年按相同日期比较,缺日断开` },
151
202
  el('defs', {}, el('linearGradient', { id: 'ov-opening-fill', x1: '0', y1: '0', x2: '0', y2: '1' }, el('stop', { offset: '0', stopColor: '#4a6f94', stopOpacity: .16 }), el('stop', { offset: '1', stopColor: '#4a6f94', stopOpacity: 0 }))),
152
- ...paths(previous, true), ...paths(points, false)) : el('span', { className: 'ov-spark-empty' }, '—'),
203
+ ...paths(previous, true), ...paths(points, false)) : el('span', { className: 'ov-spark-empty' }, reason(module.main) || description.openingState?.reason || '所选期间暂无开瓶来源记录'),
153
204
  el('span', { className: 'ov-day-axis', title: description.openingPeriod }, ...ticks.map(day => el('span', { key: day }, `${day}日`))),
154
- el('span', { className: 'ov-opening-legend', title: `${description.openingPeriod};${reason(description.openingYoY)};组织口径,不随产品筛选` },
205
+ el('span', { className: 'ov-opening-legend', title: `${description.openingPeriod};每日开瓶金额;组织口径,不随产品筛选` },
155
206
  el('span', {}, el('i', {}), year || '本年'), el('span', { className: previous.some(available) ? '' : 'is-pending' }, el('i', { className: 'is-prior' }), year ? Number(year) - 1 : '上年'), el('span', {}, '不随产品筛选')));
156
207
  }
157
- function Regions({ items, filters, groupField, drill }) {
208
+ function Regions({ items, filters, groupField, drill, quarter }) {
158
209
  const modes = [['movement', '动销/发票'], ['terminal', '签约有效率'], ['opening', '开瓶']];
159
210
  const [mode, setMode] = g.useState('movement'), listRef = g.useRef(null);
160
211
  const scopeKey = JSON.stringify([filters.month, filters.period, filters.start, filters.end, filters.region, filters.office, filters.unit, filters.product]);
161
212
  g.useLayoutEffect(() => { listRef.current?.scrollTo({ top: 0, behavior: 'instant' }); }, [scopeKey]);
162
- const rows = [...items].sort((a, b) => (available(b.invoice) ? b.invoice.value : -Infinity) - (available(a.invoice) ? a.invoice.value : -Infinity) || a.name.localeCompare(b.name, 'zh-CN'));
213
+ // 只列本视图来源里出现过的组织:库存独有路径(“库存来源 · …”)不在这三个视图展示数据,不再占行。
214
+ const viewSources = { movement: ['invoice', 'movement'], terminal: ['terminal'], opening: ['opening'] }[mode];
215
+ const relevant = items.filter(row => !Array.isArray(row.sources) || row.sources.some(id => viewSources.includes(id)));
216
+ const hidden = items.length - relevant.length;
217
+ const sortKey = mode === 'movement' ? 'quarterInvoice' : 'invoice';
218
+ const rows = [...relevant].sort((a, b) => (available(b[sortKey]) ? b[sortKey].value : -Infinity) - (available(a[sortKey]) ? a[sortKey].value : -Infinity) || a.name.localeCompare(b.name, 'zh-CN'));
219
+ const hasTargets = Boolean(model.targetSource);
163
220
  const title = filters.unit !== 'all' ? '当前单元经营' : filters.region !== 'all' ? '下级经营一览' : '区域经营一览';
164
221
  const level = groupField === 'region' ? '大区' : groupField === 'office' ? '办事处' : '主任单元';
165
222
  const range = rows.find(row => row.openingTotal.range?.end >= row.openingTotal.range?.start)?.openingTotal.range;
166
223
  const openingPeriod = range ? `${range.start} 至 ${range.end}` : '共同期间待确认';
167
224
  const subtitle = mode === 'opening' ? `年累计 · ${openingPeriod}` : mode === 'terminal' ? `${model.periodOf(filters).mode === 'range' ? `截至 ${model.periodOf(filters).end}` : '截至所选月末'} · 按终端去重` : `${model.periodOf(filters).mode === 'range' ? model.periodOf(filters).label : `${Number(filters.month.slice(5)) || '当前'} 月`} · 点击${level}下钻`;
225
+ const coverEnds = ['invoice', 'movement'].map(id => model.payload.coverage?.[id]?.end).filter(Boolean).sort();
226
+ const quarterThrough = quarter ? [quarter.end, coverEnds[0] || quarter.end].sort()[0] : null;
227
+ const quarterSubtitle = quarter ? `季度 ${quarter.label}${quarterThrough && quarterThrough < quarter.periodEnd ? ` · 截至 ${Number(quarterThrough.slice(5, 7))}/${Number(quarterThrough.slice(8))}` : ''} · 点击${level}下钻` : subtitle;
228
+ const subtitleFull = mode !== 'movement' ? subtitle : hasTargets ? quarterSubtitle : `${quarterSubtitle} · 未上传经营目标,长条暂按季度金额对比`;
168
229
  const pairs = mode === 'terminal' ? [['signed', '签约'], ['effectiveCount', '有效']] : [['invoice', '发票'], ['movement', '动销']];
169
230
  const values = rows.flatMap(row => pairs.map(([key]) => row[key]).filter(available).map(item => item.value));
170
231
  const max = Math.max(0, ...values), min = Math.min(0, ...values), span = max - min || 1, zero = -min / span * 100;
@@ -174,6 +235,22 @@ export function createV10Overview({ T, g, model, Pn }) {
174
235
  min < 0 && el('s', { style: { left: `${zero}%` } }), available(row[key])
175
236
  ? el('i', { className: `ov-${key}-bar${negative(row[key]) ? ' is-negative' : ''}`, style: { left: `${row[key].value >= 0 ? zero : zero + row[key].value / span * 100}%`, width: `${Math.abs(row[key].value) / span * 100}%`, minWidth: row[key].value === 0 ? '1px' : undefined } })
176
237
  : el('em', { 'data-state': row[key].state }, '—'))));
238
+ // 季度达成进度条;未上传目标时按季度金额相对大小画条,并在副标题注明。
239
+ const amountMax = Math.max(0, ...rows.flatMap(row => [row.quarterInvoice, row.quarterMovement]).filter(available).map(item => item.value));
240
+ const goalCell = (row, attKey, amountKey, tone, label) => {
241
+ const att = row[attKey], amount = row[amountKey];
242
+ if (!hasTargets) {
243
+ const width = available(amount) && amount.value > 0 && amountMax > 0 ? amount.value / amountMax * 100 : 0;
244
+ return el('span', { className: `ov-goal ov-goal-${tone} is-amount`, 'data-region-metric': attKey, title: `${label}季度金额 ${valueText(amount, 2)} 万元(未上传经营目标,按金额相对大小显示)` },
245
+ el('span', { className: 'ov-goal-track' }, width > 0 && el('i', { style: { width: `${width}%` } })), el('b', {}));
246
+ }
247
+ const ok = available(att);
248
+ return el('span', { className: `ov-goal ov-goal-${tone}${ok && att.value >= 100 ? ' is-done' : ''}`, 'data-region-metric': attKey, 'data-state': att?.state,
249
+ title: ok ? `${label}季度达成 ${pct(att.value)};${att.note || ''}` : `${label}季度达成:${reason(att) || '待确认'}` },
250
+ el('span', { className: 'ov-goal-track' }, ok && att.value > 0 && el('i', { style: { width: `${Math.min(att.value, 100)}%` } })),
251
+ el('b', {}, ok ? pct(att.value, att.value >= 100 ? 0 : 1) : '—'));
252
+ };
253
+ const quarterField = (row, key, yoyKey) => el('span', { className: 'ov-number', 'data-region-metric': key }, el(Value, { item: row[key], digits: 2, unit: '' }), el(Growth, { item: row[yoyKey] }));
177
254
  function onTabKey(event, index) {
178
255
  const next = event.key === 'ArrowRight' ? (index + 1) % modes.length : event.key === 'ArrowLeft' ? (index + modes.length - 1) % modes.length : event.key === 'Home' ? 0 : event.key === 'End' ? modes.length - 1 : null;
179
256
  if (next === null) return;
@@ -181,27 +258,32 @@ export function createV10Overview({ T, g, model, Pn }) {
181
258
  }
182
259
  return el('section', { className: `overview-card ov-regional ov-region-${mode}`, 'aria-label': title, 'data-region-view': mode },
183
260
  el('div', { className: 'ov-region-header' }, el('div', { className: 'ov-heading' }, el('i', { className: 'ov-dot' }), el('h2', {}, title), el(UpLevel, { filters, drill, compact: true })),
184
- el('span', { className: 'ov-region-note', title: subtitle }, subtitle),
261
+ el('span', { className: 'ov-region-note', title: subtitleFull }, subtitleFull),
185
262
  el('div', { className: 'ov-region-tabs', role: 'tablist', 'aria-label': '区域经营视图' }, ...modes.map(([key, label], index) => el('button', {
186
263
  key, id: `ov-region-tab-${key}`, type: 'button', role: 'tab', tabIndex: mode === key ? 0 : -1,
187
264
  'aria-selected': mode === key, 'aria-controls': 'ov-region-panel', onClick: () => setMode(key), onKeyDown: event => onTabKey(event, index),
188
265
  }, label)))),
189
266
  el('div', { className: 'ov-region-columns' }, el('span', {}), el('span', {}, level),
190
267
  ...(mode === 'opening' ? [el('span', { key: 'total' }, '总开瓶数 / 瓶'), el('span', { key: 'rate' }, '总开瓶率')]
191
- : [el('span', { key: 'legend', className: 'ov-pair-legend' }, ...pairs.map(([key, label]) => el('span', { key }, el('i', { className: `ov-${key}-bar` }), label))),
192
- el('span', { key: 'first' }, mode === 'terminal' ? '签约数 / 家' : '发票 / 万元'), el('span', { key: 'second' }, mode === 'terminal' ? '有效数 / 家' : '动销 / 万元'), el('span', { key: 'rate' }, mode === 'terminal' ? '签约有效率' : '动销/发票')])),
193
- el('div', { className: 'ov-region-list', ref: listRef, id: 'ov-region-panel', role: 'tabpanel', tabIndex: 0, 'aria-labelledby': `ov-region-tab-${mode}`, 'aria-label': `${level}列表,可纵向滚动查看全部组织` },
268
+ : mode === 'terminal' ? [el('span', { key: 'legend', className: 'ov-pair-legend' }, ...pairs.map(([key, label]) => el('span', { key }, el('i', { className: `ov-${key}-bar` }), label))),
269
+ el('span', { key: 'first' }, '签约数 / 家'), el('span', { key: 'second' }, '有效数 / 家'), el('span', { key: 'rate' }, '签约有效率')]
270
+ : [el('span', { key: 'goal-invoice', className: 'ov-goal-head' }, el('i', { className: 'ov-invoice-bar' }), hasTargets ? '发票季度达成' : '季度发票'),
271
+ el('span', { key: 'goal-movement', className: 'ov-goal-head' }, el('i', { className: 'ov-movement-bar' }), hasTargets ? '动销季度达成' : '季度动销'),
272
+ el('span', { key: 'first' }, '季度发票 / 万元'), el('span', { key: 'second' }, '季度动销 / 万元')])),
273
+ el('div', { key: `${mode}${scopeKey}`, className: 'ov-region-list', ref: listRef, id: 'ov-region-panel', role: 'tabpanel', tabIndex: 0, 'aria-labelledby': `ov-region-tab-${mode}`, 'aria-label': `${level}列表,可纵向滚动查看全部组织` },
194
274
  ...rows.map((row, index) => el('button', { key: row.key, type: 'button', className: 'ov-region-row', disabled: !row.drillable, 'data-region-key': row.key,
195
275
  'aria-label': `${row.drillable ? '筛选' : '查看'}${row.name}`, title: row.fullName, onClick: () => row.drillable && drill(groupField, row.key) },
196
276
  el('span', { className: 'ov-rank' }, String(index + 1).padStart(2, '0')),
197
277
  el('span', { className: 'ov-region-name', title: row.fullName }, el('strong', {}, row.name),
198
- mode === 'movement' ? el('small', { title: reason(row.invoiceShare) }, '发票占比 ', el(Value, { item: row.invoiceShare, digits: 1, unit: '%' }))
278
+ mode === 'movement' ? el('small', { title: reason(row.quarterShare) }, '季度发票占比 ', el(Value, { item: row.quarterShare, digits: 1, unit: '%' }))
199
279
  : el('small', {}, mode === 'terminal' ? '签约终端 · 家' : '年累计 · 共同期间')),
200
280
  ...(mode === 'opening' ? [field(row, 'openingTotal'), field(row, 'openingRate', 1, '%')]
201
- : [bar(row), field(row, pairs[0][0], mode === 'movement' ? 2 : 0), field(row, pairs[1][0], mode === 'movement' ? 2 : 0),
202
- mode === 'terminal' ? field(row, 'effectiveRate', 1, '%') : field(row, 'ratio', 0, '%', available(row.ratio) && row.ratio.value > 300)]))),
281
+ : mode === 'terminal' ? [bar(row), field(row, 'signed'), field(row, 'effectiveCount'), field(row, 'effectiveRate', 1, '%')]
282
+ : [goalCell(row, 'invoiceQuarterAttainment', 'quarterInvoice', 'invoice', '发票'), goalCell(row, 'movementQuarterAttainment', 'quarterMovement', 'movement', '动销'),
283
+ quarterField(row, 'quarterInvoice', 'quarterInvoiceYoY'), quarterField(row, 'quarterMovement', 'quarterMovementYoY')]))),
203
284
  !rows.length && el('p', { className: 'ov-empty' }, '当前范围暂无组织来源记录')),
204
- el('div', { className: 'ov-region-foot' }, el('span', {}, mode === 'opening' ? '累计同比 · 不随产品筛选 · — 表示待确认或缺失' : '金额下方为同比 · — 表示待确认或缺失'),
285
+ el('div', { className: 'ov-region-foot' }, el('span', {}, mode === 'opening' ? '累计同比 · 不随产品筛选 · — 表示待确认或缺失' : '金额下方为同比 · — 表示待确认或缺失',
286
+ hidden > 0 && el('span', { title: '这些组织只出现在其他板块(多为库存盘点的独立路径),可在对应详情或筛选中查看' }, ` · 另有 ${hidden} 个组织本视图无来源记录,未列出`)),
205
287
  rows.length > 3 && el('span', {}, '向下滚动查看更多')));
206
288
  }
207
289
  const shiftDay = (date, days) => new Date(Date.parse(`${date}T00:00:00Z`) + days * 86400000).toISOString().slice(0, 10);
@@ -252,12 +334,20 @@ export function createV10Overview({ T, g, model, Pn }) {
252
334
  el('button', { type: 'button', className: 'period-clear', title: '全部重置:时间回到最新月份,组织和产品回到全部', 'aria-label': '全部重置', onClick: () => { drill('region', 'all'); drill('product', 'all'); drill('month', model.defaults.month); } }, '↺'),
253
335
  el('span', { className: `period-note${issue && changed ? ' is-error' : ''}`, 'aria-live': 'polite' }, issue && changed ? issue : range ? `${period.days} 天 · 签约、库存取末日状态` : `${period.label}${bounds ? ` · 数据至 ${bounds.max.slice(5)}` : ''}`));
254
336
  }
255
- function Overview({ data, filters, open, drill }) {
337
+ // 从详情返回总览时回到原来的滚动位置(筛选由外壳保留)。
338
+ let overviewScroll = null;
339
+ function Overview({ data, filters, open: openDetail, drill }) {
256
340
  const description = g.useMemo(() => adapter.describe(data, filters), [data, filters]);
341
+ g.useLayoutEffect(() => {
342
+ if (overviewScroll === null) return;
343
+ const y = overviewScroll; overviewScroll = null;
344
+ window.scrollTo(0, y); requestAnimationFrame(() => window.scrollTo(0, y));
345
+ }, []);
346
+ const open = kind => { overviewScroll = window.scrollY; openDetail(kind); };
257
347
  return el('div', { className: 'overview-shell', 'aria-label': '战区经营总览六板块' },
258
348
  el(Hero, { kind: 'invoice', data, comparison: description.heroes.invoice, filters, open, drill }), el(Hero, { kind: 'movement', data, comparison: description.heroes.movement, filters, open, drill }),
259
- el(Operations, { data, open }), el(Opening, { data, description, open }),
260
- el(Regions, { items: description.regional, filters, groupField: data.groupField, drill }));
349
+ el(Operations, { data, open }), el(Opening, { data, description, filters, open }),
350
+ el(Regions, { items: description.regional, filters, groupField: data.groupField, drill, quarter: data.modules.invoice.targets?.quarter }));
261
351
  }
262
352
  return { Overview, PeriodFilter, UpLevel };
263
353
  }
@@ -2,6 +2,7 @@
2
2
  export function createV10Presentation(model) {
3
3
  const cache = new WeakMap();
4
4
  const finite = value => typeof value === 'number' && Number.isFinite(value);
5
+ const available = item => item?.state === 'available' && finite(item.value);
5
6
  const text = value => typeof value === 'string' && value.trim().length > 0;
6
7
  const validDate = value => typeof value === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(value)
7
8
  && Number.isFinite(Date.parse(`${value}T00:00:00Z`)) && new Date(`${value}T00:00:00Z`).toISOString().slice(0, 10) === value;
@@ -107,6 +108,15 @@ export function createV10Presentation(model) {
107
108
  let kpis = [copy(m.main), ...(m.extra || []).map(item => copy(item))];
108
109
  const targetKpi = (item, label) => item ? copy(item, { label, displayPrecision: item.unit === '%' ? 1 : item.unit === '瓶' ? 0 : undefined, note: item.note || (item.target?.note ?? '') })
109
110
  : pending(label, '%', '未上传经营目标', 'missing');
111
+ // 季度、财年(7 月起)累计实际始终展示;上传目标后追加对应达成率与时间进度。
112
+ const cumulativeKpis = () => ['quarter', 'fiscal'].flatMap(kind => {
113
+ const t = m.targets?.[kind];
114
+ if (!t) return [];
115
+ const name = kind === 'quarter' ? `季度累计(${t.label})` : `${t.label}累计`;
116
+ const actual = copy(t.actual, { label: name, note: `${t.detail};${t.actual.range ? `${t.actual.range.start} 至 ${t.actual.range.end}` : ''}` });
117
+ if (!m.targets?.available) return [actual];
118
+ return [actual, targetKpi({ ...t.attainment, note: t.attainment.note || t.attainment.reason || '' }, `${kind === 'quarter' ? '季度' : '财年'}目标达成率`)];
119
+ });
110
120
  const dayKpi = change => {
111
121
  if (!change) return pending('较昨日开瓶', '%', '当前数据未提供日度比较');
112
122
  const day = date => date ? date.slice(5) : '—', bottles = value => finite(value) ? `${model.format(value)} 瓶` : '无记录';
@@ -118,13 +128,23 @@ export function createV10Presentation(model) {
118
128
  const notes = [...(m.pending || []), '金额保留为来源元值;界面换算显示不改变计算。缺少记录不补业务零值。'];
119
129
  const trend = { monthly: [], daily: [], cumulative: [], note: '' };
120
130
  if (kind !== 'banquet' && kind !== 'terminal') {
121
- const field = kind === 'opening' ? 'bottles' : kind === 'inventory' ? 'records' : 'amount', unit = kind === 'opening' ? '瓶' : kind === 'inventory' ? '条' : '元';
122
- trend.monthly = (m.monthly || []).map(item => {
131
+ // 开瓶节奏以开瓶金额为主(2026-11-27),瓶数作为每柱的副信息。
132
+ const field = kind === 'inventory' ? 'records' : 'amount', unit = kind === 'inventory' ? '条' : '元';
133
+ // 月度节奏只画本板块来源覆盖的月份,最多 13 个月(到来源最新月,含去年同月),所选月一定在窗口内。
134
+ // 全局月份轴会被其他来源(如库存历史提交)拉长,直接使用会出现整排“—”、所选月被挤出画面。
135
+ const ownCover = model.payload.coverage?.[kind], selectedMonth = p.mode === 'range' ? p.month : f.month;
136
+ const shiftMonth = (month, offset) => new Date(Date.UTC(Number(month.slice(0, 4)), Number(month.slice(5)) - 1 + offset, 1)).toISOString().slice(0, 7);
137
+ const coverStart = ownCover?.start?.slice(0, 7), coverEnd = ownCover?.end?.slice(0, 7);
138
+ let windowEnd = coverEnd && /^\d{4}-\d{2}$/.test(coverEnd) ? coverEnd : null, windowStart = windowEnd ? shiftMonth(windowEnd, -12) : null;
139
+ if (windowStart && /^\d{4}-\d{2}$/.test(selectedMonth || '') && selectedMonth < windowStart) { windowStart = selectedMonth; windowEnd = shiftMonth(selectedMonth, 12); }
140
+ const inWindow = item => kind === 'inventory' || ((!coverStart || item.month >= coverStart) && (!coverEnd || item.month <= coverEnd)
141
+ && (!windowStart || (item.month >= windowStart && item.month <= windowEnd)));
142
+ trend.monthly = (m.monthly || []).filter(inWindow).map(item => {
123
143
  const selected = (inventoryVisit ? rows : scoped).filter(row => row.month === item.month);
124
- const metric = kind === 'inventory' ? measure(selected, field, item.month, unit) : copy(item);
125
- const negative = metric.state === 'available' && field === 'amount' ? sum(selected.filter(row => row.amount < 0), 'amount') : null;
144
+ const metric = kind === 'inventory' || kind === 'opening' ? measure(selected, field, kind === 'opening' ? '开瓶金额' : item.month, unit) : copy(item);
145
+ const negative = metric.state === 'available' && field === 'amount' && kind !== 'opening' ? sum(selected.filter(row => row.amount < 0), 'amount') : null;
126
146
  return { ...metric, key: item.month, month: item.month, label: item.month, negative, comparison: null,
127
- ...(kind === 'opening' ? { cashAmount: measure(selected, 'amount', '现金红包金额', '元', `${item.month};与本柱开瓶瓶数使用相同组织和月份范围。`) } : {}) };
147
+ ...(kind === 'opening' ? { bottles: measure(selected, 'bottles', '开瓶瓶数', '瓶', `${item.month};与本柱开瓶金额使用相同组织和月份范围。`) } : {}) };
128
148
  });
129
149
  const dates = [], coverage = model.payload.coverage[kind];
130
150
  if (/^\d{4}-\d{2}$/.test(f.month) && validDate(coverage?.start) && validDate(coverage?.end)) {
@@ -134,7 +154,7 @@ export function createV10Presentation(model) {
134
154
  }
135
155
  trend.daily = dates.map(date => {
136
156
  const selected = rows.filter(row => row.date === date), metric = measure(selected, field, date, unit);
137
- return { ...metric, key: date, date, label: date, negative: metric.state === 'available' && field === 'amount' ? sum(selected.filter(row => row.amount < 0), 'amount') : null, comparison: null };
157
+ return { ...metric, key: date, date, label: date, negative: metric.state === 'available' && field === 'amount' && kind !== 'opening' ? sum(selected.filter(row => row.amount < 0), 'amount') : null, comparison: null };
138
158
  });
139
159
  let accumulated = 0, negativeTotal = 0, known = true;
140
160
  trend.cumulative = trend.daily.map(item => {
@@ -150,13 +170,15 @@ export function createV10Presentation(model) {
150
170
  }
151
171
  trend.note = inventoryVisit ? '仅统计截至所选月最近一次盘点的提交日期分布;同一经销商产品只计最新候选,不表示各月库存趋势或全部历史提交次数。' : kind === 'inventory' ? '仅统计当前上传导出记录的提交日期分布;不重建各月历史库存或自动重新去重。' : '月度按已上传来源月份展示;日轴为所选月与来源覆盖期间的交集,缺日断开、不补零,累计遇到缺日或缺值保持未知,不推断季末集中或环比。';
152
172
  if (inventoryVisit) trend.inventoryMode = 'visit-history';
153
- } else trend.note = kind === 'banquet' ? '来源固定期间汇总,没有逐日日期,不构造月度或日度趋势。' : '签约结构遵循独立矩阵合同。';
173
+ } else trend.note = kind === 'banquet' ? '宴席来源只到执行月份,没有逐日日期,不构造日度趋势。' : '签约结构遵循独立矩阵合同。';
154
174
  if (kind === 'invoice') {
155
175
  ranking.title = '经销商 · 当月发票净额';
156
176
  ranking.items = group(rows, row => row.dealerCode, row => `${row.dealerCode} · ${row.dealerName || '未提供名称'}`, 'amount', '元', '发票净额', row => text(row.dealerCode));
157
177
  ranking.concentration = concentration(ranking.items, '当前范围发票净额合计');
178
+ // 2026-11-27 用户要求:发票详情不再展示经销商数与经销商排行。
158
179
  kpis = [copy(m.main), existing('正金额合计', '元'), existing('负金额合计', '元'), existing('当年截至所选月来源金额', '元'),
159
- distinct(rows, 'dealerCode', '来源经销商数'), targetKpi(m.targets?.attainment, '目标达成率')];
180
+ targetKpi(m.targets?.attainment, '目标达成率')];
181
+ kpis.push(...cumulativeKpis());
160
182
  if (m.targets?.available) kpis.push(targetKpi(m.targets.ytdAttainment, '年累计目标达成率'), targetKpi(m.targets.month, p.mode === 'range' ? '区间目标' : '当月目标'), targetKpi(m.targets.ytd, '年累计目标'));
161
183
  }
162
184
  if (kind === 'movement') {
@@ -166,6 +188,7 @@ export function createV10Presentation(model) {
166
188
  channels = group(rows, row => row.channel, row => row.channel, 'amount', '元', '来源渠道净额', row => text(row.channel));
167
189
  kpis = [copy(m.main), existing('扫码数量(瓶单位记录)', '瓶'), existing('负金额合计', '元'), existing('当年截至所选月来源金额', '元'),
168
190
  distinct(rows, 'terminalCode', '来源扫码终端数'), cross('invoiceMovementYtdRatio', '年累计动销 / 开票', '%')];
191
+ kpis.push(...cumulativeKpis());
169
192
  if (m.targets?.available) kpis.push(targetKpi(m.targets.attainment, '目标达成率'), targetKpi(m.targets.ytdAttainment, '年累计目标达成率'), targetKpi(m.targets.month, p.mode === 'range' ? '区间目标' : '当月目标'));
170
193
  notes.push(...['扫码数量(盒单位记录)', '来源扫码件数'].map(label => { const metric = existing(label); return `${label}:${model.formatMetric(metric)}${metric.state === 'available' ? ` ${metric.unit}` : ''}。`; }));
171
194
  notes.push('负金额合计只按源金额符号汇总,不将所有负金额推定为退货出库。');
@@ -196,17 +219,15 @@ export function createV10Presentation(model) {
196
219
  trend.note += '发票对照仅在来源关系已确认且组织、产品、实际期间一致时显示;空白对照不补零。';
197
220
  }
198
221
  if (kind === 'opening') {
199
- cities = group(rows, row => row.city, row => row.city, 'bottles', '瓶', '城市开瓶瓶数', row => text(row.city));
200
- ranking = { title: '开瓶城市 · 消费地', items: cities, concentration: concentration(cities, '当前范围开瓶瓶数合计') };
222
+ cities = group(rows, row => row.city, row => row.city, 'amount', '元', '城市开瓶金额', row => text(row.city));
223
+ ranking = { title: '开瓶城市 · 消费地', items: cities, concentration: concentration(cities, '当前范围开瓶金额合计') };
201
224
  const yearRows = scoped.filter(row => validDate(row.date) && row.date.slice(0, 4) === f.month.slice(0, 4) && (p.mode === 'range' ? row.date <= p.end : row.date.slice(0, 7) <= f.month));
202
- kpis = [copy(m.main), existing('现金红包金额', '元'), distinct(rows, 'city', '来源开瓶城市', '个'),
203
- measure(yearRows, 'bottles', '当年截至所选月来源开瓶', '瓶', '只累计当前上传中已有的当年记录,不推断未提供月份。'),
204
- cross('openingMovementRatio', '年累计开瓶 / 动销(瓶)', '%'), dayKpi(m.dayChange)];
225
+ // 2026-11-27:开瓶金额为主(万元显示),去掉“较昨日”。
226
+ kpis = [copy(existing('开瓶金额', '元'), { label: p.mode === 'range' ? '区间开瓶金额' : '当月开瓶金额' }), copy(m.main), existing('瓶均开瓶金额', '元/瓶'),
227
+ measure(yearRows, 'amount', '当年截至所选月开瓶金额', '元', '只累计当前上传中已有的当年记录,不推断未提供月份。'),
228
+ distinct(rows, 'city', '来源开瓶城市', '个'), cross('openingMovementRatio', '年累计开瓶 / 动销(瓶)', '%')];
205
229
  if (m.targets?.available) kpis.push(targetKpi(m.targets.attainment, '目标达成率'), targetKpi(m.targets.ytdAttainment, '年累计目标达成率'), targetKpi(m.targets.month, p.mode === 'range' ? '区间目标' : '当月目标'));
206
- dayChanges = (m.dayChange?.groups || []).map(item => ({ ...dayKpi(item), key: item.key, name: model.label(item.key) }));
207
- notes.push('较昨日开瓶:所选期间末日与其前一天的开瓶瓶数比较;任一天无来源记录时不计算,不补零。宴席开瓶与消费者开瓶的包含关系不保证,不计算宴席开瓶占比。');
208
- const yearAmount = measure(yearRows, 'amount', '当年来源现金红包金额', '元');
209
- notes.push(`${yearAmount.label}:${model.formatMetric(yearAmount)}${yearAmount.state === 'available' ? ' 元' : ''}。`, '城市只按来源城市字段分组,不推定城市编码或消费者身份。');
230
+ notes.push('宴席开瓶与消费者开瓶的包含关系不保证,不计算宴席开瓶占比。', '城市只按来源城市字段分组,不推定城市编码或消费者身份。');
210
231
  }
211
232
  if (kind === 'inventory') {
212
233
  ranking.title = inventoryVisit ? '经销商 · 最近盘点瓶数' : '经销商 · 当前导出盘点金额';
@@ -269,9 +290,9 @@ export function createV10Presentation(model) {
269
290
  if (!inventoryVisit) notes.push('盘点经销商按来源编码识别,记录条数不等于去重 SKU 数;当前导出不重复选择所谓“最新快照”。');
270
291
  }
271
292
  if (kind === 'banquet') {
272
- ranking.title = '执行单元 · 来源固定期间';
293
+ ranking.title = '执行单元 · 所选月份';
273
294
  ranking.items = group(rows, row => row.unit || orgKey(row, 'unit'), row => model.label(row.unit || orgKey(row, 'unit')), 'events', '场', '执行场次', fullIdentity);
274
- ranking.concentration = concentration(ranking.items, '当前组织范围、来源固定期间执行场次合计');
295
+ ranking.concentration = concentration(ranking.items, '当前组织范围、所选月份执行场次合计');
275
296
  const byUnit = new Map();
276
297
  for (const row of rows) { const key = row.unit || orgKey(row, 'unit'); if (!byUnit.has(key)) byUnit.set(key, []); byUnit.get(key).push(row); }
277
298
  efficiency = ranking.items.map(item => {
@@ -279,18 +300,18 @@ export function createV10Presentation(model) {
279
300
  const ready = item.state === 'available' && events.state === 'available' && bottles.state === 'available' && events.value > 0 && finite(bottles.value / events.value);
280
301
  return { key: item.key, name: item.name, records: item.records, events: events.value, bottles: bottles.value,
281
302
  ...(ready ? { label: '场均开瓶', unit: '瓶/场', value: bottles.value / events.value, state: 'available', reason: null } : pending('场均开瓶', '瓶/场', item.reason || '来源场次、瓶数不完整或场次不大于零')),
282
- note: '同一完整单元路径、同一来源固定期间:开瓶瓶数 / 执行场次;不设未经确认的最低场次门槛。' };
303
+ note: '同一完整单元路径、同一期间:开瓶瓶数 / 执行场次;不设未经确认的最低场次门槛。' };
283
304
  });
284
305
  sortValues(efficiency);
285
306
  const active = guard('events', '有执行的单元', '个') || (ranking.items.some(item => item.state !== 'available') ? pending('有执行的单元', '个', '完整单元路径或来源场次不足')
286
307
  : { label: '有执行的单元', unit: '个', value: ranking.items.filter(item => item.value > 0).length, state: 'available', reason: null, note: '完整单元路径汇总场次大于 0。' });
287
- kpis = [copy(m.main), existing('固定期间宴席开瓶', '瓶'), existing('场均开瓶', '瓶/场'), existing('售点推荐奖励', '元'), active,
308
+ kpis = [copy(m.main), existing('宴席开瓶', '瓶'), existing('场均开瓶', '瓶/场'), active,
288
309
  copy(ranking.concentration.find(item => item.n === 5), { label: 'Top 5 单元场次占比' })];
289
- notes.push('场均与执行排行仅按现有完整单元路径和固定期间汇总;奖励不求和,不计算宴席占消费者开瓶比例。');
310
+ notes.push('按执行月份统计;自定义区间按覆盖到的整月计入。不计算宴席占消费者开瓶比例。');
290
311
  }
291
- const primaryNotes = p.mode === 'range' ? { invoice: `按业务日期净计 ${p.label} 源金额。`, movement: `按扫码日期净计 ${p.label} 源金额。`, opening: `按抽奖日期统计 ${p.label} 来源开瓶瓶数。`,
292
- inventory: inventoryVisit ? `截至 ${p.end},每个经销商与完整产品名称的最近一次已知盘点;不是当天实时库存。` : `当前上传导出中截至 ${p.end} 的盘点记录。`, banquet: '按来源确认的固定期间汇总。', terminal: `按签约日期截至 ${p.end};遵循最新矩阵规则。` } : { invoice: '按业务日期净计当月源金额。', movement: '按扫码日期净计当月源金额。', opening: '按抽奖日期统计当月来源开瓶瓶数。',
293
- inventory: inventoryVisit ? '截至所选月,每个经销商与完整产品名称的最近一次已知盘点;不是当天实时库存。' : '当前上传导出中截至所选月的盘点记录。', banquet: '按来源确认的固定期间汇总。', terminal: '按签约日期截至所选月末;遵循最新矩阵规则。' };
312
+ const primaryNotes = p.mode === 'range' ? { invoice: `按业务日期净计 ${p.label} 源金额。`, movement: `按扫码日期净计 ${p.label} 源金额。`, opening: `按抽奖日期统计 ${p.label} 开瓶金额。`,
313
+ inventory: inventoryVisit ? `截至 ${p.end},每个经销商与完整产品名称的最近一次已知盘点;不是当天实时库存。` : `当前上传导出中截至 ${p.end} 的盘点记录。`, banquet: `按执行月份汇总 ${p.start.slice(0, 7)} 至 ${p.end.slice(0, 7)} 整月。`, terminal: `按签约日期截至 ${p.end};遵循最新矩阵规则。` } : { invoice: '按业务日期净计当月源金额。', movement: '按扫码日期净计当月源金额。', opening: '按抽奖日期统计当月开瓶金额。',
314
+ inventory: inventoryVisit ? '截至所选月,每个经销商与完整产品名称的最近一次已知盘点;不是当天实时库存。' : '当前上传导出中截至所选月的盘点记录。', banquet: '按执行月份汇总所选月。', terminal: '按签约日期截至所选月末;遵循最新矩阵规则。' };
294
315
  for (let index = 0; index < kpis.length; index++) {
295
316
  const item = kpis[index];
296
317
  if (index === 0) item.note = primaryNotes[kind] || item.note;
@@ -301,7 +322,7 @@ export function createV10Presentation(model) {
301
322
  if (item.key === 'inventorySellableMonths') item.note = '库存金额 ÷ 近三月月均扫码金额;未折算全月。';
302
323
  if (item.key === 'openingMovementRatio') item.note = '同组织、同期间的开瓶瓶数 ÷ 动销瓶数。';
303
324
  if (item.key === 'invoiceMovementYtdRatio') item.note = '同组织、同产品、同期间的累计扫码净额 ÷ 发票净额。';
304
- if (item.label === '场均开瓶') item.note = '固定期间宴席开瓶瓶数 ÷ 执行场次。';
325
+ if (item.label === '场均开瓶') item.note = '宴席开瓶瓶数 ÷ 执行场次。';
305
326
  if (item.label === 'Top 5 单元场次占比') item.note = '按完整单元路径汇总执行场次占比。';
306
327
  }
307
328
  if (p.mode === 'range') for (const item of kpis) if (item.label?.startsWith('当年截至所选月')) {
@@ -322,7 +343,7 @@ export function createV10Presentation(model) {
322
343
  if (events.state !== 'available' || bottles.state !== 'available') {
323
344
  displayed.average = pending(label, unit, events.reason || bottles.reason || '来源场次或瓶数规则未确认');
324
345
  } else if (!validDate(coverage?.start) || !validDate(coverage?.end) || coverage.start > coverage.end || coverage.status === 'pending') {
325
- displayed.average = pending(label, unit, '来源固定期间未确认,不计算派生场均');
346
+ displayed.average = pending(label, unit, '来源执行月份缺失,不计算派生场均');
326
347
  } else if (events.value <= 0 || !finite(bottles.value / events.value)) {
327
348
  displayed.average = pending(label, unit, '来源场次不大于零或比值不可表示');
328
349
  } else {
@@ -332,7 +353,12 @@ export function createV10Presentation(model) {
332
353
  }
333
354
  return displayed;
334
355
  });
335
- const result = { kpis, dayChanges, trend, organizations, brands, products, ranking, channels, cities, health, deviations, efficiency, ...(inventoryVisit ? { invalidMetrics, inventoryMode: 'visit-history', inventoryReviewSummary } : {}),
356
+ // 发票来源构成(公司发票 + 两个平台)与分销商动销参考(不计入动销合计)。
357
+ const total = kind === 'invoice' && available(m.main) ? m.main.value : null;
358
+ const platformSources = kind === 'invoice' ? (m.platformSources || []).map(item => ({ ...item, name: item.label, share: finite(total) && total !== 0 && available(item) ? item.value / total : null,
359
+ shareText: finite(total) && total !== 0 && available(item) ? `占发票 ${model.format(item.value / total * 100, 1, 1)}%` : '', note: item.key === 'company' ? '公司发票系统(销售收入明细)' : `${item.label}订单,已并入发票合计` })) : [];
360
+ const distributor = kind === 'movement' && data.distributor ? data.distributor : null;
361
+ const result = { kpis, dayChanges: [], trend, organizations, brands, products, ranking, channels, cities, health, deviations, efficiency, platformSources, distributor, ...(inventoryVisit ? { invalidMetrics, inventoryMode: 'visit-history', inventoryReviewSummary } : {}),
336
362
  rows: sourceRows, notes: [...new Set(notes)] };
337
363
  if (!byKind) { byKind = new Map(); cache.set(supplied, byKind); }
338
364
  byKind.set(cacheKey, result);