优化:统一小程序业务引用选择交互
This commit is contained in:
@@ -8,7 +8,11 @@ Page({
|
||||
registrationTicket: '',
|
||||
applicationId: '',
|
||||
shopOptions: [],
|
||||
shopIndex: 0,
|
||||
shopSelectorItems: [],
|
||||
shopSheetVisible: false,
|
||||
shopKeyword: '',
|
||||
shopLoading: false,
|
||||
shopError: '',
|
||||
selectedShopName: '',
|
||||
loading: false,
|
||||
ticketInvalid: false
|
||||
@@ -21,17 +25,26 @@ Page({
|
||||
applicationId: options && options.applicationId ? options.applicationId : '',
|
||||
ticketInvalid: !registrationTicket
|
||||
})
|
||||
await this.loadShops()
|
||||
},
|
||||
|
||||
async loadShops() {
|
||||
this.setData({ shopLoading: true, shopError: '' })
|
||||
try {
|
||||
const shops = await authApi.getAvailableRegistrationShops()
|
||||
const shopOptions = (Array.isArray(shops) ? shops : []).map(item => ({
|
||||
id: item.id,
|
||||
name: item.shopName || item.name,
|
||||
address: item.address || ''
|
||||
}))
|
||||
this.setData({
|
||||
shopOptions: (Array.isArray(shops) ? shops : []).map(item => ({
|
||||
id: item.id,
|
||||
name: item.shopName || item.name,
|
||||
address: item.address || ''
|
||||
}))
|
||||
shopOptions,
|
||||
shopSelectorItems: this.filterShops(shopOptions, this.data.shopKeyword)
|
||||
})
|
||||
} catch (error) {
|
||||
this.setData({ shopOptions: [] })
|
||||
this.setData({ shopOptions: [], shopSelectorItems: [], shopError: error.message || '门店列表加载失败' })
|
||||
} finally {
|
||||
this.setData({ shopLoading: false })
|
||||
}
|
||||
},
|
||||
|
||||
@@ -39,10 +52,30 @@ Page({
|
||||
selectRole(event) { this.setData({ role: event.currentTarget.dataset.role }) },
|
||||
continueFromRole() { if (!this.data.ticketInvalid) this.setData({ step: 2 }) },
|
||||
|
||||
filterShops(shops, keywordValue) {
|
||||
const keyword = String(keywordValue || '').trim().toLowerCase()
|
||||
return (shops || [])
|
||||
.filter(item => !keyword || [item.name, item.address].some(value => String(value || '').toLowerCase().includes(keyword)))
|
||||
.map(item => ({ ...item, title: item.name || '未命名门店', subtitle: item.address || '暂无地址' }))
|
||||
},
|
||||
|
||||
openShopSheet() {
|
||||
this.setData({ shopSheetVisible: true, shopSelectorItems: this.filterShops(this.data.shopOptions, this.data.shopKeyword) })
|
||||
if (this.data.shopError) this.loadShops()
|
||||
},
|
||||
|
||||
closeShopSheet() {
|
||||
this.setData({ shopSheetVisible: false })
|
||||
},
|
||||
|
||||
onShopSearch(event) {
|
||||
const shopKeyword = event.detail.value
|
||||
this.setData({ shopKeyword, shopSelectorItems: this.filterShops(this.data.shopOptions, shopKeyword) })
|
||||
},
|
||||
|
||||
selectShop(event) {
|
||||
const index = Number(event.detail.value)
|
||||
const shop = this.data.shopOptions[index]
|
||||
if (shop) this.setData({ shopIndex: index, selectedShopName: shop.name, 'form.shopId': shop.id })
|
||||
const shop = event.detail.item
|
||||
if (shop) this.setData({ selectedShopName: shop.name, 'form.shopId': shop.id, shopSheetVisible: false })
|
||||
},
|
||||
|
||||
goBackStep() { this.setData({ step: 1 }) },
|
||||
|
||||
Reference in New Issue
Block a user