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

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;