统一甲屿云命名体系
This commit is contained in:
@@ -0,0 +1,463 @@
|
||||
<template>
|
||||
<MobileShell title="新建预约">
|
||||
<div v-if="draftSavedAtText" class="card draft-tip">
|
||||
<span>{{ draftSavedAtText }}</span>
|
||||
<button class="text-btn" type="button" @click="clearDraft">清空</button>
|
||||
</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>
|
||||
<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>
|
||||
<div class="field"><label class="required">预计时长</label><input v-model.trim="form.durationMinutes" inputmode="numeric" placeholder="分钟" @input="refreshAvailableTimes" /></div>
|
||||
<div class="field"><label class="required">指定员工</label><select v-model="form.artistId" @change="refreshAvailableTimes"><option value="">请选择员工</option><option v-for="artist in artists" :key="String(artist.id)" :value="String(artist.id)">{{ artist.name || artist.nickname }}</option></select></div>
|
||||
<div class="field"><label class="required">预约时间</label><button class="field-value picker-value" type="button" @click="openTimeSheet">{{ form.appointmentTime || timeSelectTip }}</button></div>
|
||||
<div class="field field--stack"><label>备注</label><textarea v-model.trim="form.remark" placeholder="请输入预约备注"></textarea></div>
|
||||
</section>
|
||||
|
||||
<div v-if="conflictTip" class="conflict-tip" :class="`conflict-tip--${conflictLevel}`">{{ conflictTip }}</div>
|
||||
|
||||
<div class="fixed-bottom">
|
||||
<div class="fixed-bottom__inner button-row">
|
||||
<button class="secondary-btn" type="button" @click="saveDraft">保存草稿</button>
|
||||
<button class="primary-btn" type="button" :disabled="loading" @click="submit">{{ loading ? '提交中...' : '提交预约' }}</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<BaseModal v-model="productModalVisible" title="选择预约作品">
|
||||
<div class="product-modal">
|
||||
<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="" />
|
||||
<div>
|
||||
<strong>{{ product.title }}</strong>
|
||||
<span>{{ product.priceText }} · {{ product.durationText || '时长待定' }}</span>
|
||||
<small>{{ product.artistText }}</small>
|
||||
</div>
|
||||
</button>
|
||||
</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>
|
||||
<button class="secondary-btn" type="button" @click="useManualProduct">使用手动作品</button>
|
||||
</div>
|
||||
</PageSection>
|
||||
</div>
|
||||
</BaseModal>
|
||||
|
||||
<BaseModal v-model="timeSheetVisible" title="选择可约时间">
|
||||
<div class="time-sheet">
|
||||
<LoadingState v-if="timeLoading" text="正在计算可约时间" />
|
||||
<EmptyState v-else-if="availableTimeGroups.length === 0" title="暂无可约时间" :description="timeSelectTip" />
|
||||
<section v-for="group in availableTimeGroups" v-else :key="group.key">
|
||||
<h3>{{ group.title }}</h3>
|
||||
<div class="time-grid">
|
||||
<button v-for="time in group.times" :key="time.value" type="button" @click="selectAvailableTime(time.value)">
|
||||
<strong>{{ time.value }}</strong>
|
||||
<span>{{ time.rangeText }}</span>
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</BaseModal>
|
||||
</MobileShell>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import BaseModal from '@/components/BaseModal.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 type { AppointmentForm, Artist, Product } from '@/types/manager'
|
||||
import type { UserInfo } from '@/types/common'
|
||||
import { useSessionStore } from '@/stores/session'
|
||||
import { useToastStore } from '@/stores/toast'
|
||||
import { formatDate, minutesOfDay, timeFromMinutes } from '@/utils/date'
|
||||
import { buildAvailableTimeGroups, type AvailableTimeGroup } from '@/utils/available-times'
|
||||
import { buildClientRequestId, normalizeDuration } from '@/utils/planning'
|
||||
import { readDraftForm, removeDraftForm, writeDraftForm } from '@/utils/appointment-draft'
|
||||
import { markPlanningRefresh } from '@/utils/storage'
|
||||
|
||||
interface ProductCard extends Product {
|
||||
coverImage: string
|
||||
priceText: string
|
||||
durationText: string
|
||||
artistText: string
|
||||
}
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const session = useSessionStore()
|
||||
const toast = useToastStore()
|
||||
const baseForm = readDraftForm(session.userInfo)
|
||||
const form = reactive<AppointmentForm>({
|
||||
customerUserId: '',
|
||||
customerName: String(route.query.customerName || baseForm?.customerName || ''),
|
||||
phone: String(route.query.phone || baseForm?.phone || ''),
|
||||
appointmentDate: String(route.query.date || baseForm?.appointmentDate || formatDate(new Date())),
|
||||
appointmentTime: baseForm?.appointmentTime || '',
|
||||
productId: baseForm?.productId || '',
|
||||
manualProductTitle: baseForm?.manualProductTitle || '',
|
||||
manualProductPrice: baseForm?.manualProductPrice || '',
|
||||
manualProductDescription: baseForm?.manualProductDescription || '',
|
||||
manualProductTags: baseForm?.manualProductTags || '',
|
||||
manualProductTargetAudience: baseForm?.manualProductTargetAudience || '',
|
||||
manualProductPrecautions: baseForm?.manualProductPrecautions || '',
|
||||
manualProductImageFileIds: baseForm?.manualProductImageFileIds || '',
|
||||
manualProductImageUrl: baseForm?.manualProductImageUrl || '',
|
||||
durationMinutes: baseForm?.durationMinutes || '',
|
||||
artistId: String(route.query.artistId || baseForm?.artistId || ''),
|
||||
remark: baseForm?.remark || ''
|
||||
})
|
||||
const draftSavedAtText = ref(baseForm ? '已恢复本机草稿' : '')
|
||||
const customerOptions = ref<UserInfo[]>([])
|
||||
const customerTimer = ref<number | null>(null)
|
||||
const products = ref<ProductCard[]>([])
|
||||
const filteredProducts = ref<ProductCard[]>([])
|
||||
const productKeyword = ref('')
|
||||
const productModalVisible = ref(false)
|
||||
const artists = ref<Artist[]>([])
|
||||
const selectedProduct = ref<ProductCard | null>(null)
|
||||
const timeSheetVisible = ref(false)
|
||||
const availableTimeGroups = ref<AvailableTimeGroup[]>([])
|
||||
const timeLoading = ref(false)
|
||||
const timeSelectTip = ref('请先选择美甲师并填写时长')
|
||||
const conflictTip = ref('')
|
||||
const conflictLevel = ref<'free' | 'danger'>('free')
|
||||
const loading = ref(false)
|
||||
|
||||
const selectedProductTitle = computed(() => {
|
||||
if (selectedProduct.value) {
|
||||
return selectedProduct.value.title
|
||||
}
|
||||
if (form.manualProductTitle) {
|
||||
return form.manualProductTitle
|
||||
}
|
||||
return '请选择作品'
|
||||
})
|
||||
|
||||
const normalizeProduct = (product: Product): ProductCard => {
|
||||
const imageUrls = Array.isArray(product.imageUrls) ? product.imageUrls : []
|
||||
const durationText = product.approximateDuration || (product.serviceDurationMinutes ? `${product.serviceDurationMinutes}分钟` : '')
|
||||
return {
|
||||
...product,
|
||||
coverImage: imageUrls[0] || '',
|
||||
priceText: product.price || product.price === 0 ? `¥${product.price}` : '价格待定',
|
||||
durationText,
|
||||
artistText: '全部美甲师'
|
||||
}
|
||||
}
|
||||
|
||||
const filterProducts = (): void => {
|
||||
const keyword = productKeyword.value.toLowerCase()
|
||||
filteredProducts.value = products.value.filter(product => {
|
||||
if (!keyword) {
|
||||
return true
|
||||
}
|
||||
return [product.title, product.priceText, product.durationText, product.artistText].some(value => String(value || '').toLowerCase().includes(keyword))
|
||||
})
|
||||
}
|
||||
|
||||
const loadOptions = async (): Promise<void> => {
|
||||
const [productData, employeeData] = await Promise.all([
|
||||
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
|
||||
if (form.productId) {
|
||||
selectedProduct.value = products.value.find(item => String(item.id) === String(form.productId)) || null
|
||||
}
|
||||
}
|
||||
|
||||
const scheduleCustomerSearch = (): void => {
|
||||
if (customerTimer.value !== null) {
|
||||
window.clearTimeout(customerTimer.value)
|
||||
}
|
||||
customerTimer.value = window.setTimeout(() => {
|
||||
void searchCustomers()
|
||||
}, 250)
|
||||
}
|
||||
|
||||
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 selectCustomer = (customer: UserInfo): void => {
|
||||
form.customerUserId = String(customer.id)
|
||||
form.customerName = customer.nickname || customer.account || ''
|
||||
form.phone = customer.phone || customer.contactPhone || ''
|
||||
customerOptions.value = []
|
||||
}
|
||||
|
||||
const onDateChange = async (): Promise<void> => {
|
||||
form.appointmentTime = ''
|
||||
await refreshAvailableTimes()
|
||||
}
|
||||
|
||||
const selectProduct = (product: ProductCard): void => {
|
||||
selectedProduct.value = product
|
||||
form.productId = String(product.id)
|
||||
form.manualProductTitle = ''
|
||||
form.manualProductPrice = ''
|
||||
form.durationMinutes = String(Number.parseInt(product.approximateDuration || '', 10) || product.serviceDurationMinutes || form.durationMinutes)
|
||||
productModalVisible.value = false
|
||||
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
|
||||
productModalVisible.value = false
|
||||
}
|
||||
|
||||
const refreshAvailableTimes = async (): Promise<void> => {
|
||||
const durationMinutes = normalizeDuration(form.durationMinutes)
|
||||
if (!form.appointmentDate || !form.artistId || !durationMinutes) {
|
||||
availableTimeGroups.value = []
|
||||
timeSelectTip.value = '请先选择美甲师并填写时长'
|
||||
return
|
||||
}
|
||||
timeLoading.value = true
|
||||
try {
|
||||
const calendar = await managerPlanningApi.calendar({ startDate: form.appointmentDate, endDate: form.appointmentDate, artistId: form.artistId })
|
||||
availableTimeGroups.value = buildAvailableTimeGroups(calendar, form)
|
||||
timeSelectTip.value = availableTimeGroups.value.length > 0 ? '请选择预约时间' : '当前美甲师当天暂无可约时间'
|
||||
} finally {
|
||||
timeLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const openTimeSheet = async (): Promise<void> => {
|
||||
if (!form.appointmentDate || !form.artistId || !normalizeDuration(form.durationMinutes)) {
|
||||
toast.error('请先选择美甲师并填写时长')
|
||||
return
|
||||
}
|
||||
timeSheetVisible.value = true
|
||||
await refreshAvailableTimes()
|
||||
}
|
||||
|
||||
const selectAvailableTime = (value: string): void => {
|
||||
form.appointmentTime = value
|
||||
timeSheetVisible.value = false
|
||||
void checkAvailability()
|
||||
}
|
||||
|
||||
const checkAvailability = async (): Promise<{ ok: boolean; tip?: string }> => {
|
||||
if (!form.appointmentDate || !form.appointmentTime || !form.artistId || !normalizeDuration(form.durationMinutes)) {
|
||||
conflictTip.value = ''
|
||||
return { ok: true }
|
||||
}
|
||||
const startMinute = minutesOfDay(form.appointmentTime)
|
||||
const endMinute = startMinute + normalizeDuration(form.durationMinutes)
|
||||
if (startMinute < minutesOfDay('10:00') || endMinute > minutesOfDay('22:00')) {
|
||||
conflictTip.value = '该时间超出营业时间 10:00-22:00'
|
||||
conflictLevel.value = 'danger'
|
||||
return { ok: false, tip: conflictTip.value }
|
||||
}
|
||||
conflictTip.value = `当前时段 ${form.appointmentTime}-${timeFromMinutes(endMinute)} 可预约`
|
||||
conflictLevel.value = 'free'
|
||||
return { ok: true, tip: conflictTip.value }
|
||||
}
|
||||
|
||||
const submit = async (): Promise<void> => {
|
||||
const hasManualProduct = form.manualProductTitle.trim() && form.manualProductPrice.trim()
|
||||
if (!form.customerName || !form.phone || (!form.productId && !hasManualProduct) || !form.artistId || !form.appointmentTime) {
|
||||
toast.error('请补全预约信息')
|
||||
return
|
||||
}
|
||||
const durationMinutes = normalizeDuration(form.durationMinutes)
|
||||
if (!durationMinutes) {
|
||||
toast.error('请填写预约时长')
|
||||
return
|
||||
}
|
||||
const availability = await checkAvailability()
|
||||
if (!availability.ok) {
|
||||
toast.error(availability.tip || '该时段已被预约')
|
||||
return
|
||||
}
|
||||
loading.value = true
|
||||
try {
|
||||
const payload = {
|
||||
...form,
|
||||
customerUserId: form.customerUserId || undefined,
|
||||
productId: form.productId || undefined,
|
||||
artistId: form.artistId,
|
||||
durationMinutes,
|
||||
manualProductPrice: hasManualProduct ? Number(form.manualProductPrice) : undefined,
|
||||
clientRequestId: buildClientRequestId('manager-appointment')
|
||||
}
|
||||
const result = await managerPlanningApi.createAppointment(payload)
|
||||
removeDraftForm(session.userInfo)
|
||||
markPlanningRefresh()
|
||||
toast.success('预约已创建')
|
||||
await router.replace(`/appointments/${result.orderItemId}`)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const saveDraft = (): void => {
|
||||
writeDraftForm(session.userInfo, { ...form })
|
||||
draftSavedAtText.value = '草稿已保存到本机'
|
||||
toast.success('草稿已保存')
|
||||
}
|
||||
|
||||
const clearDraft = (): void => {
|
||||
removeDraftForm(session.userInfo)
|
||||
draftSavedAtText.value = ''
|
||||
toast.success('草稿已清空')
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await loadOptions()
|
||||
await searchCustomers()
|
||||
await refreshAvailableTimes()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.draft-tip {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 12px;
|
||||
padding: 10px 12px;
|
||||
color: var(--accent);
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.customer-options {
|
||||
display: grid;
|
||||
gap: 6px;
|
||||
padding: 8px 0;
|
||||
}
|
||||
|
||||
.customer-options button {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: 8px 10px;
|
||||
border-radius: 10px;
|
||||
background: var(--subtle);
|
||||
}
|
||||
|
||||
.picker-value {
|
||||
justify-content: flex-start;
|
||||
color: var(--ink);
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.conflict-tip {
|
||||
margin-top: 12px;
|
||||
padding: 10px 12px;
|
||||
border-radius: 12px;
|
||||
background: var(--accent-soft);
|
||||
color: var(--accent);
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.conflict-tip--danger {
|
||||
background: #fff0ee;
|
||||
color: var(--danger);
|
||||
}
|
||||
|
||||
.product-modal,
|
||||
.time-sheet {
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
padding: 14px;
|
||||
}
|
||||
|
||||
.product-card {
|
||||
display: grid;
|
||||
grid-template-columns: 72px 1fr;
|
||||
gap: 10px;
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
border-radius: 14px;
|
||||
background: var(--subtle);
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.product-card img {
|
||||
width: 72px;
|
||||
height: 72px;
|
||||
border-radius: 12px;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.product-card strong,
|
||||
.product-card span,
|
||||
.product-card small {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.product-card span,
|
||||
.product-card small {
|
||||
margin-top: 3px;
|
||||
color: var(--muted);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.manual-form {
|
||||
display: grid;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.textarea {
|
||||
min-height: 88px;
|
||||
padding: 12px;
|
||||
resize: vertical;
|
||||
}
|
||||
|
||||
.time-sheet h3 {
|
||||
margin: 0 0 8px;
|
||||
}
|
||||
|
||||
.time-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.time-grid button {
|
||||
display: grid;
|
||||
gap: 2px;
|
||||
padding: 10px 4px;
|
||||
border-radius: 12px;
|
||||
background: var(--accent-soft);
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
.time-grid span {
|
||||
font-size: 11px;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user