调整预约客户选择和快捷新增
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import type { UserInfo } from '@/types/common'
|
||||
|
||||
export interface CustomerCreateDraft {
|
||||
nickname: string
|
||||
phone: string
|
||||
}
|
||||
|
||||
export interface CustomerDisplay {
|
||||
id: string
|
||||
name: string
|
||||
phone: string
|
||||
avatar: string
|
||||
initial: string
|
||||
searchText: string
|
||||
}
|
||||
|
||||
const PHONE_PATTERN = /1[3-9]\d{9}/
|
||||
|
||||
export const buildCustomerSearchText = (name: string, phone: string): string => {
|
||||
return [name, phone].map(value => value.trim()).filter(Boolean).join(' ')
|
||||
}
|
||||
|
||||
export const buildCustomerCreateDraft = (keyword: string): CustomerCreateDraft => {
|
||||
const normalizedKeyword = keyword.trim()
|
||||
const phone = normalizedKeyword.match(PHONE_PATTERN)?.[0] || ''
|
||||
const nickname = phone ? normalizedKeyword.replace(phone, '').trim() : normalizedKeyword
|
||||
return { nickname, phone }
|
||||
}
|
||||
|
||||
export const resolveCustomerDisplay = (customer: UserInfo): CustomerDisplay => {
|
||||
const name = String(customer.nickname || customer.account || customer.phone || customer.contactPhone || '未命名客户')
|
||||
const phone = String(customer.phone || customer.contactPhone || '')
|
||||
const avatar = String(customer.avatar || '')
|
||||
return {
|
||||
id: String(customer.id),
|
||||
name,
|
||||
phone,
|
||||
avatar,
|
||||
initial: name.slice(0, 1) || '客',
|
||||
searchText: buildCustomerSearchText(name, phone)
|
||||
}
|
||||
}
|
||||
|
||||
export const validateAppointmentCustomerSelection = (customerUserId: string, customerName: string, phone: string): string | null => {
|
||||
if (!customerUserId.trim()) {
|
||||
return '请先选择客户或新增客户'
|
||||
}
|
||||
if (!customerName.trim() || !phone.trim()) {
|
||||
return '请补全客户姓名和手机号'
|
||||
}
|
||||
return null
|
||||
}
|
||||
Reference in New Issue
Block a user