优化店务小程序规划视图与表单加载
This commit is contained in:
@@ -773,6 +773,8 @@ Page({
|
||||
customerError: '',
|
||||
products: [],
|
||||
filteredProducts: [],
|
||||
productsLoaded: false,
|
||||
productsLoading: false,
|
||||
artists: [],
|
||||
selectedProduct: {},
|
||||
selectedArtist: {},
|
||||
@@ -784,6 +786,8 @@ Page({
|
||||
productKeyword: '',
|
||||
productError: '',
|
||||
tagOptions: [],
|
||||
tagsLoaded: false,
|
||||
tagsLoading: false,
|
||||
tagPickerIndex: 0,
|
||||
tagError: '',
|
||||
conflictTip: '',
|
||||
@@ -818,7 +822,6 @@ Page({
|
||||
return
|
||||
}
|
||||
this.loadOptions()
|
||||
this.searchCustomers()
|
||||
wx.nextTick(() => {
|
||||
this.setData({ customerNameFocused: true })
|
||||
})
|
||||
@@ -841,34 +844,71 @@ Page({
|
||||
async loadOptions() {
|
||||
this.showPageMask('正在加载预约信息')
|
||||
try {
|
||||
try {
|
||||
const productsData = await productsApi.list({ page: 1, size: 100 })
|
||||
const products = productsData.list || productsData || []
|
||||
this.setData({ products, productError: '' })
|
||||
} catch (error) {
|
||||
this.setData({
|
||||
products: [],
|
||||
filteredProducts: [],
|
||||
productError: error.message || '作品列表加载失败'
|
||||
})
|
||||
}
|
||||
await this.loadTags()
|
||||
await this.loadArtists()
|
||||
this.refreshProductCards()
|
||||
await this.refreshAvailableTimes()
|
||||
this.refreshAvailableTimes()
|
||||
await this.checkAvailability(this.data.form.appointmentTime)
|
||||
} finally {
|
||||
this.hidePageMask()
|
||||
}
|
||||
},
|
||||
|
||||
ensureProductsLoaded() {
|
||||
if (this.data.productsLoaded) {
|
||||
return Promise.resolve()
|
||||
}
|
||||
if (this._productsLoadingPromise) {
|
||||
return this._productsLoadingPromise
|
||||
}
|
||||
this._productsLoadingPromise = this.loadProducts().finally(() => {
|
||||
this._productsLoadingPromise = null
|
||||
})
|
||||
return this._productsLoadingPromise
|
||||
},
|
||||
|
||||
async loadProducts() {
|
||||
this.setData({ productsLoading: true })
|
||||
try {
|
||||
const productsData = await productsApi.list({ page: 1, size: 100 })
|
||||
const products = productsData.list || productsData || []
|
||||
this.setData({
|
||||
products,
|
||||
productsLoaded: true,
|
||||
productError: ''
|
||||
})
|
||||
} catch (error) {
|
||||
this.setData({
|
||||
products: [],
|
||||
filteredProducts: [],
|
||||
productsLoaded: false,
|
||||
productError: error.message || '作品列表加载失败'
|
||||
})
|
||||
} finally {
|
||||
this.setData({ productsLoading: false })
|
||||
}
|
||||
},
|
||||
|
||||
ensureTagsLoaded() {
|
||||
if (this.data.tagsLoaded) {
|
||||
return Promise.resolve()
|
||||
}
|
||||
if (this._tagsLoadingPromise) {
|
||||
return this._tagsLoadingPromise
|
||||
}
|
||||
this._tagsLoadingPromise = this.loadTags().finally(() => {
|
||||
this._tagsLoadingPromise = null
|
||||
})
|
||||
return this._tagsLoadingPromise
|
||||
},
|
||||
|
||||
async loadTags() {
|
||||
this.setData({ tagsLoading: true })
|
||||
try {
|
||||
const tagsData = await tagsApi.listAll()
|
||||
const tagOptions = normalizeTagOptions(tagsData.list || tagsData || [])
|
||||
const selectedTag = resolveTagValue(tagOptions, this.data.form.manualProductTags)
|
||||
this.setData({
|
||||
tagOptions,
|
||||
tagsLoaded: true,
|
||||
tagPickerIndex: resolveTagPickerIndex(tagOptions, selectedTag),
|
||||
'form.manualProductTags': selectedTag,
|
||||
tagError: ''
|
||||
@@ -876,9 +916,12 @@ Page({
|
||||
} catch (error) {
|
||||
this.setData({
|
||||
tagOptions: [],
|
||||
tagsLoaded: false,
|
||||
tagPickerIndex: 0,
|
||||
tagError: error.message || '标签加载失败'
|
||||
})
|
||||
} finally {
|
||||
this.setData({ tagsLoading: false })
|
||||
}
|
||||
},
|
||||
|
||||
@@ -968,6 +1011,14 @@ Page({
|
||||
const form = this.data.form
|
||||
const sourceValue = preferredField === 'phone' ? form.phone : form.customerName || form.phone
|
||||
const keyword = String(sourceValue || '').trim()
|
||||
if (!keyword) {
|
||||
this.setData({
|
||||
customerOptions: [],
|
||||
customerError: '',
|
||||
customerLoading: false
|
||||
})
|
||||
return
|
||||
}
|
||||
this.setData({ customerLoading: true })
|
||||
try {
|
||||
const data = await customersApi.list({ keyword, page: 1, size: 20 })
|
||||
@@ -1047,15 +1098,21 @@ Page({
|
||||
wx.showToast({ title: '请先填写客户姓名', icon: 'none' })
|
||||
return
|
||||
}
|
||||
this.openManualProductPanel()
|
||||
void this.openManualProductPanel()
|
||||
},
|
||||
|
||||
openProductTemplateSheet() {
|
||||
this.setData({ productKeyword: '' })
|
||||
this.refreshProductCards()
|
||||
this.setData({
|
||||
productModalVisible: true
|
||||
})
|
||||
async openProductTemplateSheet() {
|
||||
this.showPageMask('正在加载作品库')
|
||||
try {
|
||||
await Promise.all([this.ensureProductsLoaded(), this.ensureTagsLoaded()])
|
||||
this.setData({ productKeyword: '' })
|
||||
this.refreshProductCards()
|
||||
this.setData({
|
||||
productModalVisible: true
|
||||
})
|
||||
} finally {
|
||||
this.hidePageMask()
|
||||
}
|
||||
},
|
||||
|
||||
closeProductModal() {
|
||||
@@ -1064,12 +1121,18 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
openManualProductPanel() {
|
||||
async openManualProductPanel() {
|
||||
const customerName = String(this.data.form.customerName || '').trim()
|
||||
if (!customerName) {
|
||||
wx.showToast({ title: '请先填写客户姓名', icon: 'none' })
|
||||
return
|
||||
}
|
||||
this.showPageMask('正在加载作品设置')
|
||||
try {
|
||||
await this.ensureTagsLoaded()
|
||||
} finally {
|
||||
this.hidePageMask()
|
||||
}
|
||||
const imageUrls = this.data.manualProductImageUrls.length > 0
|
||||
? this.data.manualProductImageUrls
|
||||
: splitManualImageValues(this.data.form.manualProductImageUrl)
|
||||
|
||||
@@ -84,21 +84,23 @@
|
||||
}
|
||||
|
||||
.price-field {
|
||||
align-items: flex-start;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.price-control {
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
flex-direction: column;
|
||||
gap: 12rpx;
|
||||
align-items: center;
|
||||
gap: 10rpx;
|
||||
}
|
||||
|
||||
.price-input,
|
||||
.manual-price-input {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex: 1 1 0;
|
||||
min-width: 0;
|
||||
min-height: 72rpx;
|
||||
padding-right: 16rpx;
|
||||
border: 1rpx solid #eadfd2;
|
||||
@@ -113,6 +115,8 @@
|
||||
}
|
||||
|
||||
.form-card .price-input input {
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
min-height: 70rpx;
|
||||
padding: 0 18rpx;
|
||||
border: 0;
|
||||
@@ -138,12 +142,23 @@
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.price-toggle {
|
||||
flex: 0 0 auto;
|
||||
gap: 4rpx;
|
||||
font-size: 22rpx;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.price-toggle switch,
|
||||
.manual-price-toggle switch {
|
||||
transform: scale(0.72);
|
||||
transform-origin: right center;
|
||||
}
|
||||
|
||||
.price-toggle switch {
|
||||
transform: scale(0.68);
|
||||
}
|
||||
|
||||
.customer-select {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user