diff --git a/JY-Salon-Front/src/api/managerProducts.ts b/JY-Salon-Front/src/api/managerProducts.ts index 57d025de..de2f54f2 100644 --- a/JY-Salon-Front/src/api/managerProducts.ts +++ b/JY-Salon-Front/src/api/managerProducts.ts @@ -1,9 +1,25 @@ import { adminApi } from '@/api/client' -import type { PageResult } from '@/types/common' +import type { IdType, PageResult } from '@/types/common' import type { Product } from '@/types/manager' +export interface ProductCreateRequest { + title: string + description?: string + targetAudience?: string + precautions?: string + imageFileIds?: string + price: number + tags?: string + approximateDuration?: string + bookableArtists?: string + frontVisible: number +} + export const managerProductsApi = { list(params: { page: number; size: number; keyword?: string }): Promise | Product[]> { return adminApi.get('/manager/products', { params }) + }, + create(data: ProductCreateRequest): Promise { + return adminApi.post('/product/create', data) } } diff --git a/JY-Salon-Front/src/api/managerTags.ts b/JY-Salon-Front/src/api/managerTags.ts new file mode 100644 index 00000000..87f9ecef --- /dev/null +++ b/JY-Salon-Front/src/api/managerTags.ts @@ -0,0 +1,17 @@ +import { adminApi } from '@/api/client' +import type { IdType } from '@/types/common' + +export interface ManagerTag { + id: IdType + tagName: string + displayName?: string + textColor?: string + bgColor?: string + borderColor?: string +} + +export const managerTagsApi = { + listAll(): Promise { + return adminApi.get('/tag/list/all') + } +} diff --git a/JY-Salon-Front/src/components/DatePickerField.vue b/JY-Salon-Front/src/components/DatePickerField.vue new file mode 100644 index 00000000..8714c6ae --- /dev/null +++ b/JY-Salon-Front/src/components/DatePickerField.vue @@ -0,0 +1,58 @@ + + + + + diff --git a/JY-Salon-Front/src/components/DatePickerSheet.vue b/JY-Salon-Front/src/components/DatePickerSheet.vue new file mode 100644 index 00000000..ee74aca6 --- /dev/null +++ b/JY-Salon-Front/src/components/DatePickerSheet.vue @@ -0,0 +1,175 @@ + + + + + diff --git a/JY-Salon-Front/src/components/TimePickerField.vue b/JY-Salon-Front/src/components/TimePickerField.vue new file mode 100644 index 00000000..ec640ba8 --- /dev/null +++ b/JY-Salon-Front/src/components/TimePickerField.vue @@ -0,0 +1,58 @@ + + + + + diff --git a/JY-Salon-Front/src/components/TimePickerSheet.vue b/JY-Salon-Front/src/components/TimePickerSheet.vue new file mode 100644 index 00000000..50e9f600 --- /dev/null +++ b/JY-Salon-Front/src/components/TimePickerSheet.vue @@ -0,0 +1,186 @@ + + + + + diff --git a/JY-Salon-Front/src/utils/picker-options.test.ts b/JY-Salon-Front/src/utils/picker-options.test.ts new file mode 100644 index 00000000..c68effb5 --- /dev/null +++ b/JY-Salon-Front/src/utils/picker-options.test.ts @@ -0,0 +1,52 @@ +import { describe, expect, it } from 'vitest' +import { + buildDatePickerMonth, + buildHourOptions, + buildMinuteOptions, + cancelPickerDraft, + confirmPickerDraft, + createPickerDraft, + joinTimeParts, + normalizeTimeParts, + updatePickerDraft +} from '@/utils/picker-options' + +describe('picker options', () => { + it('builds a sunday-first month grid with selected date', () => { + const days = buildDatePickerMonth('2026-07-02', '2026-07-02') + + expect(days).toHaveLength(42) + expect(days.slice(0, 7).map(item => item.date)).toEqual([ + '2026-06-28', + '2026-06-29', + '2026-06-30', + '2026-07-01', + '2026-07-02', + '2026-07-03', + '2026-07-04' + ]) + expect(days.find(item => item.date === '2026-07-02')?.isSelected).toBe(true) + expect(days.find(item => item.date === '2026-06-30')?.isCurrentMonth).toBe(false) + }) + + it('builds hour and minute options', () => { + expect(buildHourOptions()[0]).toBe('00') + expect(buildHourOptions()[23]).toBe('23') + expect(buildMinuteOptions()[0]).toBe('00') + expect(buildMinuteOptions()[59]).toBe('59') + }) + + it('normalizes and joins time values', () => { + expect(normalizeTimeParts('7:5')).toEqual({ hour: '07', minute: '05' }) + expect(normalizeTimeParts('30:90')).toEqual({ hour: '23', minute: '59' }) + expect(joinTimeParts('9', '8')).toBe('09:08') + }) + + it('keeps committed value unchanged until confirm', () => { + const draft = createPickerDraft('2026-07-02', '2026-07-01') + const changedDraft = updatePickerDraft(draft, '2026-07-08') + + expect(cancelPickerDraft(changedDraft)).toBe('2026-07-02') + expect(confirmPickerDraft(changedDraft)).toBe('2026-07-08') + }) +}) diff --git a/JY-Salon-Front/src/utils/picker-options.ts b/JY-Salon-Front/src/utils/picker-options.ts new file mode 100644 index 00000000..2214285e --- /dev/null +++ b/JY-Salon-Front/src/utils/picker-options.ts @@ -0,0 +1,78 @@ +import { addDays, formatDate, startOfMonth, toDate } from '@/utils/date' + +export interface DatePickerDay { + date: string + day: number + isCurrentMonth: boolean + isSelected: boolean +} + +export interface PickerDraft { + committedValue: string + draftValue: string +} + +const pad = (value: number): string => String(value).padStart(2, '0') + +export const buildDatePickerMonth = (monthValue: string, selectedDate: string): DatePickerDay[] => { + const first = startOfMonth(monthValue) + const gridStart = addDays(first, -first.getDay()) + return Array.from({ length: 42 }, (_item, index) => { + const current = addDays(gridStart, index) + const date = formatDate(current) + return { + date, + day: current.getDate(), + isCurrentMonth: current.getMonth() === first.getMonth(), + isSelected: date === selectedDate + } + }) +} + +export const buildHourOptions = (): string[] => { + return Array.from({ length: 24 }, (_item, index) => pad(index)) +} + +export const buildMinuteOptions = (): string[] => { + return Array.from({ length: 60 }, (_item, index) => pad(index)) +} + +export const normalizeTimeParts = (value: string): { hour: string; minute: string } => { + const [rawHour, rawMinute] = String(value || '00:00').split(':') + const hourNumber = Number(rawHour) + const minuteNumber = Number(rawMinute) + const hour = Number.isFinite(hourNumber) ? Math.min(Math.max(hourNumber, 0), 23) : 0 + const minute = Number.isFinite(minuteNumber) ? Math.min(Math.max(minuteNumber, 0), 59) : 0 + return { + hour: pad(hour), + minute: pad(minute) + } +} + +export const joinTimeParts = (hour: string, minute: string): string => { + const normalized = normalizeTimeParts(`${hour}:${minute}`) + return `${normalized.hour}:${normalized.minute}` +} + +export const createPickerDraft = (modelValue: string, fallbackValue: string): PickerDraft => { + const committedValue = modelValue || fallbackValue + return { + committedValue, + draftValue: committedValue + } +} + +export const updatePickerDraft = (draft: PickerDraft, draftValue: string): PickerDraft => { + return { + committedValue: draft.committedValue, + draftValue + } +} + +export const confirmPickerDraft = (draft: PickerDraft): string => draft.draftValue + +export const cancelPickerDraft = (draft: PickerDraft): string => draft.committedValue + +export const resolveMonthCursor = (value: string): Date => { + return toDate(value || formatDate(new Date())) +} diff --git a/JY-Salon-Front/src/views/AppointmentFormView.vue b/JY-Salon-Front/src/views/AppointmentFormView.vue index c9e8b4ab..66d09862 100644 --- a/JY-Salon-Front/src/views/AppointmentFormView.vue +++ b/JY-Salon-Front/src/views/AppointmentFormView.vue @@ -52,7 +52,7 @@ -
+
@@ -78,45 +78,102 @@
- +
+ + +
- +
- -
- - - - - - -
- -
图
- - -
- +
+ + + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+ +
图
+ +
- +
+
+ +
+ +
+
+
+ +
+ +
+
+
@@ -168,14 +225,15 @@ import { computed, onMounted, reactive, ref, watch } from 'vue' import { useRoute, useRouter } from 'vue-router' import BaseModal from '@/components/BaseModal.vue' +import DatePickerField from '@/components/DatePickerField.vue' import EmptyState from '@/components/EmptyState.vue' import LoadingState from '@/components/LoadingState.vue' import MobileShell from '@/components/MobileShell.vue' -import PageSection from '@/components/PageSection.vue' import { managerCustomersApi } from '@/api/managerCustomers' import { managerEmployeesApi } from '@/api/managerEmployees' import { managerPlanningApi } from '@/api/managerPlanning' -import { managerProductsApi } from '@/api/managerProducts' +import { managerProductsApi, type ProductCreateRequest } from '@/api/managerProducts' +import { managerTagsApi, type ManagerTag } from '@/api/managerTags' import { fileApi } from '@/api/file' import type { AppointmentForm, Artist, Product } from '@/types/manager' import type { UserInfo } from '@/types/common' @@ -214,10 +272,66 @@ interface CustomerCreateForm { phone: string } +interface ProductCreateForm { + title: string + price: string + durationMinutes: string + description: string + targetAudience: string + precautions: string + imageFileIds: string + imageUrl: string + tagIds: string[] + bookableArtistIds: string[] +} + const APPOINTMENT_MODAL_STATE_DRAFT_NAME = 'appointment-modal-state' const CUSTOMER_CREATE_DRAFT_NAME = 'appointment-customer-create' +const PRODUCT_CREATE_DRAFT_NAME = 'appointment-product-create' const CUSTOMER_PHONE_PATTERN = /^1[3-9]\d{9}$/ +const normalizeStringArray = (value: string[] | undefined): string[] => { + if (!Array.isArray(value)) { + return [] + } + return value.map(item => String(item || '').trim()).filter(Boolean) +} + +const isSameStringArray = (left: string[], right: string[]): boolean => { + return left.length === right.length && left.every((item, index) => item === right[index]) +} + +const buildEmptyProductCreateForm = (): ProductCreateForm => ({ + title: '', + price: '', + durationMinutes: '', + description: '', + targetAudience: '', + precautions: '', + imageFileIds: '', + imageUrl: '', + tagIds: [], + bookableArtistIds: [] +}) + +const normalizeProductCreateForm = (value: ProductCreateForm | undefined): ProductCreateForm => { + if (!value) { + return buildEmptyProductCreateForm() + } + return { + title: value.title || '', + price: value.price || '', + durationMinutes: value.durationMinutes || '', + description: value.description || '', + targetAudience: value.targetAudience || '', + precautions: value.precautions || '', + imageFileIds: value.imageFileIds || '', + imageUrl: value.imageUrl || '', + tagIds: normalizeStringArray(value.tagIds), + bookableArtistIds: normalizeStringArray(value.bookableArtistIds) + } +} + const route = useRoute() const router = useRouter() const session = useSessionStore() @@ -225,6 +339,7 @@ const toast = useToastStore() const baseForm = readDraftForm(session.userInfo) const modalStateDraft = readFormModalDraft(session.userInfo, APPOINTMENT_MODAL_STATE_DRAFT_NAME) const createCustomerDraft = readFormModalDraft(session.userInfo, CUSTOMER_CREATE_DRAFT_NAME) +const createProductDraft = readFormModalDraft(session.userInfo, PRODUCT_CREATE_DRAFT_NAME) const form = reactive({ customerUserId: String(route.query.customerUserId || baseForm?.customerUserId || ''), customerName: String(route.query.customerName || baseForm?.customerName || ''), @@ -257,11 +372,15 @@ const createCustomerForm = reactive({ nickname: createCustomerDraft?.form.nickname || '', phone: createCustomerDraft?.form.phone || '' }) +const productCreateForm = reactive(normalizeProductCreateForm(createProductDraft?.form)) +const productCreateBaseline = ref(buildEmptyProductCreateForm()) const products = ref([]) const filteredProducts = ref([]) const productKeyword = ref('') const productModalVisible = ref(Boolean(modalStateDraft?.open && modalStateDraft.form.productModalVisible)) +const productCreateModalVisible = ref(Boolean(createProductDraft?.open)) const artists = ref([]) +const tagOptions = ref([]) const selectedProduct = ref(null) const timeSheetVisible = ref(Boolean(modalStateDraft?.open && modalStateDraft.form.timeSheetVisible)) const availableTimeGroups = ref([]) @@ -270,7 +389,8 @@ const timeSelectTip = ref('请先选择美甲师并填写时长') const conflictTip = ref('') const conflictLevel = ref<'free' | 'danger'>('free') const loading = ref(false) -const manualImageUploading = ref(false) +const creatingProduct = ref(false) +const productImageUploading = ref(false) const selectedCustomerReady = computed(() => { return Boolean(form.customerUserId) }) @@ -295,17 +415,18 @@ const selectedCustomerDisplay = computed(() => { const createCustomerChanged = computed(() => { return Boolean(createCustomerForm.nickname || createCustomerForm.phone) }) -const manualProductChanged = computed(() => { - return Boolean( - form.manualProductTitle - || form.manualProductPrice - || form.manualProductTags - || form.manualProductDescription - || form.manualProductTargetAudience - || form.manualProductPrecautions - || form.manualProductImageFileIds - || form.manualProductImageUrl - ) +const productCreateChanged = computed(() => { + const baseline = productCreateBaseline.value + return productCreateForm.title !== baseline.title + || productCreateForm.price !== baseline.price + || productCreateForm.durationMinutes !== baseline.durationMinutes + || productCreateForm.description !== baseline.description + || productCreateForm.targetAudience !== baseline.targetAudience + || productCreateForm.precautions !== baseline.precautions + || productCreateForm.imageFileIds !== baseline.imageFileIds + || productCreateForm.imageUrl !== baseline.imageUrl + || !isSameStringArray(productCreateForm.tagIds, baseline.tagIds) + || !isSameStringArray(productCreateForm.bookableArtistIds, baseline.bookableArtistIds) }) const appointmentFormChanged = computed(() => { return Boolean( @@ -392,6 +513,56 @@ const updateCreateCustomerModalVisible = (value: boolean): void => { } } +const snapshotProductCreateForm = (): ProductCreateForm => ({ + title: productCreateForm.title, + price: productCreateForm.price, + durationMinutes: productCreateForm.durationMinutes, + description: productCreateForm.description, + targetAudience: productCreateForm.targetAudience, + precautions: productCreateForm.precautions, + imageFileIds: productCreateForm.imageFileIds, + imageUrl: productCreateForm.imageUrl, + tagIds: [...productCreateForm.tagIds], + bookableArtistIds: [...productCreateForm.bookableArtistIds] +}) + +const applyProductCreateForm = (value: ProductCreateForm): void => { + productCreateForm.title = value.title + productCreateForm.price = value.price + productCreateForm.durationMinutes = value.durationMinutes + productCreateForm.description = value.description + productCreateForm.targetAudience = value.targetAudience + productCreateForm.precautions = value.precautions + productCreateForm.imageFileIds = value.imageFileIds + productCreateForm.imageUrl = value.imageUrl + productCreateForm.tagIds = [...value.tagIds] + productCreateForm.bookableArtistIds = [...value.bookableArtistIds] +} + +const resetProductCreateForm = (): void => { + applyProductCreateForm(buildEmptyProductCreateForm()) + productCreateBaseline.value = buildEmptyProductCreateForm() +} + +const syncProductCreateDraft = (): void => { + if (!productCreateModalVisible.value) { + removeFormModalDraft(session.userInfo, PRODUCT_CREATE_DRAFT_NAME) + return + } + if (!productCreateChanged.value) { + return + } + writeFormModalDraft(session.userInfo, PRODUCT_CREATE_DRAFT_NAME, snapshotProductCreateForm(), true) +} + +const updateProductCreateModalVisible = (value: boolean): void => { + productCreateModalVisible.value = value + if (!value) { + removeFormModalDraft(session.userInfo, PRODUCT_CREATE_DRAFT_NAME) + resetProductCreateForm() + } +} + const selectedProductTitle = computed(() => { if (selectedProduct.value) { return selectedProduct.value.title @@ -456,11 +627,13 @@ const filterProducts = (): void => { } const loadOptions = async (): Promise => { - const [productData, employeeData] = await Promise.all([ + const [productData, employeeData, tagData] = await Promise.all([ managerProductsApi.list({ page: 1, size: 100 }), - managerEmployeesApi.list() + managerEmployeesApi.list(), + managerTagsApi.listAll() ]) artists.value = employeeData + tagOptions.value = tagData form.artistId = normalizeArtistSelectionId(form.artistId, artists.value) const productList = Array.isArray(productData) ? productData : productData.list products.value = productList.map(product => normalizeProduct(product, artists.value)) @@ -578,38 +751,86 @@ const selectProduct = (product: ProductCard): void => { void refreshAvailableTimes() } -const useManualProduct = (): void => { - const title = form.manualProductTitle.trim() - const price = Number(form.manualProductPrice) - if (!title || Number.isNaN(price) || price < 0) { - toast.error('请填写手动预约作品名称和价格') - return - } - form.productId = '' - selectedProduct.value = null +const openCreateProductModal = (): void => { updateProductModalVisible(false) + if (!productCreateChanged.value && form.artistId) { + productCreateForm.bookableArtistIds = [form.artistId] + } + productCreateBaseline.value = snapshotProductCreateForm() + productCreateModalVisible.value = true + syncProductCreateDraft() } -const uploadManualProductImage = async (event: Event): Promise => { +const uploadProductCreateImage = async (event: Event): Promise => { const input = event.target as HTMLInputElement const file = input.files?.[0] if (!file) { return } - manualImageUploading.value = true + productImageUploading.value = true try { const uploaded = await fileApi.uploadObjectFile(file) - form.manualProductImageFileIds = String(uploaded.id) - form.manualProductImageUrl = uploaded.primaryUrl || uploaded.fileUrl || '' + productCreateForm.imageFileIds = String(uploaded.id) + productCreateForm.imageUrl = uploaded.primaryUrl || uploaded.fileUrl || '' } finally { input.value = '' - manualImageUploading.value = false + productImageUploading.value = false } } -const removeManualProductImage = (): void => { - form.manualProductImageFileIds = '' - form.manualProductImageUrl = '' +const removeProductCreateImage = (): void => { + productCreateForm.imageFileIds = '' + productCreateForm.imageUrl = '' +} + +const buildProductCreatePayload = (): ProductCreateRequest | null => { + const title = productCreateForm.title.trim() + const price = Number(productCreateForm.price) + const durationMinutes = normalizeDuration(productCreateForm.durationMinutes) + if (!title || Number.isNaN(price) || price < 0 || !durationMinutes) { + toast.error('请填写作品名称、价格和时长') + return null + } + return { + title, + price, + description: productCreateForm.description.trim() || undefined, + targetAudience: productCreateForm.targetAudience.trim() || undefined, + precautions: productCreateForm.precautions.trim() || undefined, + imageFileIds: productCreateForm.imageFileIds || undefined, + tags: productCreateForm.tagIds.join(';') || undefined, + approximateDuration: `${durationMinutes}分钟`, + bookableArtists: productCreateForm.bookableArtistIds.join(',') || undefined, + frontVisible: 1 + } +} + +const createProduct = async (): Promise => { + if (productImageUploading.value) { + toast.error('图片上传完成后再保存作品') + return + } + const payload = buildProductCreatePayload() + if (!payload) { + return + } + creatingProduct.value = true + try { + const productId = await managerProductsApi.create(payload) + await loadOptions() + const createdProduct = products.value.find(product => String(product.id) === String(productId)) + if (!createdProduct) { + throw new Error(`作品已创建但未在列表中返回,作品ID:${productId}`) + } + updateProductCreateModalVisible(false) + selectProduct(createdProduct) + toast.success('作品已新增') + } catch (error) { + const message = error instanceof Error ? error.message : '新增作品失败' + toast.error(message) + } finally { + creatingProduct.value = false + } } const refreshAvailableTimes = async (): Promise => { @@ -744,6 +965,8 @@ watch(productModalVisible, syncAppointmentModalState) watch(timeSheetVisible, syncAppointmentModalState) watch(createCustomerForm, syncCreateCustomerDraft, { deep: true }) watch(createCustomerModalVisible, syncCreateCustomerDraft) +watch(productCreateForm, syncProductCreateDraft, { deep: true }) +watch(productCreateModalVisible, syncProductCreateDraft)