完善管理师预约项目与美甲师创建
This commit is contained in:
@@ -14,6 +14,45 @@ function findArtist(artists, artistId) {
|
||||
return artists.find(item => String(item.id) === String(artistId)) || {}
|
||||
}
|
||||
|
||||
function canCreateAppointment() {
|
||||
const app = getApp()
|
||||
const userInfo = app.globalData.userInfo || {}
|
||||
return Number(userInfo.type) !== 3
|
||||
}
|
||||
|
||||
function parseProductTags(product) {
|
||||
if (Array.isArray(product.tagList) && product.tagList.length > 0) {
|
||||
return product.tagList
|
||||
}
|
||||
if (Array.isArray(product.tagInfos) && product.tagInfos.length > 0) {
|
||||
return product.tagInfos.map(item => item.tagName).filter(Boolean)
|
||||
}
|
||||
return String(product.tags || '')
|
||||
.split(/[;,,、]/)
|
||||
.map(item => item.trim())
|
||||
.filter(Boolean)
|
||||
}
|
||||
|
||||
function normalizeProduct(product, artists) {
|
||||
const imageUrls = Array.isArray(product.imageUrls) ? product.imageUrls : []
|
||||
const bookableArtists = String(product.bookableArtists || '')
|
||||
.split(',')
|
||||
.map(item => item.trim())
|
||||
.filter(Boolean)
|
||||
const artistNames = bookableArtists
|
||||
.map(id => findArtist(artists, id).name)
|
||||
.filter(Boolean)
|
||||
const durationText = product.approximateDuration || (product.serviceDurationMinutes ? `${product.serviceDurationMinutes}分钟` : '')
|
||||
return {
|
||||
...product,
|
||||
coverImage: imageUrls[0] || '',
|
||||
tagList: parseProductTags(product).slice(0, 4),
|
||||
artistText: artistNames.length > 0 ? artistNames.join('、') : '全部美甲师',
|
||||
priceText: product.price || product.price === 0 ? `¥${product.price}` : '价格待定',
|
||||
durationText
|
||||
}
|
||||
}
|
||||
|
||||
function isScheduleCoveringTime(schedule, form, startMinute, endMinute) {
|
||||
if (!schedule || String(schedule.artistId) !== String(form.artistId) || schedule.date !== form.appointmentDate) {
|
||||
return false
|
||||
@@ -34,24 +73,36 @@ Page({
|
||||
appointmentDate: dateUtil.formatDate(new Date()),
|
||||
appointmentTime: '13:00',
|
||||
productId: '',
|
||||
manualProductTitle: '',
|
||||
manualProductPrice: '',
|
||||
durationMinutes: '',
|
||||
artistId: '',
|
||||
remark: ''
|
||||
},
|
||||
products: [],
|
||||
filteredProducts: [],
|
||||
artists: [],
|
||||
selectedProduct: {},
|
||||
selectedArtist: {},
|
||||
productModalVisible: false,
|
||||
productKeyword: '',
|
||||
conflictTip: '',
|
||||
conflictLevel: 'free',
|
||||
canCreateAppointment: true,
|
||||
loading: false
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
const creatable = canCreateAppointment()
|
||||
this.setData({
|
||||
canCreateAppointment: creatable,
|
||||
'form.appointmentDate': options.date || dateUtil.formatDate(new Date()),
|
||||
'form.artistId': options.artistId || ''
|
||||
})
|
||||
if (!creatable) {
|
||||
wx.showToast({ title: '美甲师账号只能查看预约', icon: 'none' })
|
||||
return
|
||||
}
|
||||
this.loadOptions()
|
||||
},
|
||||
|
||||
@@ -69,6 +120,7 @@ Page({
|
||||
this.setData({ products: fallbackProducts })
|
||||
}
|
||||
await this.loadArtists()
|
||||
this.refreshProductCards()
|
||||
this.checkAvailability()
|
||||
},
|
||||
|
||||
@@ -80,6 +132,7 @@ Page({
|
||||
const artists = getCalendarArtists(calendar)
|
||||
const selectedArtist = this.data.form.artistId ? findArtist(artists, this.data.form.artistId) : {}
|
||||
this.setData({ artists, selectedArtist })
|
||||
this.refreshProductCards()
|
||||
},
|
||||
|
||||
onInput(event) {
|
||||
@@ -99,13 +152,62 @@ Page({
|
||||
this.checkAvailability()
|
||||
},
|
||||
|
||||
onProductChange(event) {
|
||||
const selectedProduct = this.data.products[Number(event.detail.value)] || {}
|
||||
refreshProductCards() {
|
||||
const keyword = this.data.productKeyword.trim().toLowerCase()
|
||||
const products = this.data.products
|
||||
.map(product => normalizeProduct(product, this.data.artists))
|
||||
.filter(product => {
|
||||
if (!keyword) return true
|
||||
return [product.title, product.artistText, product.priceText, product.durationText, ...(product.tagList || [])]
|
||||
.some(value => String(value || '').toLowerCase().includes(keyword))
|
||||
})
|
||||
this.setData({ filteredProducts: products })
|
||||
},
|
||||
|
||||
openProductModal() {
|
||||
this.refreshProductCards()
|
||||
this.setData({ productModalVisible: true })
|
||||
},
|
||||
|
||||
closeProductModal() {
|
||||
this.setData({ productModalVisible: false })
|
||||
},
|
||||
|
||||
stopTap() {
|
||||
},
|
||||
|
||||
onProductSearch(event) {
|
||||
this.setData({ productKeyword: event.detail.value })
|
||||
this.refreshProductCards()
|
||||
},
|
||||
|
||||
selectProduct(event) {
|
||||
const selectedProduct = this.data.filteredProducts.find(item => String(item.id) === String(event.currentTarget.dataset.id)) || {}
|
||||
this.setData({
|
||||
selectedProduct,
|
||||
'form.productId': selectedProduct.id,
|
||||
'form.manualProductTitle': '',
|
||||
'form.manualProductPrice': '',
|
||||
'form.durationMinutes': String(parseInt(selectedProduct.approximateDuration, 10) || this.data.form.durationMinutes || 60)
|
||||
})
|
||||
this.closeProductModal()
|
||||
this.checkAvailability()
|
||||
},
|
||||
|
||||
useManualProduct() {
|
||||
const title = String(this.data.form.manualProductTitle || '').trim()
|
||||
const price = Number(this.data.form.manualProductPrice)
|
||||
if (!title || Number.isNaN(price) || price < 0) {
|
||||
wx.showToast({ title: '请填写手动项目名称和价格', icon: 'none' })
|
||||
return
|
||||
}
|
||||
this.setData({
|
||||
selectedProduct: {},
|
||||
'form.productId': '',
|
||||
'form.manualProductTitle': title,
|
||||
'form.manualProductPrice': String(price)
|
||||
})
|
||||
this.closeProductModal()
|
||||
this.checkAvailability()
|
||||
},
|
||||
|
||||
@@ -170,8 +272,13 @@ Page({
|
||||
},
|
||||
|
||||
async submit() {
|
||||
if (!this.data.canCreateAppointment) {
|
||||
wx.showToast({ title: '美甲师账号只能查看预约', icon: 'none' })
|
||||
return
|
||||
}
|
||||
const form = this.data.form
|
||||
if (!form.customerName || !form.phone || !form.productId || !form.artistId) {
|
||||
const hasManualProduct = String(form.manualProductTitle || '').trim() && String(form.manualProductPrice || '').trim()
|
||||
if (!form.customerName || !form.phone || (!form.productId && !hasManualProduct) || !form.artistId) {
|
||||
wx.showToast({ title: '请补全预约信息', icon: 'none' })
|
||||
return
|
||||
}
|
||||
@@ -182,13 +289,22 @@ Page({
|
||||
}
|
||||
this.setData({ loading: true })
|
||||
try {
|
||||
const result = await planningApi.createAppointment({
|
||||
const payload = {
|
||||
...form,
|
||||
productId: String(form.productId),
|
||||
artistId: String(form.artistId),
|
||||
durationMinutes: Number(form.durationMinutes || 0) || undefined,
|
||||
clientRequestId: buildClientRequestId('manager-appointment')
|
||||
})
|
||||
}
|
||||
if (form.productId) {
|
||||
payload.productId = String(form.productId)
|
||||
payload.manualProductTitle = undefined
|
||||
payload.manualProductPrice = undefined
|
||||
} else {
|
||||
payload.productId = undefined
|
||||
payload.manualProductTitle = String(form.manualProductTitle || '').trim()
|
||||
payload.manualProductPrice = Number(form.manualProductPrice)
|
||||
}
|
||||
const result = await planningApi.createAppointment(payload)
|
||||
wx.redirectTo({ url: `/pages/appointment-detail/index?id=${result.orderItemId}` })
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '保存失败', icon: 'none' })
|
||||
|
||||
Reference in New Issue
Block a user