修复新建预约客户选择和排班可约时间
This commit is contained in:
@@ -6,13 +6,37 @@
|
||||
</div>
|
||||
|
||||
<section class="card form-card">
|
||||
<div class="field"><label class="required">客户姓名</label><input v-model.trim="form.customerName" placeholder="请输入客户姓名" @input="scheduleCustomerSearch" /></div>
|
||||
<div class="field"><label class="required">手机号</label><input v-model.trim="form.phone" inputmode="numeric" placeholder="请输入手机号" @input="scheduleCustomerSearch" /></div>
|
||||
<div v-if="customerOptions.length > 0" class="customer-options">
|
||||
<button v-for="customer in customerOptions" :key="String(customer.id)" type="button" @click="selectCustomer(customer)">
|
||||
<strong>{{ customer.nickname || customer.account }}</strong>
|
||||
<span>{{ customer.phone || customer.contactPhone }}</span>
|
||||
</button>
|
||||
<div class="field field--stack customer-combobox">
|
||||
<label class="required">客户</label>
|
||||
<div class="customer-control">
|
||||
<input
|
||||
v-model.trim="customerSearchText"
|
||||
placeholder="搜索客户姓名或手机号"
|
||||
@focus="openCustomerDropdown"
|
||||
@input="onCustomerSearchInput"
|
||||
@keydown.escape="customerDropdownOpen = false"
|
||||
/>
|
||||
<button v-if="customerSearchText" class="customer-clear" type="button" @click="clearCustomerSelection">×</button>
|
||||
</div>
|
||||
<div v-if="customerDropdownOpen" class="customer-dropdown">
|
||||
<div v-if="customerSearching" class="customer-muted">正在搜索客户...</div>
|
||||
<template v-else>
|
||||
<button v-for="customer in customerOptions" :key="String(customer.id)" class="customer-option" type="button" @click="selectCustomer(customer)">
|
||||
<span>
|
||||
<strong>{{ customer.nickname || customer.account || customer.phone || customer.contactPhone }}</strong>
|
||||
<small>{{ customer.phone || customer.contactPhone || '未填写手机号' }}</small>
|
||||
</span>
|
||||
<em>选择</em>
|
||||
</button>
|
||||
<div v-if="customerOptions.length === 0" class="customer-muted">暂无匹配客户,可继续创建新客户</div>
|
||||
</template>
|
||||
<div class="customer-new">
|
||||
<strong>新客户</strong>
|
||||
<input v-model.trim="newCustomerName" placeholder="客户姓名" />
|
||||
<input v-model.trim="newCustomerPhone" inputmode="numeric" placeholder="手机号" />
|
||||
<button class="secondary-btn" type="button" @click="useNewCustomer">使用新客户</button>
|
||||
</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><button class="field-value picker-value" type="button" @click="productModalVisible = true">{{ selectedProductTitle }}</button></div>
|
||||
@@ -38,7 +62,7 @@
|
||||
@update:model-value="updateProductModalVisible"
|
||||
>
|
||||
<div class="product-modal">
|
||||
<input v-model.trim="productKeyword" class="search-input" placeholder="搜索作品" @input="filterProducts" />
|
||||
<input v-model.trim="productKeyword" class="search-input" placeholder="搜索作品、标签、美甲师" @input="filterProducts" />
|
||||
<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="" />
|
||||
@@ -46,8 +70,12 @@
|
||||
<strong>{{ product.title }}</strong>
|
||||
<span>{{ product.priceText }} · {{ product.durationText || '时长待定' }}</span>
|
||||
<small>{{ product.artistText }}</small>
|
||||
<div v-if="product.tagList.length > 0" class="tag-row">
|
||||
<i v-for="tag in product.tagList" :key="tag">{{ tag }}</i>
|
||||
</div>
|
||||
</div>
|
||||
</button>
|
||||
<EmptyState v-if="filteredProducts.length === 0" title="暂无匹配作品" description="可以调整关键词或手动新增预约作品" />
|
||||
</div>
|
||||
<PageSection title="手动新增预约作品">
|
||||
<div class="manual-form">
|
||||
@@ -55,6 +83,17 @@
|
||||
<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>
|
||||
</PageSection>
|
||||
@@ -95,6 +134,7 @@ import { managerCustomersApi } from '@/api/managerCustomers'
|
||||
import { managerEmployeesApi } from '@/api/managerEmployees'
|
||||
import { managerPlanningApi } from '@/api/managerPlanning'
|
||||
import { managerProductsApi } from '@/api/managerProducts'
|
||||
import { fileApi } from '@/api/file'
|
||||
import type { AppointmentForm, Artist, Product } from '@/types/manager'
|
||||
import type { UserInfo } from '@/types/common'
|
||||
import { useSessionStore } from '@/stores/session'
|
||||
@@ -111,6 +151,7 @@ interface ProductCard extends Product {
|
||||
priceText: string
|
||||
durationText: string
|
||||
artistText: string
|
||||
tagList: string[]
|
||||
}
|
||||
|
||||
interface AppointmentModalState {
|
||||
@@ -148,6 +189,11 @@ const form = reactive<AppointmentForm>({
|
||||
const draftSavedAtText = ref(baseForm ? '已恢复本机草稿' : '')
|
||||
const customerOptions = ref<UserInfo[]>([])
|
||||
const customerTimer = ref<number | null>(null)
|
||||
const customerSearchText = ref([form.customerName, form.phone].filter(Boolean).join(' '))
|
||||
const customerDropdownOpen = ref(false)
|
||||
const customerSearching = ref(false)
|
||||
const newCustomerName = ref(form.customerName)
|
||||
const newCustomerPhone = ref(form.phone)
|
||||
const products = ref<ProductCard[]>([])
|
||||
const filteredProducts = ref<ProductCard[]>([])
|
||||
const productKeyword = ref('')
|
||||
@@ -161,12 +207,17 @@ const timeSelectTip = ref('请先选择美甲师并填写时长')
|
||||
const conflictTip = ref('')
|
||||
const conflictLevel = ref<'free' | 'danger'>('free')
|
||||
const loading = ref(false)
|
||||
const manualImageUploading = ref(false)
|
||||
const manualProductChanged = computed(() => {
|
||||
return Boolean(
|
||||
form.manualProductTitle
|
||||
|| form.manualProductPrice
|
||||
|| form.manualProductTags
|
||||
|| form.manualProductDescription
|
||||
|| form.manualProductTargetAudience
|
||||
|| form.manualProductPrecautions
|
||||
|| form.manualProductImageFileIds
|
||||
|| form.manualProductImageUrl
|
||||
)
|
||||
})
|
||||
const appointmentFormChanged = computed(() => {
|
||||
@@ -231,15 +282,45 @@ const selectedProductTitle = computed(() => {
|
||||
return '请选择作品'
|
||||
})
|
||||
|
||||
const normalizeProduct = (product: Product): ProductCard => {
|
||||
const parseProductTags = (product: Product): string[] => {
|
||||
if (Array.isArray(product.tagList) && product.tagList.length > 0) {
|
||||
return product.tagList.map(tag => String(tag || '').trim()).filter(Boolean)
|
||||
}
|
||||
if (Array.isArray(product.tagInfos) && product.tagInfos.length > 0) {
|
||||
return product.tagInfos.map(tag => String(tag.tagName || '').trim()).filter(Boolean)
|
||||
}
|
||||
return String(product.tags || '')
|
||||
.split(/[;,,、]/)
|
||||
.map(tag => tag.trim())
|
||||
.filter(Boolean)
|
||||
}
|
||||
|
||||
const resolveProductArtistText = (product: Product, artistOptions: Artist[]): string => {
|
||||
const artistIds = String(product.bookableArtists || '')
|
||||
.split(',')
|
||||
.map(id => id.trim())
|
||||
.filter(Boolean)
|
||||
if (artistIds.length === 0) {
|
||||
return '全部美甲师'
|
||||
}
|
||||
const artistNames = artistIds
|
||||
.map(id => artistOptions.find(artist => String(artist.id) === id))
|
||||
.filter((artist): artist is Artist => Boolean(artist))
|
||||
.map(artist => artist.name || artist.nickname || '')
|
||||
.filter(Boolean)
|
||||
return artistNames.length > 0 ? artistNames.join('、') : '指定美甲师'
|
||||
}
|
||||
|
||||
const normalizeProduct = (product: Product, artistOptions: Artist[]): ProductCard => {
|
||||
const imageUrls = Array.isArray(product.imageUrls) ? product.imageUrls : []
|
||||
const durationText = product.approximateDuration || (product.serviceDurationMinutes ? `${product.serviceDurationMinutes}分钟` : '')
|
||||
return {
|
||||
...product,
|
||||
coverImage: imageUrls[0] || '',
|
||||
tagList: parseProductTags(product).slice(0, 4),
|
||||
priceText: product.price || product.price === 0 ? `¥${product.price}` : '价格待定',
|
||||
durationText,
|
||||
artistText: '全部美甲师'
|
||||
artistText: resolveProductArtistText(product, artistOptions)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,7 +330,8 @@ const filterProducts = (): void => {
|
||||
if (!keyword) {
|
||||
return true
|
||||
}
|
||||
return [product.title, product.priceText, product.durationText, product.artistText].some(value => String(value || '').toLowerCase().includes(keyword))
|
||||
return [product.title, product.priceText, product.durationText, product.artistText, ...product.tagList]
|
||||
.some(value => String(value || '').toLowerCase().includes(keyword))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -258,10 +340,10 @@ const loadOptions = async (): Promise<void> => {
|
||||
managerProductsApi.list({ page: 1, size: 100 }),
|
||||
managerEmployeesApi.list()
|
||||
])
|
||||
const productList = Array.isArray(productData) ? productData : productData.list
|
||||
products.value = productList.map(normalizeProduct)
|
||||
filteredProducts.value = products.value
|
||||
artists.value = employeeData
|
||||
const productList = Array.isArray(productData) ? productData : productData.list
|
||||
products.value = productList.map(product => normalizeProduct(product, artists.value))
|
||||
filteredProducts.value = products.value
|
||||
if (form.productId) {
|
||||
selectedProduct.value = products.value.find(item => String(item.id) === String(form.productId)) || null
|
||||
}
|
||||
@@ -277,16 +359,67 @@ const scheduleCustomerSearch = (): void => {
|
||||
}
|
||||
|
||||
const searchCustomers = async (): Promise<void> => {
|
||||
const keyword = form.customerName || form.phone
|
||||
const data = await managerCustomersApi.list({ page: 1, size: 20, keyword })
|
||||
customerOptions.value = data.list || []
|
||||
const keyword = customerSearchText.value.trim()
|
||||
customerSearching.value = true
|
||||
try {
|
||||
const data = await managerCustomersApi.list({ page: 1, size: 20, keyword })
|
||||
customerOptions.value = data.list || []
|
||||
} finally {
|
||||
customerSearching.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const openCustomerDropdown = (): void => {
|
||||
customerDropdownOpen.value = true
|
||||
if (customerOptions.value.length === 0) {
|
||||
scheduleCustomerSearch()
|
||||
}
|
||||
}
|
||||
|
||||
const onCustomerSearchInput = (): void => {
|
||||
form.customerUserId = ''
|
||||
form.customerName = ''
|
||||
form.phone = ''
|
||||
newCustomerName.value = customerSearchText.value
|
||||
customerDropdownOpen.value = true
|
||||
scheduleCustomerSearch()
|
||||
}
|
||||
|
||||
const clearCustomerSelection = (): void => {
|
||||
form.customerUserId = ''
|
||||
form.customerName = ''
|
||||
form.phone = ''
|
||||
customerSearchText.value = ''
|
||||
newCustomerName.value = ''
|
||||
newCustomerPhone.value = ''
|
||||
customerOptions.value = []
|
||||
customerDropdownOpen.value = true
|
||||
}
|
||||
|
||||
const selectCustomer = (customer: UserInfo): void => {
|
||||
form.customerUserId = String(customer.id)
|
||||
form.customerName = customer.nickname || customer.account || ''
|
||||
form.phone = customer.phone || customer.contactPhone || ''
|
||||
customerSearchText.value = [form.customerName, form.phone].filter(Boolean).join(' ')
|
||||
newCustomerName.value = form.customerName
|
||||
newCustomerPhone.value = form.phone
|
||||
customerOptions.value = []
|
||||
customerDropdownOpen.value = false
|
||||
}
|
||||
|
||||
const useNewCustomer = (): void => {
|
||||
const name = newCustomerName.value.trim()
|
||||
const phone = newCustomerPhone.value.trim()
|
||||
if (!name || !phone) {
|
||||
toast.error('请填写新客户姓名和手机号')
|
||||
return
|
||||
}
|
||||
form.customerUserId = ''
|
||||
form.customerName = name
|
||||
form.phone = phone
|
||||
customerSearchText.value = [name, phone].filter(Boolean).join(' ')
|
||||
customerOptions.value = []
|
||||
customerDropdownOpen.value = false
|
||||
}
|
||||
|
||||
const onDateChange = async (): Promise<void> => {
|
||||
@@ -299,6 +432,12 @@ const selectProduct = (product: ProductCard): void => {
|
||||
form.productId = String(product.id)
|
||||
form.manualProductTitle = ''
|
||||
form.manualProductPrice = ''
|
||||
form.manualProductDescription = ''
|
||||
form.manualProductTags = ''
|
||||
form.manualProductTargetAudience = ''
|
||||
form.manualProductPrecautions = ''
|
||||
form.manualProductImageFileIds = ''
|
||||
form.manualProductImageUrl = ''
|
||||
form.durationMinutes = String(Number.parseInt(product.approximateDuration || '', 10) || product.serviceDurationMinutes || form.durationMinutes)
|
||||
updateProductModalVisible(false)
|
||||
void refreshAvailableTimes()
|
||||
@@ -316,6 +455,28 @@ const useManualProduct = (): void => {
|
||||
updateProductModalVisible(false)
|
||||
}
|
||||
|
||||
const uploadManualProductImage = async (event: Event): Promise<void> => {
|
||||
const input = event.target as HTMLInputElement
|
||||
const file = input.files?.[0]
|
||||
if (!file) {
|
||||
return
|
||||
}
|
||||
manualImageUploading.value = true
|
||||
try {
|
||||
const uploaded = await fileApi.uploadObjectFile(file)
|
||||
form.manualProductImageFileIds = String(uploaded.id)
|
||||
form.manualProductImageUrl = uploaded.primaryUrl || uploaded.fileUrl || ''
|
||||
} finally {
|
||||
input.value = ''
|
||||
manualImageUploading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const removeManualProductImage = (): void => {
|
||||
form.manualProductImageFileIds = ''
|
||||
form.manualProductImageUrl = ''
|
||||
}
|
||||
|
||||
const refreshAvailableTimes = async (): Promise<void> => {
|
||||
const durationMinutes = normalizeDuration(form.durationMinutes)
|
||||
if (!form.appointmentDate || !form.artistId || !durationMinutes) {
|
||||
@@ -447,18 +608,83 @@ watch(timeSheetVisible, syncAppointmentModalState)
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.customer-options {
|
||||
display: grid;
|
||||
gap: 6px;
|
||||
padding: 8px 0;
|
||||
.customer-combobox {
|
||||
position: relative;
|
||||
overflow: visible;
|
||||
}
|
||||
|
||||
.customer-options button {
|
||||
.customer-control {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.customer-control input {
|
||||
padding-right: 42px;
|
||||
}
|
||||
|
||||
.customer-clear {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
right: 8px;
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
transform: translateY(-50%);
|
||||
border-radius: 50%;
|
||||
background: var(--subtle);
|
||||
color: var(--muted);
|
||||
font-size: 18px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.customer-dropdown {
|
||||
position: absolute;
|
||||
z-index: 20;
|
||||
top: calc(100% + 8px);
|
||||
right: 0;
|
||||
left: 0;
|
||||
display: grid;
|
||||
max-height: min(420px, 70vh);
|
||||
gap: 8px;
|
||||
overflow-y: auto;
|
||||
padding: 10px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 12px;
|
||||
background: var(--surface);
|
||||
box-shadow: 0 16px 36px rgba(19, 32, 24, 0.16);
|
||||
-webkit-overflow-scrolling: touch;
|
||||
}
|
||||
|
||||
.customer-option {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 8px 10px;
|
||||
gap: 10px;
|
||||
width: 100%;
|
||||
padding: 9px 10px;
|
||||
border-radius: 10px;
|
||||
background: var(--subtle);
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.customer-option span,
|
||||
.customer-option strong,
|
||||
.customer-option small {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.customer-option small,
|
||||
.customer-option em,
|
||||
.customer-muted {
|
||||
color: var(--muted);
|
||||
font-size: 12px;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
.customer-new {
|
||||
display: grid;
|
||||
gap: 8px;
|
||||
padding-top: 8px;
|
||||
border-top: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.picker-value {
|
||||
@@ -519,11 +745,66 @@ watch(timeSheetVisible, syncAppointmentModalState)
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.tag-row {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 5px;
|
||||
margin-top: 6px;
|
||||
}
|
||||
|
||||
.tag-row i {
|
||||
padding: 2px 6px;
|
||||
border-radius: 999px;
|
||||
background: var(--accent-soft);
|
||||
color: var(--accent);
|
||||
font-size: 11px;
|
||||
font-style: normal;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.manual-form {
|
||||
display: grid;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.manual-image-row {
|
||||
display: grid;
|
||||
grid-template-columns: 72px 1fr auto;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.manual-image-row img,
|
||||
.manual-image-placeholder {
|
||||
width: 72px;
|
||||
height: 72px;
|
||||
border-radius: 12px;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.manual-image-placeholder {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
background: var(--subtle);
|
||||
color: var(--muted);
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.image-upload {
|
||||
position: relative;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 40px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.image-upload input {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.textarea {
|
||||
min-height: 88px;
|
||||
padding: 12px;
|
||||
|
||||
Reference in New Issue
Block a user