Files
wxapp_escort/pages/escort/attendants.js
T
lik 6a2a5e7775 feat(attendant): 陪诊师列表展示性别
公示接口改为返回实名后,列表在从业年限前补充性别,便于用户下单前快速筛选。
2026-11-11 21:03:49 +08:00

100 lines
2.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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) || '陪',
sexText: { male: '男', female: '女' }[item.sex] || '',
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()
}
})