优化店务预约作品快照与图片维护
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({
|
||||
|
||||
Reference in New Issue
Block a user