完善预约详情只读与修改能力

This commit is contained in:
2026-07-02 14:57:02 +08:00
parent 0b2f4b2a7a
commit 3845ee4492
12 changed files with 305 additions and 33 deletions
@@ -20,7 +20,7 @@
</div>
<div class="detail-actions">
<span class="tag">{{ appointment.statusText || '待处理' }}</span>
<button class="text-btn" type="button" @click="goTransfer">改派</button>
<button v-if="canEditAppointment" class="text-btn" type="button" @click="goEdit">修改</button>
</div>
</div>
<div class="detail-grid">
@@ -47,11 +47,10 @@
<div class="card note-card">{{ appointment.remark || '暂无备注' }}</div>
</PageSection>
<div class="fixed-bottom">
<div v-if="showBottomActions" class="fixed-bottom">
<div class="fixed-bottom__inner button-row">
<button class="secondary-btn" type="button" :disabled="saving" @click="updateStatus(1)">确认</button>
<button class="primary-btn" type="button" :disabled="saving" @click="updateStatus(2)">完成</button>
<button class="danger-btn" type="button" :disabled="saving" @click="updateStatus(3)">取消</button>
<button v-if="canEditAppointment" class="primary-btn" type="button" :disabled="saving" @click="updateStatus(2)">完成</button>
<button v-if="canCancelAppointment" class="danger-btn" type="button" :disabled="saving" @click="updateStatus(3)">取消</button>
</div>
</div>
</template>
@@ -82,6 +81,23 @@ const loadError = ref('')
const appointmentId = computed(() => String(route.params.id || ''))
const avatarText = computed(() => String(appointment.value?.customerName || '客').slice(0, 1))
const isReadonlyAppointment = computed(() => {
const status = Number(appointment.value?.status)
return status === 2 || status === 3
})
const canEditAppointment = computed(() => {
if (!appointment.value || isReadonlyAppointment.value) {
return false
}
return appointment.value.canEdit !== false
})
const canCancelAppointment = computed(() => {
if (!appointment.value || isReadonlyAppointment.value) {
return false
}
return appointment.value.canCancel !== false
})
const showBottomActions = computed(() => canEditAppointment.value || canCancelAppointment.value)
const timeText = computed(() => {
const item = appointment.value
const start = String(item?.startTime || item?.date || '').slice(0, 16)
@@ -106,6 +122,10 @@ const loadDetail = async (): Promise<void> => {
}
const updateStatus = async (status: number): Promise<void> => {
if (isReadonlyAppointment.value) {
toast.error('已完成或已取消的订单只可查看')
return
}
if (!appointment.value?.orderId) {
toast.error('当前预约缺少订单 ID,无法更新状态')
return
@@ -113,7 +133,10 @@ const updateStatus = async (status: number): Promise<void> => {
saving.value = true
try {
await managerPlanningApi.updateStatus(appointment.value.orderId, status)
markPlanningRefresh()
markPlanningRefresh({
date: appointment.value.date,
artistId: appointment.value.artistId === undefined ? '' : String(appointment.value.artistId)
})
toast.success('已更新')
await loadDetail()
} finally {
@@ -121,7 +144,11 @@ const updateStatus = async (status: number): Promise<void> => {
}
}
const goTransfer = async (): Promise<void> => {
const goEdit = async (): Promise<void> => {
if (!canEditAppointment.value) {
toast.error('已完成或已取消的订单只可查看')
return
}
await router.push(`/appointments/${appointmentId.value}/transfer`)
}
+127 -25
View File
@@ -1,6 +1,6 @@
<template>
<MobileShell title="新建预约">
<div v-if="draftSavedAtText" class="card draft-tip">
<MobileShell :title="pageTitle">
<div v-if="!isEditMode && draftSavedAtText" class="card draft-tip">
<span>{{ draftSavedAtText }}</span>
<button class="text-btn" type="button" @click="clearDraft">清空</button>
</div>
@@ -53,7 +53,7 @@
</div>
</div>
<div class="field"><label class="required">预约日期</label><DatePickerField v-model="form.appointmentDate" placeholder="请选择日期" title="日期选择" @confirm="onDateChange" /></div>
<div class="field"><label class="required">预约作品</label><button class="field-value picker-value" type="button" @click="productModalVisible = true">{{ selectedProductTitle }}</button></div>
<div class="field"><label class="required">预约作品</label><button class="field-value picker-value" type="button" @click="updateProductModalVisible(true)">{{ selectedProductTitle }}</button></div>
<div class="field">
<label class="required">预计时长</label>
<div class="duration-control">
@@ -70,8 +70,8 @@
<div class="fixed-bottom">
<div class="fixed-bottom__inner button-row">
<button class="secondary-btn" type="button" @click="saveDraft">保存草稿</button>
<button class="primary-btn" type="button" :disabled="loading" @click="submit">{{ loading ? '提交中...' : '提交预约' }}</button>
<button v-if="!isEditMode" class="secondary-btn" type="button" @click="saveDraft">保存草稿</button>
<button class="primary-btn" type="button" :disabled="loading" @click="submit">{{ submitButtonText }}</button>
</div>
</div>
@@ -235,7 +235,7 @@ import { managerPlanningApi } from '@/api/managerPlanning'
import { managerProductsApi, type ProductCreateRequest } from '@/api/managerProducts'
import { managerTagsApi, type ManagerTag } from '@/api/managerTags'
import { fileApi } from '@/api/file'
import type { AppointmentForm, Artist, Product } from '@/types/manager'
import type { Appointment, AppointmentForm, Artist, PlanningCalendar, Product } from '@/types/manager'
import type { UserInfo } from '@/types/common'
import { useSessionStore } from '@/stores/session'
import { useToastStore } from '@/stores/toast'
@@ -336,10 +336,11 @@ const route = useRoute()
const router = useRouter()
const session = useSessionStore()
const toast = useToastStore()
const baseForm = readDraftForm(session.userInfo)
const modalStateDraft = readFormModalDraft<AppointmentModalState>(session.userInfo, APPOINTMENT_MODAL_STATE_DRAFT_NAME)
const createCustomerDraft = readFormModalDraft<CustomerCreateForm>(session.userInfo, CUSTOMER_CREATE_DRAFT_NAME)
const createProductDraft = readFormModalDraft<ProductCreateForm>(session.userInfo, PRODUCT_CREATE_DRAFT_NAME)
const initialEditMode = Boolean(route.params.id)
const baseForm = initialEditMode ? null : readDraftForm(session.userInfo)
const modalStateDraft = initialEditMode ? null : readFormModalDraft<AppointmentModalState>(session.userInfo, APPOINTMENT_MODAL_STATE_DRAFT_NAME)
const createCustomerDraft = initialEditMode ? null : readFormModalDraft<CustomerCreateForm>(session.userInfo, CUSTOMER_CREATE_DRAFT_NAME)
const createProductDraft = initialEditMode ? null : readFormModalDraft<ProductCreateForm>(session.userInfo, PRODUCT_CREATE_DRAFT_NAME)
const form = reactive<AppointmentForm>({
customerUserId: String(route.query.customerUserId || baseForm?.customerUserId || ''),
customerName: String(route.query.customerName || baseForm?.customerName || ''),
@@ -391,6 +392,15 @@ const conflictLevel = ref<'free' | 'danger'>('free')
const loading = ref(false)
const creatingProduct = ref(false)
const productImageUploading = ref(false)
const isEditMode = computed(() => Boolean(route.params.id))
const editAppointmentId = computed(() => String(route.params.id || ''))
const pageTitle = computed(() => (isEditMode.value ? '修改预约' : '新建预约'))
const submitButtonText = computed(() => {
if (loading.value) {
return isEditMode.value ? '保存中...' : '提交中...'
}
return isEditMode.value ? '保存修改' : '提交预约'
})
const selectedCustomerReady = computed(() => {
return Boolean(form.customerUserId)
})
@@ -450,6 +460,9 @@ const appointmentFormChanged = computed(() => {
})
const syncAppointmentDraft = (): void => {
if (isEditMode.value) {
return
}
if (!appointmentFormChanged.value) {
return
}
@@ -460,6 +473,9 @@ const syncAppointmentDraft = (): void => {
}
const syncAppointmentModalState = (): void => {
if (isEditMode.value) {
return
}
if (!productModalVisible.value && !timeSheetVisible.value) {
removeFormModalDraft(session.userInfo, APPOINTMENT_MODAL_STATE_DRAFT_NAME)
return
@@ -495,6 +511,9 @@ const resetCreateCustomerForm = (): void => {
}
const syncCreateCustomerDraft = (): void => {
if (isEditMode.value) {
return
}
if (!createCustomerModalVisible.value) {
removeFormModalDraft(session.userInfo, CUSTOMER_CREATE_DRAFT_NAME)
return
@@ -508,7 +527,9 @@ const syncCreateCustomerDraft = (): void => {
const updateCreateCustomerModalVisible = (value: boolean): void => {
createCustomerModalVisible.value = value
if (!value) {
removeFormModalDraft(session.userInfo, CUSTOMER_CREATE_DRAFT_NAME)
if (!isEditMode.value) {
removeFormModalDraft(session.userInfo, CUSTOMER_CREATE_DRAFT_NAME)
}
resetCreateCustomerForm()
}
}
@@ -545,6 +566,9 @@ const resetProductCreateForm = (): void => {
}
const syncProductCreateDraft = (): void => {
if (isEditMode.value) {
return
}
if (!productCreateModalVisible.value) {
removeFormModalDraft(session.userInfo, PRODUCT_CREATE_DRAFT_NAME)
return
@@ -558,7 +582,9 @@ const syncProductCreateDraft = (): void => {
const updateProductCreateModalVisible = (value: boolean): void => {
productCreateModalVisible.value = value
if (!value) {
removeFormModalDraft(session.userInfo, PRODUCT_CREATE_DRAFT_NAME)
if (!isEditMode.value) {
removeFormModalDraft(session.userInfo, PRODUCT_CREATE_DRAFT_NAME)
}
resetProductCreateForm()
}
}
@@ -643,6 +669,58 @@ const loadOptions = async (): Promise<void> => {
}
}
const resolveAppointmentDateValue = (appointment: Appointment): string => {
return appointment.date || String(appointment.startTime || '').slice(0, 10) || formatDate(new Date())
}
const resolveAppointmentTimeValue = (appointment: Appointment): string => {
return String(appointment.startTime || '').slice(11, 16)
}
const applyAppointmentToForm = (appointment: Appointment): void => {
const customerId = appointment.customerId ?? appointment.customerUserId ?? ''
form.customerUserId = String(customerId || '')
form.customerName = appointment.customerName || ''
form.phone = appointment.phone || appointment.customerPhone || ''
form.appointmentDate = resolveAppointmentDateValue(appointment)
form.appointmentTime = resolveAppointmentTimeValue(appointment)
form.productId = String(appointment.productId || '')
form.manualProductTitle = appointment.productTitle || ''
form.manualProductPrice = ''
form.manualProductDescription = ''
form.manualProductTags = ''
form.manualProductTargetAudience = ''
form.manualProductPrecautions = ''
form.manualProductImageFileIds = ''
form.manualProductImageUrl = ''
form.durationMinutes = String(appointment.durationMinutes || '')
form.artistId = normalizeArtistSelectionId(String(appointment.artistId || ''), artists.value)
form.remark = appointment.remark || ''
selectedProduct.value = products.value.find(item => String(item.id) === String(form.productId)) || null
customerSearchText.value = [form.customerName, form.phone].filter(Boolean).join(' ')
conflictTip.value = ''
}
const loadAppointmentForEdit = async (): Promise<void> => {
const appointment = await managerPlanningApi.appointment(editAppointmentId.value)
if (appointment.canEdit === false || appointment.status === 2 || appointment.status === 3) {
toast.error('已完成或已取消的订单只可查看')
await router.replace(`/appointments/${editAppointmentId.value}`)
return
}
applyAppointmentToForm(appointment)
}
const withoutCurrentAppointment = (calendar: PlanningCalendar): PlanningCalendar => {
if (!isEditMode.value) {
return calendar
}
return {
...calendar,
appointments: (calendar.appointments || []).filter(item => String(item.orderItemId) !== editAppointmentId.value)
}
}
const scheduleCustomerSearch = (): void => {
if (customerTimer.value !== null) {
window.clearTimeout(customerTimer.value)
@@ -842,7 +920,7 @@ const refreshAvailableTimes = async (): Promise<void> => {
}
timeLoading.value = true
try {
const calendar = await managerPlanningApi.calendar({ startDate: form.appointmentDate, endDate: form.appointmentDate, artistId: form.artistId })
const calendar = withoutCurrentAppointment(await managerPlanningApi.calendar({ startDate: form.appointmentDate, endDate: form.appointmentDate, artistId: form.artistId }))
availableTimeGroups.value = buildAvailableTimeGroups(calendar, form)
timeSelectTip.value = availableTimeGroups.value.length > 0 ? '请选择预约时间' : '当前美甲师当天暂无可约时间'
} finally {
@@ -872,7 +950,7 @@ const checkAvailability = async (): Promise<{ ok: boolean; tip?: string }> => {
}
const startMinute = minutesOfDay(form.appointmentTime)
const endMinute = startMinute + normalizeDuration(form.durationMinutes)
const calendar = await managerPlanningApi.calendar({ startDate: form.appointmentDate, endDate: form.appointmentDate, artistId: form.artistId })
const calendar = withoutCurrentAppointment(await managerPlanningApi.calendar({ startDate: form.appointmentDate, endDate: form.appointmentDate, artistId: form.artistId }))
const daySummary = (calendar.daySummaries || []).find(item => item.date === form.appointmentDate)
const businessStartTime = String(daySummary?.businessStartTime || calendar.businessStartTime || '10:00').slice(0, 5)
const businessEndTime = String(daySummary?.businessEndTime || calendar.businessEndTime || '22:00').slice(0, 5)
@@ -921,16 +999,20 @@ const submit = async (): Promise<void> => {
artistId: form.artistId,
durationMinutes,
manualProductPrice: hasManualProduct ? Number(form.manualProductPrice) : undefined,
clientRequestId: buildClientRequestId('manager-appointment')
clientRequestId: buildClientRequestId(isEditMode.value ? 'manager-appointment-update' : 'manager-appointment')
}
const result = isEditMode.value
? await managerPlanningApi.updateAppointment(editAppointmentId.value, payload)
: await managerPlanningApi.createAppointment(payload)
if (!isEditMode.value) {
removeDraftForm(session.userInfo)
removeFormModalDraft(session.userInfo, APPOINTMENT_MODAL_STATE_DRAFT_NAME)
}
const result = await managerPlanningApi.createAppointment(payload)
removeDraftForm(session.userInfo)
removeFormModalDraft(session.userInfo, APPOINTMENT_MODAL_STATE_DRAFT_NAME)
markPlanningRefresh({
date: result.date || form.appointmentDate,
artistId: String(result.artistId ?? form.artistId)
})
toast.success('预约已创建')
toast.success(isEditMode.value ? '预约已修改' : '预约已创建')
await router.replace(`/appointments/${result.orderItemId}`)
} finally {
loading.value = false
@@ -938,12 +1020,18 @@ const submit = async (): Promise<void> => {
}
const saveDraft = (): void => {
if (isEditMode.value) {
return
}
writeDraftForm(session.userInfo, { ...form })
draftSavedAtText.value = '草稿已保存到本机'
toast.success('草稿已保存')
}
const clearDraft = (): void => {
if (isEditMode.value) {
return
}
removeDraftForm(session.userInfo)
removeFormModalDraft(session.userInfo, APPOINTMENT_MODAL_STATE_DRAFT_NAME)
draftSavedAtText.value = ''
@@ -951,13 +1039,27 @@ const clearDraft = (): void => {
}
onMounted(async () => {
await loadOptions()
if (form.customerUserId) {
const customer = await managerCustomersApi.detail(form.customerUserId)
selectCustomer(customer)
loading.value = true
try {
await loadOptions()
if (isEditMode.value) {
await loadAppointmentForEdit()
}
if (form.customerUserId) {
const customer = await managerCustomersApi.detail(form.customerUserId)
selectCustomer(customer)
}
await searchCustomers()
await refreshAvailableTimes()
} catch (error) {
const message = error instanceof Error ? error.message : '预约信息加载失败'
toast.error(message)
if (isEditMode.value) {
await router.replace(`/appointments/${editAppointmentId.value}`)
}
} finally {
loading.value = false
}
await searchCustomers()
await refreshAvailableTimes()
})
watch(form, syncAppointmentDraft, { deep: true })