Files
Aislo/M01_MasterData/M01_MasterData_UI_Pick.ts
T
eomsangdonandClaude Opus 5 9de61eb251 knowledge(마스터): 재료 열 한 벌 정리 — 시중물가 → 자재품목 · 값 다섯 열 · 유가·환율도 같은 열
- 재료_시중물가.json → 재료_자재품목.json(테이블ID MT · 키 그대로) · 모든 줄이 같은 열 한 벌(키 · 원문번호 · 구분 · 상세구분 · 이름 · 규격 · 단위 · 물가자료 · 유통물가 · 물가정보 · 거래가격 · 관급 · 출처 · 비고 · 면수)
- 값 묶음(시중·조달)을 풀어 다섯 값을 열로 · 관급 = 조달 값(4,552 줄 · 기간은 비고 「조달 26.7」) · 원문 가격정보만 남은 72 줄은 값 열에 안 넣고 비고 「가격정보 ○○」 · 구분·상세구분은 원문에 분류가 없어 비움
- 재료_오피넷유가 · 환율_한국은행환율도 열 한 벌(기준일 → 규격 · 유가 구분 = 전국평균/시도별 · 상세구분 = 지역) · 상품코드·지역코드 삭제
- 엔진 단가(연결된 줄의 낮은 값 · 출처 = 「<키>.<열>」) · check_master 열 검사 · M01 고르기(procure 걷어냄) · 빌더 · _틀.md · 화면 계약 · 시험 같이 고침

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JgUhN55Z3BCYhUJTjwTNfj
2026-09-20 15:55:40 +09:00

134 lines
4.7 KiB
TypeScript

/* =============================================================================
* M01_MasterData_UI_Pick.ts
* 고르기 모달 — 가격 연결(자재품목) · 준용 직종을 이름·규격으로 찾아 고르면 ref 를 돌려줌
* ========================================================================== */
import { el, showToast } from "@ui/ui_template_elements";
import { t as L } from "@ui/ui_template_locale";
import { fetchPick, type PickItem, type PickKind } from "./M01_MasterData_Api_Fetch";
import { show } from "./M01_MasterData_UI_Cells";
/** 지역이 갈리는 재료 — 이름·규격만 적어 두고 지역은 계산 때 입력. */
export interface Cond {
이름: string;
규격: string;
지역: "입력";
}
export interface PickOptions {
kind: PickKind;
title: string;
/** 지금 연결 글 — 비면 「연결 끊기」 꺼짐. */
current: string;
/** 처음 찾을 글 — 그 재료 이름·규격 (없는 결과면 첫 낱말만으로 다시). */
seed: string;
/** 고르면 ref · 연결 끊기 = null. */
onPick: (ref: string | null, name?: string) => void;
/** 있으면 「후보 조건으로 연결」 칸이 뜸. */
cond?: { 이름: string; 규격: string; onCond: (c: Cond) => void };
}
const button = (text: string): HTMLButtonElement =>
el("button", { className: "m01-master__row-btn", text, attrs: { type: "button" } });
const input = (value: string, placeholder: string): HTMLInputElement => {
const box = el("input", {
className: "m01-master__search",
attrs: { type: "search", placeholder },
});
box.value = value;
return box;
};
export function openPickModal(opt: PickOptions): void {
const close = (): void => back.remove();
const search = input(opt.seed, L("M01_ProcureSearch"));
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();
});
const shut = button(L("M01_ProcureClose"));
shut.addEventListener("click", close);
const condRow: HTMLElement[] = [];
if (opt.cond) {
const { onCond } = opt.cond;
const name = input(opt.cond.이름, L("M01_PriceCondName"));
const spec = input(opt.cond.규격, L("M01_PriceCondSpec"));
const go = button(L("M01_PriceCond"));
go.addEventListener("click", () => {
if (!name.value.trim()) return;
onCond({ 이름: name.value.trim(), 규격: spec.value.trim(), 지역: "입력" });
close();
});
condRow.push(el("div", { className: "m01-procure__cond", children: [name, spec, go] }));
}
const box = el("div", {
className: "m01-procure__box",
children: [
el("h3", { text: opt.title }),
el("p", { className: "m01-master__muted", text: opt.current }),
search,
list,
...condRow,
el("div", { className: "m01-procure__foot", children: [cut, shut] }),
],
});
const back = el("div", { className: "m01-procure", children: [box] });
back.addEventListener("click", (e) => {
if (e.target === back) close();
});
document.body.append(back);
const paint = (items: PickItem[], total: number): void => {
list.replaceChildren(
...(items.length
? items.map((it) => {
const tag = it.관급 ? ` · ${L("M01_Govt")}` : "";
const b = el("button", {
className: "m01-procure__item",
attrs: { type: "button" },
children: [
el("strong", { text: it.이름 }),
el("span", { text: `${it.규격} · ${it.단위} · ${show(it.)}${tag}` }),
el("span", { className: "m01-master__muted", text: it.ref }),
],
});
b.addEventListener("click", () => {
opt.onPick(it.ref, `${it.이름} ${it.규격}`.trim());
close();
});
return b;
})
: [el("p", { className: "m01-master__empty", text: L("M01_NoRows") })]),
...(total > items.length
? [el("p", { className: "m01-master__muted", text: `${items.length} / ${total}` })]
: []),
);
};
let timer: number | undefined;
const run = async (fallback = false): Promise<void> => {
try {
const q = search.value.trim();
const r = await fetchPick(opt.kind, q);
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);
search.focus();
}