{{ row.due_date || '—' }}
@@ -411,7 +419,9 @@ const queryParams = reactive({
days_bucket: '',
slot: '',
min_snooze: '',
- keyword: ''
+ keyword: '',
+ sort_field: 'due_date',
+ sort_order: 'desc'
})
/** el-input-number 清空时为 null/undefined,单独持有后再写回 queryParams 的 '' */
const minSnooze = ref(undefined)
@@ -423,6 +433,13 @@ const { pager, getLists, resetPage } = usePaging({
const doSearch = () => resetPage()
+/** 表头排序:只在倒序 / 正序间切换(sort-orders 不含 null),切换后回到第 1 页 */
+const onSortChange = ({ order }: { prop: string | null; order: string | null }) => {
+ queryParams.sort_field = 'due_date'
+ queryParams.sort_order = order === 'ascending' ? 'asc' : 'desc'
+ doSearch()
+}
+
const onMinSnoozeChange = (val: number | undefined | null) => {
queryParams.min_snooze = val === null || val === undefined ? '' : Number(val)
doSearch()
diff --git a/server/app/adminapi/lists/tcm/RevisitDueLists.php b/server/app/adminapi/lists/tcm/RevisitDueLists.php
index 0be8e51b0..98dcc9358 100755
--- a/server/app/adminapi/lists/tcm/RevisitDueLists.php
+++ b/server/app/adminapi/lists/tcm/RevisitDueLists.php
@@ -25,7 +25,7 @@ use think\facade\Db;
* 筛选:assistant_id / dept_id(经 admin_dept 子查询,含下级部门)/ state / days_bucket / slot(诊次,N 或 N+)/ min_snooze / keyword(患者姓名);默认排除失效行(closed_state<>5)。
* state 的 SQL 条件与 DiagnosisLists::applyRevisitDueFilters 完全一致,另加 closed = closed_state=4(人工关闭,主管视图标记)。
* 数据范围:HasDataScopeFilter::applyDataScopeByOwner('rd.assistant_id'),主管按角色 data_scope 看下属。
- * 排序:escalation_level desc(越点越上心优先),due_date asc(NULL 置后),id asc。
+ * 排序:sort_field=due_date + sort_order=asc|desc,默认 due_date desc(最新预计复诊在前),NULL 始终置后,见 orderSql()。
* 导出:export=1/2,字段见 setExcelFields。
*/
class RevisitDueLists extends BaseAdminDataLists implements ListsSearchInterface, ListsExcelInterface
@@ -51,7 +51,7 @@ class RevisitDueLists extends BaseAdminDataLists implements ListsSearchInterface
public function lists(): array
{
$rows = $this->buildQuery()
- ->orderRaw('rd.escalation_level DESC, rd.due_date IS NULL ASC, rd.due_date ASC, rd.id ASC')
+ ->orderRaw($this->orderSql())
->limit($this->limitOffset, $this->limitLength)
->select()
->toArray();
@@ -113,6 +113,20 @@ class RevisitDueLists extends BaseAdminDataLists implements ListsSearchInterface
// ---------------------------------------------------------------- 内部
+ /**
+ * 排序:sort_field 仅白名单列(目前 due_date = 预计复诊),sort_order asc|desc,默认 desc(最新的预计复诊日在前)。
+ * 无论正序倒序,缺预计复诊日(NULL)的行始终置后;同日按 id 同向排序保证分页稳定。
+ */
+ private function orderSql(): string
+ {
+ $fieldMap = ['due_date' => 'rd.due_date'];
+ $field = (string) ($this->params['sort_field'] ?? '');
+ $col = $fieldMap[$field] ?? $fieldMap['due_date'];
+ $dir = strtolower((string) ($this->params['sort_order'] ?? '')) === 'asc' ? 'ASC' : 'DESC';
+
+ return "{$col} IS NULL ASC, {$col} {$dir}, rd.id {$dir}";
+ }
+
/**
* @return \think\db\Query
*/