Files
Aislo/tools/stmate-test/app_modals.js
T

61 lines
2.8 KiB
JavaScript

/**
* STMATE 도구 창 공통 바인딩 · 내역 행 끼워 넣기 (app_modals.js) — api = window.STMATE_APP
* 내역 도구(wITNum · wBoqRate · wM_Rate · wExpnd)는 scr_ui_boq_dlg.js · 가격지 비교(wM_Boxa)·기준단가 수정(wM_Edt_Hal)은 scr_ui_dan.js
* 여기 남은 것 = 수량산출서 연결(wQtyList 옛 창) · 표준 카탈로그 특수산식 불러오기
*/
(function (global) {
"use strict";
function bindModalEvents(api) {
const { ctx, Calc, bindEach, closeModal, renderWorkspace } = api;
bindEach(".btn-apply-qty-expr", "onclick", (btn) => {
const id = btn.getAttribute("data-id");
const inp = document.querySelector(`.qty-expr-input[data-id="${id}"]`);
const val = inp ? Calc.evalFormula(inp.value, {}) : 0;
const item = ctx.state.boqItems.find((b) => b.id === id);
if (!item || !(val > 0) || !ctx.dbfData) return;
const B = global.STMATE_UI_BOQ;
const model = { rows: ctx.dbfData.boq_rows, items: ctx.state.boqItems, deleted: [] };
B.setCell(model, item._recno, "QTY1", Math.round(val * 100) / 100);
renderWorkspace();
});
bindEach(".btn-use-special-san", "onclick", (btn) => {
const spec = (ctx.catalogData.special_san || [])[parseInt(btn.getAttribute("data-idx"), 10)];
if (!spec || !ctx.uiState.selectedIlwiCode) return;
ctx.uiState.editedSmtMap[ctx.uiState.selectedIlwiCode] = (spec["산식행"] || []).join("\r\n");
ctx.uiState.activeScreen = "wM_Edit_iLWi";
closeModal();
renderWorkspace();
});
}
/**
* 내역 행 끼워 넣기 — 선택 행 앞(선택 없으면 끝) · 저장 원천(boq_rows)·계산 원천(boqItems) 함께
* 코드가 단가목록에 있으면 명칭·규격·단위를 단가목록 값으로
*/
function insertBoqRow(api, code, name, spec, unit, qty) {
const { ctx, renderWorkspace } = api;
const B = global.STMATE_UI_BOQ;
if (!ctx.dbfData || !ctx.dbfData.boq_rows) return alert("열린 내역서 없음");
ctx.uiState.boqDeleted = ctx.uiState.boqDeleted || [];
const model = { rows: ctx.dbfData.boq_rows, items: ctx.state.boqItems, deleted: ctx.uiState.boqDeleted };
const c = String(code || "").trim();
const cr = (ctx.dbfData.costn_rows || []).find((r) => String(r.CODE || "").trim() === c);
const row = B.makeRow(model, {
BDCODE1: c,
NAME1: cr ? cr.NAME || "" : name || "",
SIZE1: cr ? cr.SIZE || "" : spec || "",
UNIT1: cr ? cr.UNIT || "" : unit || "",
QTY1: String(Number(qty) || 0),
});
const ix = B.indexesOf(model.rows, ctx.uiState.boqSel || []);
const res = B.insertRows(model, ix.length ? ix[0] : model.rows.length, [row]);
if (!res.ok) alert(res.error);
ctx.uiState.boqSel = [row._recno];
renderWorkspace();
return row;
}
global.STMATE_APP_MODALS = { bindModalEvents, insertBoqRow };
})(window);