功能:优化Salon作品选择与历史补单
发布 Nacos 配置 / publish (push) Successful in 30s
环境分支晋级检查 / environment-promotion-source (pull_request_target) Successful in 1s

This commit is contained in:
2026-10-14 00:47:10 +08:00
parent 4101ab3408
commit 261723bc6e
29 changed files with 454 additions and 332 deletions
+49 -10
View File
@@ -5,33 +5,72 @@ const customersApi = require('../../api/customers')
const dateUtil = require('../../utils/date')
Page({
data: { form: { serviceDate: dateUtil.formatDate(new Date()), manualProductTitle: '', amount: '', customerName: '', phone: '', serviceTime: '', status: 4, remark: '', artistId: '', productId: '', customerUserId: '' }, artists: [], artistOptions: [], allProductOptions: [], productOptions: [], customerOptions: [], allCustomerOptions: [], productSelectorVisible: false, artistSelectorVisible: false, customerSelectorVisible: false, loadingProducts: false, loadingArtists: false, loadingCustomers: false, productKeyword: '', artistKeyword: '', customerKeyword: '', productError: '', artistError: '', customerError: '', selectedArtistName: '', selectedProductTitle: '', submitting: false },
onLoad() { this.loadArtists(); this.loadProducts(); this.loadCustomers() },
async loadArtists() {
data: { form: { serviceDate: dateUtil.formatDate(new Date()), manualProductTitle: '', amount: '', customerName: '', phone: '', serviceTime: '', status: 4, remark: '', artistId: '', productId: '', customerUserId: '' }, manualProductDraft: { title: '', price: '' }, manualMoreExpanded: false, productSelectorMode: 'list', artists: [], artistOptions: [], allProductOptions: [], productOptions: [], customerOptions: [], allCustomerOptions: [], productSelectorVisible: false, artistSelectorVisible: false, customerSelectorVisible: false, loadingProducts: false, loadingArtists: false, loadingCustomers: false, productKeyword: '', artistKeyword: '', customerKeyword: '', productError: '', artistError: '', customerError: '', selectedArtistName: '', selectedProductTitle: '', selectedProductPriceText: '', submitting: false },
onLoad(options = {}) {
const serviceDate = options.serviceDate || this.data.form.serviceDate
const artistId = options.artistId || ''
this.setData({ 'form.serviceDate': serviceDate, 'form.artistId': artistId })
this.loadArtists(artistId); this.loadProducts(); this.loadCustomers()
},
async loadArtists(preferredArtistId) {
try {
const result = await employeesApi.list({ page: 1, size: 100 })
const list = result.list || result || []
const normalized = list.map(item => ({ ...item, name: item.name || item.nickname || item.account || `员工${item.id}` }))
this.setData({ artists: normalized, artistOptions: normalized.map(item => ({ id: item.id, title: item.name, subtitle: item.phone || '' })), selectedArtistName: '', 'form.artistId': '' })
const selected = normalized.find(item => String(item.id) === String(preferredArtistId || this.data.form.artistId))
this.setData({ artists: normalized, artistOptions: normalized.map(item => ({ id: item.id, title: item.name, subtitle: item.phone || '' })), selectedArtistName: selected ? selected.name : '', 'form.artistId': selected ? selected.id : '' })
this.refreshProductOptions()
} catch (error) { wx.showToast({ title: error.message || '员工加载失败', icon: 'none' }) }
},
async loadProducts() { this.setData({ loadingProducts: true }); try { const result = await productsApi.list({ page: 1, size: 100 }); const list = result.list || result || []; const options = list.map(item => ({ id: item.id, title: item.title, price: item.price, subtitle: item.price == null ? '' : `¥${item.price}` })); this.setData({ allProductOptions: options, productOptions: options, productError: '' }) } catch (error) { this.setData({ productError: error.message || '项目加载失败' }) } finally { this.setData({ loadingProducts: false }) } },
async loadProducts() { this.setData({ loadingProducts: true }); try { const result = await productsApi.list({ page: 1, size: 100 }); const list = result.list || result || []; this.setData({ products: list, productError: '' }); this.refreshProductOptions() } catch (error) { this.setData({ products: [], allProductOptions: [], productOptions: [], productError: error.message || '项目加载失败' }) } finally { this.setData({ loadingProducts: false }) } },
refreshProductOptions() {
const options = (this.data.products || []).map(item => {
const artistIds = String(item.bookableArtists || '').split(',').map(id => id.trim()).filter(Boolean)
const artistNames = artistIds.map(id => this.data.artists.find(artist => String(artist.id) === id)).filter(Boolean).map(artist => artist.name)
const tagList = Array.isArray(item.tagList) ? item.tagList : Array.isArray(item.tagInfos) ? item.tagInfos.map(tag => tag.tagName).filter(Boolean) : String(item.tags || '').split(/[;,,、]/).map(tag => tag.trim()).filter(Boolean)
return {
id: item.id,
title: item.title,
price: item.price,
priceText: item.price == null ? '价格待定' : `¥${item.price}`,
coverImage: Array.isArray(item.imageUrls) ? item.imageUrls[0] || '' : '',
durationText: item.approximateDuration || (item.serviceDurationMinutes ? `${item.serviceDurationMinutes}分钟` : '时长待定'),
artistText: artistIds.length ? artistNames.join('、') || `${artistIds.length}位员工可做` : '全部员工',
tagList: tagList.slice(0, 3)
}
})
const keyword = String(this.data.productKeyword || '').trim().toLowerCase()
this.setData({ allProductOptions: options, productOptions: options.filter(item => !keyword || `${item.title} ${item.artistText} ${item.tagList.join(' ')}`.toLowerCase().includes(keyword)) })
},
async loadCustomers() { this.setData({ loadingCustomers: true }); try { const result = await customersApi.list({ page: 1, size: 30 }); const list = result.list || result || []; const options = list.map(item => ({ id: item.id, title: item.nickname || item.name || item.account, subtitle: item.phone || item.contactPhone || '' })); this.setData({ allCustomerOptions: options, customerOptions: options, customerError: '' }) } catch (error) { this.setData({ customerError: error.message || '客户加载失败' }) } finally { this.setData({ loadingCustomers: false }) } },
openProductSelector() { this.setData({ productSelectorVisible: true }) },
closeProductSelector() { this.setData({ productSelectorVisible: false }) },
openProductSelector() { this.setData({ productSelectorVisible: true, productSelectorMode: 'list' }) },
closeProductSelector() { this.setData({ productSelectorVisible: false, productSelectorMode: 'list' }) },
openManualProduct() { this.setData({ productSelectorMode: 'manual', manualMoreExpanded: false }) },
backToProductList() { this.setData({ productSelectorMode: 'list' }) },
onManualProductInput(e) { this.setData({ [`manualProductDraft.${e.detail.field}`]: e.detail.value }) },
toggleManualProductMore() { this.setData({ manualMoreExpanded: !this.data.manualMoreExpanded }) },
openArtistSelector() { this.setData({ artistSelectorVisible: true }) },
closeArtistSelector() { this.setData({ artistSelectorVisible: false }) },
openCustomerSelector() { this.setData({ customerSelectorVisible: true }) },
closeCustomerSelector() { this.setData({ customerSelectorVisible: false }) },
searchProducts(e) { const keyword = String(e.detail.value || '').toLowerCase(); this.setData({ productKeyword: keyword, productOptions: this.data.allProductOptions.filter(item => !keyword || String(item.title).toLowerCase().includes(keyword)) }) },
searchProducts(e) { const keyword = String(e.detail.value || '').trim().toLowerCase(); this.setData({ productKeyword: keyword, productOptions: this.data.allProductOptions.filter(item => !keyword || `${item.title} ${item.artistText} ${item.tagList.join(' ')}`.toLowerCase().includes(keyword)) }) },
searchArtists(e) { const keyword = String(e.detail.value || '').toLowerCase(); this.setData({ artistKeyword: keyword, artistOptions: this.data.artists.map(item => ({ id: item.id, title: item.name, subtitle: item.phone || '' })).filter(item => !keyword || item.title.toLowerCase().includes(keyword)) }) },
searchCustomers(e) { const keyword = String(e.detail.value || '').toLowerCase(); this.setData({ customerKeyword: keyword, customerOptions: this.data.allCustomerOptions.filter(item => !keyword || String(item.title).toLowerCase().includes(keyword) || String(item.subtitle).includes(keyword)) }) },
selectProduct(e) { const item = e.detail.item; this.setData({ 'form.productId': item.id, selectedProductTitle: item.title, 'form.manualProductTitle': '', 'form.amount': item.price == null ? this.data.form.amount : String(item.price), productSelectorVisible: false }) },
selectProduct(e) { const item = e.detail.item; this.setData({ 'form.productId': item.id, selectedProductTitle: item.title, selectedProductPriceText: item.priceText || (item.price == null ? '价格待定' : `¥${item.price}`), 'form.manualProductTitle': '', manualProductDraft: { title: '', price: '' }, 'form.amount': item.price == null ? this.data.form.amount : String(item.price), productSelectorVisible: false, productSelectorMode: 'list' }) },
selectArtist(e) { const item = e.detail.item; this.setData({ 'form.artistId': item.id, selectedArtistName: item.title, artistSelectorVisible: false }) },
selectCustomer(e) { const item = e.detail.item; this.setData({ 'form.customerUserId': item.id, 'form.customerName': item.title, 'form.phone': item.subtitle, customerSelectorVisible: false }) },
useWalkIn() { this.setData({ 'form.customerUserId': '', 'form.customerName': '', 'form.phone': '', customerSelectorVisible: false }) },
onCustomerNameInput(e) { this.setData({ 'form.customerName': e.detail.value, 'form.customerUserId': '' }) },
onProductNameInput(e) { this.setData({ 'form.manualProductTitle': e.detail.value, 'form.productId': '', selectedProductTitle: '' }) },
useManualProduct() {
const title = String(this.data.manualProductDraft.title || '').trim()
const priceText = String(this.data.manualProductDraft.price === undefined ? '' : this.data.manualProductDraft.price).trim()
const price = Number(priceText)
if (!title || !priceText || !Number.isFinite(price) || price < 0) {
wx.showToast({ title: '请填写作品名称和价格', icon: 'none' })
return
}
this.setData({ 'form.productId': '', 'form.manualProductTitle': title, selectedProductTitle: '', selectedProductPriceText: `¥${price}`, 'form.amount': String(price), productSelectorVisible: false, productSelectorMode: 'list' })
},
onInput(e) { this.setData({ [`form.${e.currentTarget.dataset.field}`]: e.detail.value }) },
onDateChange(e) { this.setData({ 'form.serviceDate': e.detail.value }) },
onTimeChange(e) { this.setData({ 'form.serviceTime': e.detail.value }) },