完善管理师预约项目与美甲师创建

This commit is contained in:
2026-06-24 20:54:41 +08:00
parent 03c972d90c
commit eda109cb62
28 changed files with 911 additions and 32 deletions
@@ -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' })
@@ -22,9 +22,10 @@
</view>
<view class="field">
<text class="field-label">项目内容</text>
<picker range="{{products}}" range-key="title" bindchange="onProductChange">
<view class="field-value">{{selectedProduct.title || '请选择项目'}}</view>
</picker>
<view class="field-value product-value" bindtap="openProductModal">
<text>{{selectedProduct.title || form.manualProductTitle || '请选择项目'}}</text>
<text wx:if="{{form.manualProductTitle && !form.productId}}" class="manual-badge">手动</text>
</view>
</view>
<view class="field">
<text class="field-label">预计时长</text>
@@ -53,7 +54,44 @@
<text class="tip-text">{{conflictTip}}</text>
</view>
<view wx:if="{{productModalVisible}}" class="modal-mask" bindtap="closeProductModal">
<view class="product-modal" catchtap="stopTap">
<view class="modal-head">
<view>
<text class="modal-title">选择项目内容</text>
</view>
<button class="modal-close" bindtap="closeProductModal">×</button>
</view>
<input class="product-search" value="{{productKeyword}}" bindinput="onProductSearch" placeholder="搜索作品、标签、美甲师" />
<scroll-view class="product-list" scroll-y>
<view wx:for="{{filteredProducts}}" wx:key="id" class="product-option {{form.productId == item.id ? 'active' : ''}}" data-id="{{item.id}}" bindtap="selectProduct">
<image wx:if="{{item.coverImage}}" class="product-cover" src="{{item.coverImage}}" mode="aspectFill"></image>
<view wx:else class="product-cover placeholder">图</view>
<view class="product-info">
<view class="product-title-row">
<text class="product-title">{{item.title}}</text>
<text class="product-price">{{item.priceText}}</text>
</view>
<text class="product-meta">{{item.artistText}} · {{item.durationText || '时长待定'}}</text>
<view class="tag-row">
<text wx:for="{{item.tagList}}" wx:for-item="tag" wx:key="*this" class="tag-pill">{{tag}}</text>
</view>
</view>
</view>
<view wx:if="{{filteredProducts.length === 0}}" class="product-empty">暂无匹配作品</view>
</scroll-view>
<view class="manual-panel">
<text class="manual-title">手动新增项目</text>
<view class="manual-grid">
<input value="{{form.manualProductTitle}}" data-field="manualProductTitle" bindinput="onInput" placeholder="项目名称" />
<input value="{{form.manualProductPrice}}" data-field="manualProductPrice" bindinput="onInput" type="digit" placeholder="价格" />
</view>
<button class="secondary-btn manual-btn" bindtap="useManualProduct">使用手动项目</button>
</view>
</view>
</view>
<view class="fixed-bottom">
<button class="primary-btn" loading="{{loading}}" bindtap="submit">保存预约</button>
<button wx:if="{{canCreateAppointment}}" class="primary-btn" loading="{{loading}}" bindtap="submit">保存预约</button>
</view>
</view>
@@ -3,6 +3,23 @@
font-size: 24rpx;
}
.product-value {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12rpx;
}
.manual-badge {
flex: 0 0 auto;
padding: 4rpx 12rpx;
border-radius: 999rpx;
background: #fff2df;
color: #a26428;
font-size: 22rpx;
font-weight: 800;
}
.textarea-field {
align-items: flex-start;
}
@@ -58,3 +75,202 @@
.availability-tip.danger .tip-title {
color: #c36a6a;
}
.modal-mask {
position: fixed;
inset: 0;
z-index: 80;
display: flex;
align-items: flex-end;
justify-content: center;
background: rgba(18, 15, 12, 0.48);
}
.product-modal {
width: 100%;
max-height: 88vh;
padding: 28rpx 28rpx calc(28rpx + env(safe-area-inset-bottom));
border-radius: 28rpx 28rpx 0 0;
background: #fffaf4;
box-shadow: 0 -18rpx 40rpx rgba(41, 31, 23, 0.16);
}
.modal-head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 20rpx;
margin-bottom: 20rpx;
}
.modal-title {
display: block;
}
.modal-title {
color: #27211d;
font-size: 34rpx;
font-weight: 900;
}
.modal-close {
width: 58rpx;
height: 58rpx;
margin: 0;
padding: 0;
border-radius: 50%;
background: #f2e7da;
color: #61554c;
font-size: 40rpx;
line-height: 58rpx;
}
.product-search {
height: 74rpx;
padding: 0 24rpx;
border-radius: 18rpx;
background: #f5eee6;
color: #2a2521;
font-size: 26rpx;
}
.product-list {
max-height: 560rpx;
margin-top: 20rpx;
}
.product-option {
display: flex;
align-items: stretch;
gap: 18rpx;
min-height: 156rpx;
margin-bottom: 16rpx;
padding: 14rpx;
border: 2rpx solid transparent;
border-radius: 18rpx;
background: #fff;
box-shadow: 0 10rpx 24rpx rgba(92, 66, 43, 0.08);
}
.product-option.active {
border-color: #c9874d;
background: #fff8ef;
}
.product-cover {
flex: 0 0 auto;
width: 132rpx;
height: 132rpx;
border-radius: 14rpx;
background: #efe5da;
}
.product-cover.placeholder {
display: flex;
align-items: center;
justify-content: center;
color: #b79b82;
font-size: 28rpx;
font-weight: 900;
}
.product-info {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
justify-content: center;
gap: 10rpx;
}
.product-title-row {
display: flex;
align-items: center;
gap: 16rpx;
}
.product-title {
flex: 1;
min-width: 0;
overflow: hidden;
color: #2a2521;
font-size: 28rpx;
font-weight: 900;
text-overflow: ellipsis;
white-space: nowrap;
}
.product-price {
flex: 0 0 auto;
color: #c56f36;
font-size: 28rpx;
font-weight: 900;
}
.product-meta {
overflow: hidden;
color: #8c8177;
font-size: 24rpx;
text-overflow: ellipsis;
white-space: nowrap;
}
.tag-row {
display: flex;
flex-wrap: wrap;
gap: 8rpx;
min-height: 34rpx;
}
.tag-pill {
max-width: 160rpx;
padding: 4rpx 12rpx;
overflow: hidden;
border-radius: 999rpx;
background: #f3e9df;
color: #826c5b;
font-size: 22rpx;
text-overflow: ellipsis;
white-space: nowrap;
}
.product-empty {
padding: 44rpx 0;
color: #9a9288;
font-size: 26rpx;
text-align: center;
}
.manual-panel {
margin-top: 12rpx;
padding: 20rpx;
border-radius: 18rpx;
background: #f7efe7;
}
.manual-title {
display: block;
margin-bottom: 14rpx;
color: #4e4740;
font-size: 26rpx;
font-weight: 900;
}
.manual-grid {
display: grid;
grid-template-columns: minmax(0, 1fr) 180rpx;
gap: 14rpx;
}
.manual-grid input {
height: 70rpx;
padding: 0 18rpx;
border-radius: 14rpx;
background: #fffaf4;
color: #302923;
font-size: 26rpx;
}
.manual-btn {
margin-top: 16rpx;
}