This commit is contained in:
zlwu committed 2026-08-30 18:33:13 +08:00
1 parent c8cec132bf
commit 19c5aaa8f5
95 files changed
+309129 -9838

No files matched your search

@@ -77,6 +77,87 @@ export function flattenPlanListRows(plans: Plan[]): PlPlanListDisplayRow[] {
return rows
}
function stopHasProductId(
stop: PlanLoad | PlanDelivery | null | undefined,
productId: string
): boolean {
const pid = String(productId || '').trim()
if (!pid || !stop) return false
return (stop.products || []).some((p) => String(p.productId || '') === pid)
}
/** 仅保留指定产品(计划产品行 + 各段产品行);不含该产品的送货段丢弃。 */
export function filterPlanToProductId(plan: Plan, productId: string): Plan {
const pid = String(productId || '').trim()
if (!pid) return plan
const match = (p: { productId?: string }) => String(p.productId || '') === pid
const products = (plan.products || []).filter(match)
const load = plan.load
? { ...plan.load, products: (plan.load.products || []).filter(match) }
: plan.load
const deliveries = (plan.deliveries || [])
.map((d) => ({ ...d, products: (d.products || []).filter(match) }))
.filter((d) => (d.products || []).length > 0)
return { ...plan, products, load, deliveries }
}
/**
* 展平运输计划列表行,但只保留含指定产品的段次(不展示同计划其他商品)。
* 用于合同用量等「单产品」弹窗列表。
*/
export function flattenPlanListRowsForProduct(
plans: Plan[],
productId: string
): PlPlanListDisplayRow[] {
const pid = String(productId || '').trim()
if (!pid) return flattenPlanListRows(plans)
const rows: PlPlanListDisplayRow[] = []
let planListIndex = 0
for (const raw of plans || []) {
if (!raw?.id) continue
const plan = filterPlanToProductId(raw, pid)
const { load, deliveries } = resolvePlanStopsForList(plan)
type StopSlot = {
kind: PlPlanListDisplayRowKind
stop: PlanLoad | PlanDelivery
deliverySeq?: number
}
const stops: StopSlot[] = []
if (stopHasProductId(load, pid)) {
stops.push({ kind: 'load', stop: load })
}
deliveries.forEach((delivery, index) => {
if (!stopHasProductId(delivery, pid)) return
stops.push({
kind: 'delivery',
stop: delivery,
deliverySeq: delivery.seq ?? index + 1
})
})
if (!stops.length) continue
const planRowSpan = stops.length
stops.forEach((slot, index) => {
const isLoad = slot.kind === 'load'
rows.push({
rowKey: isLoad
? `${plan.id}-load`
: `${plan.id}-delivery-${slot.deliverySeq ?? index + 1}`,
plan,
kind: slot.kind,
stop: slot.stop,
deliverySeq: slot.deliverySeq,
planListIndex,
isPlanFirstRow: index === 0,
planRowSpan,
isPlanLastRow: index === stops.length - 1
})
})
planListIndex += 1
}
return rows
}
export function getPlanListDisplayIndex(
displayRows: PlPlanListDisplayRow[],
displayRowIndex: number,
@@ -102,14 +183,16 @@ export function isPlPlanListPlanMergeColumn(
}
export function buildPlPlanListSpanMethod(
visiblePlanProps: string[]
visiblePlanProps: string[],
fixedMergeColCount: number = PLAN_FIXED_MERGE_COL_COUNT
): (args: {
row: PlPlanListDisplayRow
column: { type?: string; property?: string }
rowIndex: number
columnIndex: number
}) => { rowspan: number; colspan: number } | undefined {
const planMergeCount = PLAN_FIXED_MERGE_COL_COUNT + visiblePlanProps.length
const fixed = Math.max(0, fixedMergeColCount)
const planMergeCount = fixed + visiblePlanProps.length
return ({ row, columnIndex }) => {
if (columnIndex >= planMergeCount) return undefined
if (row.isPlanFirstRow) {
@@ -120,7 +203,10 @@ export function buildPlPlanListSpanMethod(
}
export function getPlPlanListRowClassName({ row }: { row: PlPlanListDisplayRow }): string {
const classes = [row.kind === 'load' ? 'pl-plan-list-row--load' : 'pl-plan-list-row--delivery']
const classes = [
'pl-plan-list-row',
row.kind === 'load' ? 'pl-plan-list-row--load' : 'pl-plan-list-row--delivery'
]
if (row.planListIndex % 2 === 1) classes.push('pl-plan-list-row--plan-striped')
if (row.isPlanLastRow) classes.push('pl-plan-list-row--plan-end')
return classes.join(' ')