优化:统一小程序业务引用选择交互
This commit is contained in:
@@ -6,7 +6,11 @@ Page({
|
||||
data: {
|
||||
id: '',
|
||||
artists: [],
|
||||
artistItems: [],
|
||||
selectedArtistId: '',
|
||||
selectedArtist: {},
|
||||
artistSheetVisible: false,
|
||||
artistKeyword: '',
|
||||
date: dateUtil.formatDate(new Date()),
|
||||
time: '13:00',
|
||||
loadError: '',
|
||||
@@ -20,38 +24,88 @@ Page({
|
||||
this.loadArtists()
|
||||
},
|
||||
|
||||
async loadArtists() {
|
||||
async loadArtists(preferredArtistId, fallbackEmployee) {
|
||||
try {
|
||||
const calendar = await planningApi.calendar({
|
||||
startDate: this.data.date,
|
||||
endDate: this.data.date
|
||||
})
|
||||
const artists = Array.isArray(calendar.artists) ? calendar.artists : []
|
||||
let artists = Array.isArray(calendar.artists) ? calendar.artists : []
|
||||
if (fallbackEmployee && preferredArtistId && !artists.some(item => String(item.id) === String(preferredArtistId))) {
|
||||
artists = artists.concat({ id: preferredArtistId, name: fallbackEmployee.name || fallbackEmployee.title, avatar: fallbackEmployee.avatar || '' })
|
||||
}
|
||||
const selectedArtistId = preferredArtistId || this.data.selectedArtistId
|
||||
const selectedArtist = artists.find(item => String(item.id) === String(selectedArtistId)) || {}
|
||||
this.setData({
|
||||
artists: artists.map(item => ({
|
||||
...item,
|
||||
availableStatus: 'free',
|
||||
availableText: '可选择'
|
||||
})),
|
||||
selectedArtistId: '',
|
||||
artistItems: this.filterArtistItems(artists, this.data.artistKeyword),
|
||||
selectedArtistId: selectedArtist.id || '',
|
||||
selectedArtist,
|
||||
loadError: ''
|
||||
})
|
||||
} catch (error) {
|
||||
this.setData({
|
||||
artists: [],
|
||||
artistItems: [],
|
||||
selectedArtistId: '',
|
||||
selectedArtist: {},
|
||||
loadError: error.message || '美甲师列表加载失败'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
filterArtistItems(artists, keywordValue) {
|
||||
const keyword = String(keywordValue || '').trim().toLowerCase()
|
||||
return (artists || [])
|
||||
.filter(item => !keyword || String(item.name || '').toLowerCase().includes(keyword))
|
||||
.map(item => ({
|
||||
...item,
|
||||
title: item.name || '未命名员工',
|
||||
subtitle: item.statusText || '可用于改派',
|
||||
meta: item.workStartTime && item.workEndTime ? `${item.workStartTime.slice(0, 5)}-${item.workEndTime.slice(0, 5)}` : '',
|
||||
avatar: item.avatar || item.avatarUrl || '/assets/images/default-user-avatar.png'
|
||||
}))
|
||||
},
|
||||
|
||||
openArtistSheet() {
|
||||
this.setData({ artistSheetVisible: true, artistItems: this.filterArtistItems(this.data.artists, this.data.artistKeyword) })
|
||||
},
|
||||
|
||||
closeArtistSheet() {
|
||||
this.setData({ artistSheetVisible: false })
|
||||
},
|
||||
|
||||
onArtistSearch(event) {
|
||||
const artistKeyword = event.detail.value
|
||||
this.setData({ artistKeyword, artistItems: this.filterArtistItems(this.data.artists, artistKeyword) })
|
||||
},
|
||||
|
||||
selectArtist(event) {
|
||||
this.setData({ selectedArtistId: event.currentTarget.dataset.id })
|
||||
const selectedArtist = event.detail.item || {}
|
||||
this.setData({ selectedArtistId: selectedArtist.id, selectedArtist, artistSheetVisible: false })
|
||||
},
|
||||
|
||||
retryArtists() {
|
||||
this.loadArtists()
|
||||
},
|
||||
|
||||
addEmployeeFromSelector() {
|
||||
this.setData({ artistSheetVisible: false })
|
||||
wx.navigateTo({
|
||||
url: '/pages/employee-create/index?picker=1',
|
||||
success: result => {
|
||||
result.eventChannel.on('employeeCreated', employee => this.loadArtists(employee.id, employee))
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
async onDateChange(event) {
|
||||
this.setData({ date: event.detail.value })
|
||||
await this.loadArtists()
|
||||
await this.loadArtists(this.data.selectedArtistId)
|
||||
},
|
||||
|
||||
onTimeChange(event) {
|
||||
|
||||
Reference in New Issue
Block a user