feat(manual): 手工工程导入导出(决策229/230)与本页搜索共享层
This commit is contained in:
@@ -37,6 +37,21 @@ body{margin:0;font:13px/1.5 "Source Han Sans SC","Noto Sans SC","Source Han Sans
|
||||
.panel.on{display:block}
|
||||
/* 原数据标签:左侧目录树 + 右侧标签卡,各自独立滚动 */
|
||||
#pan3{overflow:hidden}
|
||||
#pan3 .rawbox{position:relative}
|
||||
/* 导入项目弹框(决策 230,2026-10-27):同框建目录树 + 单位工程行旁导 Excel */
|
||||
#itree .ied{display:flex;align-items:center;gap:6px;padding:4px 8px;border-radius:4px}
|
||||
#itree .ied:hover{background:#f0f4fa}
|
||||
#itree .itag{flex:none;font-size:11px;border-radius:3px;padding:1px 6px}
|
||||
#itree .tg0{background:#e8edf5;color:#41506e}#itree .tg1{background:#e3ecfa;color:#1c4f9c}#itree .tg2{background:#dcf0e2;color:#17663a}
|
||||
#itree .inm{overflow:hidden;text-overflow:ellipsis;cursor:text;white-space:nowrap}
|
||||
#itree .iact{margin-left:auto;display:flex;gap:4px;align-items:center;flex:none}
|
||||
#itree .iab{font-size:11px;border:1px solid #c3cad6;background:#fff;border-radius:3px;padding:1px 6px;cursor:pointer;color:#41506e}
|
||||
#itree .iab:disabled{opacity:.35;cursor:default}
|
||||
#itree .iab.x{color:#b03a2e;border-color:#e3b6b0}
|
||||
#itree .iab.imp{color:#1c66d6;border-color:#9db9e8}
|
||||
#itree .iok{font-size:11px;color:#1f8f4d;white-space:nowrap;flex:none}
|
||||
#itree .ierr{font-size:11px;color:#b03a2e;max-width:200px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;flex:none}
|
||||
#itree .ied input{border:1px solid #9db9e8;border-radius:3px;padding:2px 6px;font-size:13px;min-width:140px;flex:1}
|
||||
table{width:100%;border-collapse:collapse;font-size:12.5px;table-layout:fixed}
|
||||
th{position:sticky;top:0;background:var(--head);color:var(--c1);font-weight:600;padding:6px 8px;border-bottom:1px solid var(--line);border-right:1px solid #eef1f6;white-space:nowrap;z-index:2}
|
||||
/* 规格 2026-10-17 ⑪:组表下拉时 ⟳ 工具行(sticky top:0)与表头都固定 */
|
||||
@@ -72,12 +87,6 @@ tr.sel td, tr.subsel td{background:#d8e9fc} /* 选中行=淡蓝(规格 2026-
|
||||
/* 拖动中:整页光标强制为 ns-resize(鼠标跑到哪儿都不丢拖动光标),并禁止选中文字 */
|
||||
body.histdrag, body.histdrag *{cursor:ns-resize !important}
|
||||
body.histdrag{user-select:none}
|
||||
/* ---- 本页搜索(决策 172,2026-10-22 主人定):命中关键字黄底 ---- */
|
||||
mark.pghl{background:#ffe58a;color:inherit;padding:0}
|
||||
mark.pghlcur{background:#ff9c40;color:#fff;padding:0} /* 决策 209:当前命中橙底 */
|
||||
.pgsrch{width:200px;height:24px;box-sizing:border-box}
|
||||
.pgsnav{height:24px;padding:0 8px;font:inherit;font-size:12px;border:1px solid #b8c4d4;border-radius:5px;background:#fff;color:#24425f;cursor:pointer;box-sizing:border-box} /* 决策 209:跳转按钮 */
|
||||
.pgsnav:disabled{background:#f0f2f5;color:#a8b4c4;border-color:#d5dde8;cursor:default}
|
||||
/* ---- 组价不一致/类似清单:左组目录树 + 分隔条(2026-10-08 主人定,样式/行为同原数据左树)---- */
|
||||
/* 决策 224(2026-10-27 主人定):#pan1 与 #pan2 同款 flex——.grpbox 拉伸满高:左树区
|
||||
不管有没有数据都分割出来、分隔条通高、收展把手恒在正中(同原数据)。
|
||||
@@ -342,6 +351,7 @@ mark.pghlcur{background:#ff9c40;color:#fff;padding:0} /* 决策 209:当前
|
||||
<div class="panel on" id="pan3">
|
||||
<div class="rawbox">
|
||||
<div class="rawtree" id="rawtree"></div>
|
||||
<div id="impWrap" style="position:absolute;top:6px;right:10px;z-index:6"></div>
|
||||
<div class="rawmain">
|
||||
<div class="stabs" id="rawstabs"></div>
|
||||
<div class="rawbody" id="rawbody"></div>
|
||||
@@ -540,11 +550,34 @@ mark.pghlcur{background:#ff9c40;color:#fff;padding:0} /* 决策 209:当前
|
||||
</div>
|
||||
<div class="mfoot" data-page-node-id="cIfN6fkvNTvkVdk85JJyPJ">
|
||||
<button class="btn" onclick="omask.classList.remove('on')" data-page-node-id="IAVuhdrc4Ln1HQDrn0cvBd">取消</button>
|
||||
<button class="btn pri" onclick="doOpen()" data-page-node-id="TE1Xb1738DYzBDAEAAT9o2">打开</button>
|
||||
<button class="btn pri" onclick="doOpen()" data-page-node-id="TE1Xb1738DYzPd3zBDAEAAT9o2">打开</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 导入项目(决策 230,2026-10-27 主人定):手工工程——同框建目录树(项目→单项工程→单位工程,
|
||||
点名改名、行尾 +/✕ 增删)+ 每个单位工程行旁「导入单位工程」选 Excel(两个 Sheet 落对应页签) -->
|
||||
<div class="mask" id="imask">
|
||||
<div class="dlg" style="width:680px;max-width:94vw">
|
||||
<h4 id="ititle">导入项目</h4>
|
||||
<div class="mbody">
|
||||
<div class="row"><span>工程名称 *</span><input id="iname" placeholder="如:某某住宅小区施工总承包"></div>
|
||||
<div class="row"><span>基准期次 *</span><input id="iper" placeholder="点这里选起~止(同月就选同一个)"></div>
|
||||
<div class="row" style="align-items:flex-start"><span style="padding-top:6px;flex:none">目录树 *</span>
|
||||
<div id="itree" style="flex:1;min-height:200px;max-height:46vh;overflow:auto;border:1px solid #e3eaf2;border-radius:6px;padding:6px 4px;background:#fbfcfe"></div>
|
||||
</div>
|
||||
<div class="tip" id="imsg"></div>
|
||||
</div>
|
||||
<div class="mfoot">
|
||||
<button class="btn" onclick="impTemplate()">模板</button>
|
||||
<span style="flex:1;font-size:12px;color:#8a97a8">模板=单位工程数据结构 Excel(Sheet:填写说明/分部分项/措施项目)</span>
|
||||
<button class="btn" onclick="imask.classList.remove('on')">取消</button>
|
||||
<button class="btn pri" id="ibtnSave" onclick="impSave()">保存并创建工程</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<input type="file" id="ifile" accept=".xlsx" style="display:none" onchange="impFile()">
|
||||
|
||||
<!-- 导出进度模态(决策 92,主人定流程):先另存为选路径 → 这里显示进度(生成逐条目% + 写盘%),
|
||||
期间模态阻塞不可做其他操作;唯一出口=「后台导出」→ 收起模态回软件继续干活,后台完成后右下角提醒。 -->
|
||||
<div class="mask" id="expmask">
|
||||
@@ -564,6 +597,23 @@ mark.pghlcur{background:#ff9c40;color:#fff;padding:0} /* 决策 209:当前
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 手工工程导出格式三选(决策 229,2026-10-27 主人定):cos/cos4 走经典整件骨架,
|
||||
Excel=每单位工程一个 xlsx(项目名文件夹打包 zip)。选完走决策 92 同款另存为+进度流程。 -->
|
||||
<div class="mask" id="fmtmask">
|
||||
<div class="dlg" style="width:420px;max-width:92vw">
|
||||
<h4>手工工程导出</h4>
|
||||
<div class="mbody" style="display:flex;flex-direction:column;gap:8px">
|
||||
<button class="btn pri" onclick="exportSession('cos4')">.cos4 经典骨架(易达新版格式)</button>
|
||||
<button class="btn" onclick="exportSession('cos')">.cos 经典骨架(易达老版格式)</button>
|
||||
<button class="btn" onclick="exportSession('xlsx')">Excel 每单位工程一个 xlsx(zip 包)</button>
|
||||
<div style="color:#8a97a8;font-size:12px">cos/cos4=经典项目整件骨架当模板,我方只落分部分项/措施价格信息;该后缀还没收过骨架时请先在后台或工作台导入一份原件。</div>
|
||||
</div>
|
||||
<div class="mfoot" style="text-align:right">
|
||||
<button class="btn" onclick="document.getElementById('fmtmask').classList.remove('on')">取消</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ================= 询价附件(2026-10-09 改版)==================
|
||||
数据 = 对比框里**工料机行**点「采纳」时该行跟随的附件(工程行=绑定的询价资料,
|
||||
价格行=刊物原件),全局收集、按内容去重。不是后台绑定关系的只读展示。
|
||||
@@ -919,16 +969,21 @@ window.__exportProgress = function(p){
|
||||
dlMsg('导出失败:' + (p.msg || ''), 'err');
|
||||
}
|
||||
};
|
||||
async function exportSession(){
|
||||
async function exportSession(fmt){
|
||||
if(!SID){ $('msg').textContent = '先打开工程再导出'; return; }
|
||||
if(MANUAL){ $('msg').textContent = '手工工程没有源文件,不能按原格式导出;请用「打开项目」选择同名源文件补传'; return; }
|
||||
/* 决策 229:手工工程三选(cos4/cos/xlsx);未选格式先弹选择框。普通工程忽略 fmt。 */
|
||||
fmt=(fmt||'').toLowerCase();
|
||||
if(MANUAL && ['cos4','cos','xlsx'].indexOf(fmt)<0){
|
||||
document.getElementById('fmtmask').classList.add('on'); return;
|
||||
}
|
||||
document.getElementById('fmtmask').classList.remove('on');
|
||||
if ($('expmask').classList.contains('on')){ $('msg').textContent = '已有导出进行中(可点「后台导出」转后台)'; return; }
|
||||
$('msg').textContent = '正在按原格式导出(大工程稍等)…';
|
||||
$('msg').textContent = MANUAL ? '正在按经典骨架导出(稍等)…' : '正在按原格式导出(大工程稍等)…';
|
||||
try{
|
||||
const hasBridge = window.pywebview && window.pywebview.api;
|
||||
// ① 新壳(决策 92):先另存为选路径 → 页面进度模态 → 后台生成写盘 → __exportProgress 收尾
|
||||
if (hasBridge && typeof window.pywebview.api.export_save_as === 'function'){
|
||||
const r = await window.pywebview.api.export_save_as(SID, '');
|
||||
const r = await window.pywebview.api.export_save_as(SID, '', fmt);
|
||||
if (r && r.cancel){ $('msg').textContent = '已取消导出'; return; }
|
||||
if (r && r.msg){ $('msg').textContent = '导出失败:' + r.msg; return; }
|
||||
if (r && r.started){ exportModalShow(r.name); return; }
|
||||
@@ -936,12 +991,12 @@ async function exportSession(){
|
||||
}
|
||||
// ② 老壳(只有决策 91 的通用下载桥):生成完才弹框,凑合用
|
||||
if (hasBridge && typeof window.pywebview.api.download_save_as === 'function'){
|
||||
const r = await window.pywebview.api.download_save_as('/api/session/export?session_id=' + SID, '');
|
||||
const r = await window.pywebview.api.download_save_as('/api/session/export?session_id=' + SID + (fmt?('&fmt='+encodeURIComponent(fmt)):''), '');
|
||||
if (r && r.ok){ $('msg').textContent = '已导出:' + (r.name || ''); dlMsg('已另存为:' + r.path, 'ok'); return; }
|
||||
if (r && r.cancel){ $('msg').textContent = '已取消导出'; return; }
|
||||
if (r && r.msg){ $('msg').textContent = '导出失败:' + r.msg; return; }
|
||||
}
|
||||
const resp = await fetch('/api/session/export?session_id=' + SID);
|
||||
const resp = await fetch('/api/session/export?session_id=' + SID + (fmt?('&fmt='+encodeURIComponent(fmt)):''));
|
||||
if(!resp.ok){ const j = await resp.json().catch(()=>null); throw new Error((j && j.msg) || ('HTTP ' + resp.status)); }
|
||||
const cd = resp.headers.get('Content-Disposition') || '';
|
||||
// 服务端同时发 filename="export.zip"(ASCII 兜底)和 filename*=UTF-8''真名(原工程名-审核版.原后缀)。
|
||||
@@ -1134,102 +1189,14 @@ async function refreshRaw(quiet){
|
||||
}
|
||||
}
|
||||
|
||||
/* ==================== 本页搜索(决策 172,2026-10-22 主人定)====================
|
||||
四个工作台页面各一个约 200px 搜索框(原数据=标签卡行·全层级、类似清单/组价=重载行、
|
||||
项目工料机=顶部行),输入即搜(300ms 防抖、不分大小写、包含匹配),本页主数据表
|
||||
命中文字黄底(mark.pghl);目录树不参与;清空恢复。
|
||||
原数据页关键字跨层级/标签保留,重画后自动重新高亮(rawDraw 包一层);
|
||||
其余三页重画后高亮消失、重输即可(第一版口径)。
|
||||
决策 209(2026-10-26 主人定):框右加「上一个/下一个」两枚跳转钮(灰=不可跳:
|
||||
框空/无命中/唯一命中已定位/在第1处无上/在末尾无下),首击「下一个」=从头查找,
|
||||
当前命中橙底(mark.pghlcur)并滚动到可视区,回车=点「下一个」,改词复位,到底不循环。 */
|
||||
let PAGESRCH = { raw: '', incon: '', sim: '', wb: '' };
|
||||
const PG_AREAS = { raw: 'rawbody', incon: 't1', sim: 't2', wb: 't0' };
|
||||
const PG_TIMER = {};
|
||||
const PGS_NAV = { raw: { i: -1 }, incon: { i: -1 }, sim: { i: -1 }, wb: { i: -1 } }; // 决策 209:各页当前命中序号(-1=未定位)
|
||||
// 决策 209:搜索框右边「上一个/下一个」两枚的 HTML(初始灰)
|
||||
function pgsNavBtnsHtml(key){ // 决策 209:搜索框右边的「上一个/下一个」两枚(初始灰,由 pgsSetNav 刷新)
|
||||
return '<button class="pgsnav" data-pg="' + key + '" data-dir="-1" title="上一个命中"'
|
||||
+ ' onclick="pageSearchNav(\'' + key + '\',-1)" disabled>上一个</button>'
|
||||
+ '<button class="pgsnav" data-pg="' + key + '" data-dir="1" title="下一个命中(首击=从头查找)"'
|
||||
+ ' onclick="pageSearchNav(\'' + key + '\',1)" disabled>下一个</button>';
|
||||
}
|
||||
// 决策 209:五态灰活唯一入口(框空/无命中/唯一已定位/第1处/末尾)
|
||||
function pgsSetNav(key){ // 决策 209:按 框空/无命中/当前位置 刷两枚钮的灰活
|
||||
const el = document.getElementById(PG_AREAS[key]);
|
||||
const n = el ? el.querySelectorAll('mark.pghl').length : 0;
|
||||
const i = PGS_NAV[key].i;
|
||||
document.querySelectorAll('button.pgsnav[data-pg="' + key + '"]').forEach(b => {
|
||||
const d = Number(b.dataset.dir);
|
||||
b.disabled = !PAGESRCH[key] ? true
|
||||
: d < 0 ? (i <= 0)
|
||||
: (i < 0 ? n < 1 : i >= n - 1);
|
||||
});
|
||||
}
|
||||
// 决策 209:命中间跳转;缺高亮(非 raw 三页重画后)先补挂再跳
|
||||
function pageSearchNav(key, dir){ // 决策 209:命中间跳转;重画丢高亮先补黄底再跳
|
||||
const kw = PAGESRCH[key];
|
||||
if (!kw) return;
|
||||
const el = document.getElementById(PG_AREAS[key]);
|
||||
if (!el) return;
|
||||
let marks = el.querySelectorAll('mark.pghl');
|
||||
if (!marks.length) { PGS_NAV[key].i = -1; hlContainer(el, kw); marks = el.querySelectorAll('mark.pghl'); }
|
||||
const n = marks.length;
|
||||
if (!n) { pgsSetNav(key); return; }
|
||||
let i = PGS_NAV[key].i;
|
||||
if (dir > 0) { if (i >= n - 1) return; i = i < 0 ? 0 : i + 1; }
|
||||
else { if (i <= 0) return; i -= 1; }
|
||||
PGS_NAV[key].i = i;
|
||||
marks.forEach(m => m.classList.remove('pghlcur'));
|
||||
marks[i].classList.add('pghlcur');
|
||||
marks[i].scrollIntoView({ block: 'center' });
|
||||
pgsSetNav(key);
|
||||
}
|
||||
window.pageSearchBox = function(){ // 原数据标签卡行用(common.js rawTabs 渲染,工作台专用)
|
||||
return '<input class="mi pgsrch" placeholder="搜索本页数据"'
|
||||
+ ' title="搜索本页数据,命中黄底(目录树不参与)" value="' + esc(PAGESRCH.raw || '') + '"'
|
||||
+ ' oninput="pageSearchGo(\'raw\', this.value)"'
|
||||
+ ' onkeydown="if(event.key===\'Enter\')pageSearchNav(\'raw\',1)">'
|
||||
+ pgsNavBtnsHtml('raw');
|
||||
};
|
||||
function hlContainer(root, kw){
|
||||
root.querySelectorAll('mark.pghl').forEach(m => { m.replaceWith(document.createTextNode(m.textContent)); });
|
||||
root.normalize();
|
||||
if (!kw) return 0;
|
||||
const kwU = kw.toUpperCase();
|
||||
const bad = { SCRIPT:1, STYLE:1, MARK:1, INPUT:1, TEXTAREA:1, SELECT:1 };
|
||||
const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, {
|
||||
acceptNode: nd => {
|
||||
if (!nd.nodeValue || !nd.nodeValue.trim()) return NodeFilter.FILTER_REJECT;
|
||||
if (bad[nd.parentNode.nodeName]) return NodeFilter.FILTER_REJECT;
|
||||
return nd.nodeValue.toUpperCase().indexOf(kwU) >= 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_REJECT;
|
||||
}});
|
||||
const hits = []; let nd;
|
||||
while ((nd = walker.nextNode())) hits.push(nd);
|
||||
hits.forEach(node => {
|
||||
const s = node.nodeValue, up = s.toUpperCase();
|
||||
const frag = document.createDocumentFragment();
|
||||
let i = 0, j;
|
||||
while ((j = up.indexOf(kwU, i)) >= 0) {
|
||||
if (j > i) frag.appendChild(document.createTextNode(s.slice(i, j)));
|
||||
const m = document.createElement('mark'); m.className = 'pghl'; m.textContent = s.slice(j, j + kw.length);
|
||||
frag.appendChild(m); i = j + kw.length;
|
||||
}
|
||||
if (i < s.length) frag.appendChild(document.createTextNode(s.slice(i)));
|
||||
node.replaceWith(frag);
|
||||
});
|
||||
return hits.length;
|
||||
}
|
||||
function pageSearchGo(key, val){
|
||||
PAGESRCH[key] = val || '';
|
||||
clearTimeout(PG_TIMER[key]);
|
||||
PG_TIMER[key] = setTimeout(() => {
|
||||
const el = document.getElementById(PG_AREAS[key]);
|
||||
if (el) hlContainer(el, PAGESRCH[key]);
|
||||
PGS_NAV[key].i = -1; // 决策 209:改词=回未查找态,首击「下一个」重新从头定位
|
||||
pgsSetNav(key);
|
||||
}, 300);
|
||||
}
|
||||
/* ==================== 本页搜索(决策 172/209;2026-10-27 决策 229 上移共享层)====================
|
||||
输入即搜黄底、上一个/下一个、五态灰、定位前自动展开收起的 ± 把手——核心全在 common.js
|
||||
(工作台四页 + 后台入库项目列表/明细/附件 共用一套)。本页只注册四个页签的内容区;
|
||||
原数据页重画后自动重新高亮 + 搜索框 × 重挂见下方 rawDraw 包一层(工作台专用)。 */
|
||||
pgReg('raw', 'rawbody', pgRawExpand); // 决策 229:命中在收起的分部/清单里 → 定位时自动展开再滚
|
||||
pgReg('incon', 't1', pgGrpExpand); // 决策 229:组表把手同款(渲染过再收起的组行定位时自动点开)
|
||||
pgReg('sim', 't2', pgGrpExpand);
|
||||
pgReg('wb', 't0');
|
||||
(function(){ // 原数据页重画后自动重新高亮 + 搜索框 × 重挂(切层级/标签/排序都走 rawDraw)
|
||||
const _rd = rawDraw;
|
||||
rawDraw = async function(){
|
||||
@@ -1806,9 +1773,10 @@ function setManualMode(manual){
|
||||
MANUAL=!!manual;
|
||||
const b=document.getElementById('btnExport');
|
||||
if(b){
|
||||
b.disabled=!!manual;
|
||||
/* 决策 229:手工工程放开导出——cos/cos4(经典骨架)与 Excel 三选,点导出先弹格式选择 */
|
||||
b.disabled=false;
|
||||
b.title=manual
|
||||
? '手工工程没有源文件,不能按原格式导出;请用「打开项目」选择同名源文件补传'
|
||||
? '手工工程导出:.cos/.cos4(经典整件骨架当模板)或 Excel(每单位工程一个文件)'
|
||||
: '按原格式导出本工程(含全部编辑:临删已省略、新增/采纳已写入)。只能对工作台的数据进行导出';
|
||||
}
|
||||
}
|
||||
@@ -3516,6 +3484,122 @@ function cfgTab(name){
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
/* ================= 导入项目(手工工程·决策 230):同框建目录树 + 按单位工程导 Excel =================
|
||||
按钮显隐三态:空态(未打开工程)显示;源文件工程隐藏;手工工程常驻(再点回弹框补目录/覆盖导入)。 */
|
||||
let ITREE=null, ISEL='';
|
||||
mkPeriod($('iper'));
|
||||
function impVis(){
|
||||
const w=$('impWrap'); if(!w) return;
|
||||
w.innerHTML = (!SID || MANUAL)
|
||||
? '<button class="btn pri" style="padding:3px 12px;font-size:12px" onclick="impDlgOpen()">导入项目</button>' : '';
|
||||
const t=document.getElementById('rawtree');
|
||||
if(t && !SID) t.innerHTML='<div style="padding:28px 14px;color:#8a97a8;text-align:center;line-height:2">尚未打开工程<br>点右上角「导入项目」:建目录树、按单位工程导入 Excel</div>';
|
||||
}
|
||||
(function(){ const _sm=setManualMode; setManualMode=function(m){ _sm(m); impVis(); }; })();
|
||||
impVis();
|
||||
|
||||
function impDlgOpen(){
|
||||
ITREE=[{name:'单项工程 1',units:[{name:'单位工程 1'}]}];
|
||||
$('iname').value=''; $('iper').value=''; $('ifile').value=''; $('imsg').textContent='';
|
||||
$('ititle').textContent='导入项目';
|
||||
$('ibtnSave').textContent='保存并创建工程';
|
||||
imask.classList.add('on');
|
||||
impTreeRender();
|
||||
if(SID && MANUAL){ // 手工工程:回填现有目录树
|
||||
J('/api/session/manual/state?session_id='+SID).then(d=>{
|
||||
if(d && d.ok && d.sections && d.sections.length){
|
||||
ITREE=d.sections.map(s=>({id:s.id,name:s.name,
|
||||
units:(s.units||[]).map(u=>({id:u.id,name:u.name,n_item:u.n_item,n_prelim:u.n_prelim}))}));
|
||||
$('iname').value=d.name||'';
|
||||
if(d.period_from){ // 基准期次回填(月序号 → YYYY-MM)
|
||||
const f2s=v=>{const y=Math.floor(v/12),m=v%12||12;return (m===12?y-1:y)+'-'+String(m).padStart(2,'0');};
|
||||
setPeriod($('iper'), f2s(d.period_from), f2s(d.period_to||d.period_from));
|
||||
}
|
||||
$('ititle').textContent='导入项目 · 编辑目录树';
|
||||
$('ibtnSave').textContent='保存(更新目录树)';
|
||||
impTreeRender();
|
||||
}
|
||||
}).catch(()=>{});
|
||||
}
|
||||
}
|
||||
function impTreeRender(){
|
||||
const nm=$('iname').value.trim()||'(工程名称)';
|
||||
let h='<div class="ied"><span class="itag tg0">项目</span><span class="inm" onclick="$(\'iname\').focus()" style="cursor:pointer" title="点改名(顶部工程名称)">'+esc(nm)+'</span>'
|
||||
+'<span class="iact"><button class="iab" onclick="impAddSec()">+单项工程</button></span></div>';
|
||||
ITREE.forEach((s,si)=>{
|
||||
h+='<div class="ied" style="padding-left:26px"><span class="itag tg1">单项工程</span><span class="inm" onclick="impRename(this,'+si+',-1)">'+esc(s.name)+'</span>'
|
||||
+'<span class="iact"><button class="iab" title="组内上移" onclick="impMovSec('+si+',-1)"'+(si===0?' disabled':'')+'>↑</button>'
|
||||
+'<button class="iab" title="组内下移" onclick="impMovSec('+si+',1)"'+(si===ITREE.length-1?' disabled':'')+'>↓</button>'
|
||||
+'<button class="iab" onclick="impAddUw('+si+')">+单位工程</button><button class="iab x" onclick="impDelSec('+si+')">✕</button></span></div>';
|
||||
s.units.forEach((u,ui)=>{
|
||||
let st='';
|
||||
if(u.err) st='<span class="ierr" title="'+esc(u.err)+'">✗ '+esc(u.err)+'</span>';
|
||||
else if(u.file) st='<span class="iok">✓ 清单'+u.n_item+'+措施'+u.n_prelim+'</span>';
|
||||
else if(u.id && (u.n_item||u.n_prelim)) st='<span class="iok">✓ 清单'+u.n_item+'+措施'+u.n_prelim+'</span>';
|
||||
h+='<div class="ied" style="padding-left:52px"><span class="itag tg2">单位工程</span><span class="inm" onclick="impRename(this,'+si+','+ui+')">'+esc(u.name)+'</span>'
|
||||
+st
|
||||
+'<span class="iact"><button class="iab" title="组内上移" onclick="impMovUw('+si+','+ui+',-1)"'+(ui===0?' disabled':'')+'>↑</button>'
|
||||
+'<button class="iab" title="组内下移" onclick="impMovUw('+si+','+ui+',1)"'+(ui===s.units.length-1?' disabled':'')+'>↓</button>'
|
||||
+'<button class="iab imp" onclick="impPick('+si+','+ui+')" title="按模板导入(整单位工程覆盖)">导入单位工程</button><button class="iab x" onclick="impDelUw('+si+','+ui+')">✕</button></span></div>';
|
||||
});
|
||||
});
|
||||
$('itree').innerHTML=h;
|
||||
}
|
||||
function impRename(sp,si,ui){
|
||||
const cur=sp.textContent, inp=document.createElement('input'); inp.value=cur;
|
||||
sp.replaceWith(inp); inp.focus(); inp.select();
|
||||
const done=()=>{ const v=inp.value.trim()||cur;
|
||||
if(ui<0) ITREE[si].name=v; else ITREE[si].units[ui].name=v;
|
||||
impTreeRender(); };
|
||||
inp.onblur=done;
|
||||
inp.onkeydown=e=>{ if(e.key==='Enter')inp.blur(); if(e.key==='Escape'){inp.value=cur;inp.blur();} };
|
||||
}
|
||||
function impAddSec(){ ITREE.push({name:'单项工程 '+(ITREE.length+1),units:[{name:'单位工程 1'}]}); impTreeRender(); }
|
||||
function impDelSec(i){ if(ITREE.length<=1){$('imsg').textContent='至少保留一个单项工程';return;} ITREE.splice(i,1); impTreeRender(); }
|
||||
function impAddUw(si){ ITREE[si].units.push({name:'单位工程 '+(ITREE[si].units.length+1)}); impTreeRender(); }
|
||||
function impDelUw(si,ui){ ITREE[si].units.splice(ui,1); impTreeRender(); }
|
||||
/* 决策 230 补记:单项/单位只在组内上下移动(单项换位=整组跟着走;单位不跨单项组) */
|
||||
function impMovSec(i,d){ const j=i+d; if(j<0||j>=ITREE.length) return;
|
||||
const t=ITREE[i]; ITREE[i]=ITREE[j]; ITREE[j]=t; impTreeRender(); }
|
||||
function impMovUw(si,ui,d){ const us=ITREE[si].units, j=ui+d; if(j<0||j>=us.length) return;
|
||||
const t=us[ui]; us[ui]=us[j]; us[j]=t; impTreeRender(); }
|
||||
function impPick(si,ui){ ISEL=si+','+ui; $('ifile').value=''; $('ifile').click(); }
|
||||
async function impFile(){
|
||||
const f=$('ifile').files[0]; $('ifile').value='';
|
||||
if(!f||!ISEL) return;
|
||||
const [si,ui]=ISEL.split(',').map(Number), u=ITREE[si].units[ui];
|
||||
$('imsg').textContent='正在上传并校验 '+f.name+'…';
|
||||
const up=await uploadFile('/api/admin/upload',f);
|
||||
if(!up.ok){ $('imsg').textContent=up.msg; return; }
|
||||
const r=await J('/api/session/manual/parse',{method:'POST',headers:{'Content-Type':'application/json'},
|
||||
body:JSON.stringify({path:up.path})});
|
||||
if(!r.ok){ u.file=''; u.err=r.msg||'校验失败'; $('imsg').textContent='✗ '+u.err; impTreeRender(); return; }
|
||||
u.file=up.path; u.n_item=r.n_item; u.n_prelim=r.n_prelim; delete u.err;
|
||||
$('imsg').textContent=''; impTreeRender();
|
||||
}
|
||||
function impTemplate(){ return saveAs('/api/session/manual/template','单位工程导入模板.xlsx'); }
|
||||
async function impSave(){
|
||||
const name=$('iname').value.trim(), pv=PVAL($('iper'));
|
||||
if(!name){ $('imsg').textContent='工程名称必填'; return; }
|
||||
if(pv.f==null||pv.t==null){ $('imsg').textContent='基准期次必填:点开选起~止(同月就选同一个)'; return; }
|
||||
for(const s of ITREE){
|
||||
if(!s.name.trim()){ $('imsg').textContent='单项工程名称不能为空'; return; }
|
||||
if(!s.units.length){ $('imsg').textContent='「'+s.name+'」下至少一个单位工程'; return; }
|
||||
for(const u of s.units) if(!u.name.trim()){ $('imsg').textContent='单位工程名称不能为空'; return; }
|
||||
}
|
||||
$('ibtnSave').disabled=true; $('imsg').textContent='正在保存…';
|
||||
try{
|
||||
const r=await J('/api/session/manual/save',{method:'POST',headers:{'Content-Type':'application/json'},
|
||||
body:JSON.stringify({sid:(SID&&MANUAL)?SID:0,name,period_from:pv.f,period_to:pv.t,
|
||||
tree:ITREE.map(s=>({id:s.id||0,name:s.name.trim(),
|
||||
units:s.units.map(u=>({id:u.id||0,name:u.name.trim(),file:u.file||''}))}))})});
|
||||
if(!r.ok){ $('imsg').textContent=r.msg||'保存失败'; return; }
|
||||
imask.classList.remove('on');
|
||||
location.href='/workbench.html?sid='+r.session_id; // 手工工程:initFromUrl 跳过重解析
|
||||
} finally { $('ibtnSave').disabled=false; }
|
||||
}
|
||||
</script>
|
||||
<script>licMount('.tabright');</script><!-- 统一设置窗口+到期预警(决策 31,实现在 common.js) -->
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user