优化店务小程序预约作品交互
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 { chooseImageFilePaths, uploadObjectFile } = require('../../utils/upload')
|
||||
|
||||
const DRAFT_STORAGE_PREFIX = 'managerAppointmentDraft'
|
||||
const TIME_SLOT_MINUTES = 15
|
||||
@@ -226,6 +226,13 @@ function normalizeProduct(product, artists) {
|
||||
}
|
||||
}
|
||||
|
||||
function splitManualImageValues(value) {
|
||||
return String(value || '')
|
||||
.split(',')
|
||||
.map(item => item.trim())
|
||||
.filter(Boolean)
|
||||
}
|
||||
|
||||
function isScheduleCoveringTime(schedule, form, startMinute, endMinute) {
|
||||
if (!schedule || String(schedule.artistId) !== String(form.artistId) || schedule.date !== form.appointmentDate) {
|
||||
return false
|
||||
@@ -284,6 +291,8 @@ Page({
|
||||
selectedProduct: {},
|
||||
selectedArtist: {},
|
||||
productModalVisible: false,
|
||||
manualProductPanelVisible: false,
|
||||
manualProductImageUrls: [],
|
||||
productKeyword: '',
|
||||
productError: '',
|
||||
conflictTip: '',
|
||||
@@ -313,6 +322,7 @@ Page({
|
||||
appointmentDate: options.date || baseForm.appointmentDate || dateUtil.formatDate(new Date()),
|
||||
artistId: options.artistId || baseForm.artistId || ''
|
||||
},
|
||||
manualProductImageUrls: splitManualImageValues(baseForm.manualProductImageUrl || ''),
|
||||
draftSavedAtText: draftForm ? '已恢复本机草稿' : ''
|
||||
})
|
||||
if (!creatable) {
|
||||
@@ -473,11 +483,34 @@ Page({
|
||||
|
||||
openProductModal() {
|
||||
this.refreshProductCards()
|
||||
this.setData({ productModalVisible: true })
|
||||
this.setData({
|
||||
productModalVisible: true,
|
||||
manualProductPanelVisible: false
|
||||
})
|
||||
},
|
||||
|
||||
closeProductModal() {
|
||||
this.setData({ productModalVisible: false })
|
||||
this.setData({
|
||||
productModalVisible: false,
|
||||
manualProductPanelVisible: false
|
||||
})
|
||||
},
|
||||
|
||||
openManualProductPanel() {
|
||||
const imageUrls = this.data.manualProductImageUrls.length > 0
|
||||
? this.data.manualProductImageUrls
|
||||
: splitManualImageValues(this.data.form.manualProductImageUrl)
|
||||
this.setData({
|
||||
manualProductPanelVisible: true,
|
||||
manualProductImageUrls: imageUrls
|
||||
})
|
||||
},
|
||||
|
||||
closeManualProductPanel() {
|
||||
if (this.data.manualImageUploading) {
|
||||
return
|
||||
}
|
||||
this.setData({ manualProductPanelVisible: false })
|
||||
},
|
||||
|
||||
stopTap() {
|
||||
@@ -501,6 +534,8 @@ Page({
|
||||
'form.manualProductPrecautions': '',
|
||||
'form.manualProductImageFileIds': '',
|
||||
'form.manualProductImageUrl': '',
|
||||
manualProductImageUrls: [],
|
||||
manualProductPanelVisible: false,
|
||||
'form.durationMinutes': String(parseInt(selectedProduct.approximateDuration, 10) || this.data.form.durationMinutes || '')
|
||||
})
|
||||
this.closeProductModal()
|
||||
@@ -519,7 +554,8 @@ Page({
|
||||
selectedProduct: {},
|
||||
'form.productId': '',
|
||||
'form.manualProductTitle': title,
|
||||
'form.manualProductPrice': String(price)
|
||||
'form.manualProductPrice': String(price),
|
||||
manualProductPanelVisible: false
|
||||
})
|
||||
this.closeProductModal()
|
||||
this.refreshAvailableTimes()
|
||||
@@ -530,21 +566,38 @@ Page({
|
||||
if (this.data.manualImageUploading) {
|
||||
return
|
||||
}
|
||||
const currentFileIds = splitManualImageValues(this.data.form.manualProductImageFileIds)
|
||||
const currentImageUrls = this.data.manualProductImageUrls.length > 0
|
||||
? this.data.manualProductImageUrls
|
||||
: splitManualImageValues(this.data.form.manualProductImageUrl)
|
||||
const remainingCount = 9 - currentFileIds.length
|
||||
if (remainingCount <= 0) {
|
||||
wx.showToast({ title: '最多上传 9 张作品图片', icon: 'none' })
|
||||
return
|
||||
}
|
||||
try {
|
||||
const filePath = await chooseImageFilePath()
|
||||
if (!filePath) {
|
||||
const filePaths = await chooseImageFilePaths(remainingCount)
|
||||
if (filePaths.length === 0) {
|
||||
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')
|
||||
const nextFileIds = currentFileIds.slice()
|
||||
const nextImageUrls = currentImageUrls.slice()
|
||||
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')
|
||||
}
|
||||
nextFileIds.push(String(fileId))
|
||||
nextImageUrls.push(fileUrl)
|
||||
}
|
||||
this.setData({
|
||||
'form.manualProductImageFileIds': String(fileId),
|
||||
'form.manualProductImageUrl': fileUrl
|
||||
'form.manualProductImageFileIds': nextFileIds.join(','),
|
||||
'form.manualProductImageUrl': nextImageUrls.join(','),
|
||||
manualProductImageUrls: nextImageUrls
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '图片上传失败', icon: 'none' })
|
||||
@@ -553,10 +606,26 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
removeManualProductImage() {
|
||||
removeManualProductImage(event) {
|
||||
const currentFileIds = splitManualImageValues(this.data.form.manualProductImageFileIds)
|
||||
const currentImageUrls = this.data.manualProductImageUrls.length > 0
|
||||
? this.data.manualProductImageUrls
|
||||
: splitManualImageValues(this.data.form.manualProductImageUrl)
|
||||
const index = Number(event.currentTarget.dataset.index)
|
||||
if (!Number.isInteger(index) || index < 0) {
|
||||
this.setData({
|
||||
'form.manualProductImageFileIds': '',
|
||||
'form.manualProductImageUrl': '',
|
||||
manualProductImageUrls: []
|
||||
})
|
||||
return
|
||||
}
|
||||
const nextFileIds = currentFileIds.filter((item, itemIndex) => itemIndex !== index)
|
||||
const nextImageUrls = currentImageUrls.filter((item, itemIndex) => itemIndex !== index)
|
||||
this.setData({
|
||||
'form.manualProductImageFileIds': '',
|
||||
'form.manualProductImageUrl': ''
|
||||
'form.manualProductImageFileIds': nextFileIds.join(','),
|
||||
'form.manualProductImageUrl': nextImageUrls.join(','),
|
||||
manualProductImageUrls: nextImageUrls
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
@@ -126,7 +126,23 @@
|
||||
</view>
|
||||
<view wx:if="{{!productError && filteredProducts.length === 0}}" class="product-empty">暂无匹配作品</view>
|
||||
</scroll-view>
|
||||
<view class="manual-panel">
|
||||
<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="作品名称" />
|
||||
@@ -138,13 +154,21 @@
|
||||
<input value="{{form.manualProductTargetAudience}}" data-field="manualProductTargetAudience" bindinput="onInput" placeholder="适合人群(选填)" />
|
||||
<input value="{{form.manualProductPrecautions}}" data-field="manualProductPrecautions" bindinput="onInput" placeholder="注意事项(选填)" />
|
||||
</view>
|
||||
<view class="manual-image-row">
|
||||
<image wx:if="{{form.manualProductImageUrl}}" class="manual-image" src="{{form.manualProductImageUrl}}" mode="aspectFill"></image>
|
||||
<view wx:else class="manual-image placeholder">图</view>
|
||||
<button class="secondary-btn image-btn" loading="{{manualImageUploading}}" bindtap="chooseManualProductImage">上传图片</button>
|
||||
<button wx:if="{{form.manualProductImageUrl}}" class="text-btn image-remove" bindtap="removeManualProductImage">移除</button>
|
||||
<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>
|
||||
<button class="secondary-btn manual-btn" bindtap="useManualProduct">确认新增</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -127,7 +127,11 @@
|
||||
}
|
||||
|
||||
.textarea-field {
|
||||
align-items: flex-start;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.textarea-field .field-label {
|
||||
align-self: center;
|
||||
}
|
||||
|
||||
.appointment-flags {
|
||||
@@ -500,11 +504,86 @@
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.manual-panel {
|
||||
margin-top: 12rpx;
|
||||
padding: 20rpx;
|
||||
.manual-entry-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 18rpx;
|
||||
margin-top: 18rpx;
|
||||
padding: 18rpx;
|
||||
border: 1rpx solid #eadfd2;
|
||||
border-radius: 18rpx;
|
||||
background: #fffdf8;
|
||||
}
|
||||
|
||||
.manual-entry-title,
|
||||
.manual-entry-desc,
|
||||
.manual-sheet-title,
|
||||
.manual-sheet-subtitle,
|
||||
.manual-image-title,
|
||||
.manual-image-desc {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.manual-entry-title {
|
||||
color: #302923;
|
||||
font-size: 26rpx;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.manual-entry-desc {
|
||||
margin-top: 8rpx;
|
||||
color: #8c8177;
|
||||
font-size: 22rpx;
|
||||
line-height: 1.45;
|
||||
}
|
||||
|
||||
.manual-entry-btn {
|
||||
flex: 0 0 auto;
|
||||
width: 196rpx;
|
||||
min-width: 196rpx;
|
||||
max-width: 196rpx;
|
||||
}
|
||||
|
||||
.manual-mask {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 90;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 38rpx 28rpx;
|
||||
background: rgba(18, 15, 12, 0.48);
|
||||
}
|
||||
|
||||
.manual-sheet {
|
||||
width: 100%;
|
||||
max-height: 86vh;
|
||||
overflow-y: auto;
|
||||
padding: 26rpx 24rpx calc(26rpx + env(safe-area-inset-bottom));
|
||||
border-radius: 28rpx;
|
||||
background: #f7efe7;
|
||||
box-shadow: 0 24rpx 54rpx rgba(41, 31, 23, 0.22);
|
||||
}
|
||||
|
||||
.manual-sheet-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 18rpx;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.manual-sheet-title {
|
||||
color: #27211d;
|
||||
font-size: 34rpx;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.manual-sheet-subtitle {
|
||||
margin-top: 8rpx;
|
||||
color: #8d8278;
|
||||
font-size: 23rpx;
|
||||
}
|
||||
|
||||
.manual-title {
|
||||
@@ -547,37 +626,94 @@
|
||||
}
|
||||
|
||||
.manual-image-row {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.manual-image-section {
|
||||
margin-top: 14rpx;
|
||||
padding: 16rpx;
|
||||
border-radius: 16rpx;
|
||||
background: #fffaf4;
|
||||
}
|
||||
|
||||
.manual-image-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14rpx;
|
||||
margin-top: 14rpx;
|
||||
justify-content: space-between;
|
||||
gap: 12rpx;
|
||||
margin-bottom: 14rpx;
|
||||
}
|
||||
|
||||
.manual-image-title {
|
||||
color: #4e4740;
|
||||
font-size: 24rpx;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.manual-image-desc {
|
||||
color: #958a7f;
|
||||
font-size: 22rpx;
|
||||
}
|
||||
|
||||
.manual-image-list {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 12rpx;
|
||||
}
|
||||
|
||||
.manual-image {
|
||||
flex: 0 0 auto;
|
||||
width: 92rpx;
|
||||
height: 92rpx;
|
||||
border-radius: 14rpx;
|
||||
display: block;
|
||||
width: 104rpx;
|
||||
height: 104rpx;
|
||||
border-radius: 16rpx;
|
||||
background: #efe5da;
|
||||
}
|
||||
|
||||
.manual-image.placeholder {
|
||||
.manual-image-item {
|
||||
position: relative;
|
||||
width: 104rpx;
|
||||
height: 104rpx;
|
||||
}
|
||||
|
||||
.manual-image-empty {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 104rpx;
|
||||
height: 104rpx;
|
||||
border-radius: 16rpx;
|
||||
background: #efe5da;
|
||||
color: #b79b82;
|
||||
font-size: 26rpx;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.manual-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;
|
||||
}
|
||||
|
||||
.image-btn {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
max-width: none;
|
||||
width: 100%;
|
||||
min-width: 100%;
|
||||
max-width: 100%;
|
||||
margin-top: 14rpx;
|
||||
}
|
||||
|
||||
.image-remove {
|
||||
flex: 0 0 auto;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.manual-btn {
|
||||
|
||||
Reference in New Issue
Block a user