Compare commits
2
Commits
a6e308f034
...
0e648c19ba
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0e648c19ba | ||
|
|
8d38c90274 |
@@ -1,6 +1,14 @@
|
||||
// pages/home/index.js
|
||||
const API = require('../../utils/api.js')
|
||||
|
||||
// 取消与 status 解耦:展示状态优先取 cancelStatus
|
||||
function resolveDisplayStatus(order) {
|
||||
const cancelStatus = order?.cancelStatus || 'none'
|
||||
if (cancelStatus === 'cancelled') return 'cancelled'
|
||||
if (cancelStatus === 'requested') return 'cancel_requested'
|
||||
return order?.status || 'pending'
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
today: '',
|
||||
@@ -28,6 +36,7 @@ Page({
|
||||
statusMap: {
|
||||
pending: '待确认',
|
||||
confirmed: '已确认',
|
||||
cancel_requested: '待取消',
|
||||
in_progress: '进行中',
|
||||
completed: '已完成',
|
||||
cancelled: '已取消'
|
||||
@@ -136,6 +145,7 @@ Page({
|
||||
item.schedule.date = item.schedule.startTime
|
||||
? `${dateText} ${item.schedule.startTime}`
|
||||
: `${dateText} ${pad(d.getHours())}:${pad(d.getMinutes())}`;
|
||||
item.displayStatus = resolveDisplayStatus(item);
|
||||
return item;
|
||||
});
|
||||
this.setData({ recentOrders: records });
|
||||
|
||||
@@ -86,8 +86,8 @@
|
||||
<view class="order-line1">
|
||||
<text class="order-patient">{{item.patient.name}}</text>
|
||||
<text class="order-service">{{item.escort.serviceName}}</text>
|
||||
<view class="status-tag status-{{item.status}}">
|
||||
<text>{{statusMap[item.status] || item.status}}</text>
|
||||
<view class="status-tag status-{{item.displayStatus}}">
|
||||
<text>{{statusMap[item.displayStatus] || item.displayStatus}}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="order-line2">
|
||||
|
||||
+24
-7
@@ -23,6 +23,14 @@ const STATUS_FILTERS = [
|
||||
{ label: '已取消', value: 'cancelled', count: 0 }
|
||||
];
|
||||
|
||||
// 取消与 status 解耦:展示状态优先取 cancelStatus
|
||||
function resolveDisplayStatus(order) {
|
||||
const cancelStatus = order?.cancelStatus || 'none'
|
||||
if (cancelStatus === 'cancelled') return 'cancelled'
|
||||
if (cancelStatus === 'requested') return 'cancel_requested'
|
||||
return order?.status || 'pending'
|
||||
}
|
||||
|
||||
Page({
|
||||
|
||||
/**
|
||||
@@ -85,7 +93,7 @@ Page({
|
||||
};
|
||||
|
||||
orders.forEach(order => {
|
||||
switch (order.status) {
|
||||
switch (resolveDisplayStatus(order)) {
|
||||
case 'pending':
|
||||
stats.pending++;
|
||||
break;
|
||||
@@ -162,9 +170,11 @@ Page({
|
||||
processOrders(orders) {
|
||||
return orders.map(order => {
|
||||
const age = calcAge(order.patient?.birth)
|
||||
const displayStatus = resolveDisplayStatus(order)
|
||||
return {
|
||||
...order,
|
||||
statusText: STATUS_MAP[order.status]?.text || order.status,
|
||||
displayStatus,
|
||||
statusText: STATUS_MAP[displayStatus]?.text || displayStatus,
|
||||
patientFirstChar: (order.patient?.name || '?')[0],
|
||||
patientAgeText: age ? `${age}岁` : '',
|
||||
schedule: {
|
||||
@@ -188,7 +198,9 @@ Page({
|
||||
const params = {
|
||||
page,
|
||||
pageSize,
|
||||
status: 'pending,confirmed,in_progress,completed,cancelled'
|
||||
// 筛选在本页按展示状态完成,因此一次取回含已取消在内的全部订单
|
||||
status: 'pending,confirmed,in_progress,completed',
|
||||
includeCancelled: 1
|
||||
};
|
||||
|
||||
API.escort.getAllRecords(params)
|
||||
@@ -214,7 +226,7 @@ Page({
|
||||
|
||||
const { currentStatus } = this.data;
|
||||
const orderList = currentStatus
|
||||
? allOrders.filter(order => order.status === currentStatus)
|
||||
? allOrders.filter(order => order.displayStatus === currentStatus)
|
||||
: allOrders;
|
||||
total = orderList.length;
|
||||
|
||||
@@ -342,10 +354,15 @@ Page({
|
||||
|
||||
const orderList = this.data.orderList.map(order => {
|
||||
if (order._id === id) {
|
||||
// 取消只写 cancelStatus,status 保留取消前的服务状态
|
||||
const next = newStatus === 'cancelled'
|
||||
? { ...order, cancelStatus: 'cancelled', cancelledAt: new Date().toISOString() }
|
||||
: { ...order, status: newStatus }
|
||||
const displayStatus = resolveDisplayStatus(next)
|
||||
return {
|
||||
...order,
|
||||
status: newStatus,
|
||||
statusText: STATUS_MAP[newStatus]?.text || newStatus,
|
||||
...next,
|
||||
displayStatus,
|
||||
statusText: STATUS_MAP[displayStatus]?.text || displayStatus,
|
||||
'meta.updatetime': new Date().toISOString()
|
||||
};
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@
|
||||
>
|
||||
<!-- 卡片头部 -->
|
||||
<view class="card-top">
|
||||
<view class="status-badge status-{{item.status}}">
|
||||
<view class="status-badge status-{{item.displayStatus}}">
|
||||
<text>{{item.statusText}}</text>
|
||||
</view>
|
||||
</view>
|
||||
@@ -113,28 +113,28 @@
|
||||
<view class="action-area">
|
||||
<view
|
||||
class="action-btn btn-ghost"
|
||||
wx:if="{{item.status === 'pending'}}"
|
||||
wx:if="{{item.displayStatus === 'pending'}}"
|
||||
data-id="{{item._id}}"
|
||||
data-action="cancel"
|
||||
catchtap="onOrderAction"
|
||||
>取消</view>
|
||||
<view
|
||||
class="action-btn btn-solid"
|
||||
wx:if="{{item.status === 'pending'}}"
|
||||
wx:if="{{item.displayStatus === 'pending'}}"
|
||||
data-id="{{item._id}}"
|
||||
data-action="confirm"
|
||||
catchtap="onOrderAction"
|
||||
>确认</view>
|
||||
<view
|
||||
class="action-btn btn-solid"
|
||||
wx:if="{{item.status === 'confirmed'}}"
|
||||
wx:if="{{item.displayStatus === 'confirmed'}}"
|
||||
data-id="{{item._id}}"
|
||||
data-action="start"
|
||||
catchtap="onOrderAction"
|
||||
>开始服务</view>
|
||||
<view
|
||||
class="action-btn btn-solid"
|
||||
wx:if="{{item.status === 'in_progress'}}"
|
||||
wx:if="{{item.displayStatus === 'in_progress'}}"
|
||||
data-id="{{item._id}}"
|
||||
data-action="complete"
|
||||
catchtap="onOrderAction"
|
||||
|
||||
@@ -19,10 +19,19 @@ const STATUS_DESC_MAP = {
|
||||
cancelled: '订单已取消'
|
||||
}
|
||||
|
||||
// 取消与 status 解耦:展示状态优先取 cancelStatus
|
||||
function resolveDisplayStatus(order) {
|
||||
const cancelStatus = order?.cancelStatus || 'none'
|
||||
if (cancelStatus === 'cancelled') return 'cancelled'
|
||||
if (cancelStatus === 'requested') return 'cancel_requested'
|
||||
return order?.status || 'pending'
|
||||
}
|
||||
|
||||
const PAYMENT_STATUS_MAP = {
|
||||
unpaid: '未支付',
|
||||
partial: '部分支付',
|
||||
paid: '已支付',
|
||||
refunding: '退款中',
|
||||
refunded: '已退款'
|
||||
}
|
||||
|
||||
@@ -33,6 +42,12 @@ const PAYMENT_METHOD_MAP = {
|
||||
offline_transfer: '线下转账'
|
||||
}
|
||||
|
||||
// 支付渠道:用户下单时的选择,历史订单缺失按线下解释
|
||||
const PAY_CHANNEL_MAP = {
|
||||
online_wechat: '微信支付',
|
||||
offline: '线下支付'
|
||||
}
|
||||
|
||||
function formatDate(timestamp) {
|
||||
if (!timestamp) return ''
|
||||
const date = new Date(timestamp)
|
||||
@@ -72,6 +87,9 @@ Page({
|
||||
updatetimeText: '',
|
||||
paymentStatusText: '',
|
||||
paymentMethodText: '',
|
||||
payChannelText: '',
|
||||
showQueryRefundBtn: false,
|
||||
queryingRefund: false,
|
||||
attendantSexText: '',
|
||||
sexRequirementText: '',
|
||||
// 操作按钮配置
|
||||
@@ -121,7 +139,8 @@ Page({
|
||||
},
|
||||
|
||||
applyOrderData(order) {
|
||||
const status = order.status || 'pending'
|
||||
const cancelStatus = order.cancelStatus || 'none'
|
||||
const status = resolveDisplayStatus(order)
|
||||
const attendant = order.attendant || {}
|
||||
const schedule = order.schedule || {}
|
||||
const payment = order.payment || {}
|
||||
@@ -135,6 +154,7 @@ Page({
|
||||
healthProfileId: order.healthProfileId || '',
|
||||
statusText: STATUS_MAP[status] || status,
|
||||
statusDesc: STATUS_DESC_MAP[status] || '',
|
||||
statusClass: status,
|
||||
attendantFirstChar: (attendant.name || '?')[0],
|
||||
scheduleDateText: formatDate(schedule.date),
|
||||
scheduleStartTimeText: schedule.startTime || '',
|
||||
@@ -143,15 +163,20 @@ Page({
|
||||
updatetimeText: formatDateTime(meta.updatetime),
|
||||
paymentStatusText: PAYMENT_STATUS_MAP[payment.status] || payment.status || '未支付',
|
||||
paymentMethodText: PAYMENT_METHOD_MAP[payment.method] || '',
|
||||
payChannelText: PAY_CHANNEL_MAP[payment.payChannel || 'offline'] || '',
|
||||
// 退款回调丢失时由管理端主动查退款补写终态
|
||||
showQueryRefundBtn: payment.status === 'refunding',
|
||||
queryingRefund: false,
|
||||
attendantSexText: attendant.sex === 'male' ? '男' : attendant.sex === 'female' ? '女' : '',
|
||||
sexRequirementText: escort.sexRequirement === 'male' ? '要求男陪诊' : escort.sexRequirement === 'female' ? '要求女陪诊' : '不限',
|
||||
// 操作按钮(任何状态下均可编辑订单信息)
|
||||
showEditBtn: true,
|
||||
showConfirmBtn: status === 'pending',
|
||||
showCancelBtn: status === 'pending' || status === 'confirmed' || status === 'cancel_requested',
|
||||
cancelBtnText: status === 'cancel_requested' ? '同意取消' : '取消订单',
|
||||
showStartBtn: status === 'confirmed',
|
||||
showCompleteBtn: status === 'in_progress'
|
||||
showConfirmBtn: cancelStatus === 'none' && status === 'pending',
|
||||
showCancelBtn: cancelStatus === 'requested'
|
||||
|| (cancelStatus === 'none' && (status === 'pending' || status === 'confirmed')),
|
||||
cancelBtnText: cancelStatus === 'requested' ? '同意取消' : '取消订单',
|
||||
showStartBtn: cancelStatus === 'none' && status === 'confirmed',
|
||||
showCompleteBtn: cancelStatus === 'none' && status === 'in_progress'
|
||||
})
|
||||
},
|
||||
|
||||
@@ -240,6 +265,33 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
// 主动查询退款结果:退款回调丢失时补写终态
|
||||
async onQueryRefund() {
|
||||
if (this.data.queryingRefund) return
|
||||
this.setData({ queryingRefund: true })
|
||||
wx.showLoading({ title: '查询中...' })
|
||||
try {
|
||||
const res = await API.escort.queryRefund(this.data.orderId)
|
||||
wx.hideLoading()
|
||||
if (res.code !== 0) {
|
||||
wx.showToast({ title: res.msg || '查询失败', icon: 'none' })
|
||||
return
|
||||
}
|
||||
const status = res.data?.refund?.status
|
||||
wx.showToast({
|
||||
title: status === 'success' ? '退款已成功' : '查询完成',
|
||||
icon: status === 'success' ? 'success' : 'none'
|
||||
})
|
||||
this.loadOrderDetail(this.data.orderId)
|
||||
} catch (err) {
|
||||
wx.hideLoading()
|
||||
console.error('查询退款结果失败', err)
|
||||
wx.showToast({ title: '网络错误', icon: 'none' })
|
||||
} finally {
|
||||
this.setData({ queryingRefund: false })
|
||||
}
|
||||
},
|
||||
|
||||
async updateStatus(newStatus) {
|
||||
wx.showLoading({ title: '处理中...' })
|
||||
try {
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
<block wx:if="{{loaded && order}}">
|
||||
<!-- 顶部状态栏 -->
|
||||
<view class="status-header status-{{order.status}}">
|
||||
<view class="status-header status-{{statusClass}}">
|
||||
<view class="status-content">
|
||||
<text class="status-text">{{statusText}}</text>
|
||||
<text class="status-desc">{{statusDesc}}</text>
|
||||
@@ -125,6 +125,10 @@
|
||||
<text class="info-label">支付状态</text>
|
||||
<text class="info-value">{{paymentStatusText}}</text>
|
||||
</view>
|
||||
<view class="info-row" wx:if="{{payChannelText}}">
|
||||
<text class="info-label">支付渠道</text>
|
||||
<text class="info-value">{{payChannelText}}</text>
|
||||
</view>
|
||||
<view class="info-row" wx:if="{{paymentMethodText}}">
|
||||
<text class="info-label">支付方式</text>
|
||||
<text class="info-value">{{paymentMethodText}}</text>
|
||||
@@ -171,7 +175,8 @@
|
||||
</view>
|
||||
|
||||
<!-- 底部操作 -->
|
||||
<view class="bottom-actions" wx:if="{{showEditBtn || showConfirmBtn || showCancelBtn || showStartBtn || showCompleteBtn}}">
|
||||
<view class="bottom-actions" wx:if="{{showEditBtn || showConfirmBtn || showCancelBtn || showStartBtn || showCompleteBtn || showQueryRefundBtn}}">
|
||||
<view class="action-btn btn-ghost" wx:if="{{showQueryRefundBtn}}" bindtap="onQueryRefund">查询退款结果</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="{{showConfirmBtn}}" bindtap="onConfirm">确认订单</view>
|
||||
|
||||
@@ -39,6 +39,8 @@ Page({
|
||||
// 支付方式选项与回显标签
|
||||
methodOptions: METHOD_OPTIONS,
|
||||
methodLabel: '',
|
||||
// 存在未支付流水时金额锁定:需先关单/取消后再改价
|
||||
amountLocked: false,
|
||||
today: '',
|
||||
submitting: false
|
||||
},
|
||||
@@ -177,7 +179,11 @@ Page({
|
||||
}
|
||||
const sexLabel = p.sex === 'male' ? '男' : (p.sex === 'female' ? '女' : '')
|
||||
const age = calcAge(p.birth)
|
||||
this.originalTotalFee = Number(order.payment && order.payment.totalFee) || 0
|
||||
const amountLocked = (order.payment?.status || 'unpaid') === 'unpaid'
|
||||
&& !!order.payment?.paymentRecordId
|
||||
this.setData({
|
||||
amountLocked,
|
||||
// 有关联档案时交由 patient-info 按 ID 加载(不读缓存,以档案最新数据为准)
|
||||
profileId: order.healthProfileId || '',
|
||||
// 无关联档案时用订单 patient 快照兜底展示姓名/性别/年龄/电话;
|
||||
@@ -463,6 +469,13 @@ Page({
|
||||
* 编辑模式:保存修改
|
||||
*/
|
||||
updateOrder(form) {
|
||||
if (this.data.amountLocked) {
|
||||
const nextTotalFee = form.payment.totalFee ? Number(form.payment.totalFee) : 0
|
||||
if (nextTotalFee !== (this.originalTotalFee || 0)) {
|
||||
return wx.showToast({ title: '存在未支付流水,请先关闭后再修改金额', icon: 'none' })
|
||||
}
|
||||
}
|
||||
|
||||
const payload = {
|
||||
'hospital.province': form.hospital.province,
|
||||
'hospital.name': form.hospital.name,
|
||||
|
||||
@@ -323,6 +323,13 @@ page {
|
||||
color: #1a1a2e;
|
||||
}
|
||||
|
||||
.field-tip {
|
||||
display: block;
|
||||
margin-top: 8rpx;
|
||||
font-size: 24rpx;
|
||||
color: #e6a23c;
|
||||
}
|
||||
|
||||
.submit-btn {
|
||||
margin-top: 16rpx;
|
||||
height: 96rpx;
|
||||
|
||||
@@ -103,7 +103,8 @@
|
||||
|
||||
<view class="field">
|
||||
<text class="field-label">费用(元)</text>
|
||||
<input class="field-input" type="digit" placeholder="请输入服务费用" value="{{form.payment.totalFee}}" data-key="payment.totalFee" bindinput="onInput" />
|
||||
<input class="field-input" type="digit" placeholder="请输入服务费用" value="{{form.payment.totalFee}}" data-key="payment.totalFee" bindinput="onInput" disabled="{{amountLocked}}" />
|
||||
<text class="field-tip" wx:if="{{amountLocked}}">存在未支付流水,金额已锁定</text>
|
||||
</view>
|
||||
|
||||
<view class="field">
|
||||
|
||||
@@ -21,6 +21,8 @@ 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}`),
|
||||
// 退款回调丢失时的人工兜底:主动查询微信退款结果并补写终态
|
||||
queryRefund: (id) => request.post(`/health/escort-record/${id}/refund/query`),
|
||||
},
|
||||
|
||||
healthProfile: {
|
||||
|
||||
Reference in New Issue
Block a user