优化店务预约作品快照与图片维护
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user