支持预约款式多图录入
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) {
|
||||
|
||||
Reference in New Issue
Block a user