区分预约完成和取消状态标识
This commit is contained in:
@@ -41,6 +41,34 @@ function resolveAppointmentTimeText(item) {
|
||||
return `${startText}-${endText}`
|
||||
}
|
||||
|
||||
function isCompletedStatus(status) {
|
||||
return Number(status) === 2
|
||||
}
|
||||
|
||||
function isCancelledStatus(status) {
|
||||
return Number(status) === 3
|
||||
}
|
||||
|
||||
function appointmentStatusClass(status) {
|
||||
if (isCompletedStatus(status)) return 'is-completed'
|
||||
if (isCancelledStatus(status)) return 'is-cancelled'
|
||||
if (Number(status) === 0) return 'pending'
|
||||
return ''
|
||||
}
|
||||
|
||||
function completedOrCancelledClass(status) {
|
||||
if (isCompletedStatus(status)) return 'is-completed'
|
||||
if (isCancelledStatus(status)) return 'is-cancelled'
|
||||
return ''
|
||||
}
|
||||
|
||||
function resolveDayStatusClass(items) {
|
||||
if (!items.length) return ''
|
||||
if (items.every(item => isCompletedStatus(item.status))) return 'is-completed'
|
||||
if (items.every(item => isCancelledStatus(item.status))) return 'is-cancelled'
|
||||
return ''
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
viewMode: 'month',
|
||||
@@ -272,7 +300,10 @@ Page({
|
||||
}))
|
||||
return dateUtil.monthGrid(this.data.currentDateText).map(day => {
|
||||
const summary = summaryMap[day.date] || {}
|
||||
const artistCounts = this.normalizeArtistCounts(summary.artistCounts || artistTemplate)
|
||||
const dayAppointments = this.appointmentsByDate(day.date)
|
||||
const artistCounts = dayAppointments.length
|
||||
? this.appointmentCountsByDate(day.date)
|
||||
: this.normalizeArtistCounts(summary.artistCounts || artistTemplate)
|
||||
return {
|
||||
...day,
|
||||
isPast: day.date < todayText,
|
||||
@@ -280,7 +311,8 @@ Page({
|
||||
dayStatus: summary.dayStatus || 'free',
|
||||
artistCounts,
|
||||
expandedBlocks: this.buildExpandedBlocks(artistCounts),
|
||||
rowBlocks: this.buildRowBlocks(artistCounts)
|
||||
rowBlocks: this.buildRowBlocks(artistCounts),
|
||||
statusClass: resolveDayStatusClass(dayAppointments)
|
||||
}
|
||||
})
|
||||
},
|
||||
@@ -292,12 +324,14 @@ Page({
|
||||
const target = dateUtil.addDays(start, index)
|
||||
const date = dateUtil.formatDate(target)
|
||||
const summary = summaryMap[date] || { artistCounts: [], totalCount: 0 }
|
||||
const artistCounts = this.normalizeArtistCounts(summary.artistCounts || []).filter(count => count.count > 0)
|
||||
const dayAppointments = this.appointmentsByDate(date)
|
||||
const artistCounts = (dayAppointments.length ? this.appointmentCountsByDate(date) : this.normalizeArtistCounts(summary.artistCounts || [])).filter(count => count.count > 0)
|
||||
return {
|
||||
date,
|
||||
weekName: `周${label}`,
|
||||
day: target.getDate(),
|
||||
totalCount: summary.totalCount || 0,
|
||||
statusClass: resolveDayStatusClass(dayAppointments),
|
||||
artistCounts: artistCounts.map(count => ({
|
||||
...count,
|
||||
width: Math.max(12, Math.min(100, count.count * 22)),
|
||||
@@ -333,7 +367,8 @@ Page({
|
||||
...item,
|
||||
top: Math.max(0, itemStart - startMinute) + laneHeaderHeight,
|
||||
height: Math.max(64, item.durationMinutes || 60),
|
||||
timeText: resolveAppointmentTimeText(item)
|
||||
timeText: resolveAppointmentTimeText(item),
|
||||
statusClass: appointmentStatusClass(item.status)
|
||||
}
|
||||
})
|
||||
return { ...artist, blocks }
|
||||
@@ -359,6 +394,41 @@ Page({
|
||||
}, {})
|
||||
},
|
||||
|
||||
appointmentsByDate(date) {
|
||||
return (this.data.appointments || []).filter(item => resolveAppointmentDate(item) === date)
|
||||
},
|
||||
|
||||
appointmentCountsByDate(date) {
|
||||
const artistMap = (this.data.artists || []).reduce((map, artist) => {
|
||||
map[String(artist.id)] = artist
|
||||
return map
|
||||
}, {})
|
||||
const grouped = new Map()
|
||||
this.appointmentsByDate(date).forEach((item, index) => {
|
||||
const artist = artistMap[String(item.artistId)] || {}
|
||||
const artistName = item.artistName || artist.name
|
||||
const statusClass = completedOrCancelledClass(item.status)
|
||||
const key = `${String(item.artistId || item.orderItemId)}-${statusClass || 'active'}`
|
||||
const existing = grouped.get(key)
|
||||
if (existing) {
|
||||
grouped.set(key, { ...existing, count: existing.count + 1 })
|
||||
} else {
|
||||
grouped.set(key, {
|
||||
key: `${key}-${index}`,
|
||||
orderItemId: item.orderItemId,
|
||||
artistId: item.artistId || item.orderItemId,
|
||||
artistName,
|
||||
shortName: artist.shortName || String(artistName || '?').slice(0, 1),
|
||||
color: artist.color || '#B8B0A6',
|
||||
count: 1,
|
||||
status: item.status,
|
||||
statusClass
|
||||
})
|
||||
}
|
||||
})
|
||||
return Array.from(grouped.values())
|
||||
},
|
||||
|
||||
normalizeArtistCounts(counts) {
|
||||
const colorMap = this.data.artists.reduce((map, artist) => {
|
||||
map[artist.id] = artist
|
||||
@@ -368,6 +438,7 @@ Page({
|
||||
const artist = colorMap[count.artistId] || {}
|
||||
return {
|
||||
...count,
|
||||
key: `${String(count.artistId)}-${count.status || 'summary'}`,
|
||||
color: count.color || artist.color || '#B8B0A6',
|
||||
shortName: count.shortName || artist.shortName || '?',
|
||||
count: Number(count.count || 0)
|
||||
@@ -379,10 +450,11 @@ Page({
|
||||
return (artistCounts || []).reduce((blocks, count) => {
|
||||
for (let index = 0; index < Number(count.count || 0); index += 1) {
|
||||
blocks.push({
|
||||
key: `${count.artistId || count.shortName}-${index}`,
|
||||
key: count.key ? `${count.key}-${index}` : `${count.artistId || count.shortName}-${index}`,
|
||||
artistId: count.artistId,
|
||||
color: count.color,
|
||||
shortName: count.shortName
|
||||
shortName: count.shortName,
|
||||
statusClass: count.statusClass
|
||||
})
|
||||
}
|
||||
return blocks
|
||||
@@ -393,11 +465,12 @@ Page({
|
||||
return (artistCounts || []).reduce((rows, count) => {
|
||||
for (let index = 0; index < Number(count.count || 0); index += 1) {
|
||||
rows.push({
|
||||
key: `${count.artistId || count.shortName}-row-${index}`,
|
||||
key: count.key ? `${count.key}-row-${index}` : `${count.artistId || count.shortName}-row-${index}`,
|
||||
artistId: count.artistId,
|
||||
color: count.color,
|
||||
shortName: count.shortName,
|
||||
artistName: count.artistName || count.shortName
|
||||
artistName: count.artistName || count.shortName,
|
||||
statusClass: count.statusClass
|
||||
})
|
||||
}
|
||||
return rows
|
||||
|
||||
Reference in New Issue
Block a user