功能:支持待分配预约与首次排班引导
This commit is contained in:
@@ -170,6 +170,24 @@ function buildAvailableTimeGroups(calendar, form, durationMinutes) {
|
||||
.filter(group => group.times.length > 0)
|
||||
}
|
||||
|
||||
function buildUnassignedTimeGroups(durationMinutes) {
|
||||
const groupMap = {
|
||||
morning: { key: 'morning', title: '上午', times: [] },
|
||||
afternoon: { key: 'afternoon', title: '下午', times: [] },
|
||||
evening: { key: 'evening', title: '晚上', times: [] }
|
||||
}
|
||||
const businessStart = dateUtil.minutesOfDay('10:00')
|
||||
const businessEnd = dateUtil.minutesOfDay('22:00')
|
||||
for (let minute = businessStart; minute + durationMinutes <= businessEnd; minute += TIME_SLOT_MINUTES) {
|
||||
const period = getTimePeriod(minute)
|
||||
groupMap[period.key].times.push({
|
||||
value: dateUtil.timeFromMinutes(minute),
|
||||
rangeText: buildTimeRangeLabel(minute, durationMinutes)
|
||||
})
|
||||
}
|
||||
return Object.keys(groupMap).map(key => groupMap[key]).filter(group => group.times.length > 0)
|
||||
}
|
||||
|
||||
function flattenTimeGroups(groups) {
|
||||
return (groups || []).reduce((list, group) => list.concat(group.times || []), [])
|
||||
}
|
||||
@@ -611,9 +629,13 @@ Page({
|
||||
|
||||
filterArtistItems(artists, keywordValue) {
|
||||
const keyword = String(keywordValue || '').trim().toLowerCase()
|
||||
return (artists || [])
|
||||
const items = (artists || [])
|
||||
.filter(item => !keyword || String(item.name || '').toLowerCase().includes(keyword))
|
||||
.map(buildArtistSelectorItem)
|
||||
if (!keyword || '暂不分配'.includes(keyword)) {
|
||||
items.unshift({ id: '__unassigned__', title: '暂不分配', subtitle: '先记录预约,后续再分配员工', badge: '待分配' })
|
||||
}
|
||||
return items
|
||||
},
|
||||
|
||||
openArtistSheet() {
|
||||
@@ -641,6 +663,17 @@ Page({
|
||||
|
||||
selectArtist(event) {
|
||||
const selectedArtist = event.detail.item || {}
|
||||
if (selectedArtist.id === '__unassigned__') {
|
||||
this.setData({
|
||||
selectedArtist: {},
|
||||
'form.artistId': '',
|
||||
artistSheetVisible: false,
|
||||
conflictTip: '',
|
||||
conflictLevel: 'free'
|
||||
})
|
||||
this.refreshAvailableTimes()
|
||||
return
|
||||
}
|
||||
this.setData({
|
||||
selectedArtist,
|
||||
'form.artistId': selectedArtist.id,
|
||||
@@ -654,7 +687,7 @@ Page({
|
||||
addEmployeeFromSelector() {
|
||||
this.setData({ artistSheetVisible: false })
|
||||
wx.navigateTo({
|
||||
url: '/pages/employee-create/index?picker=1',
|
||||
url: `/pages/employee-create/index?picker=1&date=${encodeURIComponent(this.data.form.appointmentDate || '')}&time=${encodeURIComponent(this.data.form.appointmentTime || '')}&durationMinutes=${encodeURIComponent(this.data.form.durationMinutes || '')}`,
|
||||
success: result => {
|
||||
result.eventChannel.on('employeeCreated', employee => this.handleEmployeeCreated(employee))
|
||||
}
|
||||
@@ -662,15 +695,34 @@ Page({
|
||||
},
|
||||
|
||||
async handleEmployeeCreated(employee) {
|
||||
await this.loadArtists(employee.id, employee)
|
||||
this.setData({ 'form.appointmentTime': '' })
|
||||
const originalTime = this.data.form.appointmentTime
|
||||
await this.loadArtists(employee.autoSelect === false ? '' : employee.id, employee)
|
||||
if (employee.autoSelect === false) {
|
||||
this.setData({ selectedArtist: {}, 'form.artistId': '' })
|
||||
await this.refreshAvailableTimes()
|
||||
return
|
||||
}
|
||||
if (employee.scheduleSaved && originalTime) {
|
||||
const availability = await this.checkAvailability()
|
||||
if (!availability.ok) {
|
||||
this.setData({
|
||||
selectedArtist: {},
|
||||
'form.artistId': '',
|
||||
'form.appointmentTime': originalTime,
|
||||
conflictTip: `${availability.tip || '新员工当前排班无法承接'},预约已保持待分配`,
|
||||
conflictLevel: 'danger'
|
||||
})
|
||||
}
|
||||
} else {
|
||||
this.setData({ 'form.appointmentTime': '' })
|
||||
}
|
||||
await this.refreshAvailableTimes()
|
||||
this.checkAvailability()
|
||||
if (this.data.form.artistId) this.checkAvailability()
|
||||
},
|
||||
|
||||
canOpenTimeSheet() {
|
||||
const form = this.data.form
|
||||
return Boolean(form.appointmentDate && form.artistId && normalizeDuration(form.durationMinutes))
|
||||
return Boolean(form.appointmentDate && normalizeDuration(form.durationMinutes))
|
||||
},
|
||||
|
||||
async refreshAvailableTimes() {
|
||||
@@ -678,11 +730,11 @@ Page({
|
||||
const durationMinutes = normalizeDuration(form.durationMinutes)
|
||||
const requestSeq = (this._availableTimeRequestSeq || 0) + 1
|
||||
this._availableTimeRequestSeq = requestSeq
|
||||
if (!form.appointmentDate || !form.artistId || !durationMinutes) {
|
||||
if (!form.appointmentDate || !durationMinutes) {
|
||||
const patch = {
|
||||
availableTimeGroups: [],
|
||||
timeError: '',
|
||||
timeSelectTip: '请先选择美甲师并填写时长'
|
||||
timeSelectTip: '请先填写预约日期和时长'
|
||||
}
|
||||
if (form.appointmentTime) {
|
||||
patch['form.appointmentTime'] = ''
|
||||
@@ -690,6 +742,16 @@ Page({
|
||||
this.setData(patch)
|
||||
return
|
||||
}
|
||||
if (!form.artistId) {
|
||||
const availableTimeGroups = buildUnassignedTimeGroups(durationMinutes)
|
||||
this.setData({
|
||||
availableTimeGroups,
|
||||
timeError: '',
|
||||
timeLoading: false,
|
||||
timeSelectTip: '请选择预约时间,员工可稍后分配'
|
||||
})
|
||||
return
|
||||
}
|
||||
this.setData({
|
||||
timeLoading: true,
|
||||
timeError: '',
|
||||
@@ -732,7 +794,7 @@ Page({
|
||||
|
||||
async openTimeSheet() {
|
||||
if (!this.canOpenTimeSheet()) {
|
||||
wx.showToast({ title: '请先选择美甲师并填写时长', icon: 'none' })
|
||||
wx.showToast({ title: '请先填写预约日期和时长', icon: 'none' })
|
||||
return
|
||||
}
|
||||
this.setData({ timeSheetVisible: true })
|
||||
@@ -754,7 +816,7 @@ Page({
|
||||
|
||||
async checkAvailability() {
|
||||
const form = this.data.form
|
||||
if (!form.appointmentDate || !form.appointmentTime || !form.artistId) {
|
||||
if (!form.appointmentDate || !form.appointmentTime) {
|
||||
this.setData({ conflictTip: '', conflictLevel: 'free' })
|
||||
return { ok: true }
|
||||
}
|
||||
@@ -770,6 +832,11 @@ Page({
|
||||
this.setData({ conflictTip: tip, conflictLevel: 'danger' })
|
||||
return { ok: false, tip }
|
||||
}
|
||||
if (!form.artistId) {
|
||||
const tip = '预约将保存为待分配,当前不会占用员工时间'
|
||||
this.setData({ conflictTip: tip, conflictLevel: 'free' })
|
||||
return { ok: true, tip }
|
||||
}
|
||||
try {
|
||||
const calendar = await planningApi.calendar({
|
||||
startDate: form.appointmentDate,
|
||||
@@ -815,7 +882,7 @@ Page({
|
||||
const form = this.data.form
|
||||
const hasManualProduct = String(form.manualProductTitle || '').trim() && String(form.manualProductPrice || '').trim()
|
||||
const durationMinutes = normalizeDuration(form.durationMinutes)
|
||||
if (!form.customerName || !form.phone || (!form.productId && !hasManualProduct) || !form.artistId) {
|
||||
if (!form.customerName || !form.phone || (!form.productId && !hasManualProduct) || !form.appointmentDate || !form.appointmentTime) {
|
||||
wx.showToast({ title: '请补全预约信息', icon: 'none' })
|
||||
return
|
||||
}
|
||||
@@ -832,12 +899,25 @@ Page({
|
||||
wx.showToast({ title: availability.tip || '该时段已被预约', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!form.artistId) {
|
||||
const result = await new Promise(resolve => {
|
||||
wx.showModal({
|
||||
title: '保存为待分配预约',
|
||||
content: '当前未指定员工,预约会正常保存,但不会占用员工时间。可以稍后在预约详情中分配。',
|
||||
cancelText: '返回选择',
|
||||
confirmText: '继续保存',
|
||||
success: resolve,
|
||||
fail: () => resolve({ confirm: false })
|
||||
})
|
||||
})
|
||||
if (!result.confirm) return
|
||||
}
|
||||
this.setData({ loading: true })
|
||||
try {
|
||||
const payload = {
|
||||
...form,
|
||||
customerUserId: form.customerUserId ? String(form.customerUserId) : undefined,
|
||||
artistId: String(form.artistId),
|
||||
artistId: form.artistId ? String(form.artistId) : undefined,
|
||||
durationMinutes,
|
||||
clientRequestId: buildClientRequestId('manager-appointment')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user