feat: 新增陪诊师列表与详情页,下单支持指定陪诊师

This commit is contained in:
lik
2026-11-10 15:13:59 +08:00
parent 6238f01346
commit d6d5cc732d
13 changed files with 853 additions and 3 deletions
+98
View File
@@ -0,0 +1,98 @@
const API = require('../../utils/api.js')
const PAGE_SIZE = 20
// 下单页与陪诊师列表共用的选择结果 key
const SELECTED_ATTENDANT_KEY = 'escort_selected_attendant'
Page({
data: {
attendants: [],
loading: false,
loadError: '',
hasMore: true,
selectMode: false
},
onLoad(options) {
const selectMode = String(options.select) === '1'
this.page = 1
this.setData({ selectMode })
wx.setNavigationBarTitle({ title: selectMode ? '选择陪诊师' : '陪诊师团队' })
this.loadAttendants(true)
},
async onPullDownRefresh() {
await this.loadAttendants(true)
wx.stopPullDownRefresh()
},
onReachBottom() {
if (this.data.hasMore && !this.data.loading) this.loadAttendants(false)
},
onRetry() {
this.loadAttendants(true)
},
async loadAttendants(reset) {
if (this.data.loading) return
if (reset) {
this.page = 1
this.setData({ attendants: [], hasMore: true, loadError: '' })
}
this.setData({ loading: true })
try {
const res = await API.escort.getAttendants({ page: this.page, pageSize: PAGE_SIZE })
if (!res || res.code !== 0) throw new Error((res && res.msg) || '加载失败')
const list = (res.data && res.data.attendants ? res.data.attendants : []).map(this.decorate)
this.setData({
attendants: reset ? list : this.data.attendants.concat(list),
hasMore: list.length >= PAGE_SIZE,
loadError: ''
})
this.page += 1
} catch (err) {
this.setData({ loadError: err.message || '加载失败,请稍后重试' })
} finally {
this.setData({ loading: false })
}
},
// 公示接口已脱敏,这里只补展示用字段,不再加工姓名
decorate(item) {
const name = item.name || ''
const specialties = item.specialties || []
const serviceAreas = item.serviceAreas || []
return {
...item,
initial: name.replace(/[**]/g, '').slice(0, 1) || '陪',
specialties: specialties.slice(0, 3),
areaText: serviceAreas.join('、')
}
},
goToDetail(e) {
const id = e.currentTarget.dataset.id
if (!id) return
const select = this.data.selectMode ? '&select=1' : ''
wx.navigateTo({ url: `/pages/escort/attendantdetail?id=${id}${select}` })
},
onSelect(e) {
const item = e.currentTarget.dataset.item
if (!item || !item.id) return
wx.setStorageSync(SELECTED_ATTENDANT_KEY, {
id: item.id,
name: item.name,
workYears: item.workYears || 0,
orderCount: item.orderCount || 0
})
wx.navigateBack()
},
// 选择模式下允许明确不指定,由平台抢单 / 指派
onSkip() {
wx.setStorageSync(SELECTED_ATTENDANT_KEY, { cleared: true })
wx.navigateBack()
}
})