/* ============================================================================= * B09_Estimation_UI_Tab_PriceBasis.ts * B09 단가산출근거 탭 — 목록표 + 단가산출근거 (STmate `단가산출근거목록표` · `wM_Edit_San` 보기 · PLAN 12장 1차) * * - 목록표 = 내역 일위대가가 품은 D 만, **내역에 처음 쓰인 차례**로 「산근 N호표」(내역 비고 「단산 N」과 한 번호). * - 본표 줄의 비고에 Q 식·품셈 근거를 **글자 그대로** 보임(서버 줄 `note`). * - 「부르는 호표」 칸의 글을 누르면 그 일위대가표로 되돌아 들어감. * - Q 식 편집은 2차(브레인 판정). * ========================================================================== */ import type { B09Tab, B09TabContext } from "./B09_Estimation_UI_Shell_Types"; import { renderDetail } from "./B09_Estimation_UI_Detail"; import { L, el, hint, linkButton, sheetTable } from "./B09_Estimation_UI_Sheet"; import { listHead, listRow } from "./B09_Estimation_UI_Tab_UnitPrice"; import { loadBill, type BillDto } from "./B09_Estimation_UI_Store"; let selected = ""; function draw(ctx: B09TabContext, bill: BillDto): void { const entries = bill.price_basis.entries; const page = el("div", "b09s-split"); const { wrap, tbody } = sheetTable(listHead(L("B09_Sheet_Col_Basis"))); const detail = el("div", "b09s-split"); for (const entry of entries) { const row = { ...entry, label: `${L("B09_Sheet_Basis_Long")} ${entry.number}${L("B09_Sheet_Basis_Suffix")}`, }; const tr = listRow(row, entry.unit_price_krw ?? "", entry.code === selected); const note = tr.lastElementChild as HTMLElement; for (const code of entry.unit_price_codes ?? []) { const sheet = bill.unit_price_sheet.entries.find((item) => item.code === code); if (sheet) note.append(linkButton(sheet.label, () => ctx.open("unit_price", code))); } tr.addEventListener("click", () => { selected = entry.code; ctx.body.replaceChildren(); draw(ctx, bill); }); tbody.append(tr); } page.append(el("div", "b09s-title", L("B09_Sheet_BasisList")), wrap); if (entries.length === 0) page.append(hint(L("B09_Sheet_EmptyList"))); page.append(detail); ctx.body.append(page); if (!selected) { detail.append(hint(L("B09_Sheet_PickSheet"))); return; } const picked = entries.find((entry) => entry.code === selected); const label = picked ? `${L("B09_Sheet_Basis_Long")} ${picked.number}${L("B09_Sheet_Basis_Suffix")}` : selected; renderDetail(ctx, detail, "price_basis", selected, label); } export const priceBasisTab: B09Tab = { key: "price_basis", label: () => L("B09_Estimation_Tab_PriceBasis"), render(ctx, arg) { if (!ctx.projectId) { ctx.body.append(hint(L("B09_Sheet_NoProject"))); return; } if (arg) selected = arg; ctx.body.append(hint(L("B09_Sheet_Loading"))); loadBill(ctx.projectId) .then((bill) => { ctx.body.replaceChildren(); draw(ctx, bill); }) .catch((error: Error) => { ctx.body.replaceChildren(hint(`${L("B09_Sheet_LoadFailed")} ${error.message}`, true)); }); }, };