规划页并排展示待分配预约
This commit is contained in:
@@ -47,6 +47,60 @@ function resolveAppointmentTimeText(item) {
|
||||
return `${startText}-${endText}`
|
||||
}
|
||||
|
||||
function layoutAppointmentBlocks(items, startMinute, minuteScale, laneHeaderHeight, defaultLaneWidth) {
|
||||
const entries = (items || [])
|
||||
.filter(item => item.startTime)
|
||||
.map(item => {
|
||||
const itemStart = resolveAppointmentStartMinute(item)
|
||||
const requestedDuration = Number(item.durationMinutes || 60)
|
||||
const duration = Math.max(15, Number.isFinite(requestedDuration) ? requestedDuration : 60)
|
||||
return { ...item, itemStart, itemEnd: itemStart + duration, durationMinutes: duration }
|
||||
})
|
||||
.sort((left, right) => left.itemStart - right.itemStart || left.itemEnd - right.itemEnd)
|
||||
|
||||
const groups = []
|
||||
entries.forEach(entry => {
|
||||
let group = groups[groups.length - 1]
|
||||
if (!group || entry.itemStart >= group.end) {
|
||||
group = { entries: [], end: entry.itemEnd, columnCount: 0 }
|
||||
groups.push(group)
|
||||
}
|
||||
group.entries.push(entry)
|
||||
group.end = Math.max(group.end, entry.itemEnd)
|
||||
})
|
||||
|
||||
let maxColumns = 1
|
||||
groups.forEach(group => {
|
||||
const columnEnds = []
|
||||
group.entries.forEach(entry => {
|
||||
let columnIndex = columnEnds.findIndex(end => end <= entry.itemStart)
|
||||
if (columnIndex < 0) columnIndex = columnEnds.length
|
||||
columnEnds[columnIndex] = entry.itemEnd
|
||||
entry.columnIndex = columnIndex
|
||||
})
|
||||
group.columnCount = columnEnds.length
|
||||
group.entries.forEach(entry => { entry.columnCount = group.columnCount })
|
||||
maxColumns = Math.max(maxColumns, group.columnCount)
|
||||
})
|
||||
|
||||
const laneWidth = Math.max(defaultLaneWidth, maxColumns * defaultLaneWidth)
|
||||
const blocks = entries.map(entry => {
|
||||
const slotWidth = laneWidth / entry.columnCount
|
||||
return {
|
||||
...entry,
|
||||
top: Math.max(0, entry.itemStart - startMinute) * minuteScale + laneHeaderHeight,
|
||||
height: entry.durationMinutes * minuteScale,
|
||||
left: Math.round(entry.columnIndex * slotWidth + 12),
|
||||
width: Math.round(slotWidth - 24),
|
||||
compact: entry.durationMinutes <= 15,
|
||||
overlapCount: entry.columnCount,
|
||||
timeText: resolveAppointmentTimeText(entry)
|
||||
}
|
||||
})
|
||||
|
||||
return { blocks, laneWidth }
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
viewMode: 'month',
|
||||
@@ -494,31 +548,30 @@ Page({
|
||||
...item,
|
||||
top: Math.max(0, itemStart - startMinute) * minuteScale + laneHeaderHeight,
|
||||
height: Math.max(60, (item.durationMinutes || 60) * minuteScale),
|
||||
left: 12,
|
||||
width: 224,
|
||||
compact: Number(item.durationMinutes || 60) <= 15,
|
||||
timeText: resolveAppointmentTimeText(item)
|
||||
}
|
||||
})
|
||||
return { ...artist, artistId: artist.id, blocks }
|
||||
return { ...artist, artistId: artist.id, blocks, width: 248 }
|
||||
})
|
||||
const unassignedBlocks = dayAppointments
|
||||
.filter(item => !item.artistId)
|
||||
.filter(item => item.startTime)
|
||||
.map(item => {
|
||||
const itemStart = resolveAppointmentStartMinute(item)
|
||||
return {
|
||||
...item,
|
||||
top: Math.max(0, itemStart - startMinute) * minuteScale + laneHeaderHeight,
|
||||
height: Math.max(60, (item.durationMinutes || 60) * minuteScale),
|
||||
compact: Number(item.durationMinutes || 60) <= 15,
|
||||
timeText: resolveAppointmentTimeText(item)
|
||||
}
|
||||
})
|
||||
const unassignedLayout = layoutAppointmentBlocks(
|
||||
dayAppointments.filter(item => !item.artistId),
|
||||
startMinute,
|
||||
minuteScale,
|
||||
laneHeaderHeight,
|
||||
248
|
||||
)
|
||||
const unassignedBlocks = unassignedLayout.blocks
|
||||
const lanes = this.data.selectedArtistId ? employeeLanes : [{
|
||||
id: '__unassigned__',
|
||||
artistId: '__unassigned__',
|
||||
name: '待分配',
|
||||
color: '#D59A52',
|
||||
blocks: unassignedBlocks,
|
||||
width: unassignedLayout.laneWidth,
|
||||
isUnassigned: true,
|
||||
emptyText: '暂无待分配'
|
||||
}, ...employeeLanes]
|
||||
const pendingCount = dayAppointments.filter(item => item.status === 0).length
|
||||
@@ -528,7 +581,7 @@ Page({
|
||||
timelineHeight: timelineHeight + laneHeaderHeight,
|
||||
laneHeaderHeight,
|
||||
laneItemWidth: 248,
|
||||
laneWidth: Math.max(720, lanes.length * 248),
|
||||
laneWidth: Math.max(720, lanes.reduce((width, lane) => width + (lane.width || 248), 0)),
|
||||
dayTotal: dayAppointments.length,
|
||||
freeArtistCount: employeeLanes.filter(item => item.blocks.every(block => block.historicalBackfill)).length,
|
||||
pendingCount,
|
||||
|
||||
Reference in New Issue
Block a user