优化管理师登录与预约客户选择

This commit is contained in:
2026-06-26 13:32:06 +08:00
parent a5e36dc27c
commit 3e04d75f00
11 changed files with 332 additions and 32 deletions
@@ -1,5 +1,6 @@
const planningApi = require('../../api/planning')
const productsApi = require('../../api/products')
const customersApi = require('../../api/customers')
const dateUtil = require('../../utils/date')
function buildClientRequestId(prefix) {
@@ -65,9 +66,22 @@ function isScheduleCoveringTime(schedule, form, startMinute, endMinute) {
return scheduleStartMinute <= startMinute && scheduleEndMinute >= endMinute
}
function normalizeCustomer(customer) {
const name = customer.nickname || customer.name || customer.account || ''
const phone = customer.contactPhone || customer.phone || ''
return {
id: customer.id,
name,
phone,
displayName: name || phone || '客户',
displayPhone: phone || '未填写手机号'
}
}
Page({
data: {
form: {
customerUserId: '',
customerName: '',
phone: '',
appointmentDate: dateUtil.formatDate(new Date()),
@@ -79,6 +93,10 @@ Page({
artistId: '',
remark: ''
},
customerOptions: [],
customerDropdownVisible: false,
customerLoading: false,
customerError: '',
products: [],
filteredProducts: [],
artists: [],
@@ -107,6 +125,7 @@ Page({
return
}
this.loadOptions()
this.searchCustomers()
},
async loadOptions() {
@@ -148,11 +167,81 @@ Page({
},
onInput(event) {
const field = event.currentTarget.dataset.field
const patch = {
[`form.${field}`]: event.detail.value
}
if (field === 'customerName' || field === 'phone') {
patch['form.customerUserId'] = ''
patch.customerDropdownVisible = true
}
this.setData(patch)
if (field === 'customerName' || field === 'phone') {
this.scheduleCustomerSearch(field)
}
},
onCustomerFocus(event) {
const field = event.currentTarget.dataset.field
this.setData({ customerDropdownVisible: true })
this.searchCustomers(field)
},
scheduleCustomerSearch(field) {
clearTimeout(this._customerTimer)
this._customerTimer = setTimeout(() => this.searchCustomers(field), 250)
},
async searchCustomers(preferredField) {
if (!this.data.canCreateAppointment) {
return
}
const form = this.data.form
const sourceValue = preferredField === 'phone' ? form.phone : form.customerName || form.phone
const keyword = String(sourceValue || '').trim()
this.setData({ customerLoading: true })
try {
const data = await customersApi.list({ keyword, page: 1, size: 20 })
const list = data.list || data || []
this.setData({
customerOptions: list.map(normalizeCustomer),
customerError: ''
})
} catch (error) {
this.setData({
customerOptions: [],
customerError: error.message || '客户列表加载失败'
})
} finally {
this.setData({ customerLoading: false })
}
},
selectCustomer(event) {
const customer = this.data.customerOptions.find(item => String(item.id) === String(event.currentTarget.dataset.id))
if (!customer) {
return
}
this.setData({
[`form.${event.currentTarget.dataset.field}`]: event.detail.value
'form.customerUserId': customer.id,
'form.customerName': customer.name,
'form.phone': customer.phone,
customerDropdownVisible: false
})
},
hideCustomerDropdown() {
setTimeout(() => {
this.setData({ customerDropdownVisible: false })
}, 180)
},
onUnload() {
if (this._customerTimer) {
clearTimeout(this._customerTimer)
}
},
async onDateChange(event) {
this.setData({ 'form.appointmentDate': event.detail.value })
await this.loadArtists()
@@ -303,6 +392,7 @@ Page({
try {
const payload = {
...form,
customerUserId: form.customerUserId ? String(form.customerUserId) : undefined,
artistId: String(form.artistId),
durationMinutes: Number(form.durationMinutes || 0) || undefined,
clientRequestId: buildClientRequestId('manager-appointment')