优化预约美甲师选择弹窗

This commit is contained in:
2026-07-21 21:34:45 +08:00
parent a84646ea60
commit b66e789098
3 changed files with 359 additions and 5 deletions
+118 -2
View File
@@ -8,13 +8,94 @@ const { chooseImageFilePaths, uploadObjectFile, resolveUploadedImagePreviewUrl }
const DRAFT_STORAGE_PREFIX = 'managerAppointmentDraft'
const TIME_SLOT_MINUTES = 15
const ARTIST_FALLBACK_COLORS = ['#7AA9C2', '#8EB99B', '#BDA7D8', '#D7B17D', '#D98D8D']
const ARTIST_PRESET_LABELS = {
DOUBLE_REST: '双休',
SINGLE_REST: '单休',
NINE_TO_FIVE: '朝九晚五',
LATE_SHIFT: '晚班',
CUSTOM: '自定义'
}
function buildClientRequestId(prefix) {
return `${prefix}-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`
}
function normalizeTimeText(value) {
return value ? String(value).slice(0, 5) : ''
}
function buildScheduleByArtist(calendar) {
const schedules = calendar && Array.isArray(calendar.schedules) ? calendar.schedules : []
return schedules.reduce((map, schedule) => {
if (schedule && schedule.artistId) {
map[String(schedule.artistId)] = schedule
}
return map
}, {})
}
function buildArtistTimeSummary(artist, schedule) {
const startTime = normalizeTimeText(schedule && schedule.startTime ? schedule.startTime : artist.workStartTime)
const endTime = normalizeTimeText(schedule && schedule.endTime ? schedule.endTime : artist.workEndTime)
return startTime && endTime ? `${startTime}-${endTime}` : ''
}
function buildArtistScheduleSummary(artist, schedule) {
const timeText = buildArtistTimeSummary(artist, schedule)
const mode = artist.scheduleModeSummary
|| artist.scheduleMode
|| ARTIST_PRESET_LABELS[artist.presetType]
|| (schedule ? '今日排班' : '排班未设置')
return timeText ? `${mode} ${timeText}` : mode
}
function buildArtistStatusText(artist, schedule) {
if (schedule && Number(schedule.status) !== 1) {
return '今日休息'
}
if (schedule && Number(schedule.status) === 1) {
return '今日可约'
}
return artist.statusText || (Number(artist.status) === 0 ? '休息中' : '可预约')
}
function buildArtistMetaText(artist, schedule) {
const orderCount = Number(artist.rangeCount)
if (Number.isFinite(orderCount) && orderCount > 0) {
return `今日已有 ${orderCount} 单`
}
if (schedule && Number(schedule.status) === 1) {
return '今日暂无预约'
}
if (schedule && Number(schedule.status) !== 1) {
return '可切换日期查看排班'
}
return '等待预约'
}
function normalizeArtistForCard(artist, index, scheduleByArtist) {
const name = artist.name || artist.nickname || artist.artistName || `美甲师${index + 1}`
const schedule = scheduleByArtist[String(artist.id)] || null
const statusText = buildArtistStatusText(artist, schedule)
const shortName = artist.shortName || String(name || '师').slice(-1)
return {
...artist,
name,
shortName,
avatar: artist.avatar || artist.avatarUrl || '',
color: artist.color || ARTIST_FALLBACK_COLORS[index % ARTIST_FALLBACK_COLORS.length],
scheduleSummary: buildArtistScheduleSummary(artist, schedule),
metaText: buildArtistMetaText(artist, schedule),
statusText,
statusClass: statusText.indexOf('休') >= 0 ? 'rest' : 'free'
}
}
function getCalendarArtists(calendar) {
return calendar && Array.isArray(calendar.artists) ? calendar.artists : []
const artists = calendar && Array.isArray(calendar.artists) ? calendar.artists : []
const scheduleByArtist = buildScheduleByArtist(calendar)
return artists.map((artist, index) => normalizeArtistForCard(artist, index, scheduleByArtist))
}
function findArtist(artists, artistId) {
@@ -420,6 +501,8 @@ Page({
artists: [],
selectedProduct: {},
selectedArtist: {},
artistSheetVisible: false,
pendingArtistId: '',
productModalVisible: false,
manualProductPanelVisible: false,
manualProductImageUrls: [],
@@ -836,10 +919,43 @@ Page({
onArtistChange(event) {
const selectedArtist = this.data.artists[Number(event.detail.value)] || {}
this.applyArtistSelection(selectedArtist)
},
openArtistSheet() {
this.setData({
artistSheetVisible: true,
pendingArtistId: this.data.form.artistId || ''
})
},
closeArtistSheet() {
this.setData({
artistSheetVisible: false,
pendingArtistId: ''
})
},
selectArtistCard(event) {
this.setData({ pendingArtistId: event.currentTarget.dataset.id || '' })
},
confirmArtistSheet() {
const selectedArtist = findArtist(this.data.artists, this.data.pendingArtistId)
if (!selectedArtist.id) {
wx.showToast({ title: '请选择美甲师', icon: 'none' })
return
}
this.applyArtistSelection(selectedArtist)
},
applyArtistSelection(selectedArtist) {
this.setData({
selectedArtist,
'form.artistId': selectedArtist.id,
'form.appointmentTime': ''
'form.appointmentTime': '',
artistSheetVisible: false,
pendingArtistId: ''
})
this.refreshAvailableTimes()
this.checkAvailability()