优化店务预约作品快照与图片维护

This commit is contained in:
2026-07-21 16:26:56 +08:00
parent 7415b6b451
commit 1c6dabe7d9
20 changed files with 873 additions and 161 deletions
@@ -1,5 +1,44 @@
const planningApi = require('../../api/planning')
const { markPlanningRefresh } = require('../../utils/planning-refresh')
const { chooseImageFilePaths, uploadObjectFile } = require('../../utils/upload')
function canTransferAppointment() {
const app = getApp()
const userInfo = app.globalData.userInfo || {}
return Number(userInfo.type) === 2
}
function splitImageValues(value) {
return String(value || '')
.split(',')
.map(item => item.trim())
.filter(Boolean)
}
function resolveProductImageUrls(appointment) {
if (appointment && Array.isArray(appointment.productImageUrls)) {
return appointment.productImageUrls.filter(Boolean)
}
return []
}
async function uploadAppointmentImageFiles(limit) {
const filePaths = await chooseImageFilePaths(limit)
const fileIds = []
const imageUrls = []
for (let index = 0; index < filePaths.length; index += 1) {
const filePath = filePaths[index]
const uploadResult = await uploadObjectFile(filePath)
const fileId = uploadResult.id || uploadResult.fileId
const fileUrl = uploadResult.fileUrl || uploadResult.primaryUrl || filePath
if (!fileId) {
throw new Error('预约图片上传成功但未返回文件ID')
}
fileIds.push(String(fileId))
imageUrls.push(fileUrl)
}
return { fileIds, imageUrls }
}
Page({
data: {
@@ -7,11 +46,18 @@ Page({
appointment: {},
avatarText: '',
timeText: '',
productImageUrls: [],
productImageFileIds: '',
imageUploading: false,
canTransferAppointment: false,
loadError: ''
},
onLoad(options) {
this.setData({ id: options.id || '' })
this.setData({
id: options.id || '',
canTransferAppointment: canTransferAppointment()
})
this.loadDetail()
},
@@ -24,16 +70,22 @@ Page({
appointment: {},
avatarText: '',
timeText: '',
productImageUrls: [],
productImageFileIds: '',
loadError: error.message || '预约详情加载失败'
})
}
},
applyAppointment(appointment) {
const imageUrls = resolveProductImageUrls(appointment)
this.setData({
appointment,
avatarText: String(appointment.customerName || '客').slice(0, 1),
timeText: `${(appointment.startTime || '').slice(0, 16)} - ${(appointment.endTime || '').slice(11, 16)}`,
productImageUrls: imageUrls,
productImageFileIds: String(appointment.productImageFileIds || ''),
canTransferAppointment: canTransferAppointment(),
loadError: ''
})
},
@@ -62,9 +114,97 @@ Page({
},
goTransfer() {
if (!this.data.canTransferAppointment) {
wx.showToast({ title: '只有店长可以改派预约', icon: 'none' })
return
}
wx.navigateTo({ url: `/pages/artist-transfer/index?id=${this.data.id}` })
},
async persistAppointmentImages(fileIds) {
const appointment = await planningApi.updateAppointmentImages(this.data.id, {
imageFileIds: fileIds.join(',')
})
markPlanningRefresh()
this.applyAppointment(appointment)
},
async chooseAppointmentImages() {
if (this.data.imageUploading) {
return
}
const currentFileIds = splitImageValues(this.data.productImageFileIds)
const remainingCount = 9 - currentFileIds.length
if (remainingCount <= 0) {
wx.showToast({ title: '最多上传 9 张作品图片', icon: 'none' })
return
}
this.setData({ imageUploading: true })
try {
const uploaded = await uploadAppointmentImageFiles(remainingCount)
if (uploaded.fileIds.length === 0) {
return
}
await this.persistAppointmentImages(currentFileIds.concat(uploaded.fileIds))
wx.showToast({ title: '图片已保存' })
} catch (error) {
wx.showToast({ title: error.message || '图片上传失败', icon: 'none' })
} finally {
this.setData({ imageUploading: false })
}
},
async replaceAppointmentImages() {
if (this.data.imageUploading) {
return
}
this.setData({ imageUploading: true })
try {
const uploaded = await uploadAppointmentImageFiles(9)
if (uploaded.fileIds.length === 0) {
return
}
await this.persistAppointmentImages(uploaded.fileIds)
wx.showToast({ title: '图片已保存' })
} catch (error) {
wx.showToast({ title: error.message || '图片上传失败', icon: 'none' })
} finally {
this.setData({ imageUploading: false })
}
},
async removeAppointmentImage(event) {
if (this.data.imageUploading) {
return
}
const index = Number(event.currentTarget.dataset.index)
const currentFileIds = splitImageValues(this.data.productImageFileIds)
if (!Number.isInteger(index) || index < 0 || index >= currentFileIds.length) {
return
}
const nextFileIds = currentFileIds.filter((item, itemIndex) => itemIndex !== index)
this.setData({ imageUploading: true })
try {
await this.persistAppointmentImages(nextFileIds)
wx.showToast({ title: '图片已保存' })
} catch (error) {
wx.showToast({ title: error.message || '图片保存失败', icon: 'none' })
} finally {
this.setData({ imageUploading: false })
}
},
previewProductImage(event) {
const current = this.data.productImageUrls[Number(event.currentTarget.dataset.index)]
if (!current) {
return
}
wx.previewImage({
current,
urls: this.data.productImageUrls
})
},
back() {
wx.navigateBack()
}
@@ -15,7 +15,7 @@
</view>
<view class="detail-actions">
<text class="tag">{{appointment.statusText}}</text>
<button class="small-action" bindtap="goTransfer">改派</button>
<button wx:if="{{canTransferAppointment && appointment.canEdit}}" class="small-action" bindtap="goTransfer">改派</button>
</view>
</view>
<view class="detail-grid">
@@ -38,6 +38,25 @@
</view>
</view>
<view wx:if="{{!loadError}}" class="section">
<view class="section-head">
<view class="section-title">作品图片</view>
<button class="text-btn image-action" loading="{{imageUploading}}" disabled="{{imageUploading}}" bindtap="replaceAppointmentImages">{{productImageUrls.length ? '重新上传' : '上传图片'}}</button>
</view>
<view class="card image-card">
<view wx:if="{{productImageUrls.length}}" class="detail-image-list">
<view wx:for="{{productImageUrls}}" wx:key="*this" class="detail-image-item">
<image class="detail-image" src="{{item}}" mode="aspectFill" data-index="{{index}}" bindtap="previewProductImage"></image>
<view class="detail-image-remove" data-index="{{index}}" catchtap="removeAppointmentImage">×</view>
</view>
<view wx:if="{{productImageUrls.length < 9}}" class="detail-image-add {{imageUploading ? 'disabled' : ''}}" bindtap="chooseAppointmentImages">
<text>{{imageUploading ? '...' : '+'}}</text>
</view>
</view>
<view wx:else class="detail-image-empty">暂无图片</view>
</view>
</view>
<view wx:if="{{!loadError}}" class="section">
<view class="section-title">备注</view>
<view class="card note-card">{{appointment.remark || '暂无备注'}}</view>
@@ -95,6 +95,93 @@
line-height: 1.6;
}
.section-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16rpx;
}
.image-action {
flex: 0 0 auto;
width: 156rpx;
min-width: 156rpx;
max-width: 156rpx;
padding: 0;
text-align: right;
}
.image-card {
padding: 20rpx;
}
.detail-image-list {
display: flex;
flex-wrap: wrap;
gap: 14rpx;
}
.detail-image-item {
position: relative;
width: 150rpx;
height: 150rpx;
}
.detail-image {
display: block;
width: 150rpx;
height: 150rpx;
border-radius: 16rpx;
background: #efe5da;
}
.detail-image-remove {
position: absolute;
top: -10rpx;
right: -10rpx;
display: flex;
align-items: center;
justify-content: center;
width: 34rpx;
height: 34rpx;
border-radius: 50%;
background: #bf4949;
color: #fff;
font-size: 24rpx;
font-weight: 900;
line-height: 34rpx;
}
.detail-image-add {
display: flex;
align-items: center;
justify-content: center;
width: 150rpx;
height: 150rpx;
border: 2rpx dashed #d5bfa9;
border-radius: 16rpx;
background: #fff8ef;
color: #b78b63;
font-size: 52rpx;
font-weight: 500;
line-height: 1;
}
.detail-image-add.disabled {
opacity: 0.55;
}
.detail-image-empty {
display: flex;
align-items: center;
justify-content: center;
min-height: 142rpx;
border-radius: 16rpx;
background: #f7efe7;
color: #9a9288;
font-size: 26rpx;
}
.action-row {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
+115 -17
View File
@@ -1,5 +1,6 @@
const planningApi = require('../../api/planning')
const productsApi = require('../../api/products')
const tagsApi = require('../../api/tags')
const customersApi = require('../../api/customers')
const dateUtil = require('../../utils/date')
const { markPlanningRefresh } = require('../../utils/planning-refresh')
@@ -256,6 +257,58 @@ function normalizeProduct(product, artists) {
}
}
function normalizeTagOption(tag) {
const name = String((tag && (tag.displayName || tag.tagName || tag.name)) || '').trim()
if (!name) {
return null
}
return {
id: (tag && tag.id) || name,
name
}
}
function normalizeTagOptions(tags) {
const source = Array.isArray(tags) ? tags : []
const names = new Set()
return source
.map(normalizeTagOption)
.filter(Boolean)
.filter(item => {
if (names.has(item.name)) {
return false
}
names.add(item.name)
return true
})
}
function resolveTagPickerIndex(tagOptions, value) {
const firstTag = String(value || '').split(/[;,,、]/)[0].trim()
if (!firstTag) {
return 0
}
const index = tagOptions.findIndex(item => item.name === firstTag)
return index >= 0 ? index : 0
}
function resolveTagValue(tagOptions, value) {
const tokens = String(value || '')
.split(/[;,,、]/)
.map(item => item.trim())
.filter(Boolean)
if (tokens.length === 0) {
return ''
}
if (!Array.isArray(tagOptions) || tagOptions.length === 0) {
return ''
}
const matched = tokens
.map(token => tagOptions.find(item => item.name === token))
.find(Boolean)
return matched ? matched.name : ''
}
function splitManualImageValues(value) {
return String(value || '')
.split(',')
@@ -335,6 +388,9 @@ Page({
manualProductImageUrls: [],
productKeyword: '',
productError: '',
tagOptions: [],
tagPickerIndex: 0,
tagError: '',
conflictTip: '',
conflictLevel: 'free',
canCreateAppointment: true,
@@ -385,12 +441,33 @@ Page({
productError: error.message || '作品列表加载失败'
})
}
await this.loadTags()
await this.loadArtists()
this.refreshProductCards()
await this.refreshAvailableTimes()
this.checkAvailability()
},
async loadTags() {
try {
const tagsData = await tagsApi.listAll()
const tagOptions = normalizeTagOptions(tagsData.list || tagsData || [])
const selectedTag = resolveTagValue(tagOptions, this.data.form.manualProductTags)
this.setData({
tagOptions,
tagPickerIndex: resolveTagPickerIndex(tagOptions, selectedTag),
'form.manualProductTags': selectedTag,
tagError: ''
})
} catch (error) {
this.setData({
tagOptions: [],
tagPickerIndex: 0,
tagError: error.message || '标签加载失败'
})
}
},
async loadArtists() {
try {
const calendar = await planningApi.calendar({
@@ -522,17 +599,20 @@ Page({
},
openProductModal() {
this.openManualProductPanel()
},
openProductTemplateSheet() {
this.setData({ productKeyword: '' })
this.refreshProductCards()
this.setData({
productModalVisible: true,
manualProductPanelVisible: false
productModalVisible: true
})
},
closeProductModal() {
this.setData({
productModalVisible: false,
manualProductPanelVisible: false
productModalVisible: false
})
},
@@ -542,7 +622,9 @@ Page({
: splitManualImageValues(this.data.form.manualProductImageUrl)
this.setData({
manualProductPanelVisible: true,
manualProductImageUrls: imageUrls
productModalVisible: false,
manualProductImageUrls: imageUrls,
tagPickerIndex: resolveTagPickerIndex(this.data.tagOptions, this.data.form.manualProductTags)
})
},
@@ -550,7 +632,10 @@ Page({
if (this.data.manualImageUploading) {
return
}
this.setData({ manualProductPanelVisible: false })
this.setData({
manualProductPanelVisible: false,
productModalVisible: false
})
},
stopTap() {
@@ -564,30 +649,43 @@ Page({
selectProduct(event) {
const selectedProduct = this.data.filteredProducts.find(item => String(item.id) === String(event.currentTarget.dataset.id)) || {}
const price = formatProductPrice(selectedProduct.price)
const productTag = resolveTagValue(this.data.tagOptions, parseProductTags(selectedProduct).join(','))
const imageUrls = Array.isArray(selectedProduct.imageUrls) ? selectedProduct.imageUrls : []
this.setData({
selectedProduct,
'form.productId': selectedProduct.id,
'form.manualProductTitle': '',
'form.productId': '',
'form.manualProductTitle': selectedProduct.title || '',
'form.manualProductPrice': price,
'form.manualProductDescription': '',
'form.manualProductTags': '',
'form.manualProductPrecautions': '',
'form.manualProductImageFileIds': '',
'form.manualProductImageUrl': '',
manualProductImageUrls: [],
manualProductPanelVisible: false,
'form.manualProductDescription': selectedProduct.description || '',
'form.manualProductTags': productTag,
'form.manualProductPrecautions': selectedProduct.precautions || '',
'form.manualProductImageFileIds': selectedProduct.imageFileIds || '',
'form.manualProductImageUrl': imageUrls.join(','),
manualProductImageUrls: imageUrls,
productModalVisible: false,
tagPickerIndex: resolveTagPickerIndex(this.data.tagOptions, productTag),
'form.durationMinutes': String(parseInt(selectedProduct.approximateDuration, 10) || this.data.form.durationMinutes || '')
})
this.closeProductModal()
this.refreshAvailableTimes()
this.checkAvailability()
},
onManualTagChange(event) {
const tag = this.data.tagOptions[Number(event.detail.value)]
if (!tag) {
return
}
this.setData({
tagPickerIndex: Number(event.detail.value),
'form.manualProductTags': tag.name
})
},
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' })
wx.showToast({ title: '请填写作品名称和价格', icon: 'none' })
return
}
this.setData({
@@ -31,10 +31,9 @@
</picker>
</view>
<view class="field">
<text class="field-label required">预约作品</text>
<text class="field-label required">选择作品</text>
<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>
<text>{{form.manualProductTitle || selectedProduct.title || '请选择作品'}}</text>
</view>
</view>
<view wx:if="{{form.productId || form.manualProductTitle}}" class="field">
@@ -98,18 +97,58 @@
<text class="tip-text">{{conflictTip}}</text>
</view>
<view wx:if="{{productModalVisible}}" class="modal-mask" bindtap="closeProductModal">
<view class="product-modal" catchtap="stopTap">
<view wx:if="{{manualProductPanelVisible}}" class="manual-mask" catchtap="stopTap">
<view class="manual-sheet" catchtap="stopTap">
<view class="manual-sheet-head">
<text class="manual-sheet-title">选择作品</text>
<view class="modal-close" bindtap="closeManualProductPanel">×</view>
</view>
<button class="secondary-btn template-entry-btn" bindtap="openProductTemplateSheet">使用已有作品模板</button>
<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>
<input class="manual-input-full" value="{{form.manualProductDescription}}" data-field="manualProductDescription" bindinput="onInput" placeholder="作品描述(选填)" />
<view class="manual-grid single">
<picker range="{{tagOptions}}" range-key="name" value="{{tagPickerIndex}}" bindchange="onManualTagChange" disabled="{{tagOptions.length === 0}}">
<view class="manual-picker {{form.manualProductTags ? '' : 'placeholder'}}">
<text>{{form.manualProductTags || (tagOptions.length ? '请选择标签' : '暂无标签')}}</text>
<text class="manual-picker-arrow">›</text>
</view>
</picker>
<input value="{{form.manualProductPrecautions}}" data-field="manualProductPrecautions" bindinput="onInput" placeholder="注意事项(选填)" />
</view>
<view wx:if="{{tagError}}" class="manual-tag-error">{{tagError}}</view>
<view class="manual-image-section">
<view class="manual-image-head">
<text class="manual-image-title">作品图片</text>
</view>
<view class="manual-image-list">
<view wx:for="{{manualProductImageUrls}}" wx:for-item="imageUrl" wx:key="*this" class="manual-image-item">
<image class="manual-image" src="{{imageUrl}}" mode="aspectFill"></image>
<view class="manual-image-remove" data-index="{{index}}" catchtap="removeManualProductImage">×</view>
</view>
<view class="manual-image-add {{manualImageUploading ? 'disabled' : ''}}" bindtap="chooseManualProductImage">
<text>{{manualImageUploading ? '...' : '+'}}</text>
</view>
</view>
</view>
<button class="secondary-btn manual-btn" bindtap="useManualProduct">保存内容</button>
</view>
</view>
<view wx:if="{{productModalVisible}}" class="modal-mask template-mask" catchtap="stopTap">
<view class="product-modal template-modal" catchtap="stopTap">
<view class="modal-head">
<view>
<text class="modal-title">选择预约作品</text>
<text class="modal-title">使用已有作品模板</text>
</view>
<view class="modal-close" bindtap="closeProductModal">×</view>
</view>
<input class="product-search" value="{{productKeyword}}" bindinput="onProductSearch" placeholder="搜索作品、标签、美甲师" />
<scroll-view class="product-list" scroll-y>
<view wx:if="{{productError}}" class="product-empty">{{productError}}</view>
<view wx:for="{{filteredProducts}}" wx:key="id" class="product-option {{form.productId == item.id ? 'active' : ''}}" data-id="{{item.id}}" bindtap="selectProduct">
<view wx:for="{{filteredProducts}}" wx:key="id" class="product-option" 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">
@@ -125,49 +164,6 @@
</view>
<view wx:if="{{!productError && filteredProducts.length === 0}}" class="product-empty">暂无匹配作品</view>
</scroll-view>
<view class="manual-entry-card">
<view>
<text class="manual-entry-title">没有合适作品?</text>
<text class="manual-entry-desc">临时新增一个预约作品,提交时会一并保存到预约信息。</text>
</view>
<button class="secondary-btn manual-entry-btn" bindtap="openManualProductPanel">新增作品</button>
</view>
</view>
<view wx:if="{{manualProductPanelVisible}}" class="manual-mask" catchtap="stopTap">
<view class="manual-sheet" catchtap="stopTap">
<view class="manual-sheet-head">
<view>
<text class="manual-sheet-title">新增预约作品</text>
<text class="manual-sheet-subtitle">填写本次预约使用的作品信息</text>
</view>
<view class="modal-close" bindtap="closeManualProductPanel">×</view>
</view>
<text class="manual-title required-label">手动新增预约作品</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>
<textarea class="manual-textarea" value="{{form.manualProductDescription}}" data-field="manualProductDescription" bindinput="onInput" placeholder="作品描述(选填)" />
<view class="manual-grid single">
<input value="{{form.manualProductTags}}" data-field="manualProductTags" bindinput="onInput" placeholder="标签,多个用逗号分隔(选填)" />
<input value="{{form.manualProductPrecautions}}" data-field="manualProductPrecautions" bindinput="onInput" placeholder="注意事项(选填)" />
</view>
<view class="manual-image-section">
<view class="manual-image-head">
<text class="manual-image-title">作品图片</text>
<text class="manual-image-desc">支持上传多张图片</text>
</view>
<view class="manual-image-list">
<view wx:for="{{manualProductImageUrls}}" wx:for-item="imageUrl" wx:key="*this" class="manual-image-item">
<image class="manual-image" src="{{imageUrl}}" mode="aspectFill"></image>
<view class="manual-image-remove" data-index="{{index}}" catchtap="removeManualProductImage">×</view>
</view>
<view wx:if="{{manualProductImageUrls.length === 0}}" class="manual-image-empty">图</view>
</view>
<button class="secondary-btn image-btn" loading="{{manualImageUploading}}" disabled="{{manualImageUploading}}" bindtap="chooseManualProductImage">上传图片</button>
</view>
<button class="secondary-btn manual-btn" bindtap="useManualProduct">确认新增</button>
</view>
</view>
</view>
@@ -277,6 +277,14 @@
box-shadow: 0 -18rpx 40rpx rgba(41, 31, 23, 0.16);
}
.template-mask {
z-index: 100;
}
.template-modal {
max-height: 76vh;
}
.time-modal {
width: 100%;
max-height: 82vh;
@@ -583,6 +591,13 @@
max-width: 196rpx;
}
.template-entry-btn {
width: 100%;
min-width: 0;
max-width: 100%;
margin-bottom: 18rpx;
}
.manual-mask {
position: fixed;
inset: 0;
@@ -652,17 +667,54 @@
font-size: 26rpx;
}
.manual-textarea {
.manual-input-full {
width: 100%;
min-height: 120rpx;
height: 70rpx;
margin-top: 14rpx;
padding: 18rpx;
padding: 0 18rpx;
border-radius: 14rpx;
background: #fffaf4;
color: #302923;
font-size: 26rpx;
}
.manual-picker {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12rpx;
height: 70rpx;
padding: 0 18rpx;
border-radius: 14rpx;
background: #fffaf4;
color: #302923;
font-size: 26rpx;
}
.manual-picker.placeholder {
color: #aaa096;
}
.manual-picker text:first-child {
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.manual-picker-arrow {
flex: 0 0 auto;
color: #b78b63;
font-size: 34rpx;
line-height: 1;
}
.manual-tag-error {
margin-top: 10rpx;
color: #b86858;
font-size: 22rpx;
}
.manual-image-row {
display: none;
}
@@ -726,6 +778,25 @@
font-weight: 900;
}
.manual-image-add {
display: flex;
align-items: center;
justify-content: center;
width: 104rpx;
height: 104rpx;
border: 2rpx dashed #d5bfa9;
border-radius: 16rpx;
background: #fff8ef;
color: #b78b63;
font-size: 46rpx;
font-weight: 500;
line-height: 1;
}
.manual-image-add.disabled {
opacity: 0.55;
}
.manual-image-remove {
position: absolute;
top: -10rpx;