支持预约款式多图录入
This commit is contained in:
@@ -3,7 +3,7 @@ const productsApi = require('../../api/products')
|
||||
const customersApi = require('../../api/customers')
|
||||
const dateUtil = require('../../utils/date')
|
||||
const { markPlanningRefresh } = require('../../utils/planning-refresh')
|
||||
const { chooseImageFilePath, uploadObjectFile } = require('../../utils/upload')
|
||||
const { uploadObjectFile } = require('../../utils/upload')
|
||||
|
||||
const DRAFT_STORAGE_PREFIX = 'managerAppointmentDraft'
|
||||
const TIME_SLOT_MINUTES = 15
|
||||
@@ -64,6 +64,53 @@ function removeDraftForm() {
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeManualProductImages(form) {
|
||||
const savedImages = form && Array.isArray(form.manualProductImages) ? form.manualProductImages : null
|
||||
if (savedImages) {
|
||||
return savedImages.map(image => ({
|
||||
fileId: image && image.fileId !== undefined ? String(image.fileId) : '',
|
||||
fileUrl: image && (image.fileUrl || image.url) ? String(image.fileUrl || image.url) : ''
|
||||
})).filter(image => image.fileId).slice(0, 9)
|
||||
}
|
||||
const fileIds = String(form && form.manualProductImageFileIds || '').split(',').map(fileId => fileId.trim()).filter(Boolean)
|
||||
return fileIds.slice(0, 9).map((fileId, index) => ({
|
||||
fileId,
|
||||
fileUrl: index === 0 && form && form.manualProductImageUrl ? String(form.manualProductImageUrl) : ''
|
||||
}))
|
||||
}
|
||||
|
||||
function buildManualProductImagePatch(images) {
|
||||
const normalizedImages = (images || []).slice(0, 9)
|
||||
return {
|
||||
'form.manualProductImages': normalizedImages,
|
||||
'form.manualProductImageFileIds': normalizedImages.map(image => image.fileId).filter(Boolean).join(','),
|
||||
'form.manualProductImageUrl': normalizedImages[0] ? normalizedImages[0].fileUrl || '' : ''
|
||||
}
|
||||
}
|
||||
|
||||
function chooseManualProductImagePaths(count) {
|
||||
const normalizedCount = Math.min(9, Math.max(1, Math.floor(Number(count) || 1)))
|
||||
return new Promise((resolve, reject) => {
|
||||
wx.chooseMedia({
|
||||
count: normalizedCount,
|
||||
mediaType: ['image'],
|
||||
sourceType: ['album', 'camera'],
|
||||
sizeType: ['compressed'],
|
||||
success(result) {
|
||||
resolve((result.tempFiles || []).map(file => file && file.tempFilePath).filter(Boolean).slice(0, normalizedCount))
|
||||
},
|
||||
fail(error) {
|
||||
const message = error && error.errMsg ? error.errMsg : ''
|
||||
if (message.includes('cancel')) {
|
||||
resolve([])
|
||||
return
|
||||
}
|
||||
reject(new Error(`选择图片失败:${message || '未知错误'}`))
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function normalizeDuration(value) {
|
||||
const duration = Number(value)
|
||||
return Number.isFinite(duration) && duration > 0 ? Math.floor(duration) : 0
|
||||
@@ -414,6 +461,7 @@ Page({
|
||||
manualProductPrecautions: '',
|
||||
manualProductImageFileIds: '',
|
||||
manualProductImageUrl: '',
|
||||
manualProductImages: [],
|
||||
durationMinutes: '60',
|
||||
artistId: '',
|
||||
createCustomerRecord: false,
|
||||
@@ -440,6 +488,7 @@ Page({
|
||||
selectedArtist: {},
|
||||
productModalVisible: false,
|
||||
manualProductSheetVisible: false,
|
||||
manualProductMoreVisible: false,
|
||||
productKeyword: '',
|
||||
productError: '',
|
||||
loadingProducts: false,
|
||||
@@ -471,6 +520,7 @@ Page({
|
||||
const creatable = canCreateAppointment()
|
||||
const draftForm = creatable && !hasPresetOptions(options) ? readDraftForm() : null
|
||||
const baseForm = draftForm || {}
|
||||
const manualProductImages = normalizeManualProductImages(baseForm)
|
||||
const appointmentDate = options.date || baseForm.appointmentDate || dateUtil.formatDate(new Date())
|
||||
const dateLabels = buildAppointmentDateLabels(appointmentDate)
|
||||
this.setData({
|
||||
@@ -478,6 +528,9 @@ Page({
|
||||
form: {
|
||||
...this.data.form,
|
||||
...baseForm,
|
||||
manualProductImages,
|
||||
manualProductImageFileIds: manualProductImages.map(image => image.fileId).join(','),
|
||||
manualProductImageUrl: manualProductImages[0] ? manualProductImages[0].fileUrl : '',
|
||||
customerName: options.customerName ? decodeURIComponent(options.customerName) : (baseForm.customerName || ''),
|
||||
phone: options.phone ? decodeURIComponent(options.phone) : (baseForm.phone || ''),
|
||||
appointmentDate,
|
||||
@@ -621,8 +674,7 @@ Page({
|
||||
patch['form.productId'] = ''
|
||||
patch.selectedProduct = {}
|
||||
patch.selectedProductPriceText = ''
|
||||
patch['form.manualProductImageFileIds'] = ''
|
||||
patch['form.manualProductImageUrl'] = ''
|
||||
Object.assign(patch, buildManualProductImagePatch([]))
|
||||
}
|
||||
this.setData(patch)
|
||||
},
|
||||
@@ -822,7 +874,8 @@ Page({
|
||||
openManualProduct() {
|
||||
this.setData({
|
||||
productModalVisible: false,
|
||||
manualProductSheetVisible: true
|
||||
manualProductSheetVisible: true,
|
||||
manualProductMoreVisible: false
|
||||
})
|
||||
},
|
||||
|
||||
@@ -830,9 +883,13 @@ Page({
|
||||
this.setData({ manualProductSheetVisible: false })
|
||||
},
|
||||
|
||||
toggleManualProductMore() {
|
||||
this.setData({ manualProductMoreVisible: !this.data.manualProductMoreVisible })
|
||||
},
|
||||
|
||||
confirmManualProduct() {
|
||||
const hasTitle = Boolean(String(this.data.form.manualProductTitle || '').trim())
|
||||
const hasImage = Boolean(String(this.data.form.manualProductImageFileIds || '').trim())
|
||||
const hasImage = (this.data.form.manualProductImages || []).length > 0 || Boolean(String(this.data.form.manualProductImageFileIds || '').trim())
|
||||
const hasFallbackName = Boolean(String(this.data.form.customerName || '').trim())
|
||||
if (this.data.form.productId && !hasTitle && !hasImage) {
|
||||
this.closeManualProduct()
|
||||
@@ -876,6 +933,7 @@ Page({
|
||||
'form.manualProductPrecautions': '',
|
||||
'form.manualProductImageFileIds': '',
|
||||
'form.manualProductImageUrl': '',
|
||||
'form.manualProductImages': [],
|
||||
'form.amount': selectedProduct.price === undefined || selectedProduct.price === null ? '' : String(selectedProduct.price),
|
||||
'form.durationMinutes': String(selectedDuration || this.data.form.durationMinutes || '')
|
||||
})
|
||||
@@ -888,25 +946,35 @@ Page({
|
||||
if (this.data.manualImageUploading) {
|
||||
return
|
||||
}
|
||||
const remainingCount = 9 - (this.data.form.manualProductImages || []).length
|
||||
if (remainingCount <= 0) {
|
||||
wx.showToast({ title: '最多添加9张图片', icon: 'none' })
|
||||
return
|
||||
}
|
||||
try {
|
||||
const filePath = await chooseImageFilePath()
|
||||
if (!filePath) {
|
||||
this.setData({ manualImageUploading: true })
|
||||
const filePaths = await chooseManualProductImagePaths(remainingCount)
|
||||
if (!filePaths.length) {
|
||||
return
|
||||
}
|
||||
this.setData({ manualImageUploading: true })
|
||||
const uploadResult = await uploadObjectFile(filePath)
|
||||
const fileId = uploadResult.id || uploadResult.fileId
|
||||
const fileUrl = uploadResult.fileUrl || uploadResult.primaryUrl || filePath
|
||||
if (!fileId) {
|
||||
throw new Error('作品图片上传成功但未返回文件ID')
|
||||
for (const filePath of filePaths) {
|
||||
const uploadResult = await uploadObjectFile(filePath)
|
||||
const fileId = uploadResult.id || uploadResult.fileId
|
||||
const fileUrl = uploadResult.fileUrl || uploadResult.primaryUrl || filePath
|
||||
if (!fileId) {
|
||||
throw new Error('作品图片上传成功但未返回文件ID')
|
||||
}
|
||||
const images = (this.data.form.manualProductImages || []).concat({ fileId: String(fileId), fileUrl }).slice(0, 9)
|
||||
this.setData({
|
||||
...buildManualProductImagePatch(images),
|
||||
'form.productId': '',
|
||||
selectedProduct: {},
|
||||
selectedProductPriceText: ''
|
||||
})
|
||||
}
|
||||
if (filePaths.length > 1) {
|
||||
wx.showToast({ title: `已添加${filePaths.length}张图片`, icon: 'success' })
|
||||
}
|
||||
this.setData({
|
||||
'form.productId': '',
|
||||
selectedProduct: {},
|
||||
selectedProductPriceText: '',
|
||||
'form.manualProductImageFileIds': String(fileId),
|
||||
'form.manualProductImageUrl': fileUrl
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '图片上传失败', icon: 'none' })
|
||||
} finally {
|
||||
@@ -914,11 +982,16 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
removeManualProductImage() {
|
||||
this.setData({
|
||||
'form.manualProductImageFileIds': '',
|
||||
'form.manualProductImageUrl': ''
|
||||
})
|
||||
removeManualProductImage(event) {
|
||||
if (this.data.manualImageUploading) {
|
||||
return
|
||||
}
|
||||
const index = Number(event && event.currentTarget && event.currentTarget.dataset.index)
|
||||
const images = this.data.form.manualProductImages || []
|
||||
if (!Number.isInteger(index) || index < 0 || index >= images.length) {
|
||||
return
|
||||
}
|
||||
this.setData(buildManualProductImagePatch(images.filter((image, imageIndex) => imageIndex !== index)))
|
||||
},
|
||||
|
||||
filterArtistItems(artists, keywordValue) {
|
||||
|
||||
@@ -19,9 +19,9 @@
|
||||
<view wx:else class="field-icon">✦</view>
|
||||
<view class="field-text">
|
||||
<text wx:if="{{form.manualProductTitle}}" class="field-value">{{form.manualProductTitle}}</text>
|
||||
<text wx:elif="{{form.manualProductImageUrl}}" class="field-value">已添加款式图片</text>
|
||||
<text wx:elif="{{form.manualProductImages.length}}" class="field-value">已添加 {{form.manualProductImages.length}} 张款式图片</text>
|
||||
<text wx:else class="field-value placeholder">填写款式名称或添加图片</text>
|
||||
<text class="field-label">点击可手动录入,提交预约后自动加入款式库</text>
|
||||
<text class="field-label">{{form.manualProductImages.length ? '已添加 ' + form.manualProductImages.length + ' 张图片 · 点击可编辑' : '点击可手动录入,提交预约后自动加入款式库'}}</text>
|
||||
</view>
|
||||
<text class="chevron">›</text>
|
||||
</button>
|
||||
@@ -32,7 +32,7 @@
|
||||
<button class="switch-manual-action" catchtap="openManualProduct">手动录入</button>
|
||||
</view>
|
||||
<view class="style-number-row">
|
||||
<label class="number-field"><text class="field-label required">成交金额(元)</text><view class="number-input-wrap"><input type="digit" value="{{form.amount}}" data-field="amount" bindinput="onInput" placeholder="例如 268" /><text class="number-unit">元</text></view></label>
|
||||
<label wx:if="{{form.productId}}" class="number-field"><text class="field-label required">成交金额(元)</text><view class="number-input-wrap"><input type="digit" value="{{form.amount}}" data-field="amount" bindinput="onInput" placeholder="例如 268" /><text class="number-unit">元</text></view></label>
|
||||
<label class="number-field"><text class="field-label required">预计时长(分钟)</text><view class="number-input-wrap"><input type="number" value="{{form.durationMinutes}}" data-field="durationMinutes" bindinput="onInput" placeholder="60" /><text class="number-unit">分钟</text></view></label>
|
||||
</view>
|
||||
<view class="style-remark-field"><text class="field-label">款式备注</text><textarea value="{{form.remark}}" data-field="remark" bindinput="onInput" placeholder="可填写颜色、工艺、特殊要求等(可选)" /></view>
|
||||
@@ -86,15 +86,32 @@
|
||||
|
||||
<view wx:if="{{manualProductSheetVisible}}" class="modal-mask manual-product-mask" bindtap="closeManualProduct" catchtouchmove="stopTouchMove">
|
||||
<view class="manual-style-sheet" catchtap="stopTap" catchtouchmove="stopTouchMove">
|
||||
<view class="modal-head"><view><text class="modal-title">录入本次美甲款式</text><text class="modal-subtitle">名称或图片至少填写一项</text></view><view class="modal-close" bindtap="closeManualProduct" aria-label="关闭款式录入"></view></view>
|
||||
<view class="modal-head"><view><text class="modal-title">录入本次美甲款式</text><text class="modal-subtitle">名称或图片至少填写一项 · 可添加多张图片</text></view><view class="modal-close" bindtap="closeManualProduct" aria-label="关闭款式录入"></view></view>
|
||||
<scroll-view class="manual-style-content" scroll-y enhanced show-scrollbar="{{false}}">
|
||||
<view class="style-name-row">
|
||||
<input class="style-name-input" value="{{form.manualProductTitle}}" bindinput="onStyleTitleInput" placeholder="留空时默认使用客户姓名" />
|
||||
<button class="image-action" bindtap="chooseManualProductImage" loading="{{manualImageUploading}}">{{form.manualProductImageUrl ? '更换图片' : '添加图片'}}</button>
|
||||
<input class="style-price-input" type="digit" value="{{form.amount}}" data-field="amount" bindinput="onInput" placeholder="金额" />
|
||||
</view>
|
||||
<view wx:if="{{form.manualProductImageUrl}}" class="style-image-preview-row">
|
||||
<image class="style-image-preview" src="{{form.manualProductImageUrl}}" mode="aspectFill"></image>
|
||||
<button class="remove-image-action" bindtap="removeManualProductImage">移除图片</button>
|
||||
<view class="manual-style-images">
|
||||
<view class="manual-style-image-heading"><text>款式图片</text><text class="manual-style-image-count">{{form.manualProductImages.length}} / 9</text></view>
|
||||
<view class="manual-style-image-grid">
|
||||
<view wx:for="{{form.manualProductImages}}" wx:key="fileId" class="manual-style-image-tile">
|
||||
<image src="{{item.fileUrl}}" mode="aspectFill"></image>
|
||||
<text wx:if="{{index === 0}}" class="manual-style-image-cover">封面</text>
|
||||
<button class="manual-style-image-remove" data-index="{{index}}" disabled="{{manualImageUploading}}" catchtap="removeManualProductImage" aria-label="移除图片">×</button>
|
||||
</view>
|
||||
<button wx:if="{{form.manualProductImages.length < 9}}" class="manual-style-add-image" bindtap="chooseManualProductImage" loading="{{manualImageUploading}}" disabled="{{manualImageUploading}}"><text class="manual-style-add-icon">+</text><text>添加图片</text></button>
|
||||
</view>
|
||||
<text class="manual-style-image-tip">第一张图片会作为款式封面,后续图片可展示细节或顾客实拍。</text>
|
||||
</view>
|
||||
<view class="manual-style-more">
|
||||
<view class="manual-style-more-toggle" bindtap="toggleManualProductMore"><text>补充更多信息(选填)</text><text class="manual-style-more-arrow">{{manualProductMoreVisible ? '⌃' : '⌄'}}</text></view>
|
||||
<view wx:if="{{manualProductMoreVisible}}" class="manual-style-more-fields">
|
||||
<textarea value="{{form.manualProductDescription}}" data-field="manualProductDescription" bindinput="onInput" placeholder="款式描述" />
|
||||
<input value="{{form.manualProductTags}}" data-field="manualProductTags" bindinput="onInput" placeholder="标签,多个用逗号分隔" />
|
||||
<input value="{{form.manualProductTargetAudience}}" data-field="manualProductTargetAudience" bindinput="onInput" placeholder="适合人群" />
|
||||
<input value="{{form.manualProductPrecautions}}" data-field="manualProductPrecautions" bindinput="onInput" placeholder="注意事项" />
|
||||
</view>
|
||||
</view>
|
||||
<text class="manual-style-hint">没有填写名称时,会使用客户姓名;散客预约会使用“散客款式”。</text>
|
||||
</scroll-view>
|
||||
|
||||
@@ -478,8 +478,7 @@ button.link-action {
|
||||
width:auto;
|
||||
}
|
||||
|
||||
.style-name-row,
|
||||
.style-image-preview-row {
|
||||
.style-name-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14rpx;
|
||||
@@ -497,40 +496,18 @@ button.link-action {
|
||||
font-size: 26rpx;
|
||||
}
|
||||
|
||||
.image-action,
|
||||
.remove-image-action {
|
||||
flex: 0 0 auto;
|
||||
height: 72rpx;
|
||||
.style-price-input {
|
||||
box-sizing: border-box;
|
||||
width: 164rpx;
|
||||
height: 78rpx;
|
||||
flex: 0 0 164rpx;
|
||||
padding: 0 18rpx;
|
||||
border-radius: 14rpx;
|
||||
background: #e5f4ed;
|
||||
color: #247b63;
|
||||
font-size: 23rpx;
|
||||
line-height: 72rpx;
|
||||
}
|
||||
button.image-action {
|
||||
margin:0;
|
||||
width:auto;
|
||||
}
|
||||
|
||||
.style-image-preview-row {
|
||||
justify-content: flex-start;
|
||||
margin-top: 14rpx;
|
||||
}
|
||||
|
||||
.style-image-preview {
|
||||
width: 112rpx;
|
||||
height: 112rpx;
|
||||
border-radius: 14rpx;
|
||||
background: #e7ece9;
|
||||
}
|
||||
|
||||
.remove-image-action {
|
||||
height: 58rpx;
|
||||
background: #f3f7f4;
|
||||
color: #756e66;
|
||||
font-size: 21rpx;
|
||||
line-height: 58rpx;
|
||||
border: 1rpx solid #e7ece9;
|
||||
border-radius: 15rpx;
|
||||
background: #fff;
|
||||
color: #17211f;
|
||||
font-size: 26rpx;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.selected-style-note {
|
||||
@@ -1245,10 +1222,11 @@ button.full{
|
||||
}
|
||||
|
||||
.manual-style-sheet {
|
||||
box-sizing: border-box;
|
||||
display: flex;
|
||||
width: 100%;
|
||||
height: 70vh;
|
||||
max-height: 82vh;
|
||||
height: 88vh;
|
||||
max-height: 88vh;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
padding: 28rpx 28rpx calc(24rpx + env(safe-area-inset-bottom));
|
||||
@@ -1269,13 +1247,154 @@ button.full{
|
||||
background: #fbfdfc;
|
||||
}
|
||||
|
||||
.manual-style-content .image-action {
|
||||
height: 82rpx;
|
||||
border-radius: 24rpx;
|
||||
background: #e5f4ed;
|
||||
.manual-style-images {
|
||||
margin-top: 28rpx;
|
||||
}
|
||||
|
||||
.manual-style-image-heading {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
color: #52645d;
|
||||
font-size: 23rpx;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.manual-style-image-count {
|
||||
color: #247b63;
|
||||
font-size: 21rpx;
|
||||
line-height: 82rpx;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.manual-style-image-grid {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-between;
|
||||
margin-top: 16rpx;
|
||||
}
|
||||
|
||||
.manual-style-image-tile,
|
||||
.manual-style-add-image {
|
||||
position: relative;
|
||||
box-sizing: border-box;
|
||||
width: calc((100% - 24rpx) / 3);
|
||||
height: 206rpx;
|
||||
margin: 0 0 12rpx;
|
||||
overflow: hidden;
|
||||
border-radius: 20rpx;
|
||||
}
|
||||
|
||||
.manual-style-image-tile image {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: #eaf2ee;
|
||||
}
|
||||
|
||||
.manual-style-image-cover {
|
||||
position: absolute;
|
||||
bottom: 10rpx;
|
||||
left: 10rpx;
|
||||
padding: 5rpx 10rpx;
|
||||
border-radius: 10rpx;
|
||||
background: rgba(23, 33, 31, 0.76);
|
||||
color: #fff;
|
||||
font-size: 19rpx;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
button.manual-style-image-remove {
|
||||
position: absolute;
|
||||
top: 10rpx;
|
||||
right: 10rpx;
|
||||
z-index: 1;
|
||||
width: 46rpx;
|
||||
height: 46rpx;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
border-radius: 50%;
|
||||
background: rgba(23, 33, 31, 0.68);
|
||||
color: #fff;
|
||||
font-size: 32rpx;
|
||||
line-height: 46rpx;
|
||||
}
|
||||
|
||||
button.manual-style-image-remove::after,
|
||||
button.manual-style-add-image::after {
|
||||
border: 0;
|
||||
}
|
||||
|
||||
button.manual-style-add-image {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 5rpx;
|
||||
padding: 0;
|
||||
border: 2rpx dashed #9ccdbb;
|
||||
background: #f2faf6;
|
||||
color: #247b63;
|
||||
font-size: 21rpx;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.manual-style-add-icon {
|
||||
font-size: 48rpx;
|
||||
font-weight: 300;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.manual-style-image-tip {
|
||||
display: block;
|
||||
margin-top: 2rpx;
|
||||
color: #71807a;
|
||||
font-size: 20rpx;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.manual-style-more {
|
||||
margin-top: 28rpx;
|
||||
border-top: 2rpx solid #e7ece9;
|
||||
}
|
||||
|
||||
.manual-style-more-toggle {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 24rpx 0 16rpx;
|
||||
color: #247b63;
|
||||
font-size: 22rpx;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.manual-style-more-arrow {
|
||||
color: #71807a;
|
||||
font-size: 26rpx;
|
||||
}
|
||||
|
||||
.manual-style-more-fields {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12rpx;
|
||||
padding-bottom: 8rpx;
|
||||
}
|
||||
|
||||
.manual-style-more-fields textarea,
|
||||
.manual-style-more-fields input {
|
||||
box-sizing: border-box;
|
||||
width: 100%;
|
||||
min-height: 78rpx;
|
||||
padding: 16rpx 18rpx;
|
||||
border: 2rpx solid #dce6e1;
|
||||
border-radius: 22rpx;
|
||||
background: #fbfdfc;
|
||||
color: #17211f;
|
||||
font-size: 22rpx;
|
||||
}
|
||||
|
||||
.manual-style-more-fields textarea {
|
||||
min-height: 130rpx;
|
||||
}
|
||||
|
||||
.manual-style-hint {
|
||||
|
||||
@@ -3,7 +3,31 @@ const assert = require('assert')
|
||||
let definition
|
||||
global.Page = value => { definition = value }
|
||||
const toastMessages = []
|
||||
global.wx = { showToast: options => toastMessages.push(options.title) }
|
||||
let selectedImagePaths = []
|
||||
let uploadResults = []
|
||||
let requestedImageCount = 0
|
||||
const uploadCalls = []
|
||||
const uploadModulePath = require.resolve('../../utils/upload')
|
||||
require.cache[uploadModulePath] = {
|
||||
id: uploadModulePath,
|
||||
filename: uploadModulePath,
|
||||
loaded: true,
|
||||
exports: {
|
||||
uploadObjectFile: async filePath => {
|
||||
uploadCalls.push(filePath)
|
||||
const result = uploadResults.shift()
|
||||
if (result instanceof Error) throw result
|
||||
return result
|
||||
}
|
||||
}
|
||||
}
|
||||
global.wx = {
|
||||
showToast: options => toastMessages.push(options.title),
|
||||
chooseMedia(options) {
|
||||
requestedImageCount = options.count
|
||||
options.success({ tempFiles: selectedImagePaths.slice(0, options.count).map(tempFilePath => ({ tempFilePath })) })
|
||||
}
|
||||
}
|
||||
global.getApp = () => ({ globalData: { userInfo: { id: 1, shopId: 2, type: 2 } } })
|
||||
require('./index')
|
||||
|
||||
@@ -37,6 +61,11 @@ assert.strictEqual(page.data.form.durationMinutes, '90')
|
||||
|
||||
page.openManualProduct()
|
||||
assert.strictEqual(page.data.manualProductSheetVisible, true)
|
||||
assert.strictEqual(page.data.manualProductMoreVisible, false)
|
||||
page.toggleManualProductMore()
|
||||
assert.strictEqual(page.data.manualProductMoreVisible, true)
|
||||
page.toggleManualProductMore()
|
||||
assert.strictEqual(page.data.manualProductMoreVisible, false)
|
||||
page.confirmManualProduct()
|
||||
assert.strictEqual(page.data.form.productId, 8)
|
||||
assert.strictEqual(page.data.manualProductSheetVisible, false)
|
||||
@@ -65,7 +94,76 @@ assert.match(wxml, /placeholder="留空时默认使用客户姓名"/)
|
||||
assert.match(wxml, /appointmentDateBadge/)
|
||||
assert.match(wxml, /class="customer-fields"/)
|
||||
assert.match(wxml, /class="manual-style-sheet"/)
|
||||
assert.match(wxml, /class="style-price-input"[^>]*data-field="amount"/)
|
||||
assert.match(wxml, /wx:if="\{\{form\.productId\}\}" class="number-field"/)
|
||||
assert.match(wxml, /class="manual-style-more-toggle" bindtap="toggleManualProductMore"/)
|
||||
assert.match(wxml, /data-field="manualProductDescription" bindinput="onInput"/)
|
||||
assert.match(wxml, /bind:openmanual="openManualProduct"/)
|
||||
assert.match(wxml, /show-manual-action="\{\{true\}\}"/)
|
||||
assert.match(wxml, /成交金额/)
|
||||
assert.match(wxml, /wx:for="\{\{form\.manualProductImages\}\}"/)
|
||||
assert.match(wxml, /manualProductImages\.length < 9/)
|
||||
assert.match(wxml, /data-index="\{\{index\}\}"[^>]*catchtap="removeManualProductImage"/)
|
||||
assert.match(wxml, /manualProductImages\.length\}\} \/ 9/)
|
||||
|
||||
async function testManualProductImages() {
|
||||
selectedImagePaths = ['/tmp/style-1.jpg', '/tmp/style-2.jpg', '/tmp/style-3.jpg']
|
||||
uploadResults = [
|
||||
{ id: 11, fileUrl: 'https://img.example/1.jpg' },
|
||||
{ id: 12, fileUrl: 'https://img.example/2.jpg' },
|
||||
{ id: 13, fileUrl: 'https://img.example/3.jpg' }
|
||||
]
|
||||
await page.chooseManualProductImage()
|
||||
assert.strictEqual(requestedImageCount, 9)
|
||||
assert.deepStrictEqual(uploadCalls.slice(-3), selectedImagePaths)
|
||||
assert.deepStrictEqual(page.data.form.manualProductImages, [
|
||||
{ fileId: '11', fileUrl: 'https://img.example/1.jpg' },
|
||||
{ fileId: '12', fileUrl: 'https://img.example/2.jpg' },
|
||||
{ fileId: '13', fileUrl: 'https://img.example/3.jpg' }
|
||||
])
|
||||
assert.strictEqual(page.data.form.manualProductImageFileIds, '11,12,13')
|
||||
assert.strictEqual(page.data.form.manualProductImageUrl, 'https://img.example/1.jpg')
|
||||
|
||||
page.removeManualProductImage({ currentTarget: { dataset: { index: 0 } } })
|
||||
assert.strictEqual(page.data.form.manualProductImageFileIds, '12,13')
|
||||
assert.strictEqual(page.data.form.manualProductImageUrl, 'https://img.example/2.jpg')
|
||||
|
||||
page.data.form.manualProductImages = Array.from({ length: 8 }, (_, index) => ({ fileId: String(index + 20), fileUrl: `https://img.example/${index + 20}.jpg` }))
|
||||
selectedImagePaths = ['/tmp/style-9.jpg', '/tmp/ignored.jpg']
|
||||
uploadResults = [{ id: 28, fileUrl: 'https://img.example/28.jpg' }]
|
||||
await page.chooseManualProductImage()
|
||||
assert.strictEqual(requestedImageCount, 1)
|
||||
assert.strictEqual(page.data.form.manualProductImages.length, 9)
|
||||
|
||||
page.data.form.manualProductImages = []
|
||||
selectedImagePaths = ['/tmp/style-partial-1.jpg', '/tmp/style-partial-2.jpg']
|
||||
uploadResults = [{ id: 29, fileUrl: 'https://img.example/29.jpg' }, new Error('第二张上传失败')]
|
||||
await page.chooseManualProductImage()
|
||||
assert.deepStrictEqual(page.data.form.manualProductImages, [
|
||||
{ fileId: '29', fileUrl: 'https://img.example/29.jpg' }
|
||||
])
|
||||
assert.strictEqual(toastMessages.pop(), '第二张上传失败')
|
||||
|
||||
page.selectProduct({ detail: { item: { id: 9, title: '清透裸粉', price: 188, priceText: '¥188', approximateDuration: '60' } } })
|
||||
assert.deepStrictEqual(page.data.form.manualProductImages, [])
|
||||
assert.strictEqual(page.data.form.manualProductImageFileIds, '')
|
||||
|
||||
global.wx.getStorageSync = () => ({ form: {
|
||||
appointmentDate: '2026-10-21',
|
||||
manualProductImageFileIds: '44',
|
||||
manualProductImageUrl: 'https://img.example/legacy.jpg'
|
||||
} })
|
||||
const legacyDraftPage = createPage()
|
||||
legacyDraftPage.loadOptions = () => {}
|
||||
legacyDraftPage.onLoad({})
|
||||
assert.deepStrictEqual(legacyDraftPage.data.form.manualProductImages, [
|
||||
{ fileId: '44', fileUrl: 'https://img.example/legacy.jpg' }
|
||||
])
|
||||
assert.strictEqual(legacyDraftPage.data.form.manualProductImageFileIds, '44')
|
||||
}
|
||||
|
||||
testManualProductImages().catch(error => {
|
||||
console.error(error)
|
||||
process.exitCode = 1
|
||||
})
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
# Salon 新增预约多图款式录入设计
|
||||
|
||||
## 目标
|
||||
|
||||
在新建预约的手动美甲款式录入弹层中支持一次添加多张图片,并让图片顺序、封面和删除状态清晰可见。
|
||||
|
||||
## 交互
|
||||
|
||||
- 图片区使用三列九宫格,最多添加 9 张。
|
||||
- 名称和成交金额在同一行输入;成交金额复用预约既有字段,款式库项目仍可在主表单修改。
|
||||
- 录入弹层约 88% 屏高,补充描述、标签、适合人群和注意事项默认折叠。
|
||||
- 点击“添加图片”按剩余名额打开微信图片选择器,可从相册多选,也保留拍摄来源。
|
||||
- 图片按所选顺序上传;第一张图片自动作为款式封面,移除首图后下一张自动成为封面。
|
||||
- 每张图片可单独移除;达到 9 张后隐藏添加格。
|
||||
- 上传中的图片网格禁止重复添加和移除;上传失败时保留已成功上传的图片,提示失败原因。
|
||||
- 多图选择封装在预约页内,其他页面的共用单图选择和头像上传行为保持不变。
|
||||
- 款式标题、图片至少有一项;弹层关闭后保留未确认编辑,确认后回填预约表单。
|
||||
|
||||
## 数据兼容
|
||||
|
||||
- 前端以 `{ fileId, fileUrl }[]` 管理和恢复草稿中的图片。
|
||||
- 提交仍使用现有 `manualProductImageFileIds` 字符串字段,多个 ID 以逗号连接。
|
||||
- `manualProductImageUrl` 保留为第一张图片 URL,供预约页款式摘要和旧页面逻辑读取。
|
||||
- 旧草稿只有单个 ID/URL 时自动恢复为一张图片;后端产品字段本身支持逗号分隔图片 ID,不改接口或数据库。
|
||||
|
||||
## 验收
|
||||
|
||||
- 多张选择后顺序正确,图片预览、张数、封面标记及上传状态一致。
|
||||
- 移除任意图片后 ID 字符串同步更新,首图删除后封面顺延。
|
||||
- 剩余名额限制生效,最多 9 张;选中已有款式会清除手动录入图片。
|
||||
- 草稿兼容旧单图字段并支持保存、恢复新多图数组。
|
||||
- 员工头像和个人头像继续保持单图选择行为。
|
||||
@@ -242,3 +242,11 @@
|
||||
- 将 SIT Salon 的 `messagehub.client.access-token` 从 `core.yaml` 移到同命名空间的 `secret.yaml`,由 Nacos 配置中心在运行时提供。
|
||||
- 移除 SIT 发布工作流对 `MESSAGEHUB_SIT_ACCESS_TOKEN` Gitea Actions Secret 的读取,以及旧 systemd Token 覆盖文件的写入;部署时会清理历史覆盖文件。
|
||||
- Token 不写入本次提交,需由维护人员人工填入 SIT Salon `secret.yaml` 后再发布 Nacos;空值状态下 MessageHub 短信能力不可用。
|
||||
|
||||
## 2026-10-21 Salon 新增预约款式多图录入
|
||||
|
||||
- 新增预约的手动款式录入支持最多 9 张图片,采用三列图片网格展示并可单张移除。
|
||||
- 第一张图片作为款式封面;删除首图后自动切换下一张,添加名额按剩余数量限制。
|
||||
- 上传中的图片禁止重复操作,部分上传失败时保留已成功图片。
|
||||
- 草稿增加多图数组并兼容原有单图字段;提交仍使用逗号分隔的 `manualProductImageFileIds`,不改后端、数据库或 ArtList。
|
||||
- 新增设计文档 `docs/superpowers/specs/2026-10-21-salon新增预约多图款式录入-design.md`。
|
||||
|
||||
Reference in New Issue
Block a user