完善预约详情只读与修改能力
This commit is contained in:
+11
@@ -18,6 +18,7 @@ import com.xiaowang.jayucloud.core.modules.manager.dto.ManagerCustomerCreateDTO;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentCreateDTO;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentMoveDTO;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentStatusDTO;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentUpdateDTO;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.service.PlanningService;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.vo.PlanningAppointmentVO;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.vo.PlanningCalendarVO;
|
||||
@@ -92,6 +93,16 @@ public class AdminManagerController {
|
||||
return Result.success(planningService.getAppointment(currentUser, orderItemId));
|
||||
}
|
||||
|
||||
@PutMapping("/planning/appointments/{orderItemId}")
|
||||
@RequirePermission("order:process")
|
||||
@OperationGuard(action = "manager-planning-update-appointment", ttlSeconds = 10, message = "预约修改处理中,请勿重复提交")
|
||||
public Result<PlanningAppointmentVO> updateAppointment(HttpServletRequest request,
|
||||
@PathVariable Long orderItemId,
|
||||
@RequestBody PlanningAppointmentUpdateDTO dto) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
return Result.success(planningService.updateAppointment(currentUser, orderItemId, dto));
|
||||
}
|
||||
|
||||
@PutMapping("/planning/appointments/{orderItemId}/time-artist")
|
||||
@RequirePermission("order:process")
|
||||
@OperationGuard(action = "manager-planning-move-appointment", ttlSeconds = 10, message = "预约调整处理中,请勿重复提交")
|
||||
|
||||
+11
@@ -6,6 +6,7 @@ import com.xiaowang.jayucloud.core.common.Result;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentCreateDTO;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentMoveDTO;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentStatusDTO;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentUpdateDTO;
|
||||
import com.xiaowang.jayucloud.core.modules.user.entity.UserDO;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.service.PlanningService;
|
||||
import com.xiaowang.jayucloud.core.modules.security.support.AdminScopeHelper;
|
||||
@@ -61,6 +62,16 @@ public class AdminPlanningController {
|
||||
return Result.success(planningService.getAppointment(currentUser, orderItemId));
|
||||
}
|
||||
|
||||
@PutMapping("/appointments/{orderItemId}")
|
||||
@RequirePermission("order:process")
|
||||
@OperationGuard(action = "admin-planning-update-appointment", ttlSeconds = 10, message = "预约修改处理中,请勿重复提交")
|
||||
public Result<PlanningAppointmentVO> updateAppointment(HttpServletRequest request,
|
||||
@PathVariable Long orderItemId,
|
||||
@RequestBody PlanningAppointmentUpdateDTO dto) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
return Result.success(planningService.updateAppointment(currentUser, orderItemId, dto));
|
||||
}
|
||||
|
||||
@PutMapping("/appointments/{orderItemId}/time-artist")
|
||||
@RequirePermission("order:process")
|
||||
@OperationGuard(action = "admin-planning-move-appointment", ttlSeconds = 10, message = "预约调整处理中,请勿重复提交")
|
||||
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package com.xiaowang.jayucloud.core.modules.planning.dto;
|
||||
|
||||
public class PlanningAppointmentUpdateDTO extends PlanningAppointmentCreateDTO {
|
||||
}
|
||||
+3
@@ -3,6 +3,7 @@ package com.xiaowang.jayucloud.core.modules.planning.service;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentCreateDTO;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentMoveDTO;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentStatusDTO;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentUpdateDTO;
|
||||
import com.xiaowang.jayucloud.core.modules.user.entity.UserDO;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.vo.PlanningAppointmentVO;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.vo.PlanningCalendarVO;
|
||||
@@ -16,6 +17,8 @@ public interface PlanningService {
|
||||
|
||||
PlanningAppointmentVO getAppointment(UserDO currentUser, Long orderItemId);
|
||||
|
||||
PlanningAppointmentVO updateAppointment(UserDO currentUser, Long orderItemId, PlanningAppointmentUpdateDTO dto);
|
||||
|
||||
PlanningAppointmentVO moveAppointment(UserDO currentUser, Long orderItemId, PlanningAppointmentMoveDTO dto);
|
||||
|
||||
Boolean updateStatus(UserDO currentUser, Long orderId, PlanningAppointmentStatusDTO dto);
|
||||
|
||||
+65
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentCreateDTO;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentMoveDTO;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentStatusDTO;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentUpdateDTO;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.entity.AppointmentReservationDO;
|
||||
import com.xiaowang.jayucloud.core.modules.artist.entity.ArtistScheduleExceptionDO;
|
||||
import com.xiaowang.jayucloud.core.modules.artist.entity.ArtistScheduleDO;
|
||||
@@ -229,6 +230,62 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
return toAppointmentVO(reservation, item, order, product, customerMap.get(order.getUserId()), artistMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public PlanningAppointmentVO updateAppointment(UserDO currentUser, Long orderItemId, PlanningAppointmentUpdateDTO dto) {
|
||||
if (orderItemId == null || dto == null) {
|
||||
throw new RuntimeException("修改预约信息不能为空");
|
||||
}
|
||||
OrderItemDO item = orderItemMapper.selectByIdForUpdate(orderItemId);
|
||||
if (item == null || Integer.valueOf(1).equals(item.getIsDelete())) {
|
||||
throw new RuntimeException("预约不存在");
|
||||
}
|
||||
OrderDO order = requireAccessibleOrder(currentUser, item.getOrderId());
|
||||
requireEditableAppointment(order);
|
||||
requireAppointmentDuration(dto.getDurationMinutes());
|
||||
ProductDO product = resolveAppointmentProduct(dto, order.getShopId());
|
||||
UserDO artist = requireActiveArtist(dto.getArtistId(), order.getShopId());
|
||||
UserDO customer = resolveCustomer(order.getShopId(), dto);
|
||||
|
||||
int quantity = dto.getQuantity() == null || dto.getQuantity() <= 0
|
||||
? Math.max(1, item.getQuantity() == null ? 1 : item.getQuantity())
|
||||
: dto.getQuantity();
|
||||
int durationMinutes = resolveDurationMinutes(product, dto.getDurationMinutes()) * quantity;
|
||||
LocalDateTime startTime = parseAppointmentStart(dto.getAppointmentStartTime(), dto.getAppointmentDate(), dto.getAppointmentTime());
|
||||
LocalDateTime endTime = startTime.plusMinutes(durationMinutes);
|
||||
ensureWithinBusinessHours(order.getShopId(), startTime, endTime);
|
||||
|
||||
BigDecimal unitPrice = product.getPrice() == null ? BigDecimal.ZERO : product.getPrice();
|
||||
BigDecimal amount = unitPrice.multiply(BigDecimal.valueOf(quantity));
|
||||
|
||||
appointmentCapacityService.moveReservationForArtistChange(
|
||||
order.getId(),
|
||||
item.getId(),
|
||||
order.getShopId(),
|
||||
item.getArtistId(),
|
||||
artist.getId(),
|
||||
product.getTitle(),
|
||||
startTime,
|
||||
endTime
|
||||
);
|
||||
|
||||
order.setUserId(customer.getId());
|
||||
order.setCustomerName(buildOrderCustomerNameSnapshot(dto, customer));
|
||||
order.setTotalAmount(amount);
|
||||
order.setActualAmount(amount);
|
||||
order.setCustomerRemark(trimToNull(dto.getRemark()));
|
||||
order.setPayAmount(amount);
|
||||
orderMapper.updateById(order);
|
||||
|
||||
item.setProductId(product.getId());
|
||||
item.setQuantity(quantity);
|
||||
item.setPrice(unitPrice);
|
||||
item.setArtistId(artist.getId());
|
||||
item.setAppointmentTime(startTime);
|
||||
orderItemMapper.updateById(item);
|
||||
return getAppointment(currentUser, item.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public PlanningAppointmentVO moveAppointment(UserDO currentUser, Long orderItemId, PlanningAppointmentMoveDTO dto) {
|
||||
@@ -240,6 +297,7 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
throw new RuntimeException("预约不存在");
|
||||
}
|
||||
OrderDO order = requireAccessibleOrder(currentUser, item.getOrderId());
|
||||
requireEditableAppointment(order);
|
||||
ProductDO product = requireActiveProduct(item.getProductId(), order.getShopId());
|
||||
Long targetArtistId = dto.getArtistId() == null ? item.getArtistId() : dto.getArtistId();
|
||||
UserDO artist = requireActiveArtist(targetArtistId, order.getShopId());
|
||||
@@ -879,6 +937,13 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
return order;
|
||||
}
|
||||
|
||||
private void requireEditableAppointment(OrderDO order) {
|
||||
if (Integer.valueOf(OrderStatus.COMPLETED.getCode()).equals(order.getStatus())
|
||||
|| Integer.valueOf(OrderStatus.CANCELLED.getCode()).equals(order.getStatus())) {
|
||||
throw new RuntimeException("已完成或已取消的订单只可查看,不能修改");
|
||||
}
|
||||
}
|
||||
|
||||
private AppointmentReservationDO findActiveReservation(Long orderItemId) {
|
||||
QueryWrapper<AppointmentReservationDO> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("order_item_id", orderItemId)
|
||||
|
||||
+23
@@ -12,6 +12,7 @@ import com.xiaowang.jayucloud.core.modules.order.mapper.OrderItemMapper;
|
||||
import com.xiaowang.jayucloud.core.modules.order.mapper.OrderMapper;
|
||||
import com.xiaowang.jayucloud.core.modules.order.service.OrderService;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentCreateDTO;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentUpdateDTO;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.entity.AppointmentReservationDO;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.mapper.AppointmentReservationMapper;
|
||||
import com.xiaowang.jayucloud.core.modules.planning.service.AppointmentCapacityService;
|
||||
@@ -245,6 +246,28 @@ class PlanningServiceImplTest {
|
||||
.hasMessageContaining("当前日期为店铺休息日");
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateAppointmentRejectsCompletedOrder() {
|
||||
UserDO manager = user(2, 8L);
|
||||
OrderItemDO item = orderItem(300L, 200L, 100L, 20L, LocalDateTime.of(2026, 6, 26, 13, 0));
|
||||
OrderDO order = order(200L, 8L, 30L);
|
||||
order.setStatus(2);
|
||||
PlanningAppointmentUpdateDTO dto = new PlanningAppointmentUpdateDTO();
|
||||
dto.setCustomerUserId(30L);
|
||||
dto.setProductId(100L);
|
||||
dto.setArtistId(20L);
|
||||
dto.setAppointmentDate("2026-06-26");
|
||||
dto.setAppointmentTime("13:00");
|
||||
dto.setDurationMinutes(60);
|
||||
|
||||
when(orderItemMapper.selectByIdForUpdate(300L)).thenReturn(item);
|
||||
when(orderMapper.selectById(200L)).thenReturn(order);
|
||||
|
||||
assertThatThrownBy(() -> planningService.updateAppointment(manager, 300L, dto))
|
||||
.hasMessageContaining("已完成或已取消的订单只可查看");
|
||||
org.mockito.Mockito.verify(orderItemMapper, org.mockito.Mockito.never()).updateById(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void calendarMarksMonthAvailabilityByContinuousNinetyMinuteWindow() {
|
||||
UserDO manager = user(2, 8L);
|
||||
|
||||
@@ -14,6 +14,8 @@ export interface AppointmentMoveRequest {
|
||||
artistId: string | number
|
||||
}
|
||||
|
||||
export type AppointmentUpdateRequest = AppointmentCreateRequest
|
||||
|
||||
export const managerPlanningApi = {
|
||||
calendar(params: CalendarParams): Promise<PlanningCalendar> {
|
||||
return adminApi.get('/manager/planning/calendar', { params })
|
||||
@@ -24,6 +26,9 @@ export const managerPlanningApi = {
|
||||
appointment(orderItemId: IdType): Promise<Appointment> {
|
||||
return adminApi.get(`/manager/planning/appointments/${orderItemId}`)
|
||||
},
|
||||
updateAppointment(orderItemId: IdType, data: AppointmentUpdateRequest): Promise<Appointment> {
|
||||
return adminApi.put(`/manager/planning/appointments/${orderItemId}`, data)
|
||||
},
|
||||
moveAppointment(orderItemId: IdType, data: AppointmentMoveRequest): Promise<Appointment> {
|
||||
return adminApi.put(`/manager/planning/appointments/${orderItemId}/time-artist`, data)
|
||||
},
|
||||
|
||||
@@ -16,7 +16,7 @@ const routes: RouteRecordRaw[] = [
|
||||
{ path: '/employees/:id/orders', name: 'employee-orders', component: () => import('@/views/EmployeeOrdersView.vue'), meta: { title: '员工作品/订单' } },
|
||||
{ path: '/appointments/new', name: 'appointment-form', component: () => import('@/views/AppointmentFormView.vue'), meta: { title: '新建预约' } },
|
||||
{ path: '/appointments/:id', name: 'appointment-detail', component: () => import('@/views/AppointmentDetailView.vue'), meta: { title: '预约详情' } },
|
||||
{ path: '/appointments/:id/transfer', name: 'artist-transfer', component: () => import('@/views/ArtistTransferView.vue'), meta: { title: '改派预约' } },
|
||||
{ path: '/appointments/:id/transfer', name: 'artist-transfer', component: () => import('@/views/AppointmentFormView.vue'), meta: { title: '修改预约' } },
|
||||
{ path: '/profile', name: 'profile', component: () => import('@/views/ProfileView.vue'), meta: { tab: true } },
|
||||
{ path: '/shop-settings', name: 'shop-settings', component: () => import('@/views/ShopSettingsView.vue'), meta: { title: '店铺设置' } },
|
||||
{ path: '/export', name: 'export', component: () => import('@/views/ExportView.vue'), meta: { title: '导出' } },
|
||||
|
||||
@@ -39,7 +39,9 @@ export interface Product {
|
||||
|
||||
export interface Appointment {
|
||||
orderId?: IdType
|
||||
orderNo?: string
|
||||
orderItemId: IdType
|
||||
customerId?: IdType
|
||||
customerUserId?: IdType
|
||||
customerName?: string
|
||||
customerPhone?: string
|
||||
@@ -56,6 +58,10 @@ export interface Appointment {
|
||||
date?: string
|
||||
status?: number
|
||||
statusText?: string
|
||||
occupancyStatus?: string
|
||||
canEdit?: boolean
|
||||
canCancel?: boolean
|
||||
amount?: number | string
|
||||
remark?: string
|
||||
manualProductTitle?: string
|
||||
manualProductPrice?: number
|
||||
|
||||
@@ -53,6 +53,21 @@ describe('available time groups', () => {
|
||||
expect(groups[0]?.times.map(item => item.value)).toEqual(['10:00'])
|
||||
})
|
||||
|
||||
it('allows callers to exclude the appointment being edited', () => {
|
||||
const calendar: PlanningCalendar = {
|
||||
schedules: [{ artistId: 1, date: '2026-06-29', startTime: '10:00', endTime: '11:00', status: 1 }],
|
||||
appointments: [{ orderItemId: 100, artistId: 1, date: '2026-06-29', startTime: '2026-06-29 10:00:00', endTime: '2026-06-29 11:00:00', status: 1 }]
|
||||
}
|
||||
const editableCalendar = {
|
||||
...calendar,
|
||||
appointments: calendar.appointments?.filter(item => item.orderItemId !== 100)
|
||||
}
|
||||
|
||||
const groups = buildAvailableTimeGroups(editableCalendar, buildForm())
|
||||
|
||||
expect(groups[0]?.times.map(item => item.value)).toEqual(['10:00'])
|
||||
})
|
||||
|
||||
it('returns no slots when the store day is closed', () => {
|
||||
const calendar: PlanningCalendar = {
|
||||
daySummaries: [{ date: '2026-06-29', totalCount: 0, dayStatus: 'rest' }],
|
||||
|
||||
@@ -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`)
|
||||
}
|
||||
|
||||
|
||||
@@ -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 })
|
||||
|
||||
Reference in New Issue
Block a user