@@ -52,7 +52,7 @@
< / div >
< / div >
< / div >
< div class = "field" > < label class = "required" > 预约日期 < / label > < input v-model = "form.appointmentDate" type="date" @change ="onDateChange" / > < / div >
< div class = "field" > < label class = "required" > 预约日期 < / label > < DatePickerField v-model = "form.appointmentDate" placeholder="请选择日期" title="日期选择" @confirm ="onDateChange" / > < / div >
< div class = "field" > < label class = "required" > 预约作品 < / label > < button class = "field-value picker-value" type = "button" @click ="productModalVisible = true" > {{ selectedProductTitle }} < / button > < / div >
< div class = "field" >
< label class = "required" > 预计时长 < / label >
@@ -78,45 +78,102 @@
< BaseModal
:model-value = "productModalVisible"
title = "选择预约作品"
:has-unsaved-changes = "manualProductChanged"
@ update :model-value = "updateProductModalVisible"
>
< div class = "product-modal" >
< input v -model .trim = " productKeyword " class = "search-input" placeholder = "搜索作品、标签、美甲师" @input ="filterProducts" / >
< div class = "product-modal__actions" >
< input v -model .trim = " productKeyword " class = "search-input" placeholder = "搜索作品、标签、美甲师" @input ="filterProducts" / >
< button class = "secondary-btn product-add-btn" type = "button" @click ="openCreateProductModal" > 新增 < / button >
< / div >
< div class = "list" >
< button v-for = "product in filteredProducts" :key="String(product.id)" class="product-card" type="button" @click="selectProduct(product)" >
< img v-if = "product.coverImage" :src="product.coverImage" alt="" / >
< div >
< div class = "product-card__cover" >
< img v-if = "product.coverImage" :src="product.coverImage" alt="" / >
< span v-else > 作品 < / span >
< / div >
< div class = "product-card__body" >
< strong > { { product . title } } < / strong >
< span > { { product . priceText } } · { { product . durationText || '时长待定' } } < / span >
< small > { { product . artistText } } < / small >
< p v-if = "product.description" > {{ product.description } }< / p >
< div v-if = "product.tagList.length > 0" class="tag-row" >
< i v-for = "tag in product.tagList" :key="tag" > {{ tag }} < / i >
< / div >
< div class = "product-card__meta" >
< span > { { product . priceText } } < / span >
< span > { { product . durationText || '时长待定' } } < / span >
< / div >
< small > { { product . artistText } } < / small >
< / div >
< / button >
< EmptyState v-if = "filteredProducts.length === 0" title="暂无匹配作品" description="可以调整关键词或手动新增预约 作品" / >
< EmptyState v-if = "filteredProducts.length === 0" title="暂无匹配作品" description="可以调整关键词或新增 作品" / >
< / div >
< PageSection title = "手动新增预约作品" >
< div class = "manual-form" >
< input v -model .trim = " form.manualProductTitle " class = "search-input" placeholder = "作品名称" / >
< input v -model .trim = " form.manualProductPrice " class = "search-input" inputmode = "decimal" placeholder = "价格" / >
< input v -model .trim = " form.manualProductTags " class = "search-input" placeholder = "标签,逗号分隔" / >
< textarea v -model .trim = " form.manualProductDescription " class = "search-input textarea" placeholder = "作品说明" > < / textarea >
< input v -model .trim = " form.manualProductTargetAudience " class = "search-input" placeholder = "适合人群(选填)" / >
< input v -model .trim = " form.manualProductPrecautions " class = "search-input" placeholder = "注意事项(选填)" / >
< div class = "manual-image-row" >
< img v-if = "form.manualProductImageUrl" :src="form.manualProductImageUrl" alt="" / >
< div v-else class = "manual-image-placeholder" > 图 < / div >
< label class = "secondary-btn image-upload " >
{ { manualImageUploading ? '上传中...' : '上传图片' } }
< input type = "file" accept = "image/*" :disabled = "manualImageUploading" @change ="uploadManualProductImage" / >
< / label >
< button v-if = "form.manualProductImageUrl" class="text-btn" type="button" @click="removeManualProductImage" > 移除 < / button >
< / div >
< button class = "secondary-btn " type = "button" @click ="useManualProduct" > 使用手动作品 < / button >
< / div >
< / BaseModal >
< BaseModal
:model-value = "productCreateModalVisible"
title = "新增作品"
:close-disabled = "creatingProduct"
:has-unsaved-changes = "productCreateChanged"
@ update :model-value = "updateProductCreateModalVisible"
>
< div class = "product-create-form" >
< div class = "field field--stack " >
< label class = "required" > 作品名称 < / label >
< input v -model .trim = " productCreateForm.title " class = "search-input" placeholder = "请输入作品名称" / >
< / div >
< div class = "field field--stack" >
< label class = "required" > 价格 < / label >
< input v -model .trim = " productCreateForm.price " class = "search-input " inputmode = "decimal" placeholder = "请输入价格" / >
< / div >
< div class = "field field--stack" >
< label class = "required" > 时长 < / label >
< input v -model .trim = " productCreateForm.durationMinutes " class = "search-input" inputmode = "numeric" placeholder = "请输入分钟数" / >
< / div >
< div class = "field field--stack" >
< label > 作品说明 < / label >
< textarea v -model .trim = " productCreateForm.description " class = "search-input textarea" placeholder = "请输入作品说明" > < / textarea >
< / div >
< div class = "field field--stack" >
< label > 适合人群 < / label >
< textarea v -model .trim = " productCreateForm.targetAudience " class = "search-input textarea" placeholder = "请输入适合人群" > < / textarea >
< / div >
< div class = "field field--stack" >
< label > 注意事项 < / label >
< textarea v -model .trim = " productCreateForm.precautions " class = "search-input textarea" placeholder = "请输入注意事项" > < / textarea >
< / div >
< div class = "field field--stack" >
< label > 作品首图 < / label >
< div class = "manual-image-row" >
< img v-if = "productCreateForm.imageUrl" :src="productCreateForm.imageUrl" alt="" / >
< div v-else class = "manual-image-placeholder" > 图 < / div >
< label class = "secondary-btn image-upload" >
{ { productImageUploading ? '上传中...' : '上传图片' } }
< input type = "file" accept = "image/*" :disabled = "productImageUploading" @change ="uploadProductCreateImage" / >
< / label >
< button v-if = "productCreateForm.imageUrl" class="text-btn" type="button" @click="removeProductCreateImage" > 移除 < / button >
< / div >
< / PageSection >
< / div >
< div class = "field field--stack" >
< label > 标签 < / label >
< div class = "choice-grid" >
< label v-for = "tag in tagOptions" :key="String(tag.id)" class="choice-chip" >
< input v-model = "productCreateForm.tagIds" type="checkbox" :value="String(tag.id)" / >
< span > { { tag . displayName || tag . tagName } } < / span >
< / label >
< / div >
< / div >
< div class = "field field--stack" >
< label > 可预约员工 < / label >
< div class = "choice-grid" >
< label v-for = "artist in artists" :key="String(resolveArtistUserId(artist))" class="choice-chip" >
< input v-model = "productCreateForm.bookableArtistIds" type="checkbox" :value="String(resolveArtistUserId(artist))" / >
< span > { { artist . name || artist . nickname } } < / span >
< / label >
< / div >
< / div >
< button class = "primary-btn" type = "button" : disabled = "creatingProduct || productImageUploading" @click ="createProduct" >
{{ creatingProduct ? ' 保存中... ' : ' 保存并选择 ' }}
< / button >
< / div >
< / BaseModal >
@@ -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 < AppointmentModalState > ( session . userInfo , APPOINTMENT _MODAL _STATE _DRAFT _NAME )
const createCustomerDraft = readFormModalDraft < CustomerCreateForm > ( session . userInfo , CUSTOMER _CREATE _DRAFT _NAME )
const createProductDraft = readFormModalDraft < ProductCreateForm > ( session . userInfo , PRODUCT _CREATE _DRAFT _NAME )
const form = reactive < AppointmentForm > ( {
customerUserId : String ( route . query . customerUserId || baseForm ? . customerUserId || '' ) ,
customerName : String ( route . query . customerName || baseForm ? . customerName || '' ) ,
@@ -257,11 +372,15 @@ const createCustomerForm = reactive<CustomerCreateForm>({
nickname : createCustomerDraft ? . form . nickname || '' ,
phone : createCustomerDraft ? . form . phone || ''
} )
const productCreateForm = reactive < ProductCreateForm > ( normalizeProductCreateForm ( createProductDraft ? . form ) )
const productCreateBaseline = ref < ProductCreateForm > ( buildEmptyProductCreateForm ( ) )
const products = ref < ProductCard [ ] > ( [ ] )
const filteredProducts = ref < ProductCard [ ] > ( [ ] )
const productKeyword = ref ( '' )
const productModalVisible = ref ( Boolean ( modalStateDraft ? . open && modalStateDraft . form . productModalVisible ) )
const productCreateModalVisible = ref ( Boolean ( createProductDraft ? . open ) )
const artists = ref < Artist [ ] > ( [ ] )
const tagOptions = ref < ManagerTag [ ] > ( [ ] )
const selectedProduct = ref < ProductCard | null > ( null )
const timeSheetVisible = ref ( Boolean ( modalStateDraft ? . open && modalStateDraft . form . timeSheetVisible ) )
const availableTimeGroups = ref < AvailableTimeGroup [ ] > ( [ ] )
@@ -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<CustomerDisplay>(() => {
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 < void > => {
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 < void > => {
const uploadProductCreateImage = async ( event : Event ) : Promise < void > => {
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 < void > => {
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 < void > => {
@@ -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 )
< / script >
< style scoped >
@@ -999,43 +1222,89 @@ watch(createCustomerModalVisible, syncCreateCustomerDraft)
}
. product - modal ,
. product - create - form ,
. time - sheet {
display : grid ;
gap : 12 px ;
padding : 14 px ;
}
. product - modal _ _actions {
display : grid ;
grid - template - columns : 1 fr auto ;
align - items : center ;
gap : 8 px ;
}
. product - add - btn {
min - width : 72 px ;
}
. product - card {
display : grid ;
grid - template - columns : 72 px 1 fr ;
gap : 10 px ;
grid - template - columns : 76 px 1 fr ;
gap : 12 px ;
width : 100 % ;
padding : 10 px ;
border - radius : 14 px ;
background : var ( -- subtle ) ;
border : 1 px solid var ( -- border ) ;
border - radius : 12 px ;
background : var ( -- card - bg ) ;
text - align : left ;
}
. product - card img {
width : 72 px ;
height : 72 px ;
. product - card _ _cover {
display : grid ;
width : 76 px ;
height : 76 px ;
place - items : center ;
overflow : hidden ;
border - radius : 12 px ;
background : var ( -- subtle ) ;
color : var ( -- muted ) ;
font - size : 12 px ;
font - weight : 800 ;
}
. product - card _ _cover img {
width : 100 % ;
height : 100 % ;
object - fit : cover ;
}
. product - card strong ,
. product - card span ,
. product - card small {
. product - card _ _body {
min - width : 0 ;
}
. product - card _ _body strong ,
. product - card _ _body p ,
. product - card _ _body small {
display : block ;
}
. product - card span ,
. product - card small {
margin - top : 3 px ;
. product - card _ _body strong ,
. product - card _ _body p {
overflow : hidden ;
text - overflow : ellipsis ;
white - space : nowrap ;
}
. product - card _ _body p ,
. product - card _ _body small {
margin : 3 px 0 0 ;
color : var ( -- muted ) ;
font - size : 12 px ;
}
. product - card _ _meta {
display : flex ;
flex - wrap : wrap ;
gap : 8 px ;
margin - top : 8 px ;
color : var ( -- ink ) ;
font - size : 13 px ;
font - weight : 850 ;
}
. tag - row {
display : flex ;
flex - wrap : wrap ;
@@ -1053,11 +1322,6 @@ watch(createCustomerModalVisible, syncCreateCustomerDraft)
font - weight : 700 ;
}
. manual - form {
display : grid ;
gap : 8 px ;
}
. manual - image - row {
display : grid ;
grid - template - columns : 72 px 1 fr auto ;
@@ -1102,6 +1366,39 @@ watch(createCustomerModalVisible, syncCreateCustomerDraft)
resize : vertical ;
}
. choice - grid {
display : flex ;
flex - wrap : wrap ;
gap : 8 px ;
}
. choice - chip {
position : relative ;
display : inline - flex ;
}
. choice - chip input {
position : absolute ;
opacity : 0 ;
pointer - events : none ;
}
. choice - chip span {
padding : 7 px 10 px ;
border : 1 px solid var ( -- border ) ;
border - radius : 999 px ;
background : var ( -- card - bg ) ;
color : var ( -- ink ) ;
font - size : 12 px ;
font - weight : 760 ;
}
. choice - chip input : checked + span {
border - color : var ( -- accent ) ;
background : var ( -- accent - soft ) ;
color : var ( -- accent ) ;
}
. time - sheet h3 {
margin : 0 0 8 px ;
}