feat(order): 订单池接单与共享入口,实习陪诊师只读

列表展示未分配/共享给我标记并新增接单按钮;详情页支持接单与共享给在职陪诊师,实习仅可查看脱敏信息。
This commit is contained in:
lik
2026-11-10 12:28:06 +08:00
parent 51b6ef497b
commit d70d9703ad
8 changed files with 473 additions and 24 deletions
+162 -11
View File
@@ -75,8 +75,10 @@ Page({
data: {
orderId: '',
loaded: false,
// 角色:管理员可查看档案与退款操作,陪诊员只看服务必需信息
// 角色:管理员可查看档案与退款操作,陪诊员按接单/共享关系展示操作
isAdmin: false,
isIntern: false,
canAcceptOrder: false,
// 订单数据
order: null,
// 格式化后的显示字段
@@ -97,6 +99,18 @@ Page({
completingRefund: false,
attendantSexText: '',
sexRequirementText: '',
// 接单 / 共享状态:未分配订单可从详情页接单,已接订单可共享给其他陪诊师
isPoolOrder: false,
assignedToMe: false,
sharedToMe: false,
desensitized: false,
showAcceptBtn: false,
showShareBtn: false,
// 共享弹窗
showSharePanel: false,
shareCandidates: [],
selectedShareIds: [],
sharing: false,
// 操作按钮配置
showConfirmBtn: false,
showCancelBtn: false,
@@ -108,9 +122,13 @@ Page({
onLoad(options) {
const id = options.id || ''
this.setData({ orderId: id })
// 先解析角色:详情页按角色决定是否读取档案、是否展示退款操作
role.ensureRole().then(r => {
this.setData({ isAdmin: r === 'admin' })
// 先解析角色:详情页按角色决定是否读取档案、是否展示退款与接单/共享操作
role.ensureRoleSafe().then(({ role: r, attendant }) => {
this.setData({
isAdmin: r === 'admin',
isIntern: Boolean(attendant && attendant.stage === 'intern'),
canAcceptOrder: Boolean(attendant && attendant.canAcceptOrder)
})
if (id) this.loadOrderDetail(id)
})
},
@@ -154,6 +172,12 @@ Page({
const escort = order.escort || {}
const meta = order.meta || {}
const isPoolOrder = !attendant.id
const assignedToMe = Boolean(order.attendantAssignedToMe)
const sharedToMe = Boolean(order.attendantSharedToMe)
// 管理员保持全量操作;陪诊师只能操作自己已接的订单
const canOperate = this.data.isAdmin || assignedToMe
this.setData({
loaded: true,
order: order,
@@ -182,14 +206,22 @@ Page({
completingRefund: false,
attendantSexText: attendant.sex === 'male' ? '男' : attendant.sex === 'female' ? '女' : '',
sexRequirementText: escort.sexRequirement === 'male' ? '要求男陪诊' : escort.sexRequirement === 'female' ? '要求女陪诊' : '不限',
// 操作按钮(任何状态下均可编辑订单信息)
showEditBtn: true,
showConfirmBtn: cancelStatus === 'none' && status === 'pending',
showCancelBtn: cancelStatus === 'requested'
|| (cancelStatus === 'none' && (status === 'pending' || status === 'confirmed')),
// 接单 / 共享:未分配订单正式陪诊师可接,已接订单仅接单本人可共享
isPoolOrder,
assignedToMe,
sharedToMe,
desensitized: Boolean(order.desensitized),
showAcceptBtn: !this.data.isAdmin && this.data.canAcceptOrder && isPoolOrder,
showShareBtn: !this.data.isAdmin && assignedToMe,
// 操作按钮:支付/状态流转仍只对已接订单开放
showEditBtn: this.data.isAdmin
|| (assignedToMe && status !== 'pending' && status !== 'cancelled'),
showConfirmBtn: canOperate && cancelStatus === 'none' && status === 'pending',
showCancelBtn: canOperate && (cancelStatus === 'requested'
|| (cancelStatus === 'none' && (status === 'pending' || status === 'confirmed'))),
cancelBtnText: cancelStatus === 'requested' ? '同意取消' : '取消订单',
showStartBtn: cancelStatus === 'none' && status === 'confirmed',
showCompleteBtn: cancelStatus === 'none' && status === 'in_progress'
showStartBtn: canOperate && cancelStatus === 'none' && status === 'confirmed',
showCompleteBtn: canOperate && cancelStatus === 'none' && status === 'in_progress'
})
},
@@ -219,6 +251,125 @@ Page({
})
},
// 接单:正式陪诊师把未分配订单接到自己名下
onAccept() {
wx.showModal({
title: '确认接单',
content: '接单后该订单将从其他陪诊师的未分配列表中移除,确认接单?',
confirmColor: '#C26A2E',
success: (res) => {
if (!res.confirm) return
wx.showLoading({ title: '接单中...' })
API.escort.acceptRecord(this.data.orderId)
.then(result => {
wx.hideLoading()
if (result.code !== 0) {
wx.showToast({ title: result.msg || '接单失败', icon: 'none' })
return
}
wx.showToast({ title: '接单成功', icon: 'success' })
this.loadOrderDetail(this.data.orderId)
})
.catch(err => {
wx.hideLoading()
console.error('接单失败', err)
wx.showToast({ title: '网络错误,请重试', icon: 'none' })
})
}
})
},
// 打开共享弹窗:候选为所有在职陪诊师(含实习),已共享的默认勾选
onShare() {
if (this.data.showSharePanel) return
wx.showLoading({ title: '加载中...' })
API.employee.getShareableAttendants()
.then(res => {
wx.hideLoading()
if (res.code !== 0) {
wx.showToast({ title: res.msg || '加载失败', icon: 'none' })
return
}
const sharedIds = this.data.order?.attendantSharedEmployeeIds || []
const candidates = (res.data?.attendants || []).map(item => ({
...item,
selected: sharedIds.indexOf(item.employeeId) > -1
}))
this.setData({
showSharePanel: true,
shareCandidates: candidates,
selectedShareIds: sharedIds.slice()
})
})
.catch(err => {
wx.hideLoading()
console.error('加载共享名单失败', err)
wx.showToast({ title: '网络错误,请重试', icon: 'none' })
})
},
onToggleShareTarget(e) {
const employeeId = e.currentTarget.dataset.id
const selected = this.data.selectedShareIds.slice()
const index = selected.indexOf(employeeId)
if (index > -1) selected.splice(index, 1)
else selected.push(employeeId)
this.setData({
selectedShareIds: selected,
shareCandidates: this.data.shareCandidates.map(item => ({
...item,
selected: selected.indexOf(item.employeeId) > -1
}))
})
},
onCloseShare() {
if (this.data.sharing) return
this.setData({ showSharePanel: false })
},
// 保存共享关系:新增调用 share,取消调用 unshare,最后刷新详情
onConfirmShare() {
if (this.data.sharing) return
const current = this.data.order?.attendantSharedEmployeeIds || []
const selected = this.data.selectedShareIds
const toAdd = selected.filter(id => current.indexOf(id) === -1)
const toRemove = current.filter(id => selected.indexOf(id) === -1)
if (toAdd.length === 0 && toRemove.length === 0) {
this.setData({ showSharePanel: false })
return
}
this.setData({ sharing: true })
wx.showLoading({ title: '保存中...' })
const tasks = []
if (toAdd.length) tasks.push(API.escort.shareRecord(this.data.orderId, { employeeIds: toAdd }))
if (toRemove.length) tasks.push(API.escort.unshareRecord(this.data.orderId, { employeeIds: toRemove }))
Promise.all(tasks)
.then(results => {
wx.hideLoading()
const failed = results.find(res => res.code !== 0)
if (failed) {
wx.showToast({ title: failed.msg || '保存失败', icon: 'none' })
return
}
wx.showToast({ title: '共享已更新', icon: 'success' })
this.setData({ showSharePanel: false })
this.loadOrderDetail(this.data.orderId)
})
.catch(err => {
wx.hideLoading()
console.error('更新共享失败', err)
wx.showToast({ title: '网络错误,请重试', icon: 'none' })
})
.finally(() => {
this.setData({ sharing: false })
})
},
noop() {},
// 编辑订单
onEdit() {
wx.navigateTo({