优化预约表单并支持散客预约
This commit is contained in:
+2
@@ -16,6 +16,8 @@ public class PlanningAppointmentCreateDTO {
|
||||
private String appointmentTime;
|
||||
private String appointmentStartTime;
|
||||
private Integer durationMinutes;
|
||||
private BigDecimal amount;
|
||||
private Boolean createCustomerRecord;
|
||||
private String manualProductTitle;
|
||||
private BigDecimal manualProductPrice;
|
||||
private String manualProductDescription;
|
||||
|
||||
+37
-15
@@ -44,6 +44,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
@@ -183,11 +184,18 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
ensureWithinBusinessHours(shopId, startTime, endTime);
|
||||
|
||||
BigDecimal unitPrice = product.getPrice() == null ? BigDecimal.ZERO : product.getPrice();
|
||||
BigDecimal amount = unitPrice.multiply(BigDecimal.valueOf(quantity));
|
||||
BigDecimal amount = dto.getAmount() == null
|
||||
? unitPrice.multiply(BigDecimal.valueOf(quantity))
|
||||
: dto.getAmount();
|
||||
if (amount.compareTo(BigDecimal.ZERO) < 0) {
|
||||
throw new RuntimeException("成交金额不能小于0");
|
||||
}
|
||||
|
||||
OrderDO order = new OrderDO();
|
||||
order.setOrderNo("ORD" + snowflakeIdGenerator.nextIdString());
|
||||
order.setUserId(customer.getId());
|
||||
order.setUserId(customer == null ? null : customer.getId());
|
||||
order.setCustomerNameSnapshot(customer == null ? trimToNull(dto.getCustomerName()) : null);
|
||||
order.setCustomerPhoneSnapshot(customer == null ? trimToNull(dto.getPhone()) : null);
|
||||
order.setShopId(shopId);
|
||||
order.setTotalAmount(amount);
|
||||
order.setActualAmount(amount);
|
||||
@@ -208,7 +216,7 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
item.setOrderId(order.getId());
|
||||
item.setProductId(product.getId());
|
||||
item.setQuantity(quantity);
|
||||
item.setPrice(unitPrice);
|
||||
item.setPrice(amount.divide(BigDecimal.valueOf(quantity), 2, RoundingMode.HALF_UP));
|
||||
item.setArtistId(artist == null ? null : artist.getId());
|
||||
item.setAppointmentTime(startTime);
|
||||
item.setIsDelete(0);
|
||||
@@ -295,7 +303,8 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
Map<Long, PlanningArtistVO> artistMap = listArtists(order.getShopId(), item.getArtistId()).stream()
|
||||
.collect(Collectors.toMap(PlanningArtistVO::getId, Function.identity(), (a, b) -> a));
|
||||
Map<Long, UserDO> customerMap = order.getUserId() == null ? Map.of() : loadUsers(Set.of(order.getUserId()));
|
||||
return toAppointmentVO(reservation, item, order, product, customerMap.get(order.getUserId()), artistMap);
|
||||
UserDO customer = order.getUserId() == null ? null : customerMap.get(order.getUserId());
|
||||
return toAppointmentVO(reservation, item, order, product, customer, artistMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -516,7 +525,7 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
continue;
|
||||
}
|
||||
ProductDO product = item == null ? null : productMap.get(item.getProductId());
|
||||
UserDO customer = customerMap.get(order.getUserId());
|
||||
UserDO customer = order.getUserId() == null ? null : customerMap.get(order.getUserId());
|
||||
result.add(toAppointmentVO(reservation, item, order, product, customer, artistMap));
|
||||
if (reservation.getOrderItemId() != null) {
|
||||
reservationItemIds.add(reservation.getOrderItemId());
|
||||
@@ -531,7 +540,7 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
continue;
|
||||
}
|
||||
ProductDO product = productMap.get(item.getProductId());
|
||||
UserDO customer = customerMap.get(order.getUserId());
|
||||
UserDO customer = order.getUserId() == null ? null : customerMap.get(order.getUserId());
|
||||
result.add(toAppointmentVO(null, item, order, product, customer, artistMap));
|
||||
}
|
||||
result.sort(Comparator.comparing(PlanningAppointmentVO::getStartTime, Comparator.nullsLast(String::compareTo))
|
||||
@@ -731,12 +740,19 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
|
||||
private ProductDO createManualAppointmentProduct(PlanningAppointmentCreateDTO dto, Long shopId) {
|
||||
String title = trimToNull(dto.getManualProductTitle());
|
||||
String imageFileIds = trimToNull(dto.getManualProductImageFileIds());
|
||||
if (!hasText(title)) {
|
||||
throw new RuntimeException("请选择预约作品或填写手动作品名称");
|
||||
title = firstNonBlank(dto.getCustomerName(), hasText(imageFileIds) ? "散客款式" : null);
|
||||
}
|
||||
BigDecimal price = dto.getManualProductPrice();
|
||||
if (price == null || price.compareTo(BigDecimal.ZERO) < 0) {
|
||||
throw new RuntimeException("手动作品价格不能小于0");
|
||||
if (!hasText(title) && !hasText(imageFileIds)) {
|
||||
throw new RuntimeException("请填写美甲款式名称或上传款式图片");
|
||||
}
|
||||
BigDecimal price = dto.getManualProductPrice() == null ? dto.getAmount() : dto.getManualProductPrice();
|
||||
if (price == null) {
|
||||
throw new RuntimeException("成交金额不能为空");
|
||||
}
|
||||
if (price.compareTo(BigDecimal.ZERO) < 0) {
|
||||
throw new RuntimeException("成交金额不能小于0");
|
||||
}
|
||||
int durationMinutes = requireAppointmentDuration(dto.getDurationMinutes());
|
||||
ProductDO product = new ProductDO();
|
||||
@@ -746,7 +762,7 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
product.setTags(trimToNull(dto.getManualProductTags()));
|
||||
product.setTargetAudience(trimToNull(dto.getManualProductTargetAudience()));
|
||||
product.setPrecautions(trimToNull(dto.getManualProductPrecautions()));
|
||||
product.setImageFileIds(trimToNull(dto.getManualProductImageFileIds()));
|
||||
product.setImageFileIds(imageFileIds);
|
||||
product.setPrice(price);
|
||||
product.setLikeCount(0);
|
||||
product.setCollectCount(0);
|
||||
@@ -786,11 +802,17 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
}
|
||||
return customer;
|
||||
}
|
||||
String customerName = firstNonBlank(dto.getCustomerName(), dto.getPhone());
|
||||
if (!hasText(customerName)) {
|
||||
throw new RuntimeException("客户姓名不能为空");
|
||||
}
|
||||
String customerName = trimToNull(dto.getCustomerName());
|
||||
String phone = trimToNull(dto.getPhone());
|
||||
if (!hasText(customerName) && hasText(phone)) {
|
||||
throw new RuntimeException("填写手机号时请同时填写客户姓名");
|
||||
}
|
||||
if (Boolean.FALSE.equals(dto.getCreateCustomerRecord())) {
|
||||
return null;
|
||||
}
|
||||
if (!hasText(customerName)) {
|
||||
return null;
|
||||
}
|
||||
List<com.xiaowang.jayucloud.salon.core.modules.user.vo.UserVO> matches =
|
||||
userService.findCustomerMatches(customerName, phone, shopId);
|
||||
if (matches.size() > 1) {
|
||||
|
||||
+348
@@ -0,0 +1,348 @@
|
||||
package com.xiaowang.jayucloud.salon.core.modules.planning.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.artist.mapper.ArtistScheduleExceptionMapper;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.artist.mapper.ArtistScheduleMapper;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.artist.mapper.NailArtistInfoMapper;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.entity.OrderDO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.entity.OrderItemDO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.mapper.OrderItemMapper;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.mapper.OrderMapper;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.service.OrderService;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.support.OrderStatus;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.planning.dto.PlanningAppointmentStatusDTO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.planning.dto.PlanningAppointmentCreateDTO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.planning.mapper.AppointmentReservationMapper;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.planning.service.AppointmentCapacityService;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.product.mapper.ProductMapper;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.product.entity.ProductDO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.security.support.AdminScopeHelper;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.shop.mapper.ShopMapper;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.shop.entity.ShopDO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.user.entity.UserDO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.user.mapper.UserMapper;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.user.service.UserService;
|
||||
import com.xiaowang.jayucloud.salon.core.support.id.TimeOrderedSnowflakeIdGenerator;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class PlanningServiceImplTest {
|
||||
|
||||
@Mock private AdminScopeHelper adminScopeHelper;
|
||||
@Mock private UserMapper userMapper;
|
||||
@Mock private UserService userService;
|
||||
@Mock private NailArtistInfoMapper nailArtistInfoMapper;
|
||||
@Mock private ArtistScheduleMapper artistScheduleMapper;
|
||||
@Mock private ArtistScheduleExceptionMapper artistScheduleExceptionMapper;
|
||||
@Mock private AppointmentReservationMapper appointmentReservationMapper;
|
||||
@Mock private OrderMapper orderMapper;
|
||||
@Mock private OrderItemMapper orderItemMapper;
|
||||
@Mock private ProductMapper productMapper;
|
||||
@Mock private ShopMapper shopMapper;
|
||||
@Mock private AppointmentCapacityService appointmentCapacityService;
|
||||
@Mock private OrderService orderService;
|
||||
@Mock private TimeOrderedSnowflakeIdGenerator snowflakeIdGenerator;
|
||||
|
||||
private PlanningServiceImpl service;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
service = new PlanningServiceImpl(adminScopeHelper, userMapper, userService, nailArtistInfoMapper, artistScheduleMapper,
|
||||
artistScheduleExceptionMapper, appointmentReservationMapper, orderMapper, orderItemMapper,
|
||||
productMapper, shopMapper, appointmentCapacityService, orderService, snowflakeIdGenerator);
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsCompletingUnassignedAppointment() {
|
||||
UserDO operator = new UserDO();
|
||||
OrderDO order = order(11L, OrderStatus.PENDING_SERVICE.getCode());
|
||||
when(orderMapper.selectById(11L)).thenReturn(order);
|
||||
when(orderItemMapper.selectCount(any(Wrapper.class))).thenReturn(1L);
|
||||
PlanningAppointmentStatusDTO dto = new PlanningAppointmentStatusDTO();
|
||||
dto.setStatus(OrderStatus.COMPLETED.getCode());
|
||||
|
||||
RuntimeException error = assertThrows(RuntimeException.class, () -> service.updateStatus(operator, 11L, dto));
|
||||
|
||||
assertEquals("请先分配员工", error.getMessage());
|
||||
verify(orderService, never()).processOrder(11L, OrderStatus.COMPLETED.getCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void allowsCancellingUnassignedAppointment() {
|
||||
UserDO operator = new UserDO();
|
||||
OrderDO order = order(12L, OrderStatus.PENDING_SERVICE.getCode());
|
||||
when(orderMapper.selectById(12L)).thenReturn(order);
|
||||
PlanningAppointmentStatusDTO dto = new PlanningAppointmentStatusDTO();
|
||||
dto.setStatus(OrderStatus.CANCELLED.getCode());
|
||||
|
||||
service.updateStatus(operator, 12L, dto);
|
||||
|
||||
verify(orderService).processOrder(12L, OrderStatus.CANCELLED.getCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createsUnassignedAppointmentWithoutReservation() {
|
||||
service = spy(service);
|
||||
UserDO operator = new UserDO();
|
||||
operator.setType(2);
|
||||
UserDO customer = new UserDO();
|
||||
customer.setId(31L);
|
||||
customer.setType(0);
|
||||
ProductDO product = new ProductDO();
|
||||
product.setId(41L);
|
||||
product.setShopId(21L);
|
||||
product.setTitle("纯色美甲");
|
||||
product.setPrice(java.math.BigDecimal.valueOf(99));
|
||||
product.setIsDelete(0);
|
||||
ShopDO shop = new ShopDO();
|
||||
shop.setId(21L);
|
||||
shop.setBusinessHours("10:00-22:00");
|
||||
when(adminScopeHelper.resolveShopScope(operator, null)).thenReturn(21L);
|
||||
when(productMapper.selectById(41L)).thenReturn(product);
|
||||
when(userMapper.selectById(31L)).thenReturn(customer);
|
||||
when(shopMapper.selectById(21L)).thenReturn(shop);
|
||||
when(snowflakeIdGenerator.nextIdString()).thenReturn("10001");
|
||||
doAnswer(invocation -> {
|
||||
OrderDO value = invocation.getArgument(0);
|
||||
value.setId(51L);
|
||||
return 1;
|
||||
}).when(orderMapper).insert(any(OrderDO.class));
|
||||
doAnswer(invocation -> {
|
||||
OrderItemDO value = invocation.getArgument(0);
|
||||
value.setId(61L);
|
||||
return 1;
|
||||
}).when(orderItemMapper).insert(any(OrderItemDO.class));
|
||||
doReturn(new com.xiaowang.jayucloud.salon.core.modules.planning.vo.PlanningAppointmentVO())
|
||||
.when(service).getAppointment(operator, 61L);
|
||||
PlanningAppointmentCreateDTO dto = new PlanningAppointmentCreateDTO();
|
||||
dto.setCustomerUserId(31L);
|
||||
dto.setProductId(41L);
|
||||
dto.setAppointmentDate("2026-10-13");
|
||||
dto.setAppointmentTime("14:00");
|
||||
dto.setDurationMinutes(60);
|
||||
|
||||
service.createAppointment(operator, dto);
|
||||
|
||||
ArgumentCaptor<OrderItemDO> itemCaptor = ArgumentCaptor.forClass(OrderItemDO.class);
|
||||
verify(orderItemMapper).insert(itemCaptor.capture());
|
||||
assertNull(itemCaptor.getValue().getArtistId());
|
||||
verify(appointmentCapacityService, never()).reserveConfirmedOrThrow(
|
||||
any(), any(), any(), any(), any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createsWalkInAppointmentWithPhotoOnlyStyleAndSnapshotAmount() {
|
||||
service = spy(service);
|
||||
UserDO operator = new UserDO();
|
||||
operator.setType(2);
|
||||
ShopDO shop = new ShopDO();
|
||||
shop.setId(21L);
|
||||
shop.setBusinessHours("10:00-22:00");
|
||||
when(adminScopeHelper.resolveShopScope(operator, null)).thenReturn(21L);
|
||||
when(shopMapper.selectById(21L)).thenReturn(shop);
|
||||
when(snowflakeIdGenerator.nextIdString()).thenReturn("10002");
|
||||
doAnswer(invocation -> {
|
||||
ProductDO value = invocation.getArgument(0);
|
||||
value.setId(42L);
|
||||
return 1;
|
||||
}).when(productMapper).insert(any(ProductDO.class));
|
||||
doAnswer(invocation -> {
|
||||
OrderDO value = invocation.getArgument(0);
|
||||
value.setId(52L);
|
||||
return 1;
|
||||
}).when(orderMapper).insert(any(OrderDO.class));
|
||||
doAnswer(invocation -> {
|
||||
OrderItemDO value = invocation.getArgument(0);
|
||||
value.setId(62L);
|
||||
return 1;
|
||||
}).when(orderItemMapper).insert(any(OrderItemDO.class));
|
||||
doReturn(new com.xiaowang.jayucloud.salon.core.modules.planning.vo.PlanningAppointmentVO())
|
||||
.when(service).getAppointment(operator, 62L);
|
||||
|
||||
PlanningAppointmentCreateDTO dto = new PlanningAppointmentCreateDTO();
|
||||
dto.setCustomerName("小鹿");
|
||||
dto.setCreateCustomerRecord(false);
|
||||
dto.setManualProductImageFileIds("file-42");
|
||||
dto.setAmount(java.math.BigDecimal.valueOf(168));
|
||||
dto.setAppointmentDate("2026-10-22");
|
||||
dto.setAppointmentTime("14:00");
|
||||
dto.setDurationMinutes(60);
|
||||
|
||||
service.createAppointment(operator, dto);
|
||||
|
||||
ArgumentCaptor<ProductDO> productCaptor = ArgumentCaptor.forClass(ProductDO.class);
|
||||
verify(productMapper).insert(productCaptor.capture());
|
||||
assertEquals("小鹿", productCaptor.getValue().getTitle());
|
||||
assertEquals("file-42", productCaptor.getValue().getImageFileIds());
|
||||
assertEquals(java.math.BigDecimal.valueOf(168), productCaptor.getValue().getPrice());
|
||||
|
||||
ArgumentCaptor<OrderDO> orderCaptor = ArgumentCaptor.forClass(OrderDO.class);
|
||||
verify(orderMapper).insert(orderCaptor.capture());
|
||||
assertNull(orderCaptor.getValue().getUserId());
|
||||
assertEquals("小鹿", orderCaptor.getValue().getCustomerNameSnapshot());
|
||||
assertEquals(java.math.BigDecimal.valueOf(168), orderCaptor.getValue().getActualAmount());
|
||||
|
||||
ArgumentCaptor<OrderItemDO> itemCaptor = ArgumentCaptor.forClass(OrderItemDO.class);
|
||||
verify(orderItemMapper).insert(itemCaptor.capture());
|
||||
assertEquals(0, itemCaptor.getValue().getPrice().compareTo(java.math.BigDecimal.valueOf(168)));
|
||||
verify(userService, never()).createManagerCustomer(any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createsWalkInAppointmentWithoutCustomerUsingWalkInStyleTitle() {
|
||||
service = spy(service);
|
||||
UserDO operator = new UserDO();
|
||||
operator.setType(2);
|
||||
ShopDO shop = new ShopDO();
|
||||
shop.setId(21L);
|
||||
shop.setBusinessHours("10:00-22:00");
|
||||
when(adminScopeHelper.resolveShopScope(operator, null)).thenReturn(21L);
|
||||
when(shopMapper.selectById(21L)).thenReturn(shop);
|
||||
when(snowflakeIdGenerator.nextIdString()).thenReturn("10003");
|
||||
doAnswer(invocation -> {
|
||||
ProductDO value = invocation.getArgument(0);
|
||||
value.setId(43L);
|
||||
return 1;
|
||||
}).when(productMapper).insert(any(ProductDO.class));
|
||||
doAnswer(invocation -> {
|
||||
OrderDO value = invocation.getArgument(0);
|
||||
value.setId(53L);
|
||||
return 1;
|
||||
}).when(orderMapper).insert(any(OrderDO.class));
|
||||
doAnswer(invocation -> {
|
||||
OrderItemDO value = invocation.getArgument(0);
|
||||
value.setId(63L);
|
||||
return 1;
|
||||
}).when(orderItemMapper).insert(any(OrderItemDO.class));
|
||||
doReturn(new com.xiaowang.jayucloud.salon.core.modules.planning.vo.PlanningAppointmentVO())
|
||||
.when(service).getAppointment(operator, 63L);
|
||||
|
||||
PlanningAppointmentCreateDTO dto = new PlanningAppointmentCreateDTO();
|
||||
dto.setCreateCustomerRecord(false);
|
||||
dto.setManualProductImageFileIds("file-43");
|
||||
dto.setAmount(java.math.BigDecimal.valueOf(88));
|
||||
dto.setAppointmentDate("2026-10-22");
|
||||
dto.setAppointmentTime("14:00");
|
||||
dto.setDurationMinutes(45);
|
||||
|
||||
service.createAppointment(operator, dto);
|
||||
|
||||
ArgumentCaptor<ProductDO> productCaptor = ArgumentCaptor.forClass(ProductDO.class);
|
||||
verify(productMapper).insert(productCaptor.capture());
|
||||
assertEquals("散客款式", productCaptor.getValue().getTitle());
|
||||
|
||||
ArgumentCaptor<OrderDO> orderCaptor = ArgumentCaptor.forClass(OrderDO.class);
|
||||
verify(orderMapper).insert(orderCaptor.capture());
|
||||
assertNull(orderCaptor.getValue().getUserId());
|
||||
assertNull(orderCaptor.getValue().getCustomerNameSnapshot());
|
||||
assertNull(orderCaptor.getValue().getCustomerPhoneSnapshot());
|
||||
verify(userService, never()).createManagerCustomer(any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void readsWalkInAppointmentCustomerSnapshotWithoutLookingUpNullUserId() {
|
||||
UserDO operator = new UserDO();
|
||||
operator.setType(2);
|
||||
OrderDO order = order(54L, OrderStatus.PENDING_SERVICE.getCode());
|
||||
order.setCustomerNameSnapshot("散客预约");
|
||||
order.setCustomerPhoneSnapshot("13800138000");
|
||||
OrderItemDO item = new OrderItemDO();
|
||||
item.setId(64L);
|
||||
item.setOrderId(54L);
|
||||
item.setQuantity(1);
|
||||
item.setAppointmentTime(java.time.LocalDateTime.of(2026, 10, 22, 14, 0));
|
||||
|
||||
when(orderItemMapper.selectById(64L)).thenReturn(item);
|
||||
when(orderMapper.selectById(54L)).thenReturn(order);
|
||||
when(userMapper.selectList(any(Wrapper.class))).thenReturn(java.util.List.of());
|
||||
|
||||
com.xiaowang.jayucloud.salon.core.modules.planning.vo.PlanningAppointmentVO result =
|
||||
service.getAppointment(operator, 64L);
|
||||
|
||||
assertNull(result.getCustomerId());
|
||||
assertEquals("散客预约", result.getCustomerName());
|
||||
assertEquals("13800138000", result.getCustomerPhone());
|
||||
verify(userMapper, never()).selectById(org.mockito.ArgumentMatchers.isNull());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createsCustomerInAppointmentFlowWhenConfirmed() {
|
||||
service = spy(service);
|
||||
UserDO operator = new UserDO();
|
||||
operator.setType(2);
|
||||
UserDO customer = new UserDO();
|
||||
customer.setId(71L);
|
||||
customer.setType(0);
|
||||
ProductDO product = new ProductDO();
|
||||
product.setId(41L);
|
||||
product.setShopId(21L);
|
||||
product.setTitle("纯色美甲");
|
||||
product.setPrice(java.math.BigDecimal.valueOf(99));
|
||||
product.setIsDelete(0);
|
||||
ShopDO shop = new ShopDO();
|
||||
shop.setId(21L);
|
||||
shop.setBusinessHours("10:00-22:00");
|
||||
when(adminScopeHelper.resolveShopScope(operator, null)).thenReturn(21L);
|
||||
when(productMapper.selectById(41L)).thenReturn(product);
|
||||
when(userMapper.selectById(71L)).thenReturn(customer);
|
||||
when(userService.findCustomerMatches("小周", "13800138000", 21L)).thenReturn(java.util.List.of());
|
||||
when(userService.createManagerCustomer("小周", "13800138000", 21L)).thenReturn(71L);
|
||||
when(shopMapper.selectById(21L)).thenReturn(shop);
|
||||
when(snowflakeIdGenerator.nextIdString()).thenReturn("10004");
|
||||
doAnswer(invocation -> {
|
||||
OrderDO value = invocation.getArgument(0);
|
||||
value.setId(55L);
|
||||
return 1;
|
||||
}).when(orderMapper).insert(any(OrderDO.class));
|
||||
doAnswer(invocation -> {
|
||||
OrderItemDO value = invocation.getArgument(0);
|
||||
value.setId(65L);
|
||||
return 1;
|
||||
}).when(orderItemMapper).insert(any(OrderItemDO.class));
|
||||
doReturn(new com.xiaowang.jayucloud.salon.core.modules.planning.vo.PlanningAppointmentVO())
|
||||
.when(service).getAppointment(operator, 65L);
|
||||
|
||||
PlanningAppointmentCreateDTO dto = new PlanningAppointmentCreateDTO();
|
||||
dto.setCustomerName("小周");
|
||||
dto.setPhone("13800138000");
|
||||
dto.setCreateCustomerRecord(true);
|
||||
dto.setProductId(41L);
|
||||
dto.setAmount(java.math.BigDecimal.valueOf(128));
|
||||
dto.setAppointmentDate("2026-10-22");
|
||||
dto.setAppointmentTime("14:00");
|
||||
dto.setDurationMinutes(60);
|
||||
|
||||
service.createAppointment(operator, dto);
|
||||
|
||||
verify(userService).createManagerCustomer("小周", "13800138000", 21L);
|
||||
ArgumentCaptor<OrderDO> orderCaptor = ArgumentCaptor.forClass(OrderDO.class);
|
||||
verify(orderMapper).insert(orderCaptor.capture());
|
||||
assertEquals(71L, orderCaptor.getValue().getUserId());
|
||||
assertNull(orderCaptor.getValue().getCustomerNameSnapshot());
|
||||
}
|
||||
|
||||
private OrderDO order(Long id, int status) {
|
||||
OrderDO order = new OrderDO();
|
||||
order.setId(id);
|
||||
order.setShopId(21L);
|
||||
order.setStatus(status);
|
||||
order.setIsDelete(0);
|
||||
return order;
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,9 @@ Component({
|
||||
errorText: { type: String, value: '' },
|
||||
emptyText: { type: String, value: '暂无可选内容' },
|
||||
actionText: { type: String, value: '' },
|
||||
showViewSwitch: { type: Boolean, value: false },
|
||||
viewMode: { type: String, value: 'list' },
|
||||
sortLabel: { type: String, value: '' },
|
||||
showSearch: { type: Boolean, value: true }
|
||||
},
|
||||
|
||||
@@ -36,6 +39,14 @@ Component({
|
||||
|
||||
action() {
|
||||
this.triggerEvent('action')
|
||||
},
|
||||
|
||||
changeView(event) {
|
||||
this.triggerEvent('changeview', { mode: event.currentTarget.dataset.mode })
|
||||
},
|
||||
|
||||
sort() {
|
||||
this.triggerEvent('sort')
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -10,6 +10,14 @@
|
||||
<input class="selector-search" value="{{keyword}}" bindinput="onSearch" placeholder="{{placeholder}}" confirm-type="search" />
|
||||
</view>
|
||||
|
||||
<view wx:if="{{showViewSwitch || sortLabel}}" class="selector-toolbar">
|
||||
<view wx:if="{{showViewSwitch}}" class="selector-view-switch">
|
||||
<button class="{{viewMode === 'list' ? 'active' : ''}}" data-mode="list" bindtap="changeView">列表视图</button>
|
||||
<button class="{{viewMode === 'card' ? 'active' : ''}}" data-mode="card" bindtap="changeView">卡片视图</button>
|
||||
</view>
|
||||
<button wx:if="{{sortLabel}}" class="selector-sort" bindtap="sort">{{sortLabel}}</button>
|
||||
</view>
|
||||
|
||||
<scroll-view class="selector-scroll" scroll-y enhanced show-scrollbar="{{false}}">
|
||||
<view wx:if="{{loading}}" class="selector-state">
|
||||
<view class="selector-loading-dot"></view>
|
||||
@@ -20,12 +28,13 @@
|
||||
<button class="selector-retry" bindtap="retry">重新加载</button>
|
||||
</view>
|
||||
<view wx:elif="{{items.length === 0}}" class="selector-state">{{emptyText}}</view>
|
||||
<view wx:else class="selector-list">
|
||||
<view wx:for="{{items}}" wx:key="id" class="selector-item {{selectedId == item.id ? 'selected' : ''}}" data-index="{{index}}" bindtap="selectItem">
|
||||
<view wx:else class="selector-list {{viewMode === 'card' ? 'card-view' : ''}}">
|
||||
<view wx:for="{{items}}" wx:key="id" class="selector-item {{selectedId == item.id ? 'selected' : ''}} {{viewMode === 'card' ? 'card-view' : ''}}" data-index="{{index}}" bindtap="selectItem">
|
||||
<image wx:if="{{item.avatar}}" class="selector-avatar" src="{{item.avatar}}" mode="aspectFill"></image>
|
||||
<view class="selector-copy {{item.avatar ? '' : 'without-avatar'}}">
|
||||
<view class="selector-title-row">
|
||||
<text class="selector-item-title">{{item.title}}</text>
|
||||
<text wx:if="{{item.rightText}}" class="selector-right-text">{{item.rightText}}</text>
|
||||
<text wx:if="{{item.badge}}" class="selector-badge">{{item.badge}}</text>
|
||||
</view>
|
||||
<text wx:if="{{item.subtitle}}" class="selector-subtitle">{{item.subtitle}}</text>
|
||||
|
||||
@@ -125,6 +125,35 @@
|
||||
transform: rotate(45deg);
|
||||
}
|
||||
|
||||
.selector-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12rpx;
|
||||
padding: 0 28rpx 16rpx;
|
||||
}
|
||||
|
||||
.selector-view-switch {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
gap: 8rpx;
|
||||
}
|
||||
|
||||
.selector-view-switch button,
|
||||
.selector-sort {
|
||||
height: 58rpx;
|
||||
padding: 0 18rpx;
|
||||
border-radius: 16rpx;
|
||||
background: #f1f5f3;
|
||||
color: #687a72;
|
||||
font-size: 22rpx;
|
||||
line-height: 58rpx;
|
||||
}
|
||||
|
||||
.selector-view-switch button { flex: 1; }
|
||||
.selector-view-switch button.active { background: #dff1e9; color: #247b63; font-weight: 800; }
|
||||
.selector-sort { flex: 0 0 auto; color: #476259; }
|
||||
|
||||
.selector-search {
|
||||
height: 78rpx;
|
||||
flex: 1;
|
||||
@@ -157,6 +186,28 @@
|
||||
.selector-item:active { transform: scale(0.99); }
|
||||
.selector-item.selected { border-color: #8eafa3; background: #f0f6f3; }
|
||||
|
||||
.selector-list.card-view {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 12rpx;
|
||||
}
|
||||
|
||||
.selector-item.card-view {
|
||||
position: relative;
|
||||
display: block;
|
||||
min-height: 190rpx;
|
||||
margin: 0;
|
||||
padding: 18rpx;
|
||||
}
|
||||
|
||||
.selector-item.card-view .selector-avatar { width: 66rpx; height: 66rpx; margin-bottom: 12rpx; }
|
||||
.selector-item.card-view .selector-copy { margin-left: 0; }
|
||||
.selector-item.card-view .selector-title-row { align-items: flex-start; }
|
||||
.selector-item.card-view .selector-item-title { white-space: normal; }
|
||||
.selector-item.card-view .selector-subtitle,
|
||||
.selector-item.card-view .selector-meta { display: block; margin-top: 8rpx; }
|
||||
.selector-item.card-view .selector-check { position: absolute; right: 18rpx; bottom: 16rpx; }
|
||||
|
||||
.selector-avatar {
|
||||
width: 76rpx;
|
||||
height: 76rpx;
|
||||
@@ -180,6 +231,8 @@
|
||||
}
|
||||
|
||||
.selector-item-title {
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
color: #2b2621;
|
||||
font-size: 28rpx;
|
||||
@@ -188,6 +241,13 @@
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.selector-right-text {
|
||||
flex: 0 0 auto;
|
||||
color: #756e66;
|
||||
font-size: 23rpx;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.selector-badge {
|
||||
flex: 0 0 auto;
|
||||
padding: 5rpx 12rpx;
|
||||
|
||||
@@ -13,6 +13,7 @@ Component({
|
||||
manualForm: { type: Object, value: {} },
|
||||
manualMoreExpanded: { type: Boolean, value: false },
|
||||
showManualExtra: { type: Boolean, value: true },
|
||||
showManualAction: { type: Boolean, value: true },
|
||||
manualImageUrl: { type: String, value: '' },
|
||||
manualImageUploading: { type: Boolean, value: false }
|
||||
},
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
<view class="product-selector-footer"><button class="product-selector-action" bindtap="openManual">+ 手动录入作品</button></view>
|
||||
<view wx:if="{{showManualAction}}" class="product-selector-footer"><button class="product-selector-action" bindtap="openManual">+ 手动录入作品</button></view>
|
||||
</block>
|
||||
<block wx:else>
|
||||
<scroll-view class="product-selector-scroll manual" scroll-y enhanced show-scrollbar="{{false}}">
|
||||
|
||||
@@ -46,16 +46,13 @@ async function run() {
|
||||
page.onCustomerInput({ currentTarget: { dataset: { field: 'customerName' } }, detail: { value: '新客户' } })
|
||||
assert.strictEqual(page.data.form.customerUserId, '')
|
||||
assert.strictEqual(page.data.form.customerName, '新客户')
|
||||
assert.strictEqual(page.data.form.phone, '')
|
||||
assert.strictEqual(page.data.form.phone, '13800138000')
|
||||
|
||||
customersApi.matchIdentity = async () => []
|
||||
customersApi.create = async payload => {
|
||||
assert.strictEqual(payload.nickname, '新客户')
|
||||
assert.strictEqual(payload.phone, undefined)
|
||||
return '42'
|
||||
}
|
||||
customersApi.create = async () => { throw new Error('预约客户建档应随预约请求提交') }
|
||||
assert.strictEqual(await page.ensureCustomerBeforeSubmit(), true)
|
||||
assert.strictEqual(page.data.form.customerUserId, '42')
|
||||
assert.strictEqual(page.data.form.customerUserId, '')
|
||||
assert.strictEqual(page.data.form.createCustomerRecord, true)
|
||||
|
||||
page.data.form.customerUserId = ''
|
||||
page.data.form.customerName = '小周'
|
||||
|
||||
@@ -192,6 +192,113 @@ function flattenTimeGroups(groups) {
|
||||
return (groups || []).reduce((list, group) => list.concat(group.times || []), [])
|
||||
}
|
||||
|
||||
function buildTimeValues(durationMinutes) {
|
||||
const values = []
|
||||
const open = dateUtil.minutesOfDay('10:00')
|
||||
const close = dateUtil.minutesOfDay('22:00')
|
||||
for (let minute = open; minute + durationMinutes <= close; minute += TIME_SLOT_MINUTES) {
|
||||
values.push(dateUtil.timeFromMinutes(minute))
|
||||
}
|
||||
return values
|
||||
}
|
||||
|
||||
function buildTimePickerSlots(calendar, form, durationMinutes) {
|
||||
const schedules = calendar.schedules || []
|
||||
const busyRanges = form.artistId ? buildBusyRanges(calendar.appointments || [], form) : []
|
||||
return buildTimeValues(durationMinutes).map(value => {
|
||||
const startMinute = dateUtil.minutesOfDay(value)
|
||||
const endMinute = startMinute + durationMinutes
|
||||
const occupied = hasBusyConflict(startMinute, endMinute, busyRanges)
|
||||
const scheduled = !form.artistId || schedules.some(schedule =>
|
||||
isScheduleCoveringTime(schedule, form, startMinute, endMinute)
|
||||
)
|
||||
const status = occupied ? 'occupied' : scheduled ? 'available' : 'off-shift'
|
||||
return {
|
||||
value,
|
||||
hour: Number(value.slice(0, 2)),
|
||||
minute: Number(value.slice(3, 5)),
|
||||
rangeText: buildTimeRangeLabel(startMinute, durationMinutes),
|
||||
status,
|
||||
statusText: status === 'occupied' ? '已占用' : status === 'off-shift' ? '无排班' : ''
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function buildTimePickerGroups(slots) {
|
||||
const groupMap = {
|
||||
morning: { key: 'morning', title: '上午', times: [] },
|
||||
afternoon: { key: 'afternoon', title: '下午', times: [] },
|
||||
evening: { key: 'evening', title: '晚上', times: [] }
|
||||
}
|
||||
;(slots || []).forEach(slot => groupMap[getTimePeriod(dateUtil.minutesOfDay(slot.value)).key].times.push(slot))
|
||||
return Object.keys(groupMap).map(key => groupMap[key]).filter(group => group.times.length > 0)
|
||||
}
|
||||
|
||||
function buildTimeWheelState(slots, preferredTime) {
|
||||
if (!slots || slots.length === 0) {
|
||||
return {
|
||||
timePickerHours: [],
|
||||
timePickerMinutes: [],
|
||||
timePickerValue: [0, 0],
|
||||
selectedTimeCandidate: '',
|
||||
timePickerCandidateStatus: 'off-shift'
|
||||
}
|
||||
}
|
||||
const preferredSlot = slots.find(slot => slot.value === preferredTime) || slots.find(slot => slot.value === '14:00')
|
||||
const firstAvailableSlot = slots.find(slot => slot.status === 'available')
|
||||
const selectedSlot = preferredSlot && preferredSlot.status === 'available'
|
||||
? preferredSlot
|
||||
: firstAvailableSlot || preferredSlot || slots[0]
|
||||
const hours = Array.from(new Set(slots.map(slot => slot.hour)))
|
||||
const selectedHourIndex = Math.max(0, hours.indexOf(selectedSlot.hour))
|
||||
const minuteValues = [0, 15, 30, 45]
|
||||
const minutes = minuteValues.map(minute => {
|
||||
const slot = slots.find(item => item.hour === selectedSlot.hour && item.minute === minute)
|
||||
return {
|
||||
value: minute,
|
||||
label: String(minute).padStart(2, '0'),
|
||||
status: slot ? slot.status : 'off-shift',
|
||||
disabled: !slot || slot.status !== 'available'
|
||||
}
|
||||
})
|
||||
const selectedMinuteIndex = Math.max(0, minuteValues.indexOf(selectedSlot.minute))
|
||||
return {
|
||||
timePickerHours: hours.map(hour => ({
|
||||
value: hour,
|
||||
label: String(hour).padStart(2, '0'),
|
||||
disabled: !slots.some(slot => slot.hour === hour && slot.status === 'available')
|
||||
})),
|
||||
timePickerMinutes: minutes,
|
||||
timePickerValue: [selectedHourIndex, selectedMinuteIndex],
|
||||
selectedTimeCandidate: selectedSlot.value,
|
||||
timePickerCandidateStatus: selectedSlot.status
|
||||
}
|
||||
}
|
||||
|
||||
function timeWheelStateForHour(slots, hour, selectedMinute) {
|
||||
const minuteValues = [0, 15, 30, 45]
|
||||
const minutes = minuteValues.map(minute => {
|
||||
const slot = slots.find(item => item.hour === hour && item.minute === minute)
|
||||
return {
|
||||
value: minute,
|
||||
label: String(minute).padStart(2, '0'),
|
||||
status: slot ? slot.status : 'off-shift',
|
||||
disabled: !slot || slot.status !== 'available'
|
||||
}
|
||||
})
|
||||
const selectedMinuteIndex = Math.max(0, minuteValues.indexOf(selectedMinute))
|
||||
return { timePickerMinutes: minutes, selectedMinuteIndex }
|
||||
}
|
||||
|
||||
function customerCreatedAt(customer) {
|
||||
return customer.createTime || customer.createdAt || customer.addedAt || ''
|
||||
}
|
||||
|
||||
function formatCustomerCreatedAt(value) {
|
||||
if (!value) return '添加时间未知'
|
||||
return `添加于 ${String(value).replace('T', ' ').slice(0, 16)}`
|
||||
}
|
||||
|
||||
function parseProductTags(product) {
|
||||
if (Array.isArray(product.tagList) && product.tagList.length > 0) {
|
||||
return product.tagList
|
||||
@@ -245,7 +352,8 @@ function normalizeCustomer(customer) {
|
||||
name,
|
||||
phone,
|
||||
displayName: name || phone || '客户',
|
||||
displayPhone: phone || '未填写手机号'
|
||||
displayPhone: phone || '未填写手机号',
|
||||
createdAt: customerCreatedAt(customer)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,8 +361,8 @@ function buildCustomerSelectorItem(customer) {
|
||||
return {
|
||||
...customer,
|
||||
title: customer.displayName,
|
||||
subtitle: customer.displayPhone,
|
||||
badge: '已有客户'
|
||||
subtitle: formatCustomerCreatedAt(customer.createdAt),
|
||||
rightText: customer.displayPhone
|
||||
}
|
||||
}
|
||||
|
||||
@@ -276,6 +384,7 @@ Page({
|
||||
phone: '',
|
||||
appointmentDate: dateUtil.formatDate(new Date()),
|
||||
appointmentTime: '',
|
||||
amount: '',
|
||||
productId: '',
|
||||
manualProductTitle: '',
|
||||
manualProductPrice: '',
|
||||
@@ -285,14 +394,18 @@ Page({
|
||||
manualProductPrecautions: '',
|
||||
manualProductImageFileIds: '',
|
||||
manualProductImageUrl: '',
|
||||
durationMinutes: '',
|
||||
durationMinutes: '60',
|
||||
artistId: '',
|
||||
createCustomerRecord: false,
|
||||
remark: ''
|
||||
},
|
||||
manualProductDraft: { title: '', price: '', description: '', tags: '', targetAudience: '', precautions: '', imageFileIds: '', imageUrl: '' },
|
||||
customerOptions: [],
|
||||
customerDirectory: [],
|
||||
customerSheetVisible: false,
|
||||
customerKeyword: '',
|
||||
customerViewMode: 'list',
|
||||
customerNewestFirst: true,
|
||||
customerSuggestions: [],
|
||||
customerLoading: false,
|
||||
customerError: '',
|
||||
products: [],
|
||||
@@ -306,8 +419,6 @@ Page({
|
||||
selectedProductPriceText: '',
|
||||
selectedArtist: {},
|
||||
productModalVisible: false,
|
||||
productSelectorMode: 'list',
|
||||
manualProductMoreExpanded: false,
|
||||
productKeyword: '',
|
||||
productError: '',
|
||||
loadingProducts: false,
|
||||
@@ -317,6 +428,14 @@ Page({
|
||||
draftSavedAtText: '',
|
||||
manualImageUploading: false,
|
||||
timeSheetVisible: false,
|
||||
timePickerMode: 'wheel',
|
||||
timePickerValue: [0, 0],
|
||||
timePickerHours: [],
|
||||
timePickerMinutes: [],
|
||||
timePickerSlots: [],
|
||||
timePickerGroups: [],
|
||||
timePickerCandidateStatus: 'off-shift',
|
||||
selectedTimeCandidate: '',
|
||||
timeLoading: false,
|
||||
timeError: '',
|
||||
timeSelectTip: '请先选择美甲师并填写时长',
|
||||
@@ -330,16 +449,6 @@ Page({
|
||||
const baseForm = draftForm || {}
|
||||
this.setData({
|
||||
canCreateAppointment: creatable,
|
||||
manualProductDraft: {
|
||||
title: baseForm.manualProductTitle || '',
|
||||
price: baseForm.manualProductPrice || '',
|
||||
description: baseForm.manualProductDescription || '',
|
||||
tags: baseForm.manualProductTags || '',
|
||||
targetAudience: baseForm.manualProductTargetAudience || '',
|
||||
precautions: baseForm.manualProductPrecautions || '',
|
||||
imageFileIds: baseForm.manualProductImageFileIds || '',
|
||||
imageUrl: baseForm.manualProductImageUrl || ''
|
||||
},
|
||||
form: {
|
||||
...this.data.form,
|
||||
...baseForm,
|
||||
@@ -375,10 +484,14 @@ Page({
|
||||
await this.loadArtists()
|
||||
this.refreshProductCards()
|
||||
const selectedProduct = this.data.filteredProducts.find(item => String(item.id) === String(this.data.form.productId)) || {}
|
||||
this.setData({
|
||||
const selectedProductPatch = {
|
||||
selectedProduct,
|
||||
selectedProductPriceText: selectedProduct.priceText || ''
|
||||
})
|
||||
}
|
||||
if (selectedProduct.id && (this.data.form.amount === '' || this.data.form.amount === undefined)) {
|
||||
selectedProductPatch['form.amount'] = selectedProduct.price === undefined || selectedProduct.price === null ? '' : String(selectedProduct.price)
|
||||
}
|
||||
this.setData(selectedProductPatch)
|
||||
await this.refreshAvailableTimes()
|
||||
this.checkAvailability()
|
||||
},
|
||||
@@ -420,6 +533,47 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
async loadCustomerDirectory() {
|
||||
this.setData({ customerLoading: true })
|
||||
try {
|
||||
const size = 100
|
||||
const rows = []
|
||||
let page = 1
|
||||
let total = Number.POSITIVE_INFINITY
|
||||
while (rows.length < total) {
|
||||
const result = await customersApi.list({ page, size })
|
||||
const currentRows = Array.isArray(result) ? result : (result.list || [])
|
||||
rows.push(...currentRows)
|
||||
if (!Array.isArray(result) && Number.isFinite(Number(result.total))) {
|
||||
total = Number(result.total)
|
||||
} else if (currentRows.length < size) {
|
||||
total = rows.length
|
||||
}
|
||||
if (currentRows.length === 0) break
|
||||
page += 1
|
||||
}
|
||||
const directory = rows.map(normalizeCustomer)
|
||||
this.setData({
|
||||
customerDirectory: directory,
|
||||
customerOptions: this.sortCustomerOptions(directory),
|
||||
customerError: ''
|
||||
})
|
||||
this.refreshCustomerSuggestions(this.data.form.customerName, this.data.form.phone)
|
||||
} catch (error) {
|
||||
this.setData({ customerDirectory: [], customerOptions: [], customerError: error.message || '客户列表加载失败' })
|
||||
} finally {
|
||||
this.setData({ customerLoading: false })
|
||||
}
|
||||
},
|
||||
|
||||
sortCustomerOptions(customers, newestFirst = this.data.customerNewestFirst) {
|
||||
return (customers || []).slice().sort((left, right) => {
|
||||
const leftDate = String(left.createdAt || '')
|
||||
const rightDate = String(right.createdAt || '')
|
||||
return newestFirst ? rightDate.localeCompare(leftDate) : leftDate.localeCompare(rightDate)
|
||||
}).map(buildCustomerSelectorItem)
|
||||
},
|
||||
|
||||
onInput(event) {
|
||||
const field = event.currentTarget.dataset.field
|
||||
const patch = {
|
||||
@@ -432,18 +586,81 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
onStyleTitleInput(event) {
|
||||
const patch = { 'form.manualProductTitle': event.detail.value }
|
||||
if (this.data.form.productId) {
|
||||
patch['form.productId'] = ''
|
||||
patch.selectedProduct = {}
|
||||
patch.selectedProductPriceText = ''
|
||||
patch['form.manualProductImageFileIds'] = ''
|
||||
patch['form.manualProductImageUrl'] = ''
|
||||
}
|
||||
this.setData(patch)
|
||||
},
|
||||
|
||||
onCustomerInput(event) {
|
||||
const field = event.currentTarget.dataset.field
|
||||
const patch = {
|
||||
[`form.${field}`]: event.detail.value,
|
||||
'form.customerUserId': ''
|
||||
}
|
||||
if (field === 'customerName' && this.data.form.customerUserId) {
|
||||
patch['form.phone'] = ''
|
||||
'form.customerUserId': '',
|
||||
'form.createCustomerRecord': false
|
||||
}
|
||||
this.setData({
|
||||
...patch
|
||||
})
|
||||
const customerName = field === 'customerName' ? event.detail.value : this.data.form.customerName
|
||||
const phone = field === 'phone' ? event.detail.value : this.data.form.phone
|
||||
this.refreshCustomerSuggestions(customerName, phone)
|
||||
},
|
||||
|
||||
refreshCustomerSuggestions(nameValue, phoneValue) {
|
||||
const name = String(nameValue || '').trim().toLowerCase()
|
||||
const phone = String(phoneValue || '').trim().toLowerCase()
|
||||
if (!name && !phone) {
|
||||
this._customerSuggestionSeq = (this._customerSuggestionSeq || 0) + 1
|
||||
clearTimeout(this._suggestionTimer)
|
||||
this.setData({ customerSuggestions: [] })
|
||||
return
|
||||
}
|
||||
const suggestions = this.data.customerDirectory
|
||||
.filter(customer => (!name || customer.name.toLowerCase().includes(name)) && (!phone || customer.phone.toLowerCase().includes(phone)))
|
||||
.slice(0, 3)
|
||||
.map(buildCustomerSelectorItem)
|
||||
this.setData({ customerSuggestions: suggestions })
|
||||
const requestSeq = (this._customerSuggestionSeq || 0) + 1
|
||||
this._customerSuggestionSeq = requestSeq
|
||||
clearTimeout(this._suggestionTimer)
|
||||
this._suggestionTimer = setTimeout(async () => {
|
||||
try {
|
||||
const result = await customersApi.list({ page: 1, size: 50, keyword: name || phone })
|
||||
if (requestSeq !== this._customerSuggestionSeq) return
|
||||
const rows = Array.isArray(result) ? result : (result.list || [])
|
||||
const remoteSuggestions = rows.map(normalizeCustomer)
|
||||
.filter(customer => (!name || customer.name.toLowerCase().includes(name)) && (!phone || customer.phone.toLowerCase().includes(phone)))
|
||||
.slice(0, 3)
|
||||
.map(buildCustomerSelectorItem)
|
||||
this.setData({ customerSuggestions: remoteSuggestions })
|
||||
} catch (error) {
|
||||
if (requestSeq === this._customerSuggestionSeq && suggestions.length === 0) {
|
||||
this.setData({ customerSuggestions: [] })
|
||||
}
|
||||
}
|
||||
}, 240)
|
||||
},
|
||||
|
||||
selectCustomerSuggestion(event) {
|
||||
const index = Number(event.currentTarget.dataset.index)
|
||||
const customer = this.data.customerSuggestions[index]
|
||||
if (!customer) return
|
||||
this.setData({
|
||||
'form.customerUserId': customer.id,
|
||||
'form.customerName': customer.name,
|
||||
'form.phone': customer.phone,
|
||||
'form.createCustomerRecord': false,
|
||||
customerSuggestions: [],
|
||||
customerSheetVisible: false,
|
||||
customerKeyword: ''
|
||||
})
|
||||
},
|
||||
|
||||
openCustomerSheet() {
|
||||
@@ -467,22 +684,24 @@ Page({
|
||||
return
|
||||
}
|
||||
const keyword = String(keywordValue === undefined ? this.data.customerKeyword : keywordValue || '').trim()
|
||||
this.setData({ customerLoading: true })
|
||||
try {
|
||||
const data = await customersApi.list({ keyword, page: 1, size: 20 })
|
||||
const list = data.list || data || []
|
||||
this.setData({
|
||||
customerOptions: list.map(normalizeCustomer).map(buildCustomerSelectorItem),
|
||||
customerError: ''
|
||||
})
|
||||
} catch (error) {
|
||||
this.setData({
|
||||
customerOptions: [],
|
||||
customerError: error.message || '客户列表加载失败'
|
||||
})
|
||||
} finally {
|
||||
this.setData({ customerLoading: false })
|
||||
}
|
||||
if (this.data.customerDirectory.length === 0) await this.loadCustomerDirectory()
|
||||
const matches = this.data.customerDirectory.filter(customer =>
|
||||
!keyword || `${customer.name} ${customer.phone}`.toLowerCase().includes(keyword.toLowerCase())
|
||||
)
|
||||
this.setData({ customerOptions: this.sortCustomerOptions(matches), customerError: '' })
|
||||
},
|
||||
|
||||
changeCustomerView(event) {
|
||||
this.setData({ customerViewMode: event.detail.mode || 'list' })
|
||||
},
|
||||
|
||||
toggleCustomerSort() {
|
||||
const customerNewestFirst = !this.data.customerNewestFirst
|
||||
const keyword = String(this.data.customerKeyword || '').trim().toLowerCase()
|
||||
const matches = this.data.customerDirectory.filter(customer =>
|
||||
!keyword || `${customer.name} ${customer.phone}`.toLowerCase().includes(keyword)
|
||||
)
|
||||
this.setData({ customerNewestFirst, customerOptions: this.sortCustomerOptions(matches, customerNewestFirst) })
|
||||
},
|
||||
|
||||
retryCustomerSearch() {
|
||||
@@ -498,8 +717,10 @@ Page({
|
||||
'form.customerUserId': customer.id,
|
||||
'form.customerName': customer.name,
|
||||
'form.phone': customer.phone,
|
||||
'form.createCustomerRecord': false,
|
||||
customerSheetVisible: false,
|
||||
customerKeyword: ''
|
||||
customerKeyword: '',
|
||||
customerSuggestions: []
|
||||
})
|
||||
},
|
||||
|
||||
@@ -507,6 +728,9 @@ Page({
|
||||
if (this._customerTimer) {
|
||||
clearTimeout(this._customerTimer)
|
||||
}
|
||||
if (this._suggestionTimer) {
|
||||
clearTimeout(this._suggestionTimer)
|
||||
}
|
||||
},
|
||||
|
||||
async onDateChange(event) {
|
||||
@@ -555,29 +779,20 @@ Page({
|
||||
|
||||
openProductModal() {
|
||||
this.refreshProductCards()
|
||||
this.setData({ productModalVisible: true, productSelectorMode: 'list' })
|
||||
this.setData({ productModalVisible: true })
|
||||
},
|
||||
|
||||
closeProductModal() {
|
||||
this.setData({ productModalVisible: false, productSelectorMode: 'list' })
|
||||
this.setData({ productModalVisible: false })
|
||||
},
|
||||
|
||||
openManualProduct() {
|
||||
this.setData({ productSelectorMode: 'manual', manualProductMoreExpanded: false })
|
||||
},
|
||||
|
||||
backToProductList() {
|
||||
this.setData({ productSelectorMode: 'list' })
|
||||
this.refreshProductCards()
|
||||
},
|
||||
|
||||
onManualProductInput(event) {
|
||||
const field = event.detail.field
|
||||
this.setData({ [`manualProductDraft.${field}`]: event.detail.value })
|
||||
},
|
||||
|
||||
toggleManualProductMore() {
|
||||
this.setData({ manualProductMoreExpanded: !this.data.manualProductMoreExpanded })
|
||||
this.setData({
|
||||
productModalVisible: false,
|
||||
selectedProduct: {},
|
||||
selectedProductPriceText: '',
|
||||
'form.productId': ''
|
||||
})
|
||||
},
|
||||
|
||||
stopTap() {
|
||||
@@ -597,16 +812,8 @@ Page({
|
||||
this.setData({
|
||||
selectedProduct,
|
||||
selectedProductPriceText: selectedProduct.priceText || '',
|
||||
manualProductDraft: { title: '', price: '', description: '', tags: '', targetAudience: '', precautions: '', imageFileIds: '', imageUrl: '' },
|
||||
'form.productId': selectedProduct.id,
|
||||
'form.manualProductTitle': '',
|
||||
'form.manualProductPrice': '',
|
||||
'form.manualProductDescription': '',
|
||||
'form.manualProductTags': '',
|
||||
'form.manualProductTargetAudience': '',
|
||||
'form.manualProductPrecautions': '',
|
||||
'form.manualProductImageFileIds': '',
|
||||
'form.manualProductImageUrl': '',
|
||||
'form.amount': selectedProduct.price === undefined || selectedProduct.price === null ? '' : String(selectedProduct.price),
|
||||
'form.durationMinutes': String(selectedDuration || this.data.form.durationMinutes || '')
|
||||
})
|
||||
this.closeProductModal()
|
||||
@@ -614,33 +821,6 @@ Page({
|
||||
this.checkAvailability()
|
||||
},
|
||||
|
||||
useManualProduct() {
|
||||
const draft = this.data.manualProductDraft
|
||||
const title = String(draft.title || '').trim()
|
||||
const priceText = String(draft.price === undefined ? '' : draft.price).trim()
|
||||
const price = Number(priceText)
|
||||
if (!title || !priceText || !Number.isFinite(price) || price < 0) {
|
||||
wx.showToast({ title: '请填写手动预约作品名称和价格', icon: 'none' })
|
||||
return
|
||||
}
|
||||
this.setData({
|
||||
selectedProduct: {},
|
||||
selectedProductPriceText: `¥${price}`,
|
||||
'form.productId': '',
|
||||
'form.manualProductTitle': title,
|
||||
'form.manualProductPrice': String(price),
|
||||
'form.manualProductDescription': String(draft.description || '').trim(),
|
||||
'form.manualProductTags': String(draft.tags || '').trim(),
|
||||
'form.manualProductTargetAudience': String(draft.targetAudience || '').trim(),
|
||||
'form.manualProductPrecautions': String(draft.precautions || '').trim(),
|
||||
'form.manualProductImageFileIds': String(draft.imageFileIds || ''),
|
||||
'form.manualProductImageUrl': String(draft.imageUrl || '')
|
||||
})
|
||||
this.closeProductModal()
|
||||
this.refreshAvailableTimes()
|
||||
this.checkAvailability()
|
||||
},
|
||||
|
||||
async chooseManualProductImage() {
|
||||
if (this.data.manualImageUploading) {
|
||||
return
|
||||
@@ -658,8 +838,11 @@ Page({
|
||||
throw new Error('作品图片上传成功但未返回文件ID')
|
||||
}
|
||||
this.setData({
|
||||
'manualProductDraft.imageFileIds': String(fileId),
|
||||
'manualProductDraft.imageUrl': fileUrl
|
||||
'form.productId': '',
|
||||
selectedProduct: {},
|
||||
selectedProductPriceText: '',
|
||||
'form.manualProductImageFileIds': String(fileId),
|
||||
'form.manualProductImageUrl': fileUrl
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '图片上传失败', icon: 'none' })
|
||||
@@ -670,8 +853,8 @@ Page({
|
||||
|
||||
removeManualProductImage() {
|
||||
this.setData({
|
||||
'manualProductDraft.imageFileIds': '',
|
||||
'manualProductDraft.imageUrl': ''
|
||||
'form.manualProductImageFileIds': '',
|
||||
'form.manualProductImageUrl': ''
|
||||
})
|
||||
},
|
||||
|
||||
@@ -781,6 +964,13 @@ Page({
|
||||
if (!form.appointmentDate || !durationMinutes) {
|
||||
const patch = {
|
||||
availableTimeGroups: [],
|
||||
timePickerGroups: [],
|
||||
timePickerSlots: [],
|
||||
timePickerHours: [],
|
||||
timePickerMinutes: [],
|
||||
timePickerValue: [0, 0],
|
||||
selectedTimeCandidate: '',
|
||||
timePickerCandidateStatus: 'off-shift',
|
||||
timeError: '',
|
||||
timeSelectTip: '请先填写预约日期和时长'
|
||||
}
|
||||
@@ -792,8 +982,12 @@ Page({
|
||||
}
|
||||
if (!form.artistId) {
|
||||
const availableTimeGroups = buildUnassignedTimeGroups(durationMinutes)
|
||||
const timePickerSlots = buildTimePickerSlots({ schedules: [], appointments: [] }, form, durationMinutes)
|
||||
this.setData({
|
||||
availableTimeGroups,
|
||||
timePickerSlots,
|
||||
timePickerGroups: buildTimePickerGroups(timePickerSlots),
|
||||
...buildTimeWheelState(timePickerSlots, form.appointmentTime),
|
||||
timeError: '',
|
||||
timeLoading: false,
|
||||
timeSelectTip: '请选择预约时间,员工可稍后分配'
|
||||
@@ -816,8 +1010,12 @@ Page({
|
||||
}
|
||||
const availableTimeGroups = buildAvailableTimeGroups(calendar, form, durationMinutes)
|
||||
const availableTimes = flattenTimeGroups(availableTimeGroups).map(item => item.value)
|
||||
const timePickerSlots = buildTimePickerSlots(calendar, form, durationMinutes)
|
||||
const patch = {
|
||||
availableTimeGroups,
|
||||
timePickerSlots,
|
||||
timePickerGroups: buildTimePickerGroups(timePickerSlots),
|
||||
...buildTimeWheelState(timePickerSlots, form.appointmentTime),
|
||||
timeSelectTip: availableTimes.length > 0 ? '请选择预约时间' : '当前美甲师当天暂无可约时间'
|
||||
}
|
||||
if (form.appointmentTime && !availableTimes.includes(form.appointmentTime)) {
|
||||
@@ -845,7 +1043,7 @@ Page({
|
||||
wx.showToast({ title: '请先填写预约日期和时长', icon: 'none' })
|
||||
return
|
||||
}
|
||||
this.setData({ timeSheetVisible: true })
|
||||
this.setData({ timeSheetVisible: true, timePickerMode: 'wheel' })
|
||||
await this.refreshAvailableTimes()
|
||||
},
|
||||
|
||||
@@ -855,16 +1053,61 @@ Page({
|
||||
|
||||
selectAvailableTime(event) {
|
||||
const value = event.currentTarget.dataset.value
|
||||
this.setData({
|
||||
'form.appointmentTime': value,
|
||||
timeSheetVisible: false
|
||||
})
|
||||
this.checkAvailability()
|
||||
const slot = this.data.timePickerSlots.find(item => item.value === value)
|
||||
if (!slot || slot.status !== 'available') {
|
||||
wx.showToast({ title: slot && slot.status === 'occupied' ? '该时间已被占用' : '该时间不可预约', icon: 'none' })
|
||||
return
|
||||
}
|
||||
this.setData({ selectedTimeCandidate: value, timePickerCandidateStatus: slot.status })
|
||||
},
|
||||
|
||||
async checkAvailability() {
|
||||
onTimePickerModeChange(event) {
|
||||
this.setData({ timePickerMode: event.currentTarget.dataset.mode || 'wheel' })
|
||||
},
|
||||
|
||||
onTimePickerChange(event) {
|
||||
const values = event.detail.value || [0, 0]
|
||||
const hourItem = this.data.timePickerHours[values[0]]
|
||||
if (!hourItem) return
|
||||
const hour = Number(hourItem.value)
|
||||
const minuteIndex = Number(values[1] || 0)
|
||||
const minuteItem = this.data.timePickerMinutes[minuteIndex]
|
||||
const minute = minuteItem ? Number(minuteItem.value) : 0
|
||||
const candidate = `${String(hour).padStart(2, '0')}:${String(minute).padStart(2, '0')}`
|
||||
const slot = this.data.timePickerSlots.find(item => item.value === candidate)
|
||||
const nextMinutes = timeWheelStateForHour(this.data.timePickerSlots, hour, minute)
|
||||
this.setData({
|
||||
timePickerValue: [Number(values[0]), nextMinutes.selectedMinuteIndex],
|
||||
timePickerMinutes: nextMinutes.timePickerMinutes,
|
||||
selectedTimeCandidate: candidate,
|
||||
timePickerCandidateStatus: slot ? slot.status : 'off-shift'
|
||||
})
|
||||
},
|
||||
|
||||
confirmTimeSelection() {
|
||||
const candidate = this.data.selectedTimeCandidate
|
||||
const slot = this.data.timePickerSlots.find(item => item.value === candidate)
|
||||
if (!slot || slot.status !== 'available') {
|
||||
wx.showToast({ title: slot && slot.status === 'occupied' ? '该时间已被占用' : '该时间不可预约', icon: 'none' })
|
||||
return
|
||||
}
|
||||
this.checkAvailability(candidate).then(availability => {
|
||||
if (!availability.ok) {
|
||||
wx.showToast({
|
||||
title: availability.tip && availability.tip.includes('已有预约') ? '该时间已被占用' : availability.tip || '该时间不可预约',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
this.setData({ 'form.appointmentTime': candidate, timeSheetVisible: false })
|
||||
this.checkAvailability()
|
||||
})
|
||||
},
|
||||
|
||||
async checkAvailability(candidateTime) {
|
||||
const form = this.data.form
|
||||
if (!form.appointmentDate || !form.appointmentTime) {
|
||||
const appointmentTime = candidateTime || form.appointmentTime
|
||||
if (!form.appointmentDate || !appointmentTime) {
|
||||
this.setData({ conflictTip: '', conflictLevel: 'free' })
|
||||
return { ok: true }
|
||||
}
|
||||
@@ -873,7 +1116,7 @@ Page({
|
||||
this.setData({ conflictTip: '', conflictLevel: 'free' })
|
||||
return { ok: true }
|
||||
}
|
||||
const startMinute = dateUtil.minutesOfDay(form.appointmentTime)
|
||||
const startMinute = dateUtil.minutesOfDay(appointmentTime)
|
||||
const endMinute = startMinute + durationMinutes
|
||||
if (startMinute < dateUtil.minutesOfDay('10:00') || endMinute > dateUtil.minutesOfDay('22:00')) {
|
||||
const tip = '该时间超出营业时间 10:00-22:00'
|
||||
@@ -912,7 +1155,7 @@ Page({
|
||||
this.setData({ conflictTip: tip, conflictLevel: 'danger' })
|
||||
return { ok: false, tip }
|
||||
}
|
||||
const tip = `${this.data.selectedArtist.name || '该美甲师'} ${form.appointmentTime}-${dateUtil.timeFromMinutes(endMinute)} 可预约`
|
||||
const tip = `${this.data.selectedArtist.name || '该美甲师'} ${appointmentTime}-${dateUtil.timeFromMinutes(endMinute)} 可预约`
|
||||
this.setData({ conflictTip: tip, conflictLevel: 'free' })
|
||||
return { ok: true, tip }
|
||||
} catch (error) {
|
||||
@@ -925,8 +1168,12 @@ Page({
|
||||
async ensureCustomerBeforeSubmit() {
|
||||
const name = String(this.data.form.customerName || '').trim()
|
||||
const phone = String(this.data.form.phone || '').trim()
|
||||
if (!name && !phone) {
|
||||
this.setData({ 'form.createCustomerRecord': false })
|
||||
return true
|
||||
}
|
||||
if (!name) {
|
||||
wx.showToast({ title: '请输入客户姓名', icon: 'none' })
|
||||
wx.showToast({ title: '填写手机号时请同时填写客户姓名', icon: 'none' })
|
||||
return false
|
||||
}
|
||||
if (phone && !/^1[3-9]\d{9}$/.test(phone)) {
|
||||
@@ -934,6 +1181,7 @@ Page({
|
||||
return false
|
||||
}
|
||||
if (this.data.form.customerUserId) {
|
||||
this.setData({ 'form.createCustomerRecord': false })
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -941,6 +1189,20 @@ Page({
|
||||
try {
|
||||
const matches = await customersApi.matchIdentity(name, phone || undefined)
|
||||
if (matches.length > 1) {
|
||||
const choice = await new Promise(resolve => {
|
||||
wx.showModal({
|
||||
title: '找到多个同名客户',
|
||||
content: phone ? '无法确定唯一客户,请选择已有客户或按散客继续。' : '请先补充手机号或选择一个已有客户,也可以按散客继续。',
|
||||
cancelText: '不关联提交',
|
||||
confirmText: '选择客户',
|
||||
success: resolve,
|
||||
fail: () => resolve({ confirm: false })
|
||||
})
|
||||
})
|
||||
if (!choice.confirm) {
|
||||
this.setData({ 'form.createCustomerRecord': false })
|
||||
return true
|
||||
}
|
||||
this.setData({
|
||||
customerOptions: matches.map(normalizeCustomer).map(buildCustomerSelectorItem),
|
||||
customerKeyword: name,
|
||||
@@ -954,20 +1216,22 @@ Page({
|
||||
wx.showModal({
|
||||
title: '客户已存在',
|
||||
content: `系统中已有“${name}”${phone ? `(${phone})` : ''},是否使用该客户?`,
|
||||
cancelText: '取消',
|
||||
cancelText: '不关联提交',
|
||||
confirmText: '使用已有',
|
||||
success: resolve,
|
||||
fail: () => resolve({ confirm: false })
|
||||
})
|
||||
})
|
||||
if (!choice.confirm) {
|
||||
return false
|
||||
if (choice.confirm) {
|
||||
this.setData({
|
||||
'form.customerUserId': customer.id,
|
||||
'form.customerName': customer.name,
|
||||
'form.phone': customer.phone,
|
||||
'form.createCustomerRecord': false
|
||||
})
|
||||
} else {
|
||||
this.setData({ 'form.createCustomerRecord': false })
|
||||
}
|
||||
this.setData({
|
||||
'form.customerUserId': customer.id,
|
||||
'form.customerName': customer.name,
|
||||
'form.phone': customer.phone
|
||||
})
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -981,11 +1245,7 @@ Page({
|
||||
fail: () => resolve({ confirm: false })
|
||||
})
|
||||
})
|
||||
if (!createChoice.confirm) {
|
||||
return false
|
||||
}
|
||||
const customerId = await customersApi.create({ nickname: name, phone: phone || undefined })
|
||||
this.setData({ 'form.customerUserId': customerId })
|
||||
this.setData({ 'form.createCustomerRecord': Boolean(createChoice.confirm) })
|
||||
return true
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '客户校验失败,请稍后重试', icon: 'none' })
|
||||
@@ -1003,13 +1263,25 @@ Page({
|
||||
wx.showToast({ title: '当前账号仅支持查看预约', icon: 'none' })
|
||||
return
|
||||
}
|
||||
const form = this.data.form
|
||||
const hasManualProduct = String(form.manualProductTitle || '').trim() && String(form.manualProductPrice || '').trim()
|
||||
let form = this.data.form
|
||||
const manualProductTitle = String(form.manualProductTitle || '').trim()
|
||||
const manualProductImageFileIds = String(form.manualProductImageFileIds || '').trim()
|
||||
const hasManualProduct = Boolean(manualProductTitle || manualProductImageFileIds || String(form.customerName || '').trim())
|
||||
const amountText = String(form.amount === undefined || form.amount === null ? '' : form.amount).trim()
|
||||
const amount = Number(amountText)
|
||||
const durationMinutes = normalizeDuration(form.durationMinutes)
|
||||
if (!form.customerName || (!form.productId && !hasManualProduct) || !form.appointmentDate || !form.appointmentTime) {
|
||||
if ((!form.productId && !hasManualProduct) || !form.appointmentDate || !form.appointmentTime || !amountText) {
|
||||
wx.showToast({ title: '请补全预约信息', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!Number.isFinite(amount) || amount < 0) {
|
||||
wx.showToast({ title: '请输入不小于0的成交金额', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (form.phone && !String(form.customerName || '').trim()) {
|
||||
wx.showToast({ title: '填写手机号时请同时填写客户姓名', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (form.phone && !/^1[3-9]\d{9}$/.test(String(form.phone).trim())) {
|
||||
wx.showToast({ title: '请输入正确手机号', icon: 'none' })
|
||||
return
|
||||
@@ -1039,12 +1311,17 @@ Page({
|
||||
if (!(await this.ensureCustomerBeforeSubmit())) {
|
||||
return
|
||||
}
|
||||
form = this.data.form
|
||||
this.setData({ loading: true })
|
||||
try {
|
||||
const payload = {
|
||||
...form,
|
||||
customerUserId: form.customerUserId ? String(form.customerUserId) : undefined,
|
||||
artistId: form.artistId ? String(form.artistId) : undefined,
|
||||
customerName: String(form.customerName || '').trim() || undefined,
|
||||
phone: String(form.phone || '').trim() || undefined,
|
||||
amount,
|
||||
createCustomerRecord: Boolean(form.createCustomerRecord),
|
||||
durationMinutes,
|
||||
clientRequestId: buildClientRequestId('manager-appointment')
|
||||
}
|
||||
@@ -1054,8 +1331,8 @@ Page({
|
||||
payload.manualProductPrice = undefined
|
||||
} else {
|
||||
payload.productId = undefined
|
||||
payload.manualProductTitle = String(form.manualProductTitle || '').trim()
|
||||
payload.manualProductPrice = Number(form.manualProductPrice)
|
||||
payload.manualProductTitle = manualProductTitle || undefined
|
||||
payload.manualProductPrice = amount
|
||||
payload.manualProductDescription = String(form.manualProductDescription || '').trim() || undefined
|
||||
payload.manualProductTags = String(form.manualProductTags || '').trim() || undefined
|
||||
payload.manualProductTargetAudience = String(form.manualProductTargetAudience || '').trim() || undefined
|
||||
|
||||
@@ -1,136 +1,67 @@
|
||||
<view class="page no-tab">
|
||||
<view class="card form-card">
|
||||
<view class="field customer-field">
|
||||
<text class="field-label required">客户姓名</text>
|
||||
<view class="customer-entry">
|
||||
<input class="customer-name-input" value="{{form.customerName}}" data-field="customerName" bindinput="onCustomerInput" placeholder="请输入客户姓名" />
|
||||
<button class="customer-select-btn" catchtap="openCustomerSheet">选择已有客户</button>
|
||||
</view>
|
||||
<input class="customer-phone-input" value="{{form.phone}}" data-field="phone" bindinput="onCustomerInput" type="number" maxlength="11" placeholder="手机号(可选)" />
|
||||
<text wx:if="{{form.customerUserId}}" class="customer-selected-tip">已关联系统客户</text>
|
||||
<view class="page no-tab appointment-page">
|
||||
<view class="card form-card style-section">
|
||||
<view class="section-heading">
|
||||
<view><text class="section-title-main">美甲款式</text><text class="section-caption">手动输入为主,也可快速选择已有款式</text></view>
|
||||
<button class="link-action" bindtap="openProductModal">{{form.productId ? '更换款式' : '选择已有款式'}}</button>
|
||||
</view>
|
||||
<view class="field">
|
||||
<text class="field-label required">预约日期</text>
|
||||
<picker mode="date" value="{{form.appointmentDate}}" bindchange="onDateChange">
|
||||
<view class="field-value">{{form.appointmentDate}}</view>
|
||||
</picker>
|
||||
<view wx:if="{{form.productId}}" class="selected-style-card">
|
||||
<image wx:if="{{selectedProduct.coverImage}}" class="selected-style-image" src="{{selectedProduct.coverImage}}" mode="aspectFill"></image>
|
||||
<view class="selected-style-copy"><text class="selected-style-title">{{selectedProduct.title}}</text><text class="selected-style-meta">参考价 {{selectedProductPriceText || '待定'}} · {{selectedProduct.durationText || '时长待定'}}</text></view>
|
||||
<button class="switch-manual-action" bindtap="openManualProduct">手动录入</button>
|
||||
</view>
|
||||
<view class="field product-field" bindtap="openProductModal">
|
||||
<text class="field-label required" bindtap="openProductModal">预约作品</text>
|
||||
<button class="field-value product-value product-picker-button" bindtap="openProductModal">
|
||||
<view><text>{{selectedProduct.title || form.manualProductTitle || '请选择预约作品'}}</text><text wx:if="{{selectedProductPriceText || form.manualProductPrice}}" class="product-selected-price">{{selectedProductPriceText || ('¥' + form.manualProductPrice)}}</text></view>
|
||||
<text wx:if="{{form.manualProductTitle && !form.productId}}" class="manual-badge">手动</text>
|
||||
</button>
|
||||
<view wx:else class="style-name-row">
|
||||
<input class="style-name-input" value="{{form.manualProductTitle}}" bindinput="onStyleTitleInput" placeholder="款式名称(选填)" />
|
||||
<button class="image-action" bindtap="chooseManualProductImage" loading="{{manualImageUploading}}">{{form.manualProductImageUrl ? '更换图片' : '添加图片'}}</button>
|
||||
</view>
|
||||
<view class="field">
|
||||
<text class="field-label required">预计时长</text>
|
||||
<input value="{{form.durationMinutes}}" data-field="durationMinutes" bindinput="onInput" type="number" placeholder="请输入预约时长" />
|
||||
<text class="unit">分钟</text>
|
||||
<view wx:if="{{!form.productId && form.manualProductImageUrl}}" class="style-image-preview-row">
|
||||
<image class="style-image-preview" src="{{form.manualProductImageUrl}}" mode="aspectFill"></image>
|
||||
<button class="remove-image-action" bindtap="removeManualProductImage">移除图片</button>
|
||||
</view>
|
||||
<view class="field">
|
||||
<text class="field-label">员工(可稍后分配)</text>
|
||||
<view class="field-value reference-value" bindtap="openArtistSheet">
|
||||
<text>{{selectedArtist.name || '暂不分配'}}</text>
|
||||
<text class="reference-arrow">›</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="field">
|
||||
<text class="field-label required">预约时间</text>
|
||||
<view class="field-value time-value {{form.appointmentTime ? '' : 'placeholder'}}" bindtap="openTimeSheet">
|
||||
<view>
|
||||
<text>{{form.appointmentTime || timeSelectTip}}</text>
|
||||
<text wx:if="{{form.appointmentTime}}" class="time-range">{{form.appointmentDate}} · {{selectedArtist.name || '待分配'}} · {{form.durationMinutes}}分钟</text>
|
||||
</view>
|
||||
<text class="time-arrow">›</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="field textarea-field">
|
||||
<text class="field-label">备注</text>
|
||||
<textarea value="{{form.remark}}" data-field="remark" bindinput="onInput" placeholder="客户偏好、款式说明" />
|
||||
<view class="style-number-row">
|
||||
<view class="number-field"><text class="field-label required">成交金额</text><input type="digit" value="{{form.amount}}" data-field="amount" bindinput="onInput" placeholder="请输入实际金额" /><text class="number-unit">元</text></view>
|
||||
<view class="number-field"><text class="field-label required">预计时长</text><input type="number" value="{{form.durationMinutes}}" data-field="durationMinutes" bindinput="onInput" placeholder="60" /><text class="number-unit">分钟</text></view>
|
||||
</view>
|
||||
<view class="style-remark-field"><text class="field-label">款式备注</text><textarea value="{{form.remark}}" data-field="remark" bindinput="onInput" placeholder="客户偏好、款式说明(选填)" /></view>
|
||||
<text class="style-hint">名称和图片至少填写一项;名称为空时会使用客户姓名或“散客款式”。</text>
|
||||
</view>
|
||||
|
||||
<view class="capacity-tip card">
|
||||
<text class="tip-title">容量校验</text>
|
||||
<text class="tip-text">已指定员工时会校验排班和冲突;暂不分配时只校验营业时间,后续分配时再完整校验。</text>
|
||||
<view class="card form-card appointment-info-section">
|
||||
<view class="section-heading"><view><text class="section-title-main">预约信息</text><text class="section-caption">时间默认使用滚轮选择</text></view></view>
|
||||
<view class="field"><text class="field-label required">预约日期</text><picker mode="date" value="{{form.appointmentDate}}" bindchange="onDateChange"><view class="field-value">{{form.appointmentDate}}</view></picker></view>
|
||||
<view class="field"><text class="field-label required">预约时间</text><view class="field-value time-value {{form.appointmentTime ? '' : 'placeholder'}}" bindtap="openTimeSheet"><view><text>{{form.appointmentTime || timeSelectTip}}</text><text wx:if="{{form.appointmentTime}}" class="time-range">{{form.appointmentDate}} · {{selectedArtist.name || '待分配'}} · {{form.durationMinutes}}分钟</text></view><text class="time-arrow">›</text></view></view>
|
||||
<view class="field"><text class="field-label">员工(可稍后分配)</text><view class="field-value reference-value" bindtap="openArtistSheet"><text>{{selectedArtist.name || '暂不分配'}}</text><text class="reference-arrow">›</text></view></view>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{draftSavedAtText}}" class="draft-tip card">
|
||||
<text>{{draftSavedAtText}}</text>
|
||||
<button class="text-btn draft-clear" bindtap="clearDraft">清空</button>
|
||||
<view class="card form-card customer-section">
|
||||
<view class="section-heading"><view><text class="section-title-main">客户</text><text class="section-caption">可留空,按散客保存</text></view></view>
|
||||
<view class="customer-entry"><input class="customer-name-input" value="{{form.customerName}}" data-field="customerName" bindinput="onCustomerInput" placeholder="客户姓名(选填)" /><button class="customer-select-btn" catchtap="openCustomerSheet">选择已有客户</button></view>
|
||||
<input class="customer-phone-input" value="{{form.phone}}" data-field="phone" bindinput="onCustomerInput" type="number" maxlength="11" placeholder="手机号(选填,填写时需同时填写姓名)" />
|
||||
<view wx:if="{{customerSuggestions.length}}" class="customer-suggestion-list"><view wx:for="{{customerSuggestions}}" wx:key="id" class="customer-suggestion" data-index="{{index}}" bindtap="selectCustomerSuggestion"><text>{{item.name}}</text><text>{{item.phone || '未填写手机号'}}</text></view></view>
|
||||
<text wx:if="{{form.customerUserId}}" class="customer-selected-tip">已关联系统客户</text>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{conflictTip}}" class="availability-tip card {{conflictLevel}}">
|
||||
<text class="tip-title">时段检查</text>
|
||||
<text class="tip-text">{{conflictTip}}</text>
|
||||
</view>
|
||||
<view class="capacity-tip card"><text class="tip-title">容量校验</text><text class="tip-text">已指定员工时会校验排班和冲突;暂不分配时不校验员工占用,后续分配时再完整校验。</text></view>
|
||||
<view wx:if="{{draftSavedAtText}}" class="draft-tip card"><text>{{draftSavedAtText}}</text><button class="text-btn draft-clear" bindtap="clearDraft">清空</button></view>
|
||||
<view wx:if="{{conflictTip}}" class="availability-tip card {{conflictLevel}}"><text class="tip-title">时段检查</text><text class="tip-text">{{conflictTip}}</text></view>
|
||||
|
||||
<entity-selector-sheet
|
||||
visible="{{customerSheetVisible}}"
|
||||
title="选择客户"
|
||||
keyword="{{customerKeyword}}"
|
||||
placeholder="搜索客户姓名或手机号"
|
||||
items="{{customerOptions}}"
|
||||
selected-id="{{form.customerUserId}}"
|
||||
loading="{{customerLoading}}"
|
||||
error-text="{{customerError}}"
|
||||
empty-text="暂无匹配客户"
|
||||
bind:search="onCustomerSearch"
|
||||
bind:select="selectCustomer"
|
||||
bind:retry="retryCustomerSearch"
|
||||
bind:close="closeCustomerSheet"
|
||||
/>
|
||||
<entity-selector-sheet visible="{{customerSheetVisible}}" title="选择客户" keyword="{{customerKeyword}}" placeholder="搜索客户姓名或手机号" items="{{customerOptions}}" selected-id="{{form.customerUserId}}" loading="{{customerLoading}}" error-text="{{customerError}}" empty-text="暂无匹配客户" show-view-switch="{{true}}" view-mode="{{customerViewMode}}" sort-label="{{customerNewestFirst ? '最新添加' : '最早添加'}}" bind:search="onCustomerSearch" bind:select="selectCustomer" bind:retry="retryCustomerSearch" bind:changeview="changeCustomerView" bind:sort="toggleCustomerSort" bind:close="closeCustomerSheet" />
|
||||
<entity-selector-sheet visible="{{artistSheetVisible}}" title="选择员工" keyword="{{artistKeyword}}" placeholder="搜索员工姓名" items="{{artistSelectorItems}}" selected-id="{{form.artistId}}" loading="{{false}}" error-text="{{artistError}}" empty-text="暂无匹配员工" action-text="快速新增员工" bind:search="onArtistSearch" bind:select="selectArtist" bind:retry="retryArtists" bind:action="addEmployeeFromSelector" bind:close="closeArtistSheet" />
|
||||
<product-selector-sheet visible="{{productModalVisible}}" mode="list" title="选择已有款式" keyword="{{productKeyword}}" placeholder="搜索款式、标签、美甲师" items="{{filteredProducts}}" selected-id="{{form.productId}}" loading="{{loadingProducts}}" error-text="{{productError}}" empty-text="暂无匹配款式" show-manual-action="{{false}}" bind:search="onProductSearch" bind:select="selectProduct" bind:retry="loadOptions" bind:close="closeProductModal" />
|
||||
|
||||
<entity-selector-sheet
|
||||
visible="{{artistSheetVisible}}"
|
||||
title="选择员工"
|
||||
keyword="{{artistKeyword}}"
|
||||
placeholder="搜索员工姓名"
|
||||
items="{{artistSelectorItems}}"
|
||||
selected-id="{{form.artistId}}"
|
||||
loading="{{false}}"
|
||||
error-text="{{artistError}}"
|
||||
empty-text="暂无匹配员工"
|
||||
action-text="快速新增员工"
|
||||
bind:search="onArtistSearch"
|
||||
bind:select="selectArtist"
|
||||
bind:retry="retryArtists"
|
||||
bind:action="addEmployeeFromSelector"
|
||||
bind:close="closeArtistSheet"
|
||||
/>
|
||||
|
||||
<product-selector-sheet visible="{{productModalVisible}}" mode="{{productSelectorMode}}" title="选择预约作品" keyword="{{productKeyword}}" placeholder="搜索作品、标签、美甲师" items="{{filteredProducts}}" selected-id="{{form.productId}}" loading="{{loadingProducts}}" error-text="{{productError}}" empty-text="暂无匹配作品" manual-form="{{manualProductDraft}}" manual-more-expanded="{{manualProductMoreExpanded}}" manual-image-url="{{manualProductDraft.imageUrl}}" manual-image-uploading="{{manualImageUploading}}" bind:search="onProductSearch" bind:select="selectProduct" bind:openmanual="openManualProduct" bind:backtolist="backToProductList" bind:manualinput="onManualProductInput" bind:togglemore="toggleManualProductMore" bind:chooseimage="chooseManualProductImage" bind:removeimage="removeManualProductImage" bind:confirmmanual="useManualProduct" bind:retry="loadOptions" bind:close="closeProductModal" />
|
||||
|
||||
<view wx:if="{{timeSheetVisible}}" class="modal-mask" bindtap="closeTimeSheet">
|
||||
<view class="time-modal" catchtap="stopTap">
|
||||
<view class="modal-head">
|
||||
<view>
|
||||
<text class="modal-title">选择预约时间</text>
|
||||
<text class="modal-subtitle">{{form.appointmentDate}} · {{selectedArtist.name || '待分配'}} · {{form.durationMinutes}}分钟</text>
|
||||
</view>
|
||||
<view class="modal-close" bindtap="closeTimeSheet">×</view>
|
||||
</view>
|
||||
<view wx:if="{{timeSheetVisible}}" class="modal-mask" bindtap="closeTimeSheet" catchtouchmove="stopTouchMove">
|
||||
<view class="time-modal" catchtap="stopTap" catchtouchmove="stopTouchMove">
|
||||
<view class="modal-head"><view><text class="modal-title">选择预约时间</text><text class="modal-subtitle">{{form.appointmentDate}} · {{selectedArtist.name || '待分配'}} · {{form.durationMinutes}}分钟</text></view><view class="modal-close" bindtap="closeTimeSheet" aria-label="关闭时间选择"></view></view>
|
||||
<view class="time-mode-switch"><button class="{{timePickerMode === 'wheel' ? 'active' : ''}}" data-mode="wheel" bindtap="onTimePickerModeChange">滚轮选择</button><button class="{{timePickerMode === 'grid' ? 'active' : ''}}" data-mode="grid" bindtap="onTimePickerModeChange">15分钟时段</button></view>
|
||||
<view wx:if="{{timeLoading}}" class="time-empty">正在计算可约时间...</view>
|
||||
<view wx:elif="{{timeError}}" class="time-empty">{{timeError}}</view>
|
||||
<view wx:elif="{{availableTimeGroups.length === 0}}" class="time-empty">当前没有可选时间</view>
|
||||
<scroll-view wx:else class="time-list" scroll-y>
|
||||
<view wx:for="{{availableTimeGroups}}" wx:key="key" class="time-group">
|
||||
<text class="time-group-title">{{item.title}}</text>
|
||||
<view class="time-grid">
|
||||
<view wx:for="{{item.times}}" wx:for-item="time" wx:key="value" class="time-chip {{form.appointmentTime === time.value ? 'active' : ''}}" data-value="{{time.value}}" bindtap="selectAvailableTime">
|
||||
<text>{{time.value}}</text>
|
||||
<text>{{time.rangeText}}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
<block wx:elif="{{timePickerMode === 'wheel'}}">
|
||||
<picker-view class="time-wheel" indicator-style="height: 76rpx;" value="{{timePickerValue}}" bindchange="onTimePickerChange"><picker-view-column><view wx:for="{{timePickerHours}}" wx:key="value" class="wheel-item {{item.disabled ? 'disabled' : ''}}">{{item.label}}</view></picker-view-column><picker-view-column><view wx:for="{{timePickerMinutes}}" wx:key="value" class="wheel-item {{item.disabled ? 'disabled' : ''}}">{{item.label}}</view></picker-view-column></picker-view>
|
||||
<view class="time-wheel-caption">{{selectedTimeCandidate || '请选择时间'}}<text wx:if="{{timePickerCandidateStatus === 'occupied'}}"> · 已被占用</text><text wx:elif="{{timePickerCandidateStatus === 'off-shift'}}"> · 当前无排班</text></view>
|
||||
<button class="time-confirm-btn" bindtap="confirmTimeSelection">确认时间</button>
|
||||
</block>
|
||||
<block wx:else><scroll-view class="time-list" scroll-y><view wx:for="{{timePickerGroups}}" wx:key="key" class="time-group"><text class="time-group-title">{{item.title}}</text><view class="time-grid"><view wx:for="{{item.times}}" wx:for-item="time" wx:key="value" class="time-chip {{selectedTimeCandidate === time.value ? 'active' : ''}} {{time.status !== 'available' ? 'disabled' : ''}}" data-value="{{time.value}}" bindtap="selectAvailableTime"><text>{{time.value}}</text><text>{{time.statusText || time.rangeText}}</text></view></view></view></scroll-view><button class="time-confirm-btn" bindtap="confirmTimeSelection">确认当前时间</button></block>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="fixed-bottom">
|
||||
<view wx:if="{{canCreateAppointment}}" class="action-row">
|
||||
<button class="secondary-btn draft-btn" bindtap="saveDraft">保存草稿</button>
|
||||
<button class="primary-btn submit-btn" loading="{{loading}}" bindtap="submit">提交预约</button>
|
||||
</view>
|
||||
</view>
|
||||
<view class="fixed-bottom"><view wx:if="{{canCreateAppointment}}" class="action-row"><button class="secondary-btn draft-btn" bindtap="saveDraft">保存草稿</button><button class="primary-btn submit-btn" loading="{{loading}}" bindtap="submit">提交预约</button></view></view>
|
||||
</view>
|
||||
|
||||
@@ -269,8 +269,12 @@
|
||||
}
|
||||
|
||||
.time-modal {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
height: 76vh;
|
||||
max-height: 82vh;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
padding: 28rpx 28rpx calc(28rpx + env(safe-area-inset-bottom));
|
||||
border-radius: 28rpx 28rpx 0 0;
|
||||
background: #fffaf4;
|
||||
@@ -337,10 +341,17 @@
|
||||
}
|
||||
|
||||
.time-list {
|
||||
max-height: 620rpx;
|
||||
height: 0;
|
||||
min-height: 0;
|
||||
flex: 1;
|
||||
padding-right: 2rpx;
|
||||
}
|
||||
|
||||
.time-wheel {
|
||||
min-height: 260rpx;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.time-group {
|
||||
margin-bottom: 28rpx;
|
||||
}
|
||||
@@ -427,3 +438,358 @@
|
||||
min-width: 0;
|
||||
max-width: none;
|
||||
}
|
||||
|
||||
.appointment-page .form-card {
|
||||
margin-bottom: 18rpx;
|
||||
padding: 20rpx 24rpx 10rpx;
|
||||
}
|
||||
|
||||
.section-heading {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 16rpx;
|
||||
margin: 0 0 18rpx;
|
||||
}
|
||||
|
||||
.section-title-main,
|
||||
.section-caption {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.section-title-main {
|
||||
color: #302a24;
|
||||
font-size: 30rpx;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.section-caption {
|
||||
margin-top: 5rpx;
|
||||
color: #9a9288;
|
||||
font-size: 21rpx;
|
||||
}
|
||||
|
||||
.link-action {
|
||||
flex: 0 0 auto;
|
||||
height: 60rpx;
|
||||
padding: 0 17rpx;
|
||||
border: 1rpx solid #d7b38e;
|
||||
border-radius: 14rpx;
|
||||
background: #fff7ed;
|
||||
color: #9f5f2d;
|
||||
font-size: 22rpx;
|
||||
line-height: 60rpx;
|
||||
}
|
||||
|
||||
.style-name-row,
|
||||
.style-image-preview-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14rpx;
|
||||
}
|
||||
|
||||
.style-name-input {
|
||||
min-width: 0;
|
||||
height: 78rpx;
|
||||
flex: 1;
|
||||
padding: 0 18rpx;
|
||||
border: 1rpx solid #e7e0d7;
|
||||
border-radius: 15rpx;
|
||||
background: #fff;
|
||||
color: #29241f;
|
||||
font-size: 26rpx;
|
||||
}
|
||||
|
||||
.image-action,
|
||||
.remove-image-action {
|
||||
flex: 0 0 auto;
|
||||
height: 72rpx;
|
||||
padding: 0 18rpx;
|
||||
border-radius: 14rpx;
|
||||
background: #edf4f1;
|
||||
color: #2f6f62;
|
||||
font-size: 23rpx;
|
||||
line-height: 72rpx;
|
||||
}
|
||||
|
||||
.style-image-preview-row {
|
||||
justify-content: flex-start;
|
||||
margin-top: 14rpx;
|
||||
}
|
||||
|
||||
.style-image-preview {
|
||||
width: 112rpx;
|
||||
height: 112rpx;
|
||||
border-radius: 14rpx;
|
||||
background: #eee9e2;
|
||||
}
|
||||
|
||||
.remove-image-action {
|
||||
height: 58rpx;
|
||||
background: #f5f0e9;
|
||||
color: #756e66;
|
||||
font-size: 21rpx;
|
||||
line-height: 58rpx;
|
||||
}
|
||||
|
||||
.selected-style-note {
|
||||
margin-top: 12rpx;
|
||||
color: #4f766d;
|
||||
font-size: 23rpx;
|
||||
line-height: 1.45;
|
||||
}
|
||||
|
||||
.style-number-row {
|
||||
display: flex;
|
||||
gap: 18rpx;
|
||||
margin-top: 18rpx;
|
||||
}
|
||||
|
||||
.number-field {
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
height: 88rpx;
|
||||
flex: 1;
|
||||
align-items: center;
|
||||
gap: 8rpx;
|
||||
border-bottom: 1rpx solid #eee8df;
|
||||
}
|
||||
|
||||
.number-field .field-label {
|
||||
width: auto;
|
||||
flex: 0 0 auto;
|
||||
font-size: 22rpx;
|
||||
}
|
||||
|
||||
.number-field input {
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
color: #302923;
|
||||
font-size: 27rpx;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.number-unit {
|
||||
flex: 0 0 auto;
|
||||
color: #9a9288;
|
||||
font-size: 22rpx;
|
||||
}
|
||||
|
||||
.style-remark-field {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 14rpx;
|
||||
padding: 18rpx 0 8rpx;
|
||||
border-bottom: 1rpx solid #eee8df;
|
||||
}
|
||||
|
||||
.style-remark-field .field-label {
|
||||
width: 124rpx;
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
.style-remark-field textarea {
|
||||
min-height: 86rpx;
|
||||
flex: 1;
|
||||
padding: 0;
|
||||
color: #302923;
|
||||
font-size: 25rpx;
|
||||
}
|
||||
|
||||
.style-hint {
|
||||
display: block;
|
||||
padding: 12rpx 0 16rpx;
|
||||
color: #a1978c;
|
||||
font-size: 20rpx;
|
||||
line-height: 1.45;
|
||||
}
|
||||
|
||||
.appointment-info-section .section-heading,
|
||||
.customer-section .section-heading {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.appointment-info-section .field:last-child {
|
||||
border-bottom: 0;
|
||||
}
|
||||
|
||||
.customer-section {
|
||||
padding-bottom: 22rpx !important;
|
||||
}
|
||||
|
||||
.customer-section .customer-entry {
|
||||
margin-top: 16rpx;
|
||||
}
|
||||
|
||||
.customer-entry .customer-name-input {
|
||||
height: 76rpx;
|
||||
}
|
||||
|
||||
.customer-entry .customer-select-btn {
|
||||
min-width: 170rpx;
|
||||
height: 76rpx;
|
||||
line-height: 76rpx;
|
||||
}
|
||||
|
||||
.customer-phone-input {
|
||||
height: 70rpx;
|
||||
}
|
||||
|
||||
.customer-suggestion-list {
|
||||
margin-top: 10rpx;
|
||||
overflow: hidden;
|
||||
border: 1rpx solid #e8e0d7;
|
||||
border-radius: 14rpx;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.customer-suggestion {
|
||||
display: flex;
|
||||
min-height: 68rpx;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 18rpx;
|
||||
padding: 0 16rpx;
|
||||
border-bottom: 1rpx solid #f0ebe4;
|
||||
color: #39332d;
|
||||
font-size: 23rpx;
|
||||
}
|
||||
|
||||
.customer-suggestion:last-child {
|
||||
border-bottom: 0;
|
||||
}
|
||||
|
||||
.customer-suggestion text:last-child {
|
||||
color: #82796f;
|
||||
font-size: 21rpx;
|
||||
}
|
||||
|
||||
.time-mode-switch {
|
||||
display: flex;
|
||||
gap: 8rpx;
|
||||
margin-bottom: 18rpx;
|
||||
padding: 6rpx;
|
||||
border-radius: 15rpx;
|
||||
background: #f2eee8;
|
||||
}
|
||||
|
||||
.time-mode-switch button {
|
||||
height: 58rpx;
|
||||
flex: 1;
|
||||
border-radius: 11rpx;
|
||||
color: #81786e;
|
||||
font-size: 23rpx;
|
||||
line-height: 58rpx;
|
||||
}
|
||||
|
||||
.time-mode-switch button.active {
|
||||
background: #fffdf8;
|
||||
color: #4f766d;
|
||||
font-weight: 800;
|
||||
box-shadow: 0 3rpx 8rpx rgba(58, 48, 34, 0.08);
|
||||
}
|
||||
|
||||
.time-wheel {
|
||||
width: 100%;
|
||||
height: 320rpx;
|
||||
border-top: 1rpx solid #eee7de;
|
||||
border-bottom: 1rpx solid #eee7de;
|
||||
}
|
||||
|
||||
.wheel-item {
|
||||
height: 76rpx;
|
||||
color: #302923;
|
||||
font-size: 34rpx;
|
||||
line-height: 76rpx;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.wheel-item.disabled {
|
||||
color: #c8c1b8;
|
||||
}
|
||||
|
||||
.time-wheel-caption {
|
||||
padding: 18rpx 0 8rpx;
|
||||
color: #736a60;
|
||||
font-size: 23rpx;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.time-confirm-btn {
|
||||
width: 100%;
|
||||
height: 76rpx;
|
||||
margin-top: 12rpx;
|
||||
border-radius: 16rpx;
|
||||
background: #4f766d;
|
||||
color: #fff;
|
||||
font-size: 26rpx;
|
||||
font-weight: 800;
|
||||
line-height: 76rpx;
|
||||
}
|
||||
|
||||
.time-chip.disabled {
|
||||
border-color: #e8e4df;
|
||||
background: #f3f1ee;
|
||||
color: #bcb5ad;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.time-chip.disabled text:last-child {
|
||||
color: #c1bab2;
|
||||
}
|
||||
|
||||
.selected-style-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14rpx;
|
||||
min-height: 104rpx;
|
||||
padding: 12rpx;
|
||||
border: 1rpx solid #d9e5df;
|
||||
border-radius: 15rpx;
|
||||
background: #f4f8f5;
|
||||
}
|
||||
|
||||
.selected-style-image {
|
||||
width: 82rpx;
|
||||
height: 82rpx;
|
||||
flex: 0 0 auto;
|
||||
border-radius: 12rpx;
|
||||
background: #e9e5df;
|
||||
}
|
||||
|
||||
.selected-style-copy {
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
flex-direction: column;
|
||||
gap: 6rpx;
|
||||
}
|
||||
|
||||
.selected-style-title,
|
||||
.selected-style-meta {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.selected-style-title {
|
||||
color: #302923;
|
||||
font-size: 26rpx;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.selected-style-meta {
|
||||
color: #81796f;
|
||||
font-size: 21rpx;
|
||||
}
|
||||
|
||||
.switch-manual-action {
|
||||
height: 58rpx;
|
||||
flex: 0 0 auto;
|
||||
padding: 0 14rpx;
|
||||
border-radius: 12rpx;
|
||||
background: #e7f0ec;
|
||||
color: #4f766d;
|
||||
font-size: 21rpx;
|
||||
line-height: 58rpx;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ const wxss = fs.readFileSync(path.join(__dirname, 'index.wxss'), 'utf8')
|
||||
const pageScript = fs.readFileSync(path.join(__dirname, 'index.js'), 'utf8')
|
||||
|
||||
assert.match(wxml, /<product-selector-sheet[^>]*bind:close="closeProductModal"/)
|
||||
assert.match(wxml, /manual-form="\{\{manualProductDraft\}\}"/)
|
||||
assert.match(wxml, /show-manual-action="\{\{false\}\}"/)
|
||||
assert.match(wxml, /bind:select="selectProduct"/)
|
||||
const componentWxml = fs.readFileSync(path.join(__dirname, '../../components/product-selector-sheet/index.wxml'), 'utf8')
|
||||
const componentWxss = fs.readFileSync(path.join(__dirname, '../../components/product-selector-sheet/index.wxss'), 'utf8')
|
||||
@@ -15,6 +15,8 @@ assert.match(componentWxml, /catchtouchmove="stopEvent"/)
|
||||
assert.match(componentWxml, /bindtap="openManual"/)
|
||||
assert.match(componentWxml, /bindtap="selectItem"/)
|
||||
assert.match(componentWxml, /bindtap="confirmManual"/)
|
||||
assert.match(wxml, /picker-view class="time-wheel"/)
|
||||
assert.match(wxml, /data-mode="grid" bindtap="onTimePickerModeChange"/)
|
||||
assert.match(componentWxss, /\.product-selector-sheet\{[^}]*height:88vh;[^}]*max-height:88vh;/s)
|
||||
assert.match(componentWxss, /.product-selector-scroll{height:0;min-height:0;flex:1}/)
|
||||
assert.match(pageScript, /openManualProduct\(\)\s*\{/)
|
||||
|
||||
@@ -24,20 +24,25 @@ function createPage() {
|
||||
const page = createPage()
|
||||
page.openProductModal()
|
||||
assert.strictEqual(page.data.productModalVisible, true)
|
||||
assert.strictEqual(page.data.productSelectorMode, 'list')
|
||||
page.refreshAvailableTimes = () => {}
|
||||
page.checkAvailability = () => {}
|
||||
page.selectProduct({ detail: { item: { id: 8, title: '法式', price: 238, priceText: '¥238', approximateDuration: '90' } } })
|
||||
assert.strictEqual(page.data.form.productId, 8)
|
||||
assert.strictEqual(page.data.selectedProduct.title, '法式')
|
||||
assert.strictEqual(page.data.selectedProductPriceText, '¥238')
|
||||
assert.strictEqual(page.data.form.amount, '238')
|
||||
assert.strictEqual(page.data.form.manualProductTitle, '')
|
||||
assert.strictEqual(page.data.form.durationMinutes, '90')
|
||||
|
||||
page.data.manualProductDraft = { title: '手绘款', price: '299', description: '', tags: '', targetAudience: '', precautions: '', imageFileIds: '', imageUrl: '' }
|
||||
page.useManualProduct()
|
||||
page.onStyleTitleInput({ detail: { value: '手绘款' } })
|
||||
assert.strictEqual(page.data.form.productId, '')
|
||||
assert.strictEqual(page.data.form.manualProductTitle, '手绘款')
|
||||
assert.strictEqual(page.data.form.manualProductPrice, '299')
|
||||
assert.strictEqual(page.data.selectedProductPriceText, '¥299')
|
||||
assert.strictEqual(page.data.form.amount, '238')
|
||||
assert.strictEqual(page.data.selectedProductPriceText, '')
|
||||
|
||||
const wxml = require('fs').readFileSync(require('path').join(__dirname, 'index.wxml'), 'utf8')
|
||||
assert.ok(wxml.indexOf('美甲款式') < wxml.indexOf('预约信息'))
|
||||
assert.ok(wxml.indexOf('预约信息') < wxml.indexOf('>客户</text>'))
|
||||
assert.match(wxml, /placeholder="款式名称(选填)"/)
|
||||
assert.match(wxml, /成交金额/)
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ async function run() {
|
||||
productId: '41',
|
||||
appointmentDate: '2026-10-13',
|
||||
appointmentTime: '14:00',
|
||||
amount: '120',
|
||||
durationMinutes: '60',
|
||||
artistId: ''
|
||||
})
|
||||
@@ -62,7 +63,32 @@ async function run() {
|
||||
|
||||
assert.strictEqual(submittedPayload.artistId, undefined)
|
||||
assert.strictEqual(submittedPayload.appointmentTime, '14:00')
|
||||
assert.strictEqual(submittedPayload.amount, 120)
|
||||
assert.strictEqual(submittedPayload.createCustomerRecord, false)
|
||||
assert.strictEqual(redirectedTo, '/pages/appointment-detail/index?id=61')
|
||||
|
||||
const walkInPage = createPage()
|
||||
Object.assign(walkInPage.data.form, {
|
||||
productId: '41',
|
||||
appointmentDate: '2026-10-13',
|
||||
appointmentTime: '15:00',
|
||||
amount: '88',
|
||||
durationMinutes: '45',
|
||||
artistId: ''
|
||||
})
|
||||
let walkInPayload
|
||||
planningApi.createAppointment = async payload => {
|
||||
walkInPayload = payload
|
||||
return { orderItemId: 62 }
|
||||
}
|
||||
await walkInPage.submit()
|
||||
|
||||
assert.strictEqual(walkInPayload.customerUserId, undefined)
|
||||
assert.strictEqual(walkInPayload.customerName, undefined)
|
||||
assert.strictEqual(walkInPayload.phone, undefined)
|
||||
assert.strictEqual(walkInPayload.createCustomerRecord, false)
|
||||
assert.strictEqual(walkInPayload.artistId, undefined)
|
||||
assert.strictEqual(walkInPayload.appointmentTime, '15:00')
|
||||
}
|
||||
|
||||
run().catch(error => {
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
# Salon 新增预约表单与客户身份设计
|
||||
|
||||
## 目标
|
||||
|
||||
让店长能快速记录预约,不因暂时没有客户档案或员工安排而中断;同时保持用户主键稳定,并按客户业务身份规则避免重复建档。
|
||||
|
||||
## 表单结构
|
||||
|
||||
页面按“美甲款式、预约信息、客户”排列。
|
||||
|
||||
- 美甲款式优先手动填写,也可搜索并选择已有作品。选择后带入作品名称、参考价格和时长;金额表示成交价,仍可修改。
|
||||
- 手动款式名称或图片至少填写一项。名称为空时依次使用客户姓名、“散客款式”作为兜底名称。
|
||||
- 预约信息包含日期、时间、员工、成交金额和时长。时间默认使用上下滚动的时分选择器,保留 15 分钟时段模式。
|
||||
- 客户允许留空;输入手机号时必须同时提供姓名。客户姓名和联系电话可搜索已有客户并快速选择。
|
||||
- 页面不提供单独的历史补单按钮;历史日期进入补单流程,普通预约继续执行历史日期拦截。
|
||||
|
||||
## 客户身份与建档
|
||||
|
||||
- `t_user.id` 是内部技术主键,继续使用 `UserDO` 的 `IdType.ASSIGN_ID` 雪花式生成策略。
|
||||
- 客户业务去重独立于内部主键:填写姓名和手机号时按姓名与手机号组合匹配;未填写手机号时按姓名匹配。
|
||||
- 前端仅负责提交前提示和选择,后端在预约事务内再次匹配并创建,避免以客户端校验作为唯一保障。
|
||||
- 用户选择已有客户后使用其 `customerUserId`;确认新建时在预约事务内创建客户档案;选择不新建或完全不填写客户时,订单保留客户快照字段,`user_id` 为空。
|
||||
- 不为散客构造用户 ID,不把姓名或手机号作为 `user_id`。
|
||||
|
||||
## 员工与时间
|
||||
|
||||
- 员工允许选择“暂不分配”。无员工时预约仍需日期、时间和时长,只检查门店营业时间,不请求员工日历、不执行员工占用校验,也不创建预约容量占用。
|
||||
- 指定员工时,时间选择页展示排班和冲突;不可用时间置灰,提交选择时再次校验。后端保留最终排班与容量校验。
|
||||
- 后续分配员工时沿用改派流程并执行完整校验。
|
||||
|
||||
## 验证范围
|
||||
|
||||
- 覆盖无客户、客户建档、已有客户、姓名或手机号不完整、款式图片兜底标题、金额及时长、未分配员工和指定员工预约。
|
||||
- 小程序执行完整 Node 测试;Core 执行预约服务测试与编译。
|
||||
- 本次不改数据库结构、初始化 SQL、Nacos、后台管理或 ArtList。
|
||||
@@ -1,5 +1,14 @@
|
||||
# 项目变更记录
|
||||
|
||||
## 2026-10-20 Salon 新增预约表单与客户身份优化
|
||||
|
||||
- 新增预约表单按“美甲款式、预约信息、客户”排列;款式以手动录入为主,也可选择已有作品快速带入参考价格和时长,成交金额仍可修改。
|
||||
- 手动款式名称或图片至少填写一项;名称为空时使用客户姓名,没有客户姓名时使用“散客款式”。
|
||||
- 客户允许留空;手机号填写时必须同时填写姓名。确认建档后由预约事务创建客户,选择不建档或不填写客户时以散客快照保存,不生成虚假用户关联。
|
||||
- 客户身份判重使用姓名与手机号组合,手机号为空时姓名必须唯一;`t_user.id` 保持实体现有 `ASSIGN_ID` 雪花式主键策略,不将业务字段用作主键。
|
||||
- 时间选择默认使用滚轮,并保留 15 分钟时段视图;指定员工时校验排班与占用,暂不分配员工时不做员工时段占用检查。
|
||||
- 更新预约表单状态测试和 Core 补单式散客预约测试;未修改 SQL、Nacos、后台管理或 ArtList。
|
||||
|
||||
## 2026-10-16 Salon 预约客户输入与选择优化
|
||||
|
||||
- 新增预约客户字段改为“客户姓名输入框 + 选择已有客户”按钮,手机号改为可选输入,输入文本时自动解除旧客户绑定。
|
||||
|
||||
Reference in New Issue
Block a user