优化店务小程序预约作品交互
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
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user