From d70d9703ad9c6773789da02f45fc78d6ab58557a Mon Sep 17 00:00:00 2001 From: lik Date: Tue, 10 Nov 2026 12:28:06 +0800 Subject: [PATCH] =?UTF-8?q?feat(order):=20=E8=AE=A2=E5=8D=95=E6=B1=A0?= =?UTF-8?q?=E6=8E=A5=E5=8D=95=E4=B8=8E=E5=85=B1=E4=BA=AB=E5=85=A5=E5=8F=A3?= =?UTF-8?q?=EF=BC=8C=E5=AE=9E=E4=B9=A0=E9=99=AA=E8=AF=8A=E5=B8=88=E5=8F=AA?= =?UTF-8?q?=E8=AF=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 列表展示未分配/共享给我标记并新增接单按钮;详情页支持接单与共享给在职陪诊师,实习仅可查看脱敏信息。 --- pages/order/index.js | 58 +++++++++++- pages/order/index.less | 24 +++++ pages/order/index.wxml | 21 ++++- pages/order/orderDetail.js | 173 ++++++++++++++++++++++++++++++++--- pages/order/orderDetail.wxml | 47 +++++++++- pages/order/orderDetail.wxss | 162 +++++++++++++++++++++++++++++++- utils/api.js | 6 ++ utils/role.js | 6 ++ 8 files changed, 473 insertions(+), 24 deletions(-) diff --git a/pages/order/index.js b/pages/order/index.js index c130ea6..52c29b0 100644 --- a/pages/order/index.js +++ b/pages/order/index.js @@ -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' }); + }); + }, + /** * 更新订单状态 */ diff --git a/pages/order/index.less b/pages/order/index.less index 86a769a..2f0b65f 100644 --- a/pages/order/index.less +++ b/pages/order/index.less @@ -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; diff --git a/pages/order/index.wxml b/pages/order/index.wxml index 693724c..cd3cf81 100644 --- a/pages/order/index.wxml +++ b/pages/order/index.wxml @@ -62,6 +62,10 @@ > + + 未分配 + 共享给我 + {{item.statusText}} @@ -113,28 +117,35 @@ 取消 接单 + 确认 开始服务 { - 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({ diff --git a/pages/order/orderDetail.wxml b/pages/order/orderDetail.wxml index 4d7cf86..a785f8c 100644 --- a/pages/order/orderDetail.wxml +++ b/pages/order/orderDetail.wxml @@ -9,11 +9,20 @@ - {{statusText}} + + {{statusText}} + 未分配 + 共享给我 + {{statusDesc}} + + + 实习陪诊师仅可查看脱敏信息,接单后可见完整资料 + + 患者信息 @@ -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 @@ - + 查询退款结果 确认已退款 + 共享给陪诊师 编辑订单 {{cancelBtnText}} + 接单 确认订单 开始服务 完成服务 + + + diff --git a/pages/order/orderDetail.wxss b/pages/order/orderDetail.wxss index 5c3fdf5..e7e209b 100644 --- a/pages/order/orderDetail.wxss +++ b/pages/order/orderDetail.wxss @@ -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; +} diff --git a/utils/api.js b/utils/api.js index b6d765d..7685a05 100644 --- a/utils/api.js +++ b/utils/api.js @@ -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'), }, // 陪诊师入驻申请:提交/查询本人只要求登录,审核接口仅管理员 diff --git a/utils/role.js b/utils/role.js index 02e4a10..8f7b491 100644 --- a/utils/role.js +++ b/utils/role.js @@ -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