feat(order): 订单池接单与共享入口,实习陪诊师只读
列表展示未分配/共享给我标记并新增接单按钮;详情页支持接单与共享给在职陪诊师,实习仅可查看脱敏信息。
This commit is contained in:
+54
-4
@@ -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' });
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* 更新订单状态
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user