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
+54 -4
View File
@@ -60,9 +60,11 @@ Page({
* 页面的初始数据
*/
data: {
// 角色:管理员可新增预约,陪诊员只看本人订单
// 角色:管理员可新增预约,陪诊员只看订单池/本人订单
role: '',
isAdmin: false,
// 实习陪诊师:能看到未分配订单,但不能接单
isIntern: false,
// 统计
stats: {
total: 0,
@@ -92,9 +94,13 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad(options) {
// 先解析角色:陪诊员走本人订单接口,管理员走全量接口
role.ensureRole().then(r => {
this.setData({ role: r, isAdmin: r === 'admin' })
// 先解析角色:陪诊员走订单池接口,管理员走全量接口
role.ensureRoleSafe().then(({ role: r, attendant }) => {
this.setData({
role: r,
isAdmin: r === 'admin',
isIntern: Boolean(attendant && attendant.stage === 'intern')
})
this.loadOrderList();
})
},
@@ -147,12 +153,21 @@ Page({
return orders.map(order => {
const age = calcAge(order.patient?.birth)
const displayStatus = resolveDisplayStatus(order)
// 接单/共享标记由服务端按身份计算;未分配 = attendant.id 为空
const isPoolOrder = Boolean(order.isPoolOrder)
const assignedToMe = Boolean(order.attendantAssignedToMe)
return {
...order,
displayStatus,
statusText: STATUS_MAP[displayStatus]?.text || displayStatus,
patientFirstChar: (order.patient?.name || '?')[0],
patientAgeText: age ? `${age}岁` : '',
isPoolOrder,
assignedToMe,
sharedToMe: Boolean(order.attendantSharedToMe),
canAccept: !this.data.isAdmin && !this.data.isIntern && isPoolOrder,
// 状态流转只对自己已接的订单开放,管理员保持全量可操作
canOperate: this.data.isAdmin || assignedToMe,
schedule: {
...order.schedule,
dateText: this.formatDate(order.schedule?.date)
@@ -276,6 +291,18 @@ Page({
const order = this.data.orderList.find(item => item._id === id);
if (!order) return;
if (action === 'accept') {
wx.showModal({
title: '确认接单',
content: '接单后该订单将从其他陪诊师的未分配列表中移除,确认接单?',
confirmColor: '#C26A2E',
success: (res) => {
if (res.confirm) this.acceptOrder(id);
}
});
return;
}
const isCancelRequest = action === 'cancel' && order.displayStatus === 'cancel_requested';
const actionMap = {
confirm: { title: '确认订单', content: '确认接受此订单?', nextStatus: 'confirmed' },
@@ -309,6 +336,29 @@ Page({
});
},
/**
* 接单:服务端会再次校验身份与订单是否已被接走
*/
acceptOrder(id) {
wx.showLoading({ title: '接单中...' });
API.escort.acceptRecord(id)
.then(res => {
wx.hideLoading();
if (res.code !== 0) {
wx.showToast({ title: res.msg || '接单失败', icon: 'none' });
this.refreshData();
return;
}
wx.showToast({ title: '接单成功', icon: 'success' });
this.refreshData();
})
.catch(err => {
console.error('接单失败', err);
wx.hideLoading();
wx.showToast({ title: '网络错误,请重试', icon: 'none' });
});
},
/**
* 更新订单状态
*/
+24
View File
@@ -223,6 +223,30 @@ page {
margin-bottom: 12rpx;
}
.card-tags {
display: flex;
align-items: center;
gap: 10rpx;
margin-right: auto;
}
.order-tag {
font-size: 20rpx;
padding: 4rpx 14rpx;
border-radius: 20rpx;
font-weight: 500;
}
.tag-pool {
background: #EEF3EE;
color: #5B7A5B;
}
.tag-shared {
background: #FBF0DC;
color: #A97712;
}
.order-no {
font-size: 24rpx;
color: @muted;
+16 -5
View File
@@ -62,6 +62,10 @@
>
<!-- 卡片头部 -->
<view class="card-top">
<view class="card-tags">
<text class="order-tag tag-pool" wx:if="{{item.isPoolOrder}}">未分配</text>
<text class="order-tag tag-shared" wx:if="{{item.sharedToMe}}">共享给我</text>
</view>
<view class="status-badge status-{{item.displayStatus}}">
<text>{{item.statusText}}</text>
</view>
@@ -113,28 +117,35 @@
<view class="action-area">
<view
class="action-btn btn-ghost"
wx:if="{{item.displayStatus === 'pending'}}"
wx:if="{{item.displayStatus === 'pending' && item.canOperate}}"
data-id="{{item._id}}"
data-action="cancel"
catchtap="onOrderAction"
>取消</view>
<view
class="action-btn btn-solid"
wx:if="{{item.displayStatus === 'pending'}}"
wx:if="{{item.canAccept}}"
data-id="{{item._id}}"
data-action="accept"
catchtap="onOrderAction"
>接单</view>
<view
class="action-btn btn-solid"
wx:if="{{item.displayStatus === 'pending' && item.canOperate}}"
data-id="{{item._id}}"
data-action="confirm"
catchtap="onOrderAction"
>确认</view>
<view
class="action-btn btn-solid"
wx:if="{{item.displayStatus === 'confirmed'}}"
wx:if="{{item.displayStatus === 'confirmed' && item.canOperate}}"
data-id="{{item._id}}"
data-action="start"
catchtap="onOrderAction"
>开始服务</view>
<view
class="action-btn btn-solid"
wx:if="{{item.displayStatus === 'in_progress'}}"
wx:if="{{item.displayStatus === 'in_progress' && item.canOperate}}"
data-id="{{item._id}}"
data-action="complete"
catchtap="onOrderAction"
@@ -142,7 +153,7 @@
<!-- 待取消订单:列表内可直接同意取消 -->
<view
class="action-btn btn-solid"
wx:if="{{item.displayStatus === 'cancel_requested'}}"
wx:if="{{item.displayStatus === 'cancel_requested' && item.canOperate}}"
data-id="{{item._id}}"
data-action="cancel"
catchtap="onOrderAction"
+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({
+44 -3
View File
@@ -9,11 +9,20 @@
<!-- 顶部状态栏 -->
<view class="status-header status-{{statusClass}}">
<view class="status-content">
<text class="status-text">{{statusText}}</text>
<view class="status-title-row">
<text class="status-text">{{statusText}}</text>
<text class="order-tag tag-pool" wx:if="{{isPoolOrder}}">未分配</text>
<text class="order-tag tag-shared" wx:if="{{sharedToMe}}">共享给我</text>
</view>
<text class="status-desc">{{statusDesc}}</text>
</view>
</view>
<!-- 实习陪诊师看未分配订单:服务端已脱敏 -->
<view class="tip-banner" wx:if="{{desensitized}}">
<text>实习陪诊师仅可查看脱敏信息,接单后可见完整资料</text>
</view>
<!-- 患者信息 -->
<view class="info-section">
<text class="section-title">患者信息</text>
@@ -25,7 +34,7 @@
snapshot="{{order.patient}}"
can-load-profile="{{isAdmin}}"
use-cache="{{false}}"
dial="{{true}}"
dial="{{!desensitized}}"
bind:call="callPhone"
bindtap="onProfileTap"
/>
@@ -193,14 +202,46 @@
</view>
<!-- 底部操作 -->
<view class="bottom-actions" wx:if="{{showEditBtn || showConfirmBtn || showCancelBtn || showStartBtn || showCompleteBtn || showQueryRefundBtn || showManualRefundBtn}}">
<view class="bottom-actions" wx:if="{{showEditBtn || showConfirmBtn || showCancelBtn || showStartBtn || showCompleteBtn || showQueryRefundBtn || showManualRefundBtn || showAcceptBtn || showShareBtn}}">
<view class="action-btn btn-ghost" wx:if="{{showQueryRefundBtn}}" bindtap="onQueryRefund">查询退款结果</view>
<view class="action-btn btn-ghost" wx:if="{{showManualRefundBtn}}" bindtap="onCompleteManualRefund">确认已退款</view>
<view class="action-btn btn-ghost" wx:if="{{showShareBtn}}" bindtap="onShare">共享给陪诊师</view>
<view class="action-btn btn-ghost" wx:if="{{showEditBtn}}" bindtap="onEdit">编辑订单</view>
<view class="action-btn btn-ghost" wx:if="{{showCancelBtn}}" bindtap="onCancel">{{cancelBtnText}}</view>
<view class="action-btn btn-solid" wx:if="{{showAcceptBtn}}" bindtap="onAccept">接单</view>
<view class="action-btn btn-solid" wx:if="{{showConfirmBtn}}" bindtap="onConfirm">确认订单</view>
<view class="action-btn btn-solid" wx:if="{{showStartBtn}}" bindtap="onStart">开始服务</view>
<view class="action-btn btn-solid" wx:if="{{showCompleteBtn}}" bindtap="onComplete">完成服务</view>
</view>
</block>
<!-- 共享弹窗:候选为在职陪诊师(含实习) -->
<view class="share-mask" wx:if="{{showSharePanel}}" catchtap="onCloseShare">
<view class="share-panel" catchtap="noop">
<view class="share-header">
<text class="share-title">共享给陪诊师</text>
<text class="share-close" catchtap="onCloseShare">关闭</text>
</view>
<scroll-view scroll-y class="share-list">
<view
class="share-item"
wx:for="{{shareCandidates}}"
wx:key="employeeId"
data-id="{{item.employeeId}}"
catchtap="onToggleShareTarget"
>
<view class="share-check {{item.selected ? 'checked' : ''}}">{{item.selected ? '✓' : ''}}</view>
<view class="share-meta">
<text class="share-name">{{item.name || '陪诊师'}}</text>
<text class="share-stage">{{item.stageText}}{{item.gradeText ? ' · ' + item.gradeText : ''}}</text>
</view>
</view>
<view class="share-empty" wx:if="{{shareCandidates.length === 0}}">暂无可共享的陪诊师</view>
</scroll-view>
<view class="share-actions">
<view class="share-btn ghost" catchtap="onCloseShare">取消</view>
<view class="share-btn solid" catchtap="onConfirmShare">保存({{selectedShareIds.length}})</view>
</view>
</view>
</view>
</view>
+161 -1
View File
@@ -275,12 +275,13 @@ page {
padding-bottom: calc(24rpx + env(safe-area-inset-bottom));
box-shadow: 0 -4rpx 24rpx rgba(0, 0, 0, 0.06);
display: flex;
flex-wrap: wrap;
gap: 20rpx;
z-index: 100;
}
.action-btn {
flex: 1;
flex: 1 1 200rpx;
padding: 24rpx 0;
border-radius: 28rpx;
font-size: 28rpx;
@@ -299,3 +300,162 @@ page {
color: #A3988B;
border: 1rpx solid #F0EAE2;
}
/* === 接单 / 共享标识 === */
.status-title-row {
display: flex;
align-items: center;
gap: 14rpx;
margin-bottom: 12rpx;
}
.status-title-row .status-text {
margin-bottom: 0;
}
.order-tag {
font-size: 20rpx;
padding: 4rpx 14rpx;
border-radius: 20rpx;
font-weight: 500;
}
.tag-pool {
background: rgba(255, 255, 255, 0.2);
color: #fff;
}
.tag-shared {
background: rgba(255, 255, 255, 0.2);
color: #fff;
}
.tip-banner {
margin: 24rpx 32rpx 0;
padding: 20rpx 24rpx;
border-radius: 20rpx;
background: #FBF0DC;
color: #A97712;
font-size: 24rpx;
line-height: 1.5;
}
/* === 共享弹窗 === */
.share-mask {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: rgba(0, 0, 0, 0.45);
z-index: 200;
display: flex;
align-items: flex-end;
}
.share-panel {
width: 100%;
max-height: 78vh;
background: #ffffff;
border-radius: 32rpx 32rpx 0 0;
padding: 32rpx 32rpx calc(32rpx + env(safe-area-inset-bottom));
display: flex;
flex-direction: column;
}
.share-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 24rpx;
}
.share-title {
font-size: 32rpx;
font-weight: 600;
color: #3A322B;
}
.share-close {
font-size: 26rpx;
color: #A3988B;
}
.share-list {
flex: 1;
max-height: 56vh;
}
.share-item {
display: flex;
align-items: center;
padding: 24rpx 8rpx;
border-bottom: 1rpx solid #F5EFE8;
}
.share-check {
width: 40rpx;
height: 40rpx;
border-radius: 50%;
border: 2rpx solid #D9CFC3;
margin-right: 24rpx;
font-size: 24rpx;
line-height: 40rpx;
text-align: center;
color: #fff;
}
.share-check.checked {
background: #C26A2E;
border-color: #C26A2E;
}
.share-meta {
display: flex;
flex-direction: column;
}
.share-name {
font-size: 28rpx;
color: #3A322B;
font-weight: 500;
}
.share-stage {
font-size: 22rpx;
color: #A3988B;
margin-top: 6rpx;
}
.share-empty {
padding: 60rpx 0;
text-align: center;
font-size: 26rpx;
color: #A3988B;
}
.share-actions {
display: flex;
gap: 20rpx;
margin-top: 24rpx;
}
.share-btn {
flex: 1;
padding: 24rpx 0;
border-radius: 28rpx;
font-size: 28rpx;
font-weight: 600;
text-align: center;
}
.share-btn.ghost {
background: #FAF6F1;
color: #A3988B;
border: 1rpx solid #F0EAE2;
}
.share-btn.solid {
background: #C26A2E;
color: #fff;
}
+6
View File
@@ -21,6 +21,10 @@ const API = {
updateRecord: (id, data) => request.put(`/health/escort-record/${id}`, data),
updateStatus: (id, data) => request.patch(`/health/escort-record/${id}/status`, data),
deleteRecord: (id) => request.delete(`/health/escort-record/${id}`),
// 陪诊师接单 / 共享 / 取消共享:可见范围与身份全部由服务端判定
acceptRecord: (id) => request.post(`/health/escort-record/${id}/accept`),
shareRecord: (id, data) => request.post(`/health/escort-record/${id}/share`, data),
unshareRecord: (id, data) => request.post(`/health/escort-record/${id}/unshare`, data),
// 退款回调丢失时的人工兜底:主动查询微信退款结果并补写终态
queryRefund: (id) => request.post(`/health/escort-record/${id}/refund/query`),
// 线下/人工退款完成后核销:确认已退款,把订单置为「已退款」
@@ -38,6 +42,8 @@ const API = {
// 当前账号的员工档案:登录即可访问,用于判定在职陪诊员身份
employee: {
getMe: () => request.get('/health/employee/me'),
// 共享订单时的陪诊师候选(在职陪诊师,含实习)
getShareableAttendants: () => request.get('/health/employee/shareable-attendants'),
},
// 陪诊师入驻申请:提交/查询本人只要求登录,审核接口仅管理员
+6
View File
@@ -184,6 +184,11 @@ function getRoleSync() {
return cachedRole
}
// 陪诊师阶段/等级快照(仅展示用),需先调用 ensureRole/ensureRoleSafe
function getAttendantSync() {
return cachedAttendant
}
/**
* 退出登录 / 清除缓存后重置,避免沿用上一个账号的角色
*/
@@ -236,6 +241,7 @@ module.exports = {
ensureRole,
ensureRoleSafe,
getRoleSync,
getAttendantSync,
resetRole,
queryOrders,
guardAdminPage