区分预约完成和取消状态标识

This commit is contained in:
2026-07-12 11:51:52 +08:00
parent 157af9f45b
commit 58498db422
8 changed files with 424 additions and 30 deletions
+179 -11
View File
@@ -66,7 +66,7 @@
v-for="block in lane.blocks"
:key="String(block.orderItemId)"
class="appointment-block"
:class="{ pending: block.status === 0 }"
:class="appointmentStatusClass(block.status)"
type="button"
:style="{ top: `${block.top}px`, height: `${block.height}px`, borderLeftColor: lane.color || '#b8b0a6' }"
@click="openAppointment(block.orderItemId)"
@@ -88,7 +88,7 @@
v-for="day in weekDays"
:key="day.date"
class="card week-day-card"
:class="{ active: day.date === currentDateText }"
:class="[{ active: day.date === currentDateText }, day.statusClass]"
type="button"
@click="selectDate(day.date)"
>
@@ -109,6 +109,7 @@
v-for="count in day.artistCounts"
:key="String(count.artistId)"
class="week-count-bar"
:class="count.statusClass"
:style="{ width: `${count.barWidth}%`, backgroundColor: count.color }"
>
{{ count.shortName }}{{ count.count }}
@@ -147,18 +148,18 @@
<span v-if="!day.isPast && day.totalCount > 0 && day.dayStatus === 'full'" class="day-mark full">满</span>
<span v-else-if="!day.isPast && day.totalCount > 0 && day.dayStatus === 'rest'" class="day-mark rest">休</span>
<div v-if="monthDisplayMode === 'count'" class="month-bars">
<span v-for="count in day.artistCounts.filter(item => item.count > 0)" :key="String(count.artistId)" :style="{ backgroundColor: count.color }">
<span v-for="count in day.artistCounts.filter(item => item.count > 0)" :key="count.key || String(count.artistId)" :class="count.statusClass" :style="{ backgroundColor: count.color }">
<b>{{ resolveMonthCountName(count) }}</b>
<em>{{ count.count }}</em>
</span>
<small v-if="day.totalCount === 0">空</small>
</div>
<div v-else-if="monthDisplayMode === 'blocks'" class="month-blocks">
<span v-for="block in day.expandedBlocks" :key="block.key" :style="{ backgroundColor: block.color }"></span>
<span v-for="block in day.expandedBlocks" :key="block.key" :class="block.statusClass" :style="{ backgroundColor: block.color }"></span>
<small v-if="day.totalCount === 0">空</small>
</div>
<div v-else class="month-blocks month-blocks--rows">
<span v-for="block in day.rowBlocks" :key="block.key" :style="{ backgroundColor: block.color }">{{ monthRowLabelVisible ? block.artistName : '' }}</span>
<span v-for="block in day.rowBlocks" :key="block.key" :class="block.statusClass" :style="{ backgroundColor: block.color }">{{ monthRowLabelVisible ? block.artistName : '' }}</span>
<small v-if="day.totalCount === 0">空</small>
</div>
</button>
@@ -205,12 +206,15 @@ type ViewMode = 'day' | 'week' | 'month'
type MonthDisplayMode = 'count' | 'blocks' | 'rows'
interface NormalizedCount {
key?: string
artistId: IdType
artistName?: string
shortName?: string
color: string
count: number
status?: string
statusClass?: string
orderItemId?: IdType
width?: number
barWidth?: number
}
@@ -221,6 +225,7 @@ interface MonthBlock {
color: string
shortName?: string
artistName?: string
statusClass?: string
}
interface MonthDay {
@@ -233,6 +238,7 @@ interface MonthDay {
artistCounts: NormalizedCount[]
expandedBlocks: MonthBlock[]
rowBlocks: MonthBlock[]
statusClass: string
}
interface WeekDay {
@@ -241,6 +247,7 @@ interface WeekDay {
day: number
totalCount: number
artistCounts: NormalizedCount[]
statusClass: string
}
interface DayLane extends Artist {
@@ -302,6 +309,64 @@ const resolveRange = (): { start: string; end: string } => {
return { start: currentDateText.value, end: currentDateText.value }
}
const isCompletedStatus = (status?: number | string): boolean => Number(status) === 2
const isCancelledStatus = (status?: number | string): boolean => Number(status) === 3
const appointmentStatusClass = (status?: number | string): string => {
if (isCompletedStatus(status)) return 'is-completed'
if (isCancelledStatus(status)) return 'is-cancelled'
if (Number(status) === 0) return 'pending'
return ''
}
const completedOrCancelledClass = (status?: number | string): string => {
if (isCompletedStatus(status)) return 'is-completed'
if (isCancelledStatus(status)) return 'is-cancelled'
return ''
}
const resolveDayStatusClass = (items: Appointment[]): string => {
if (items.length === 0) return ''
if (items.every(item => isCompletedStatus(item.status))) return 'is-completed'
if (items.every(item => isCancelledStatus(item.status))) return 'is-cancelled'
return ''
}
const appointmentsByDate = (date: string): Appointment[] => appointments.value.filter(item => resolveAppointmentDate(item) === date)
const appointmentCountsByDate = (date: string): NormalizedCount[] => {
const dayItems = appointmentsByDate(date)
const artistMap = artists.value.reduce<Record<string, Artist>>((result, artist) => {
result[String(resolveArtistUserId(artist))] = artist
return result
}, {})
const grouped = new Map<string, NormalizedCount>()
dayItems.forEach((item, index) => {
const artist = artistMap[String(item.artistId)]
const artistName = item.artistName || artist?.name
const shortName = artist?.shortName || String(artistName || '?').slice(0, 1)
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,
color: artist?.color || '#b8b0a6',
count: 1,
status: String(item.status ?? ''),
statusClass
})
}
})
return Array.from(grouped.values())
}
const normalizeArtistCounts = (counts: NonNullable<DaySummary['artistCounts']>): NormalizedCount[] => {
const artistMap = artists.value.reduce<Record<string, Artist>>((result, artist) => {
result[String(resolveArtistUserId(artist))] = artist
@@ -310,6 +375,7 @@ const normalizeArtistCounts = (counts: NonNullable<DaySummary['artistCounts']>):
return counts.map(count => {
const artist = artistMap[String(count.artistId)]
return {
key: `${String(count.artistId)}-${count.status || 'summary'}`,
artistId: count.artistId,
artistName: count.artistName || artist?.name,
shortName: count.shortName || artist?.shortName || String(count.artistName || artist?.name || '?').slice(0, 1),
@@ -322,11 +388,12 @@ const normalizeArtistCounts = (counts: NonNullable<DaySummary['artistCounts']>):
const buildExpandedBlocks = (counts: NormalizedCount[]): MonthBlock[] => {
return counts.flatMap(count => Array.from({ length: count.count }, (_item, index) => ({
key: `${count.artistId}-${index}`,
key: count.key ? `${count.key}-${index}` : `${count.artistId}-${index}`,
artistId: count.artistId,
color: count.color,
shortName: count.shortName,
artistName: count.artistName
artistName: count.artistName,
statusClass: count.statusClass
})))
}
@@ -348,7 +415,10 @@ const buildMonthDays = (): MonthDay[] => {
}))
return monthGrid(currentDateText.value).map(day => {
const summary = map[day.date]
const artistCounts = normalizeArtistCounts(summary?.artistCounts || artistTemplate)
const dayAppointments = appointmentsByDate(day.date)
const artistCounts = dayAppointments.length > 0
? appointmentCountsByDate(day.date)
: normalizeArtistCounts(summary?.artistCounts || artistTemplate)
return {
...day,
isPast: day.date < todayText,
@@ -356,7 +426,8 @@ const buildMonthDays = (): MonthDay[] => {
dayStatus: summary?.dayStatus || 'free',
artistCounts,
expandedBlocks: buildExpandedBlocks(artistCounts),
rowBlocks: buildExpandedBlocks(artistCounts)
rowBlocks: buildExpandedBlocks(artistCounts),
statusClass: resolveDayStatusClass(dayAppointments)
}
})
}
@@ -368,14 +439,15 @@ const buildWeekDays = (): WeekDay[] => {
const target = addDays(start, index)
const date = formatDate(target)
const summary = map[date]
const counts = normalizeArtistCounts(summary?.artistCounts || [])
const dayAppointments = appointmentsByDate(date)
const counts = (dayAppointments.length > 0 ? appointmentCountsByDate(date) : normalizeArtistCounts(summary?.artistCounts || []))
.filter(count => count.count > 0)
.map(count => ({
...count,
width: Math.max(12, Math.min(100, count.count * 22)),
barWidth: Math.max(14, Math.min(100, count.count * 18))
}))
return { date, weekName: `周${label}`, day: target.getDate(), totalCount: summary?.totalCount || 0, artistCounts: counts }
return { date, weekName: `周${label}`, day: target.getDate(), totalCount: summary?.totalCount || 0, artistCounts: counts, statusClass: resolveDayStatusClass(dayAppointments) }
})
}
@@ -722,6 +794,41 @@ onMounted(() => {
background: #fff0de;
}
.appointment-block.is-completed {
background: #f5fff7;
border-color: #c8ead1;
}
.appointment-block.is-cancelled {
background: #fff5f6;
border-color: #e8c7cc;
}
.appointment-block.is-completed::after,
.appointment-block.is-cancelled::after,
.week-day-card.is-completed::after,
.week-day-card.is-cancelled::after {
content: "";
position: absolute;
right: 8px;
left: 8px;
top: 50%;
border-top: 3px solid;
pointer-events: none;
transform: rotate(-15deg);
transform-origin: center;
}
.appointment-block.is-completed::after,
.week-day-card.is-completed::after {
border-color: rgba(69, 130, 91, 0.78);
}
.appointment-block.is-cancelled::after,
.week-day-card.is-cancelled::after {
border-color: rgba(198, 78, 91, 0.8);
}
.appointment-block strong,
.appointment-block span,
.appointment-block small {
@@ -746,12 +853,23 @@ onMounted(() => {
}
.week-day-card {
position: relative;
display: grid;
justify-items: center;
flex: 0 0 86px;
padding: 12px 8px;
}
.week-day-card.is-completed {
background: #f5fff7;
border-color: #c8ead1;
}
.week-day-card.is-cancelled {
background: #fff5f6;
border-color: #e8c7cc;
}
.week-day-card.active {
color: var(--accent);
outline: 2px solid var(--accent-soft);
@@ -802,6 +920,7 @@ onMounted(() => {
}
.week-count-bar {
position: relative;
display: grid;
place-items: center;
min-width: 28px;
@@ -811,6 +930,53 @@ onMounted(() => {
font-weight: 800;
}
.week-count-bar.is-completed::after,
.week-count-bar.is-cancelled::after,
.month-bars span.is-completed::after,
.month-bars span.is-cancelled::after,
.month-blocks span.is-completed::after,
.month-blocks span.is-cancelled::after {
content: "";
position: absolute;
right: 3px;
left: 3px;
top: 50%;
border-top: 2px solid rgba(255, 255, 255, 0.92);
pointer-events: none;
transform: rotate(-15deg);
transform-origin: center;
}
.week-count-bar.is-completed::before,
.week-count-bar.is-cancelled::before,
.month-bars span.is-completed::before,
.month-bars span.is-cancelled::before,
.month-blocks span.is-completed::before,
.month-blocks span.is-cancelled::before {
content: "";
position: absolute;
right: 3px;
left: 3px;
top: 50%;
border-top: 1px solid;
pointer-events: none;
transform: rotate(-15deg);
transform-origin: center;
z-index: 1;
}
.week-count-bar.is-completed::before,
.month-bars span.is-completed::before,
.month-blocks span.is-completed::before {
border-color: rgba(69, 130, 91, 0.9);
}
.week-count-bar.is-cancelled::before,
.month-bars span.is-cancelled::before,
.month-blocks span.is-cancelled::before {
border-color: rgba(198, 78, 91, 0.92);
}
.month-toolbar {
display: flex;
align-items: center;
@@ -910,6 +1076,7 @@ onMounted(() => {
}
.month-bars span {
position: relative;
display: flex;
align-items: center;
justify-content: space-between;
@@ -944,6 +1111,7 @@ onMounted(() => {
}
.month-blocks span {
position: relative;
width: 8px;
height: 8px;
border-radius: 50%;