100 lines
2.8 KiB
JavaScript
100 lines
2.8 KiB
JavaScript
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()
|
||
}
|
||
})
|