瀏覽代碼

fix(web): 对账清单默认查询全部自然月

sy 2 天之前
父節點
當前提交
d75efa2097

+ 12 - 22
web-scaffold/src/pages/SettlementRecordPages.tsx

@@ -111,7 +111,6 @@ const batchPath = (holderId: string, batchNo: string) =>
 /** URL 搜索参数筛选(返回列表时保留条件;⛔ 路由级收敛另行处理)。 */
 function useListFilters() {
   const [params, setParams] = useSearchParams();
-  const has = (key: string) => params.has(key);
   const get = (key: string) => params.get(key) ?? "";
   const set = (key: string, value: string, resetPage = false) =>
     setParams((current) => {
@@ -122,7 +121,7 @@ function useListFilters() {
       return next;
     }, { replace: true });
   const reset = () => setParams({}, { replace: true });
-  return { has, get, set, reset };
+  return { get, set, reset };
 }
 
 /** 失败原因行末红点(fail_reason 原文悬浮;⚠️ 不是 KLT-* 码,对账§7.1 末格)。 */
@@ -280,10 +279,10 @@ export function SettlementStatementListPage() {
   const canExportAll = !identity || identity.role === "admin" || identity.role === "regAdmin";
   const isAdmin = !identity || identity.role === "admin";
 
-  const defaultMonth = lastClosedMonth();
-  // 自然月三态:参数缺席 ⇒ 默认预选 lastClosedMonth();显式 "all" ⇒ 全部自然月(空值项,⛔ 不得删除)。
-  const monthAll = filters.get("month") === "all";
-  const month = monthAll ? "" : filters.get("month") || defaultMonth;
+  const lastClosedPeriod = lastClosedMonth();
+  const monthParam = filters.get("month");
+  // 无参数时显示全部自然月,同时兼容旧链接的 month=all。
+  const month = monthParam === "all" ? "" : monthParam;
   const type = filters.get("type");
   const party = filters.get("party");
   const reconcile = filters.get("reconcile");
@@ -292,8 +291,7 @@ export function SettlementStatementListPage() {
   const zero = filters.get("zero") === "1";
   const q = filters.get("q");
   const page = Number(filters.get("page") || "1") || 1;
-  const setMonth = (value: string) => filters.set("month", value === "" ? "all" : value === defaultMonth ? "" : value, true);
-  const hasFilter = Boolean(monthAll || filters.get("month") || type || party || reconcile || status || trigger || zero || q);
+  const hasFilter = Boolean(month || type || party || reconcile || status || trigger || zero || q);
 
   const periodsFetch = useReconPeriods();
   // D-19:下拉选项=接口期次 ∪ 上一个已结束自然月(与人工补跑弹窗 `lastClosedMonth()` 同基准)。
@@ -301,29 +299,21 @@ export function SettlementStatementListPage() {
   const periods = (() => {
     const raw = periodsFetch.data?.periods ?? null;
     if (!raw) return null;
-    if (raw.includes(defaultMonth)) return raw;
-    return [defaultMonth, ...raw];
+    if (raw.includes(lastClosedPeriod)) return raw;
+    return [lastClosedPeriod, ...raw];
   })();
-  // 仅当**用户显式选了**不在选项内的历史月(例如书签)才纠偏;默认预选月即使暂无批次也保留。
+  // 仅纠正不在选项内的显式月份(例如旧书签中的月份)。
   const [monthFallback, setMonthFallback] = useState(false);
   useEffect(() => {
     if (!periods?.length) return;
-    if (monthAll) {
-      setMonthFallback(false);
-      return;
-    }
-    if (!filters.has("month")) {
-      setMonthFallback(false);
-      return;
-    }
-    if (periods.includes(month)) {
+    if (!month || periods.includes(month)) {
       setMonthFallback(false);
       return;
     }
     filters.set("month", periods[0], true);
     setMonthFallback(true);
     // eslint-disable-next-line react-hooks/exhaustive-deps
-  }, [periods, month, monthAll]);
+  }, [periods, month]);
 
   const list = useReconList({
     period: month,
@@ -461,7 +451,7 @@ export function SettlementStatementListPage() {
               onCommit={(value) => filters.set("party", value, true)} />
             {party && <button type="button" aria-label="清空分成方" onClick={() => filters.set("party", "", true)}><X size={15} aria-hidden="true" /></button>}
           </label>
-          <FilterSelect icon="month" aria-label="自然月" value={monthAll ? "" : month} onChange={(event) => setMonth(event.target.value)}>
+          <FilterSelect icon="month" aria-label="自然月" value={month} onChange={(event) => filters.set("month", event.target.value, true)}>
             <option value="">{ALL_PERIODS_LABEL}</option>
             {(periods ?? (month ? [month] : [])).map((p) => <option key={p} value={p}>{p}</option>)}
           </FilterSelect>

+ 19 - 1
web-scaffold/src/pages/__tests__/settlement-statement-list.test.tsx

@@ -70,7 +70,7 @@ function renderPage(search = "") {
 }
 
 it("从页头导出,表格分开展示两种状态,改筛选时返回第一页", async () => {
-  renderPage("?page=2&type=operator");
+  renderPage("?page=2&type=operator&month=2026-10");
   const table = within(screen.getByRole("region", { name: "对账批次,可横向滚动查看字段" }));
   expect(await table.findByRole("link", { name: "RECON-001" })).toBeTruthy();
   expect(table.getByRole("columnheader", { name: "出账状态" })).toBeTruthy();
@@ -94,6 +94,24 @@ it("从页头导出,表格分开展示两种状态,改筛选时返回第一
   expect(within(screen.getByRole("region", { name: "期次出账进度" })).getByText("上海市")).toBeTruthy();
 });
 
+it.each(["", "?month=all"])("默认查询全部自然月并支持选月和重置(查询串 %j)", async (search) => {
+  renderPage(search);
+  const monthSelect = screen.getByRole<HTMLSelectElement>("combobox", { name: "自然月" });
+  expect(monthSelect.selectedOptions[0].textContent).toBe("全部自然月");
+  await waitFor(() => expect(reconGetList).toHaveBeenLastCalledWith(expect.objectContaining({ period: undefined })));
+  await screen.findByRole("link", { name: "RECON-001" });
+  fireEvent.click(screen.getByRole("button", { name: "导出当前结果" }));
+  await waitFor(() => expect(reconExportList).toHaveBeenCalledWith(expect.objectContaining({ period: undefined })));
+
+  await screen.findByRole("option", { name: "2026-10" });
+  fireEvent.change(monthSelect, { target: { value: "2026-10" } });
+  await waitFor(() => expect(reconGetList).toHaveBeenLastCalledWith(expect.objectContaining({ period: "2026-10" })));
+
+  fireEvent.click(screen.getByRole("button", { name: "重置筛选" }));
+  expect(monthSelect.selectedOptions[0].textContent).toBe("全部自然月");
+  await waitFor(() => expect(reconGetList).toHaveBeenLastCalledWith(expect.objectContaining({ period: undefined })));
+});
+
 it("补跑对话框预览选择的分成方和账期,完成后进入新批次并保留来路", async () => {
   renderPage("?type=operator");
   fireEvent.click(screen.getByRole("button", { name: "人工补跑" }));