fix(salon): 完善预约草稿与表单重置

This commit is contained in:
2026-10-31 23:03:13 +08:00
parent 5426df3ef2
commit e52e04685d
8 changed files with 619 additions and 46 deletions
+58 -1
View File
@@ -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)) }) },
@@ -20,7 +20,7 @@
<text wx:elif="{{form.manualProductImages.length}}" class="field-value">已添加 {{form.manualProductImages.length}} 张款式图片</text>
<text wx:else class="field-value placeholder">填写款式名称或添加图片</text>
<text wx:if="{{form.amount || form.durationMinutes}}" class="field-meta">{{form.amount || '待填'}} 元 · 预计 {{form.durationMinutes || '60'}} 分钟</text>
<text class="field-label">{{form.manualProductImages.length ? '已添加图片 · 点击可编辑' : '点击手动录入,提交后自动加入款式库'}}</text>
<text class="field-label">{{form.manualProductImages.length ? '已添加图片 · 点击可编辑' : '点击手动录入,提交后自动保存到本店款式库'}}</text>
</view>
<text class="chevron">›</text>
</button>
@@ -31,6 +31,7 @@
<button class="switch-manual-action" catchtap="openManualProduct">调整</button>
</view>
<text class="style-hint">名称和图片至少填写一项;名称未填时会使用客户姓名,未选择客户则使用“散客款式”。</text>
<text class="style-hint">手动录入款式在补录提交成功后自动保存到本店款式库,仅门店可见,不会公开展示。</text>
</view>
<view class="card form-card appointment-info-section">
@@ -66,6 +67,8 @@
<text class="style-hint">历史补单不校验美甲师排班,也不会占用预约时段。</text>
</view>
<view class="draft-tip card"><text>恢复默认值会清空本次填写,并保留入口日期和美甲师。</text><button class="text-btn draft-clear" bindtap="resetForm">恢复默认值</button></view>
<view class="fixed-bottom"><button class="primary-btn submit-btn" loading="{{submitting}}" disabled="{{submitting}}" bindtap="submit">保存历史补单</button></view>
<product-selector-sheet visible="{{productSelectorVisible}}" mode="list" title="选择已有款式" keyword="{{productKeyword}}" placeholder="搜索款式、标签、美甲师" items="{{productOptions}}" selected-id="{{form.productId}}" loading="{{loadingProducts}}" error-text="{{productError}}" empty-text="暂无匹配款式" show-manual-action="{{true}}" bind:search="searchProducts" bind:select="selectProduct" bind:openmanual="openManualProduct" bind:close="closeProductSelector" bind:retry="loadProducts" />