fix(salon): 完善预约草稿与表单重置
This commit is contained in:
@@ -34,7 +34,64 @@ Page({
|
||||
manualProductDraft: { title: '', price: '', durationMinutes: '60', description: '' },
|
||||
artists: [], artistOptions: [], products: [], productOptions: [], allCustomerOptions: [], customerOptions: [], productSelectorVisible: false, manualProductSheetVisible: false, artistSelectorVisible: false, customerSelectorVisible: false, loadingProducts: false, loadingArtists: false, loadingCustomers: false, manualImageUploading: false, submitting: false, productKeyword: '', artistKeyword: '', customerKeyword: '', productError: '', artistError: '', customerError: '', selectedArtistName: '', selectedProduct: {}, selectedProductTitle: '', selectedProductPriceText: '', manualProductTitleLength: 0, manualProductMoreVisible: false
|
||||
},
|
||||
onLoad(options = {}) { this.setData({ 'form.serviceDate': options.serviceDate || this.data.form.serviceDate, 'form.artistId': options.artistId || '' }); this.loadArtists(options.artistId); this.loadProducts(); this.loadCustomers() },
|
||||
onLoad(options = {}) { const serviceDate = options.serviceDate || this.data.form.serviceDate; const artistId = options.artistId || ''; this._entryDefaults = { serviceDate, artistId }; this.setData({ 'form.serviceDate': serviceDate, 'form.artistId': artistId }); this.loadArtists(options.artistId); this.loadProducts(); this.loadCustomers() },
|
||||
async resetForm() {
|
||||
if (this.data.submitting) return
|
||||
if (this.data.manualImageUploading) {
|
||||
wx.showToast({ title: '图片上传中,请稍后再恢复默认值', icon: 'none' })
|
||||
return
|
||||
}
|
||||
const result = await new Promise(resolve => wx.showModal({
|
||||
title: '恢复默认值',
|
||||
content: '将清除本次补录内容,但不会删除已上传图片文件。保留入口带入的日期和美甲师,确定继续吗?',
|
||||
cancelText: '继续填写',
|
||||
confirmText: '恢复默认',
|
||||
success: resolve,
|
||||
fail: () => resolve({ confirm: false })
|
||||
}))
|
||||
if (!result.confirm) return
|
||||
const defaults = this._entryDefaults || {}
|
||||
const artistId = defaults.artistId || ''
|
||||
const artist = this.data.artists.find(item => String(item.id) === String(artistId))
|
||||
this.setData({
|
||||
form: {
|
||||
serviceDate: defaults.serviceDate || dateUtil.formatDate(new Date()),
|
||||
serviceTime: '',
|
||||
artistId,
|
||||
productId: '',
|
||||
manualProductTitle: '',
|
||||
manualProductDescription: '',
|
||||
manualProductTags: '',
|
||||
manualProductTargetAudience: '',
|
||||
manualProductPrecautions: '',
|
||||
manualProductImageFileIds: '',
|
||||
manualProductImageUrl: '',
|
||||
manualProductImages: [],
|
||||
customerUserId: '',
|
||||
customerName: '',
|
||||
wechatId: '',
|
||||
phone: '',
|
||||
amount: '',
|
||||
durationMinutes: '60',
|
||||
status: 4,
|
||||
remark: ''
|
||||
},
|
||||
manualProductDraft: { title: '', price: '', durationMinutes: '60', description: '' },
|
||||
selectedArtistName: artist ? artist.name : '',
|
||||
selectedProduct: {},
|
||||
selectedProductTitle: '',
|
||||
selectedProductPriceText: '',
|
||||
manualProductTitleLength: 0,
|
||||
manualProductMoreVisible: false,
|
||||
productKeyword: '',
|
||||
artistKeyword: '',
|
||||
customerKeyword: '',
|
||||
customerSelectorVisible: false,
|
||||
artistSelectorVisible: false,
|
||||
productSelectorVisible: false,
|
||||
manualProductSheetVisible: false
|
||||
})
|
||||
},
|
||||
async loadArtists(preferredArtistId) { this.setData({ loadingArtists: true }); try { const result = await employeesApi.list({ page: 1, size: 100 }); const list = result.list || result || []; const artists = list.map(item => ({ ...item, name: item.name || item.nickname || item.account || `美甲师${item.id}` })); const selected = artists.find(item => String(item.id) === String(preferredArtistId || this.data.form.artistId)); this.setData({ artists, artistOptions: artists.map(item => ({ id: item.id, title: item.name, subtitle: item.phone || '' })), selectedArtistName: selected ? selected.name : '', 'form.artistId': selected ? selected.id : '', artistError: '' }); this.refreshProductOptions() } catch (error) { this.setData({ artists: [], artistOptions: [], artistError: error.message || '美甲师加载失败' }) } finally { this.setData({ loadingArtists: false }) } },
|
||||
async loadProducts() { this.setData({ loadingProducts: true }); try { const result = await productsApi.list({ page: 1, size: 100 }); this.setData({ products: result.list || result || [], productError: '' }); this.refreshProductOptions() } catch (error) { this.setData({ products: [], productOptions: [], productError: error.message || '款式加载失败' }) } finally { this.setData({ loadingProducts: false }) } },
|
||||
refreshProductOptions() { const keyword = String(this.data.productKeyword || '').trim().toLowerCase(); const all = (this.data.products || []).map(product => normalizeProduct(product, this.data.artists)); this.setData({ productOptions: all.filter(item => !keyword || `${item.title} ${item.artistText} ${item.durationText} ${item.tagList.join(' ')}`.toLowerCase().includes(keyword)) }) },
|
||||
|
||||
Reference in New Issue
Block a user