chore(AdminCost): 移除 COS4 数据结构迁移的一次性脚本与参考资料

This commit is contained in:
lianjianwei2024
2026-11-01 15:27:27 +08:00
parent 386e1ad624
commit f0b1033b12
69 changed files with 5936 additions and 42964 deletions

View File

@@ -183,6 +183,25 @@ a:hover{text-decoration:underline}
#dbody.simflex{display:flex}
#simtree{width:230px;flex:none;border-right:1px solid var(--line);overflow:auto;padding:6px 4px;background:#fcfdfe}
.close{cursor:pointer;color:#8899aa;font-size:20px;line-height:1}
/* 决策 245(2026-11-01):导入弹框「导入Excel」树区——样式照工作台 #itree 同款(同码同形) */
#aitree .ied{display:flex;align-items:center;gap:6px;padding:4px 8px;border-radius:4px}
#aitree .ied:hover{background:#f0f4fa}
#aitree .itag{flex:none;font-size:11px;border-radius:3px;padding:1px 6px}
#aitree .tg0{background:#e8edf5;color:#41506e}#aitree .tg1{background:#e3ecfa;color:#1c4f9c}#aitree .tg2{background:#dcf0e2;color:#17663a}
#aitree .inm{overflow:hidden;text-overflow:ellipsis;cursor:text;white-space:nowrap}
#aitree .iact{margin-left:auto;display:flex;gap:4px;align-items:center;flex:none}
#aitree .iab{font-size:11px;border:1px solid #c3cad6;background:#fff;border-radius:3px;padding:1px 6px;cursor:pointer;color:#41506e}
#aitree .iab:disabled{opacity:.35;cursor:default}
#aitree .iab.x{color:#b03a2e;border-color:#e3b6b0}
#aitree .iab.imp{color:#1c66d6;border-color:#9db9e8}
#aitree .iok{font-size:11px;color:#1f8f4d;white-space:nowrap;flex:none}
#aitree .ierr{font-size:11px;color:#b03a2e;max-width:260px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;flex:none}
#aitree .ied input{border:1px solid #9db9e8;border-radius:3px;padding:2px 6px;font-size:13px;min-width:140px;flex:1}
#idlg{width:min(640px,92vw)}
#idlg.exp{height:672px}
#idlg.exp #ibody{flex:1;min-height:0}
#ileft{flex:1}
#idlg.exp #ileft{flex:none;width:388px}
.tip{color:var(--muted);font-size:12px;padding:6px 0}
/* 明细:左侧目录 + 右侧内容(照上传 HTML 的版式) */
#dpage .db.fx{display:flex;overflow:hidden}
@@ -466,56 +485,70 @@ td.pcell input{width:100%;padding:3px 7px;font-size:12.5px;border:1px solid #9fb
</div>
<div class="mask" id="imask">
<div class="dlg" style="width:min(720px,92vw)">
<div class="dh"><b>导入工程文件</b><span class="close" onclick="closeImp()">×</span></div>
<div class="bar" style="flex-direction:column;align-items:stretch;gap:10px">
<div style="display:flex;gap:8px;align-items:center">
<span style="width:74px">文件 *</span>
<input type="file" id="ifile" style="flex:1" onchange="pickFile(this)">
<!-- 决策 245(2026-11-01 主人定):后台弹框与工作台「打开项目」弹框统一,以工作台为准——
字段/顺序/提示/按钮一致,唯一区别=写入库(这里写 history.db 批次,工作台写 session.db 会话);
底部提示词两侧逐字相同。价格类(信息价/市场价)仍用本框的价格字段,工程类走同款字段。 -->
<div class="dlg" id="idlg">
<div class="dh"><b id="impTitle">打开项目</b><span class="close" onclick="closeImp()">×</span></div>
<div class="bar" id="ibody" style="flex-direction:row;align-items:stretch;gap:16px;overflow:hidden">
<div id="ileft" style="min-width:0;display:flex;flex-direction:column;gap:10px">
<div id="irowFile" style="display:flex;gap:8px;align-items:center">
<span style="width:88px">全国电子标书</span>
<input type="file" id="ifile" style="flex:1" onchange="pickFile(this)">
</div>
<div id="ifileInfo" class="tip" style="padding:0 0 0 82px"></div>
<div style="display:flex;gap:8px;align-items:center">
<span style="width:88px">工程名称 *</span>
<input id="iname" style="flex:1" placeholder="选文件后自动带出文件名,可改">
</div>
<div id="irowPer" style="display:flex;gap:8px;align-items:center">
<span style="width:88px">基准期次 *</span>
<input id="iper" style="flex:1" placeholder="点这里选起~止(同月就选同一个)">
</div>
<div style="display:flex;gap:8px;align-items:center">
<span style="width:88px">地区 *</span>
<select id="iprov" style="flex:1"><option value="">省</option></select>
<select id="icity" style="flex:1"><option value="">市</option></select>
<select id="idist" style="flex:1"><option value="">区/县/镇</option></select>
</div>
<div id="irowBuid" style="display:flex;gap:8px;align-items:center">
<span style="width:88px">建设单位 *</span>
<input id="ibuid" style="flex:1" placeholder="输入或从历史项目选择" autocomplete="off">
</div>
<div id="irowFk" style="display:flex;gap:8px;align-items:center">
<span style="width:88px">单价类型 *</span>
<select id="ifk" style="flex:1"></select>
</div>
<div id="irowPub" style="display:flex;gap:8px;align-items:center">
<span style="width:88px">发布单位 *</span>
<select id="ipub" style="flex:1"></select>
</div>
<div id="irowPdf" style="display:flex;gap:8px;align-items:center">
<span style="width:88px">附件</span>
<input type="file" id="ipdf" style="flex:1">
<span class="tip" style="width:110px">任意格式,选填</span>
</div>
<div id="irowNote" style="display:flex;gap:8px;align-items:center">
<span style="width:88px">备注</span>
<input id="inote" style="flex:1" placeholder="选填">
</div>
<div id="irowTip" class="tip" style="padding:0 0 0 82px"></div>
</div>
<div id="ifileInfo" class="tip" style="padding:0 0 0 82px"></div>
<div style="display:flex;gap:8px;align-items:center">
<span style="width:74px">名称 *</span>
<input id="iname" style="flex:1" placeholder="必填:工程名称">
</div>
<div style="display:flex;gap:8px;align-items:center">
<span style="width:74px">地区 *</span>
<select id="iprov" style="flex:1"><option value="">省</option></select>
<select id="icity" style="flex:1"><option value="">市</option></select>
<select id="idist" style="flex:1"><option value="">区/县/镇</option></select>
</div>
<div style="display:flex;gap:8px;align-items:center">
<span style="width:74px">期次 *</span>
<input id="iper" style="flex:1" placeholder="点这里选起~止(同一个月就选同一个)">
</div>
<div id="irowBuid" style="display:flex;gap:8px;align-items:center">
<span style="width:74px">建设单位 *</span>
<input id="ibuid" style="flex:1" placeholder="输入或从历史项目选择" autocomplete="off">
</div>
<div id="irowFk" style="display:flex;gap:8px;align-items:center">
<span style="width:74px">单价类型 *</span>
<select id="ifk" style="flex:1"></select>
</div>
<div id="irowPub" style="display:flex;gap:8px;align-items:center">
<span style="width:74px">发布单位 *</span>
<select id="ipub" style="flex:1"></select>
</div>
<div id="irowPdf" style="display:flex;gap:8px;align-items:center">
<span style="width:74px">附件</span>
<input type="file" id="ipdf" style="flex:1">
<span class="tip" style="width:110px">任意格式,选填</span>
</div>
<div id="irowNote" style="display:flex;gap:8px;align-items:center">
<span style="width:74px">备注</span>
<input id="inote" style="flex:1" placeholder="选填">
</div>
<div id="irowTip" class="tip" style="padding:0 0 0 82px"></div>
<div style="display:flex;gap:8px;align-items:center;justify-content:flex-end">
<span class="tip" id="imsg"></span>
<button class="btn" onclick="closeImp()">取消</button>
<button class="btn pri" onclick="doImport()">开始导入</button>
<!-- 导入Excel 右侧目录树面板(决策 245):与工作台同一套树/模板/按钮,Excel 建的工程落批次库 -->
<div id="apanel" style="display:none;flex:1;min-width:0;flex-direction:column">
<div id="aitree" style="flex:1;min-height:0;overflow:auto;border:1px solid #e3eaf2;border-radius:6px;padding:6px 4px;background:#fbfcfe"></div>
<div class="tip" id="aimsg" style="padding-top:8px"></div>
</div>
</div>
<div style="display:flex;gap:10px;align-items:center;padding:10px 16px;border-top:1px solid #e3eaf2;background:#fafcff">
<span class="tip" id="imRemind" style="flex:1;min-width:0;color:#b03a2e;line-height:1.45">提醒:建议在打开或导入项目时,先把工程独有的增加费(暗室、超高降效、预算包干、垂直运输等)取消后再入库或工作台的审核对比,否则容易造成数据失真!</span>
<span class="tip" id="imsg"></span>
<button class="btn" onclick="closeImp()">取消</button>
<button class="btn" id="impBtnX" onclick="aimpToggle()" title="右边展开目录树:按单位工程导入 Excel 建工程(与工作台同一套模板)">导入Excel</button>
<input type="file" id="iprojfile" accept=".xlsx" style="display:none" onchange="aimpProjFile()">
<input type="file" id="ifile2" accept=".xlsx" style="display:none" onchange="aimpFile()">
<button class="btn pri" id="ibtnGo" onclick="doImport()">打开</button>
</div>
</div>
</div>
@@ -1225,6 +1258,11 @@ function almeRender(){
const view=sortRows(ALME_ROWS, ALME_SORT.k, ALME_SORT.dir, ALME_NUM);
document.getElementById('dtbd').innerHTML=renderLme(view, WB_OPTS)
||`<tr><td colspan="${AC_LME.length}" class="tip" style="text-align:center;padding:16px">没有数据</td></tr>`;
// 决策 243 补记三:切页签回来找回上次选中的工料机行(同工作台 wantLme 手法)
if(window.ALME_ID){
const tr=document.querySelector('#dtbd tr[data-id="'+window.ALME_ID+'"]');
if(tr){ tr.classList.add('sel'); tr.scrollIntoView({block:'center'}); }
}
}
// 定额(挂在清单下):定额编码 / 定额名称 / 单位 / 单价(COL_PRICE 已上移进价格明细模块,2026-10-12)
const COL_NORM=[{t:'定额编码',a:'c',w:130},{t:'定额名称',a:'l',w:300},
@@ -1244,9 +1282,17 @@ var _rawPickBaseAdm = rawPick;
rawPick = async function(k, id, el){
if(RVSEL.k==='uw' && RVSEL.id){
const sel=document.querySelector('#drawbody tr.sel');
const sp=(function(e){for(let x=e&&e.parentElement;x&&x!==document.body;x=x.parentElement){const cs=getComputedStyle(x);if(/(auto|scroll)/.test(cs.overflowY)&&x.scrollHeight>x.clientHeight+2)return x;}return null;})(document.querySelector('#drawbody'));
RAWSEL_MEM[DID+':'+RVSEL.id]={ bid: sel?sel.dataset.bid:((RAWSEL_MEM[DID+':'+RVSEL.id]||{}).bid||null),
rvtab: RVTAB, scroll: sp?sp.scrollTop:null };
const sub=document.querySelector('#drawbody tr.subsel');
// 决策 243 补记三:**有现场才写存档**——WB_RAW.load() 内部恢复树也会调 rawPick,
// 此刻 drawbody 是重画初的空表,空抓拍会把已有存档覆盖成全 null(实测踩坑)
if(sel || sub){
const sp=(function(e){for(let x=e;x&&x!==document.body;x=x.parentElement){const cs=getComputedStyle(x);if(/(auto|scroll)/.test(cs.overflowY)&&x.scrollHeight>x.clientHeight+2)return x;}return null;})(document.querySelector('#drawbody'));
const o=RAWSEL_MEM[DID+':'+RVSEL.id]||{};
RAWSEL_MEM[DID+':'+RVSEL.id]=Object.assign(o, {
bid: sel?sel.dataset.bid:(sub?sub.dataset.bid:(o.bid||null)),
rvtab: RVTAB, scroll: sp?sp.scrollTop:null,
normsel: sub?sub.dataset.nid:(o.normsel||null) });
}
}
await _rawPickBaseAdm(k, id, el);
if(k==='uw'){
@@ -1260,6 +1306,9 @@ rawPick = async function(k, id, el){
else tr.scrollIntoView({block:'center'});
}
}
// 决策 243 补记三:恢复 sel+定额(守窗自愈)
if(rec && (rec.bid || rec.normsel))
_rawSceneGuard(document.getElementById('drawbody'), rec.bid || null, rec.normsel || null, 3000);
}
};
var WB_RAW = RawView({
@@ -1269,8 +1318,24 @@ var WB_RAW = RawView({
normApi: function(nid){ return '/api/admin/norm/' + nid + '/res'; },
lmeApi: function(){ return '/api/admin/lme/res?batch_id=' + DID; },
treeEl: 'drawtree', tabsEl: 'drawstabs', bodyEl: 'drawbody',
rowClick: 'admPick', // 决策 243 补记三:后台原数据清单/定额可点选(记忆+守窗恢复的前提)
lmeBackend: true // 决策 147:后台原数据项目级卡=后台项目工料机列集(无取消采纳/备注列)
});
/* 决策 243 补记三:后台原数据清单行点选(同工作台 pick 的视觉语义:单选 sel、清定额 subsel;
纯视觉+记忆,后台无对比框/采纳链路,不动 CUR) */
window.admPick = function(type, id, tr) {
document.querySelectorAll('#drawbody tr.sel').forEach(x => x.classList.remove('sel'));
document.querySelectorAll('#drawbody tr.subsel').forEach(x => x.classList.remove('subsel'));
if (tr) tr.classList.add('sel');
};
/* 决策 243 补记三:后台定额子行点选(同工作台规格 2026-10-16③,无 SID 条件的后台版) */
document.addEventListener('click', function(e) {
const tr = e.target.closest && e.target.closest('#drawbody tr.sub');
if (!tr || !tr.dataset.nid) return;
document.querySelectorAll('#drawbody tr.subsel').forEach(x => x.classList.remove('subsel'));
tr.classList.add('subsel');
document.querySelectorAll('#drawbody tr.sel').forEach(x => x.classList.remove('sel'));
});
/* 明细弹框布局编排(2026-10-13 收编,**单一写入点**):
弹框是同一个 DOM 被四种内容复用 —— price=价格明细(左目录树+右一张表)/
@@ -1413,6 +1478,25 @@ window.addEventListener('resize', ()=>{ if(XACT>=0){ const t=XTABS[XACT];
showPage(t && t.kind==='inq' ? 'inq' : 'detail'); } });
async function loadTab(pid, fresh){
// 决策 243 补记三:切走前抓拍现场——p3=原数据(清单/定额选中+展开+滚动);p0=工料机选中行
if(KIND==='project'){
if(pid!=='p3' && document.querySelector('#drawbody tr.brow')){ // 正在**离开** p3 → 抓拍现场
if (RVSEL.k==='uw') {
const rec=RAWSEL_MEM[DID+':'+RVSEL.id]||{};
const scene=_normSceneCapture(document.getElementById('drawbody'));
const sel=document.querySelector('#drawbody tr.sel');
const sp=(function(e){for(let x=e;x&&x!==document.body;x=x.parentElement){const cs=getComputedStyle(x);if(/(auto|scroll)/.test(cs.overflowY)&&x.scrollHeight>x.clientHeight+2)return x;}return null;})(document.querySelector('#drawbody'));
RAWSEL_MEM[DID+':'+RVSEL.id]=Object.assign(rec, {
bid: sel?sel.dataset.bid:(rec.bid||null), rvtab: RVTAB,
scroll: sp?sp.scrollTop:(rec.scroll!=null?rec.scroll:null),
normsel: scene.normsel });
}
}
if(pid==='p0'){
const sel=document.querySelector('#dtbd tr.sel');
window.ALME_ID = sel ? (sel.dataset.id||null) : (window.ALME_ID||null);
}
}
document.querySelectorAll('#dtabs .tab').forEach(x=>x.classList.toggle('on',x.dataset.p===pid));
dPgReset(); // 决策 229:换页签=搜索复位(关键词/黄底/跳转钮路由)
const cg=document.getElementById('dcg'), th=document.getElementById('dth'), tb=document.getElementById('dtbd');
@@ -1432,12 +1516,11 @@ async function loadTab(pid, fresh){
ldStage(40,'正在加载原数据(目录树+汇总卡)…');
await WB_RAW.load();
// 决策 214 补:回到明细原数据 → 恢复该单位工程上次选中行
// 决策 243 补记三:恢复用**守窗自愈**(同工作台 _p3RestoreSel,防异步重画洗掉)
(function(){
const rec=RAWSEL_MEM[DID+':'+RVSEL.id];
if(rec && rec.bid && !document.querySelector('#drawbody tr.sel')){
const tr=document.querySelector('#drawbody tr.brow[data-bid="'+rec.bid+'"]');
if(tr){ tr.classList.add('sel'); tr.scrollIntoView({block:'center'}); }
}
if(!rec || (!rec.bid && !rec.normsel)) return;
_rawSceneGuard(document.getElementById('drawbody'), rec.bid || null, rec.normsel || null, 3500);
})();
return;
}
@@ -1488,11 +1571,17 @@ async function loadTab(pid, fresh){
async function openImp(){
imask.classList.add('on');
const isPrice = (KIND!=='project');
// 决策 245(2026-11-01 主人定):工程类弹框与工作台「打开项目」一模一样——字段/顺序/提示/按钮同款
document.getElementById('impTitle').textContent = isPrice ? '导入工程文件' : '打开项目';
document.getElementById('irowBuid').style.display = isPrice?'none':'flex';
document.getElementById('irowFk').style.display = isPrice?'none':'flex';
document.getElementById('irowNote').style.display = isPrice?'flex':'none';
document.getElementById('irowPub').style.display = isPrice?'flex':'none';
document.getElementById('irowPdf').style.display = isPrice?'flex':'none';
document.getElementById('impBtnX').style.display = isPrice?'none':'inline-block';
document.getElementById('ibtnGo').textContent = isPrice ? '开始导入' : '打开';
document.getElementById('imRemind').style.display = isPrice?'none':'block';
if(AIOPEN) aimpToggle(); // 每次打开先收回树区(与工作台 openDlg 同款)
ipdf.value='';
// 每次只能导入一个文件:从你自己电脑的任意位置选,选完会传进软件目录
ifile.value=''; UPF=null;
@@ -1502,12 +1591,15 @@ async function openImp(){
//(深圳数据交换标准,散装 XML 或压缩包内 XML;扩展名不分大小写)。
ifile.accept = isPrice ? '.xlsx' : '.cos4,.cos,.swt,.swz';
document.getElementById('ifileInfo').textContent='';
document.getElementById('ifileInfo').style.display = isPrice?'block':'none';
document.getElementById('irowTip').textContent = isPrice
? '信息价/市场价:只收「标准模板」Excel(.xlsx,每次一个)+ 附件原件(任意格式,选填)。'
+ '名称留空或点文件后自动带出文件名(可改);期次留空时自动从文件名里认(如「珠海信息价_2026年7月」→ 2026-07)。'
: '工程:选择一个 .cos4 / .cos / .swt / .swz 文件(可从电脑任意位置选,每次只能一个)。全部必填。';
: '';
imsg.textContent='';
await loadImpFilters();
// 单价类型默认「预算综合单价」(与工作台打开项目弹框同一默认)
try{ if(ifk.options.length) ifk.value='1'; }catch(e){}
}
async function pickFile(inp){
@@ -1532,6 +1624,133 @@ async function pickFile(inp){
function closeImp(){ imask.classList.remove('on') }
/* ================= 导入Excel(决策 245,2026-11-01 主人定):后台弹框与工作台同款树区 =================
项目行:单位模板/项目模板/项目导入/+单项工程;单位工程行:↑↓/导入单位工程/✕。
与工作台唯一区别=落库目标:这里写 history.db 批次(工作台写 session.db 会话);
模板与校验完全同一套(/api/session/manual/* 只读或模板下载)。 */
let AITREE=null, AISEL='', AIOPEN=false;
function aimpToggle(){
const isPrice = (KIND!=='project');
if(isPrice && !AIOPEN) return; // 价格类没有树区;但切到价格类时允许收起
AIOPEN=!AIOPEN;
const on=AIOPEN;
$('apanel').style.display=on?'flex':'none';
$('irowFile').style.display=on?'none':'flex';
$('impBtnX').classList[on?'add':'remove']('pri');
$('idlg').style.width=on?'1100px':'';
$('idlg').classList[on?'add':'remove']('exp');
$('ibtnGo').textContent=on?'创建工程':(isPrice?'开始导入':'打开');
$('ibtnGo').onclick=on?aimpSave:doImport;
$('impTitle').textContent=on?'打开项目 · 导入Excel':(isPrice?'导入工程文件':'打开项目');
if(typeof dlgPin==='function') dlgPin($('idlg')); // 改宽后重居中(与工作台 impExcelToggle 同款)
if(on){
AITREE=[{name:'单项工程 1',units:[{name:'单位工程 1'}]}];
$('iprojfile').value=''; $('aimsg').textContent='';
aimpRender();
}
}
function aimpRender(){
if(!AITREE) return;
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="aimpTemplate()" title="下载单位工程数据结构 Excel(填写说明/分部分项/措施项目)">单位模板</button>'
+'<button class="iab" onclick="aimpProjPick()" title="下载项目导入模板(项目目录+多对 Sheet,每对 Sheet=1 个单位工程,一把导入建项目)">项目模板</button>'
+'<button class="iab" onclick="$(\'iprojfile\').click()" title="选项目模板 Excel:项目目录 Sheet 定目录树,分部分项N/措施项目N 对应序号 N 的单位工程,一把建项目">项目导入</button>'
+'<button class="iab" onclick="aimpAddSec()">+单项工程</button></span></div>';
AITREE.forEach((s,si)=>{
h+='<div class="ied" style="padding-left:26px"><span class="itag tg1">单项工程</span><span class="inm" onclick="aimpRename(this,'+si+',-1)">'+esc(s.name)+'</span>'
+'<span class="iact"><button class="iab" title="组内上移" onclick="aimpMovSec('+si+',-1)"'+(si===0?' disabled':'')+'>↑</button>'
+'<button class="iab" title="组内下移" onclick="aimpMovSec('+si+',1)"'+(si===AITREE.length-1?' disabled':'')+'>↓</button>'
+'<button class="iab" onclick="aimpAddUw('+si+')">+单位工程</button><button class="iab x" onclick="aimpDelSec('+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>';
h+='<div class="ied" style="padding-left:52px"><span class="itag tg2">单位工程</span><span class="inm" title="'+esc(u.name)+'" onclick="aimpRename(this,'+si+','+ui+')">'+esc(u.name)+'</span>'
+st
+'<span class="iact"><button class="iab" title="组内上移" onclick="aimpMovUw('+si+','+ui+',-1)"'+(ui===0?' disabled':'')+'>↑</button>'
+'<button class="iab" title="组内下移" onclick="aimpMovUw('+si+','+ui+',1)"'+(ui===s.units.length-1?' disabled':'')+'>↓</button>'
+'<button class="iab imp" onclick="aimpPick('+si+','+ui+')" title="按模板导入(整单位工程覆盖)">导入单位工程</button><button class="iab x" onclick="aimpDelUw('+si+','+ui+')">✕</button></span></div>';
});
});
$('aitree').innerHTML=h;
}
function aimpRename(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) AITREE[si].name=v; else AITREE[si].units[ui].name=v;
aimpRender(); };
inp.onblur=done;
inp.onkeydown=e=>{ if(e.key==='Enter')inp.blur(); if(e.key==='Escape'){inp.value=cur;inp.blur();} };
}
function aimpAddSec(){ AITREE.push({name:'单项工程 '+(AITREE.length+1),units:[{name:'单位工程 1'}]}); aimpRender(); }
function aimpDelSec(i){ if(AITREE.length<=1){$('aimsg').textContent='至少保留一个单项工程';return;} AITREE.splice(i,1); aimpRender(); }
function aimpAddUw(si){ AITREE[si].units.push({name:'单位工程 '+(AITREE[si].units.length+1)}); aimpRender(); }
function aimpDelUw(si,ui){ AITREE[si].units.splice(ui,1); aimpRender(); }
function aimpMovSec(i,d){ const j=i+d; if(j<0||j>=AITREE.length) return;
const t=AITREE[i]; AITREE[i]=AITREE[j]; AITREE[j]=t; aimpRender(); }
function aimpMovUw(si,ui,d){ const us=AITREE[si].units, j=ui+d; if(j<0||j>=us.length) return;
const t=us[ui]; us[ui]=us[j]; us[j]=t; aimpRender(); }
function aimpPick(si,ui){ AISEL=si+','+ui; $('ifile2').value=''; $('ifile2').click(); }
async function aimpFile(){
const f=$('ifile2').files[0]; $('ifile2').value='';
if(!f||!AISEL) return;
const [si,ui]=AISEL.split(',').map(Number), u=AITREE[si].units[ui];
$('aimsg').textContent='正在上传并校验 '+f.name+'…';
const up=await uploadFile('/api/admin/upload',f);
if(!up.ok){ $('aimsg').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||'校验失败'; $('aimsg').textContent='✗ '+u.err; aimpRender(); return; }
u.file=up.path; u.n_item=r.n_item; u.n_prelim=r.n_prelim; delete u.err;
$('aimsg').textContent=''; aimpRender();
}
function aimpTemplate(){ return saveAs('/api/session/manual/template','单位工程导入模板.xlsx'); }
function aimpProjPick(){ return saveAs('/api/session/manual/project_template','整项目导入模板.xlsx'); }
async function aimpProjFile(){
const f=$('iprojfile').files[0]; $('iprojfile').value='';
if(!f) return;
const v=aimpCommon(); if(!v) return;
$('aimsg').textContent='正在上传 '+f.name+'…';
const up=await uploadFile('/api/admin/upload',f);
if(!up.ok){ $('aimsg').textContent=up.msg; return; }
$('aimsg').textContent='正在导入整项目…';
const r=await J('/api/admin/import_project',{method:'POST',headers:{'Content-Type':'application/json'},
body:JSON.stringify(Object.assign(v,{path:up.path}))});
if(!r.ok){ $('aimsg').textContent=r.msg||'导入失败'; return; }
alert('导入成功!\n'+r.msg); closeImp(); load(1); loadSummary(); loadFilters();
}
function aimpCommon(){
const name=$('iname').value.trim(), pv=PVAL($('iper'));
if(!name){ $('aimsg').textContent='工程名称必填(左边共用字段)'; return null; }
if(pv.f==null||pv.t==null){ $('aimsg').textContent='基准期次必填:点开选起~止(同月就选同一个)'; return null; }
if(!iprov.value||!icity.value||!idist.value){ $('aimsg').textContent='请填写:地区(省/市/区)'; return null; }
if(!ibuid.value.trim()){ $('aimsg').textContent='请填写:建设单位'; return null; }
if(!ifk.value){ $('aimsg').textContent='请选择单价类型'; return null; }
return {name,period_from:pv.f,period_to:pv.t,
province:iprov.value,city:icity.value,district:idist.value,
bulid_unit:ibuid.value.trim(),file_kind:+ifk.value};
}
async function aimpSave(){
if(!AITREE) return;
const v=aimpCommon(false); if(!v) return;
for(const s of AITREE){
if(!s.name.trim()){ $('aimsg').textContent='单项工程名称不能为空'; return; }
if(!s.units.length){ $('aimsg').textContent='「'+s.name+'」下至少一个单位工程'; return; }
for(const u of s.units) if(!u.name.trim()){ $('aimsg').textContent='单位工程名称不能为空'; return; }
}
$('ibtnGo').disabled=true; $('aimsg').textContent='正在保存…';
try{
const r=await J('/api/admin/import_project',{method:'POST',headers:{'Content-Type':'application/json'},
body:JSON.stringify(Object.assign(v,{tree:AITREE.map(s=>({name:s.name.trim(),
units:s.units.map(u=>({name:u.name.trim(),file:u.file||''}))}))}))});
if(!r.ok){ $('aimsg').textContent=r.msg||'保存失败'; return; }
alert('导入成功!\n'+r.msg); closeImp(); load(1); loadSummary(); loadFilters();
} finally { $('ibtnGo').disabled=false; }
}
async function loadImpFilters(){
const f=await J('/api/admin/filters');
// 2026-10-08 主人定:地区/建设单位 改「历史项目搜索」——选项来自已导入项目的实际数据
@@ -1561,17 +1780,22 @@ function kindOptions(kinds, cur){
async function doImport(){
const isPrice = (KIND!=='project');
// 决策 245:工程类校验文案与工作台「打开项目」逐字同款(两侧同规则)
if(!isPrice){
if(!UPF){ imsg.textContent='请选择文件'; return; }
if(!iname.value.trim()){ imsg.textContent='请填写:工程名称'; return; }
const pv0=PVAL($('iper'));
if(pv0.f==null||pv0.t==null){ imsg.textContent='基准期次必填:点开选起~止(同一个月就选同一个)'; return; }
if(!iprov.value||!icity.value||!idist.value){ imsg.textContent='请填写:地区(省/市/区)'; return; }
if(!ibuid.value.trim()){ imsg.textContent='请填写:建设单位'; return; }
if(!ifk.value){ imsg.textContent='请选择单价类型'; return; }
}
const miss=[];
if(!UPF) miss.push(isPrice?'标准模板 Excel 文件(每次只能一个)':'文件(每次只能一个)');
if(!iname.value.trim()) miss.push('名称');
if(!iprov.value||!icity.value||!idist.value) miss.push('地区(省/市/区)');
if(isPrice && !UPF) miss.push('标准模板 Excel 文件(每次只能一个)');
if(!iname.value.trim()) miss.push('工程名称');
const pv=PVAL($('iper'));
const p1=pv.f, p2=pv.t;
if(p1==null||p2==null) miss.push('期次(点开选起~止,同一个月就选同一个)');
if(!isPrice){
if(!ibuid.value.trim()) miss.push('建设单位');
if(!ifk.value) miss.push('单价类型');
} // 发布单位、备注:选填,不校验
if(isPrice && (p1==null||p2==null)) miss.push('基准期次(点开选起~止,同一个月就选同一个)');
// 备注选填,不校验
if(miss.length){ imsg.textContent='请填写:'+miss.join('、'); return; }