Prechádzať zdrojové kódy

fix(web): 调整本方对账月份范围与筛选重置

sy 2 dní pred
rodič
commit
4b1982b8e4

+ 9 - 14
web-scaffold/src/components/ui/month-filter.tsx

@@ -5,26 +5,21 @@ import { cn } from "../../lib/utils";
 import { FilterIcon } from "./filter-select";
 import "../../styles/month-filter.css";
 
-export function MonthFilter({ value, onChange, maxMonth, allowAll = true, availableMonths, disabled = false }: {
+export function MonthFilter({ value, onChange, maxMonth, allowAll = true }: {
   value: string;
   onChange: (value: string) => void;
   /** 可选上界(YYYY-MM),默认本月。人工补跑传最近一个已结束的自然月。 */
   maxMonth?: string;
   /** 是否给「全部自然月」这一项;必填期次的场景(人工补跑)传 false。 */
   allowAll?: boolean;
-  /** 可选的服务端账期清单,传入时仅允许选择清单内的月份。 */
-  availableMonths?: readonly string[];
-  disabled?: boolean;
 }) {
   const id = useId();
   const popup = useRef<HTMLDivElement>(null);
   const trigger = useRef<HTMLButtonElement>(null);
   const limit = maxMonth ?? businessToday().slice(0, 7);
-  const availableYears = availableMonths?.map((month) => Number(month.slice(0, 4)));
-  const maxYear = availableYears?.length ? Math.max(...availableYears) : Number(limit.slice(0, 4));
-  const minYear = availableYears ? Math.min(maxYear, ...availableYears) : 1;
+  const maxYear = Number(limit.slice(0, 4));
   const selectedYear = Number(value.slice(0, 4));
-  const initialYear = selectedYear > 0 ? Math.max(minYear, Math.min(selectedYear, maxYear)) : maxYear;
+  const initialYear = selectedYear > 0 ? Math.min(selectedYear, maxYear) : maxYear;
   const [year, setYear] = useState(initialYear);
   const label = value || "全部自然月";
   const limitHint = maxMonth ? "只能选已结束的月份" : "只能选择本月及之前的月份";
@@ -37,13 +32,13 @@ export function MonthFilter({ value, onChange, maxMonth, allowAll = true, availa
 
   return <>
     <button type="button" ref={trigger} className="filter-select month-filter-trigger" popoverTarget={id}
-      aria-label={`自然月:${label}`} aria-haspopup="dialog" disabled={disabled} onClick={() => setYear(initialYear)}>
+      aria-label={`自然月:${label}`} aria-haspopup="dialog" onClick={() => setYear(initialYear)}>
       <FilterIcon kind="month" />
       <span className={cn("filter-select-value", !value && "is-placeholder")}>{label}</span>
     </button>
     <div id={id} ref={popup} popover="auto" role="dialog" aria-label="选择自然月" className="month-filter-popup">
       <div className="month-filter-heading">
-        <button type="button" aria-label="上一年" disabled={year <= minYear} onClick={() => setYear(year - 1)}><ChevronLeft size={16} aria-hidden="true" /></button>
+        <button type="button" aria-label="上一年" disabled={year === 1} onClick={() => setYear(year - 1)}><ChevronLeft size={16} aria-hidden="true" /></button>
         <strong aria-live="polite">{year} 年</strong>
         <button type="button" aria-label="下一年"
           disabled={year >= maxYear}
@@ -52,13 +47,13 @@ export function MonthFilter({ value, onChange, maxMonth, allowAll = true, availa
       <div className="month-filter-grid">
         {Array.from({ length: 12 }, (_, index) => {
           const month = `${String(year).padStart(4, "0")}-${String(index + 1).padStart(2, "0")}`;
-          const unavailable = availableMonths ? !availableMonths.includes(month) : month > limit;
-          return <button type="button" key={month} aria-pressed={month === value} disabled={disabled || unavailable}
-            title={unavailable ? (availableMonths ? "本方暂无此账期" : limitHint) : undefined}
+          const beyond = month > limit;
+          return <button type="button" key={month} aria-pressed={month === value} disabled={beyond}
+            title={beyond ? limitHint : undefined}
             onClick={() => choose(month)}>{index + 1} 月</button>;
         })}
       </div>
-      {allowAll && <button type="button" className="month-filter-all" aria-pressed={!value} disabled={disabled} onClick={() => choose("")}>全部自然月</button>}
+      {allowAll && <button type="button" className="month-filter-all" aria-pressed={!value} onClick={() => choose("")}>全部自然月</button>}
     </div>
   </>;
 }

+ 11 - 12
web-scaffold/src/pages/PartyViewPages.tsx

@@ -16,7 +16,7 @@
  * 硬纪律:⛔「无权限」字样(U-68/总则§16.4);⛔ history.back()(14.6);
  * ⛔ 列表级导出/批量操作/人工补跑/已读异议按钮(14.5 白名单);
  * ⛔「涉及分成方」卡与「同一张应收上其他分成方」面板(14.5,服务端亦不返回);
- * 金额整数分传输、前端不做浮点运算;月份默认预选 lastClosedMonth()(U-67 定案,三身份同口径)。
+ * 金额整数分传输、前端不做浮点运算;本方对账默认全部自然月,其余只读台账默认预选 lastClosedMonth()。
  */
 import { useCallback, useEffect, useRef, useState } from "react";
 import { PageIntro } from "../components/PageIntro";
@@ -193,7 +193,8 @@ function PartyReconMergedPage({ kind }: { kind: "partner" | "team" }) {
   const title = kind === "partner" ? "本运营区域对账" : "本方对账";
   const prefix = kindPrefix(kind);
   const { saved, stateFor } = usePartyListReturn();
-  const [month, setMonth] = useState(saved?.month ?? lastClosedMonth());
+  const defaultMonth = teamView ? "" : lastClosedMonth();
+  const [month, setMonth] = useState(saved?.month ?? defaultMonth);
   const [keyword, setKeyword] = useState(saved?.keyword ?? "");
   const [page, setPage] = useState(saved?.page ?? 1);
   const linkState = stateFor({ month, keyword, page });
@@ -215,14 +216,14 @@ function PartyReconMergedPage({ kind }: { kind: "partner" | "team" }) {
 
   // C35:预选月不在 month_options 内 ⇒ 退回首项 month_options[0](⛔ 停在空月份静默成「筛选无结果」)。
   useEffect(() => {
-    if (!monthOptions?.length || !month) return;
+    if (teamView || !monthOptions?.length || !month) return;
     if (!monthOptions.some((o) => o.period === month)) setMonth(monthOptions[0].period);
-  }, [monthOptions, month]);
-  const monthFallback = Boolean(monthOptions?.length && month && !monthOptions.some((o) => o.period === month));
+  }, [teamView, monthOptions, month]);
+  const monthFallback = !teamView && Boolean(monthOptions?.length && month && !monthOptions.some((o) => o.period === month));
 
   function resetFilter() {
     setKeyword("");
-    setMonth(lastClosedMonth());
+    setMonth(defaultMonth);
     setPage(1);
   }
   /** 表 1「查看明细」=页内锚点定位表 2 并自动填筛选(不跳页,视图§4.1.2)。 */
@@ -261,11 +262,9 @@ function PartyReconMergedPage({ kind }: { kind: "partner" | "team" }) {
         />
         {keyword && <button type="button" aria-label="清空搜索" onClick={() => { setKeyword(""); setPage(1); }}><X size={15} aria-hidden="true" /></button>}
       </label>
-      {/* 月份选项取接口返回的两表并集。 */}
+      {/* 合伙人视图的月份选项取接口返回的两表并集。 */}
       {teamView ? <MonthFilter
         value={month}
-        availableMonths={monthOptions?.map((option) => option.period)}
-        disabled={!monthOptions}
         onChange={(value) => { setMonth(value); setPage(1); }}
       /> : <FilterSelect
         icon="month"
@@ -277,15 +276,15 @@ function PartyReconMergedPage({ kind }: { kind: "partner" | "team" }) {
         <option value="">{ALL_PERIODS_LABEL}</option>
         {(monthOptions ?? (month ? [{ period: month }] : [])).map((o) => <option key={o.period} value={o.period}>{o.period}</option>)}
       </FilterSelect>}
-      <Button variant="ghost" size="sm" onClick={resetFilter}>重置筛选</Button>
+      {(!teamView || month || keyword) && <Button variant="ghost" size="sm" onClick={resetFilter}>重置筛选</Button>}
       {teamView && <span className="team-recon-filter-hint" role={fetchState.loading && data ? "status" : "note"}>
         <Info size={14} aria-hidden="true" />{fetchState.loading && data ? "正在更新筛选结果…" : VIEW_KEYWORD_FILTER_NOTE}
       </span>}
     </div>
     {!teamView && <p className="ops-import-note" role="note">{VIEW_KEYWORD_FILTER_NOTE}</p>}
     {monthFallback && <p className="ops-import-note" role="status">{VIEW_MONTH_NO_BATCH}</p>}
-    {data?.month_options_truncated && <p className="ops-import-note" role="status">{viewMonthTruncated(monthOptions?.length ?? 0)}</p>}
-    {monthOptionsFailed && <p className="ops-import-note" role="status">{WORD_FETCH_FAILED}:月份选项暂不可用。</p>}
+    {!teamView && data?.month_options_truncated && <p className="ops-import-note" role="status">{viewMonthTruncated(monthOptions?.length ?? 0)}</p>}
+    {!teamView && monthOptionsFailed && <p className="ops-import-note" role="status">{WORD_FETCH_FAILED}:月份选项暂不可用。</p>}
   </>;
 
   return (

+ 1 - 2
web-scaffold/src/styles/month-filter.css

@@ -1,6 +1,5 @@
 .month-filter-trigger { cursor: pointer; }
-.month-filter-trigger:enabled:hover { border-color: var(--border-hover); }
-.month-filter-trigger:disabled { cursor: not-allowed; opacity: .55; }
+.month-filter-trigger:hover { border-color: var(--border-hover); }
 .month-filter-trigger:focus-visible { outline: none; border-color: var(--ring); box-shadow: 0 0 0 3px var(--ring-glow); }
 .month-filter-popup {
   width: min(248px, calc(100vw - 20px));