Files
Aislo/M01_MasterData/M01_MasterData_UI_Pick.ts
T
eomsangdonandClaude Opus 5.5 4060d0ea72 refactor(853-1): M01 품셈재료(MP) 화면 가지 걷음 — 묶음 ③
- 확인: 재료_품셈재료.json 은 old/ 에만 있음 · 왼쪽 목록은 첫 층 파일만 보여 화면에서 닿지 않음
- Rows: LINKED 파일 · 연결 칸(linkedCell) · 「못 이은 줄만」 단추 · 머리 칸 걷음(fetchRows 의 unlinked 자리는 false — 다른 부르는 곳과 같은 꼴)
- UI_Pick: 「후보 조건으로 연결」 칸(cond · Cond) 걷음 — 모달 자체는 인력 「준용 직종」 고르기가 써서 남김
- Side 재료 차례에서 품셈재료 뺌 · CSS .m01-procure__cond 걷음
- 남김: Store._REF_FILE 의 MP · rows 의 unlinked(M02 Logic_Lib_Read 가 자리 인자로 넘김) · master_material · master_formula · check_master 의 MP 가지(옛 엔진 = 다음 걸음 몫) · 공용 글 사전 M01_PriceCond* · M01_OnlyUnlinked · M01_PriceCol(sub2 몫)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 12:30:14 +09:00

99 lines
3.9 KiB
TypeScript

/* =============================================================================
* M01_MasterData_UI_Pick.ts
* 고르기 모달 — 준용 직종(가격 연결 자재품목도 같은 꼴)을 이름·규격으로 찾아 고르면 ref 를 돌려줌
* ========================================================================== */
import { createButton, createInputField, el, showToast } from "@ui/ui_template_elements";
import { createEmpty } from "@ui/ui_template_empty";
import { openModal } from "@ui/ui_template_modal";
import { createText } from "@ui/ui_template_text";
import { t as L } from "@ui/ui_template_locale";
import { fetchPick, placeNote, type PickItem, type PickKind } from "./M01_MasterData_Api_Fetch";
import { show } from "./M01_MasterData_UI_Cells";
export interface PickOptions {
kind: PickKind;
title: string;
/** 지금 연결 글 — 비면 「연결 끊기」 꺼짐. */
current: string;
/** 처음 찾을 글 — 그 재료 이름·규격 (없는 결과면 첫 낱말만으로 다시). */
seed: string;
/** 고르면 ref · 연결 끊기 = null. */
onPick: (ref: string | null, name?: string, value?: unknown) => void;
}
const button = (label: string): HTMLButtonElement => createButton({ label, variant: "ghost" });
const field = (value: string, placeholder: string): ReturnType<typeof createInputField> =>
createInputField({ type: "search", placeholder, value });
export function openPickModal(opt: PickOptions): void {
const searchField = field(opt.seed, L("M01_ProcureSearch"));
const search = searchField.input;
const list = el("div", { className: "m01-procure__list" });
const cut = button(L("M01_ProcureCut"));
cut.disabled = !opt.current;
cut.addEventListener("click", () => {
opt.onPick(null);
close();
});
// 모달 부품 — 제목줄 [닫기] · 바깥 누르기 · Esc · 위 고정(공용 꼴) · [연결 끊기] 는 머리 단추 자리
const { close } = openModal({
title: opt.title,
closeLabel: L("M01_ProcureClose"),
width: "40rem",
dialogClass: "m01-procure__box",
actions: [cut],
mount: (body) => body.append(createText(opt.current), searchField.root, list),
});
const paint = (items: PickItem[], total: number): void => {
list.replaceChildren(
...(items.length
? items.map((it) => {
const tag =
(it.관급 ? ` · ${L("M01_Govt")}` : "") + (placeNote(it) && ` · ${placeNote(it)}`);
const b = el("button", {
className: "m01-procure__item ui-list-row ui-sidebar-row",
attrs: { type: "button", "data-size": "36" },
children: [
el("strong", { text: it.이름 }),
el("span", { text: `${it.규격} · ${it.단위} · ${show(it.값)}${tag}` }),
el("span", { className: "ui-text", text: it.ref }),
],
});
b.addEventListener("click", () => {
opt.onPick(it.ref, `${it.이름} ${it.규격}`.trim(), it.값);
close();
});
return b;
})
: [createEmpty({ text: L("M01_NoRows"), small: true })]),
...(total > items.length ? [createText(`${items.length} / ${total}`)] : []),
);
};
let timer: number | undefined;
let seq = 0; // 늦게 온 옛 응답은 버림(829-1)
const run = async (fallback = false): Promise<void> => {
const mine = ++seq;
try {
const q = search.value.trim();
const r = await fetchPick(opt.kind, q);
if (mine !== seq) return;
if (!r.total && fallback && q.includes(" ")) {
search.value = q.split(/\s+/)[0];
return run();
}
paint(r.items, r.total);
} catch (error) {
showToast(error instanceof Error ? error.message : L("M01_LoadFailed"), "error");
}
};
search.addEventListener("input", () => {
window.clearTimeout(timer);
timer = window.setTimeout(() => void run(), 300);
});
void run(true);
}