feat(admin): 新增陪诊员入驻申请与全局角色守卫

- 新增 pages/apply 入驻申请页:填写资料、上传证件、查看审核状态
- 新增 utils/role.js 统一角色解析与管理端页面守卫
- app.js 包装 Page 构造器集中做 onShow 守卫,无身份用户重定向至申请页
- 订单、客户、档案、统计等按角色区分能力:陪诊员不请求档案接口,改用订单快照
- 订单列表支持待取消订单一键同意取消;新增订单价格由服务目录决定只读展示
This commit is contained in:
lik
2026-11-08 12:01:48 +08:00
parent bfe820aa31
commit c8bcc79865
27 changed files with 1332 additions and 206 deletions
+70 -119
View File
@@ -1,15 +1,16 @@
// pages/order/index.js
const API = require('../../utils/api.js')
const { calcAge } = require('../../utils/format.js')
const role = require('../../utils/role.js')
// 状态映射配置
const STATUS_MAP = {
pending: { label: '待确认', text: '待确认', color: '#f59f00' },
confirmed: { label: '已确认', text: '已确认', color: '#1abc9c' },
cancel_requested: { label: '待取消', text: '待取消', color: '#f59f00' },
in_progress: { label: '进行中', text: '进行中', color: '#20c997' },
completed: { label: '已完成', text: '已完成', color: '#51cf66' },
cancelled: { label: '已取消', text: '已取消', color: '#ff6b6b' }
pending: { label: '待确认', text: '待确认', color: '#D98E04' },
confirmed: { label: '已确认', text: '已确认', color: '#3E6E9E' },
cancel_requested: { label: '待取消', text: '待取消', color: '#C0564A' },
in_progress: { label: '进行中', text: '进行中', color: '#C26A2E' },
completed: { label: '已完成', text: '已完成', color: '#8A7BB5' },
cancelled: { label: '已取消', text: '已取消', color: '#C0564A' }
};
// 状态筛选选项
@@ -31,12 +32,37 @@ function resolveDisplayStatus(order) {
return order?.status || 'pending'
}
// 页签 → 服务端筛选参数:筛选、分页、计数全部交给后端,避免按当前页过滤
function buildTabFilter(status) {
switch (status) {
case '':
return { includeCancelled: 1 }
case 'pending':
return { status: 'pending', cancelStatus: 'none' }
case 'cancel_requested':
return { cancelStatus: 'requested' }
case 'confirmed':
return { status: 'confirmed', cancelStatus: 'none' }
case 'in_progress':
return { status: 'in_progress', cancelStatus: 'none' }
case 'completed':
return { status: 'completed', cancelStatus: 'none' }
case 'cancelled':
return { cancelStatus: 'cancelled' }
default:
return {}
}
}
Page({
/**
* 页面的初始数据
*/
data: {
// 角色:管理员可新增预约,陪诊员只看本人订单
role: '',
isAdmin: false,
// 统计
stats: {
total: 0,
@@ -66,7 +92,11 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.loadOrderList();
// 先解析角色:陪诊员走本人订单接口,管理员走全量接口
role.ensureRole().then(r => {
this.setData({ role: r, isAdmin: r === 'admin' })
this.loadOrderList();
})
},
/**
@@ -79,77 +109,23 @@ Page({
},
/**
* 计算统计数据
* 更新筛选标签计数(口径由后端聚合,避免按当前页统计)
*/
calculateStats(orders) {
const stats = {
total: orders.length,
pending: 0,
cancelRequested: 0,
confirmed: 0,
inProgress: 0,
completed: 0,
cancelled: 0
updateFilterCounts(counts) {
const c = counts || {};
const countMap = {
'': c.all,
pending: c.pending,
cancel_requested: c.cancelRequested,
confirmed: c.confirmed,
in_progress: c.inProgress,
completed: c.completed,
cancelled: c.cancelled
};
orders.forEach(order => {
switch (resolveDisplayStatus(order)) {
case 'pending':
stats.pending++;
break;
case 'cancel_requested':
stats.cancelRequested++;
break;
case 'confirmed':
stats.confirmed++;
break;
case 'in_progress':
stats.inProgress++;
break;
case 'completed':
stats.completed++;
break;
case 'cancelled':
stats.cancelled++;
break;
}
});
return stats;
},
/**
* 更新筛选标签计数
*/
updateFilterCounts(stats) {
const statusFilters = this.data.statusFilters.map(filter => {
let count = 0;
switch (filter.value) {
case '':
count = stats.total;
break;
case 'pending':
count = stats.pending;
break;
case 'cancel_requested':
count = stats.cancelRequested;
break;
case 'confirmed':
count = stats.confirmed;
break;
case 'in_progress':
count = stats.inProgress;
break;
case 'completed':
count = stats.completed;
break;
case 'cancelled':
count = stats.cancelled;
break;
}
return { ...filter, count };
});
const statusFilters = this.data.statusFilters.map(filter => ({
...filter,
count: Number(countMap[filter.value]) || 0
}));
this.setData({ statusFilters });
},
@@ -186,7 +162,7 @@ Page({
},
/**
* 加载订单列表
* 加载订单列表:筛选、分页与计数全部使用服务端口径
*/
loadOrderList(isRefresh = false) {
if (this.data.isLoading || this.data.isLoadingMore) return;
@@ -198,12 +174,10 @@ Page({
const params = {
page,
pageSize,
// 筛选在本页按展示状态完成,因此一次取回含已取消在内的全部订单
status: 'pending,confirmed,in_progress,completed',
includeCancelled: 1
...buildTabFilter(currentStatus)
};
API.escort.getAllRecords(params)
role.queryOrders(params)
.then(res => {
if (res.code !== 0) {
wx.showToast({ title: res.msg || '获取订单失败', icon: 'none' });
@@ -213,30 +187,24 @@ Page({
const data = res.data || {};
const list = data.records || [];
let total = list.length || 0;
const total = Number(data.total) || 0;
const processedOrders = this.processOrders(list);
const allOrders = isRefresh && page > 1
const orderList = isRefresh && page > 1
? [...this.data.orderList, ...processedOrders]
: processedOrders;
const stats = this.calculateStats(allOrders);
this.updateFilterCounts(stats);
const { currentStatus } = this.data;
const orderList = currentStatus
? allOrders.filter(order => order.displayStatus === currentStatus)
: allOrders;
total = orderList.length;
this.updateFilterCounts(data.counts);
this.setData({
orderList,
stats,
// 头部总数用后端「全部」口径,页签内条数仍由 currentStatus 决定
stats: { ...this.data.stats, total: Number((data.counts || {}).all) || total },
isLoading: false,
isLoadingMore: false,
isRefreshing: false,
hasMore: orderList.length < total
// total 由服务端返回,不能用当前页长度推断
hasMore: page * pageSize < total
});
})
.catch(err => {
@@ -308,9 +276,12 @@ Page({
const order = this.data.orderList.find(item => item._id === id);
if (!order) return;
const isCancelRequest = action === 'cancel' && order.displayStatus === 'cancel_requested';
const actionMap = {
confirm: { title: '确认订单', content: '确认接受此订单?', nextStatus: 'confirmed' },
cancel: { title: '取消订单', content: '确定要取消此订单?', nextStatus: 'cancelled' },
cancel: isCancelRequest
? { title: '同意取消', content: '同意取消该订单?已收款订单将进入退款流程。', nextStatus: 'cancelled' }
: { title: '取消订单', content: '确定要取消此订单?未确认且未收款的订单会被直接删除,已收款订单将进入退款。', nextStatus: 'cancelled' },
start: { title: '开始服务', content: '确认开始陪诊服务?', nextStatus: 'in_progress' },
complete: { title: '完成服务', content: '确认陪诊服务已完成?', nextStatus: 'completed' },
detail: { title: '', content: '', nextStatus: '' }
@@ -329,7 +300,7 @@ Page({
wx.showModal({
title: actionConfig.title,
content: actionConfig.content,
confirmColor: '#1abc9c',
confirmColor: '#C26A2E',
success: (res) => {
if (res.confirm) {
this.updateOrderStatus(id, actionConfig.nextStatus);
@@ -346,35 +317,15 @@ Page({
API.escort.updateStatus(id, { status: newStatus })
.then(res => {
wx.hideLoading();
if (res.code !== 0) {
wx.showToast({ title: res.msg || '操作失败', icon: 'none' });
wx.hideLoading();
return;
}
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 {
...next,
displayStatus,
statusText: STATUS_MAP[displayStatus]?.text || displayStatus,
'meta.updatetime': new Date().toISOString()
};
}
return order;
});
const stats = this.calculateStats(orderList);
this.updateFilterCounts(stats);
this.setData({ orderList, stats });
wx.hideLoading();
wx.showToast({ title: '操作成功', icon: 'success' });
// 取消可能物理删除订单,状态与计数以服务端为准,不做本地推断
this.refreshData();
})
.catch(err => {
console.error('更新订单状态失败', err);