feat(order): 新增订单 tab,支持未分配与我的订单分栏
This commit is contained in:
+65
-13
@@ -65,6 +65,8 @@ Page({
|
||||
isAdmin: false,
|
||||
// 实习陪诊师:能看到未分配订单,但不能接单
|
||||
isIntern: false,
|
||||
// 订单分栏:pool=未分配订单,mine=我的订单
|
||||
currentScope: 'pool',
|
||||
// 统计
|
||||
stats: {
|
||||
total: 0,
|
||||
@@ -77,6 +79,9 @@ Page({
|
||||
},
|
||||
// 状态筛选
|
||||
statusFilters: STATUS_FILTERS,
|
||||
// 状态下拉:picker 只认索引,文案与 statusFilters 保持同序
|
||||
statusFilterLabels: STATUS_FILTERS.map(filter => filter.label),
|
||||
statusIndex: 0,
|
||||
currentStatus: 'pending',
|
||||
// 订单列表
|
||||
orderList: [],
|
||||
@@ -96,10 +101,20 @@ Page({
|
||||
onLoad(options) {
|
||||
// 先解析角色:陪诊员走订单池接口,管理员走全量接口
|
||||
role.ensureRoleSafe().then(({ role: r, attendant }) => {
|
||||
const isAdmin = r === 'admin'
|
||||
// 管理员与陪诊员统一从「未分配订单」进入,两个分栏都可见
|
||||
const currentStatus = isAdmin ? this.data.currentStatus : ''
|
||||
const statusIndex = Math.max(
|
||||
0,
|
||||
STATUS_FILTERS.findIndex(filter => filter.value === currentStatus)
|
||||
)
|
||||
this.setData({
|
||||
role: r,
|
||||
isAdmin: r === 'admin',
|
||||
isIntern: Boolean(attendant && attendant.stage === 'intern')
|
||||
isAdmin,
|
||||
isIntern: Boolean(attendant && attendant.stage === 'intern'),
|
||||
currentScope: 'pool',
|
||||
currentStatus,
|
||||
statusIndex
|
||||
})
|
||||
this.loadOrderList();
|
||||
})
|
||||
@@ -115,7 +130,7 @@ Page({
|
||||
},
|
||||
|
||||
/**
|
||||
* 更新筛选标签计数(口径由后端聚合,避免按当前页统计)
|
||||
* 更新状态下拉的计数(口径由后端聚合,避免按当前页统计)
|
||||
*/
|
||||
updateFilterCounts(counts) {
|
||||
const c = counts || {};
|
||||
@@ -132,7 +147,11 @@ Page({
|
||||
...filter,
|
||||
count: Number(countMap[filter.value]) || 0
|
||||
}));
|
||||
this.setData({ statusFilters });
|
||||
// 下拉项直接带计数,替代原筛选条上的数字
|
||||
const statusFilterLabels = statusFilters.map(filter =>
|
||||
filter.count > 0 ? `${filter.label}(${filter.count})` : filter.label
|
||||
);
|
||||
this.setData({ statusFilters, statusFilterLabels });
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -184,14 +203,17 @@ Page({
|
||||
loadOrderList(isRefresh = false) {
|
||||
if (this.data.isLoading || this.data.isLoadingMore) return;
|
||||
|
||||
const { currentStatus, page, pageSize } = this.data;
|
||||
const { currentStatus, currentScope, page, pageSize } = this.data;
|
||||
|
||||
this.setData({ isLoading: !isRefresh, isLoadingMore: isRefresh && page > 1 });
|
||||
|
||||
const params = {
|
||||
page,
|
||||
pageSize,
|
||||
...buildTabFilter(currentStatus)
|
||||
// 陪诊员:pool=未分配,mine=我的;管理员不传,保持全量口径
|
||||
...(currentScope ? { scope: currentScope } : {}),
|
||||
// 未分配订单不做状态筛选,所有可接订单都要能刷到
|
||||
...(currentScope === 'pool' ? {} : buildTabFilter(currentStatus))
|
||||
};
|
||||
|
||||
role.queryOrders(params)
|
||||
@@ -215,8 +237,11 @@ Page({
|
||||
|
||||
this.setData({
|
||||
orderList,
|
||||
// 头部总数用后端「全部」口径,页签内条数仍由 currentStatus 决定
|
||||
stats: { ...this.data.stats, total: Number((data.counts || {}).all) || total },
|
||||
// 头部总数用后端「全部」口径;未分配池与当前筛选完全一致,直接用 total
|
||||
stats: {
|
||||
...this.data.stats,
|
||||
total: currentScope === 'pool' ? total : Number((data.counts || {}).all) || total
|
||||
},
|
||||
isLoading: false,
|
||||
isLoadingMore: false,
|
||||
isRefreshing: false,
|
||||
@@ -259,14 +284,41 @@ Page({
|
||||
},
|
||||
|
||||
/**
|
||||
* 状态筛选切换
|
||||
* 状态筛选下拉切换
|
||||
*/
|
||||
onStatusChange(e) {
|
||||
const status = e.currentTarget.dataset.status;
|
||||
if (status === this.data.currentStatus) return;
|
||||
onStatusPick(e) {
|
||||
const index = Number(e.detail.value) || 0;
|
||||
const filter = this.data.statusFilters[index];
|
||||
if (!filter || filter.value === this.data.currentStatus) return;
|
||||
|
||||
this.setData({
|
||||
currentStatus: status,
|
||||
currentStatus: filter.value,
|
||||
statusIndex: index,
|
||||
page: 1,
|
||||
hasMore: true,
|
||||
orderList: []
|
||||
}, () => {
|
||||
this.loadOrderList();
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* 未分配订单 / 我的订单切换:范围、分页、计数都由服务端按 scope 重算
|
||||
*/
|
||||
onScopeChange(e) {
|
||||
const scope = e.currentTarget.dataset.scope;
|
||||
if (!scope || scope === this.data.currentScope) return;
|
||||
|
||||
const statusFilters = this.data.statusFilters.map(filter => ({ ...filter, count: 0 }));
|
||||
this.setData({
|
||||
currentScope: scope,
|
||||
// 我的订单默认展示全部状态;未分配订单不参与状态筛选
|
||||
currentStatus: scope === 'mine' ? '' : this.data.currentStatus,
|
||||
statusIndex: scope === 'mine' ? 0 : this.data.statusIndex,
|
||||
statusFilters,
|
||||
// 清空上一分栏的状态计数,等本次请求返回后再写入
|
||||
statusFilterLabels: statusFilters.map(filter => filter.label),
|
||||
stats: { ...this.data.stats, total: 0 },
|
||||
page: 1,
|
||||
hasMore: true,
|
||||
orderList: []
|
||||
|
||||
Reference in New Issue
Block a user