📋

分部分项工程量清单(手工录入)

照抄甲方招标书里的工程量 · 套定额算钱 · 不用识别图纸
⏳ 未连接工具库
⚙️ 清单信息(决定套哪个省的哪年定额)
未指定定额册:套定额时按省份 + 年份自动过滤
0
清单项数
0
已套定额条数
¥0
清单合价合计(元)
¥0
单方造价(元/㎡)
📋 分部分项工程量清单 表格里直接改,数字自动重算
序号 分部 项目编码 项目名称 项目特征 计量单位 工程量 套用定额 综合单价 合价(元) 操作
合计(元) 0.00
'; var blob = new Blob(['\ufeff' + html], { type: 'application/vnd.ms-excel;charset=utf-8' }); var a = document.createElement('a'); a.href = URL.createObjectURL(blob); a.download = '工程量清单_' + (BILL.name || BILL.code) + '.xls'; document.body.appendChild(a); a.click(); setTimeout(function () { document.body.removeChild(a); URL.revokeObjectURL(a.href); }, 500); toast('已导出 Excel', 'success'); } /* ---------------- 与工具库交互 ---------------- */ function saveToServer() { if (!ONLINE) { toast('未连接工具库,先保存到本机也行(数据会自动记住)', 'error'); return; } if (!BILL.name) { toast('先填一下工程名称', 'error'); return; } recomputeAll(); var items = (BILL.items || []).map(function (it, i) { var o = {}; for (var k in it) { o[k] = it[k]; } o.seq = i + 1; o.totalAmount = undefined; return o; }); var body = { bill: { billCode: BILL.code, name: BILL.name, place: BILL.place, province: BILL.province, pubYear: BILL.pubYear, bookId: BILL.bookId, bookCode: BILL.bookCode, projectType: BILL.projectType, buildArea: BILL.buildArea, remark: BILL.remark }, items: items }; setStatus('⏳ 保存中…', 'info'); apiFetch('/quota-bill/save', { method: 'POST', body: body }).then(function (res) { var d = (res && res.data) || {}; setStatus('✅ 已保存到工具库', 'success'); toast('已保存:' + d.itemCount + ' 行,合计 ' + fmt(d.totalAmount, 2) + ' 元', 'success'); saveLocal(); }).catch(function (e) { setStatus('❌ 保存失败', 'error'); toast('保存失败:' + e.message, 'error'); }); } function openServerList() { var mask = document.getElementById('listMask'); if (mask) { mask.classList.add('show'); } var el = document.getElementById('serverList'); if (!ONLINE) { el.innerHTML = '
📡
未连接工具库
当前清单已自动存在本机浏览器,刷新不丢。后端起来后才能多台机器共用。
'; return; } el.innerHTML = '
读取中…
'; apiFetch('/quota-bill/list').then(function (res) { var rows = (res && res.data) || []; if (!rows.length) { el.innerHTML = '
📂
工具库里还没有清单
填好上面这张表,点「保存到工具库」就会出现在这里。
'; return; } var h = '
' + '' + ''; rows.forEach(function (r) { h += '' + '' + '' + '' + '' + '' + '' + ''; }); h += '
清单编码工程名称地点项数合价(元)最后更新操作
' + esc(r.billCode) + '' + esc(r.name) + '' + esc(r.place || '') + '' + (r.itemCount || 0) + '' + fmt(r.totalAmount, 2) + '' + esc(r.updateTime || '') + '' + ' ' + ' ' + '' + '
'; el.innerHTML = h; }).catch(function (e) { el.innerHTML = '
读取失败:' + esc(e.message) + '
'; }); } function closeList() { var mask = document.getElementById('listMask'); if (mask) { mask.classList.remove('show'); } } function loadFromServer(id) { apiFetch('/quota-bill/' + id).then(function (res) { var d = (res && res.data) || {}; var b = d.bill || {}; var items = (d.items || []).map(function (r) { var it = blankItem(); it.seq = r.seq; it.section = r.section || ''; it.itemCode = r.itemCode || ''; it.itemName = r.itemName || ''; it.itemFeature = r.itemFeature || ''; it.unit = r.unit || ''; it.quantity = r.quantity === null ? null : num(r.quantity); it.unitPrice = r.unitPrice === null ? null : num(r.unitPrice); it.amount = r.amount === null ? null : num(r.amount); it.remark = r.remark || ''; it.quotas = (r.quotas || []).map(function (q) { return { code: q.code || '', name: q.name || '', unitLabel: q.unitLabel || '', unitFactor: q.unitFactor || 1, price: num(q.price), qty: num(q.qty), amount: num(q.amount), auto: !!q.auto }; }); return it; }); loadBillObj({ code: b.billCode, name: b.name, place: b.place, province: b.province, pubYear: b.pubYear, bookId: b.bookId, bookCode: b.bookCode, projectType: b.projectType, buildArea: b.buildArea, items: items }); closeList(); toast('已打开:' + b.name, 'success'); }).catch(function (e) { toast('打开失败:' + e.message, 'error'); }); } function copyOnServer(id) { var code = prompt('新清单编码:', ''); if (code === null) { return; } var nm = prompt('新工程名称:', ''); if (nm === null) { return; } apiFetch('/quota-bill/' + id + '/copy', { method: 'POST', body: { billCode: code || null, name: nm || null } }) .then(function () { toast('已复制', 'success'); openServerList(); }) .catch(function (e) { toast('复制失败:' + e.message, 'error'); }); } function delOnServer(id) { if (!confirm('确定删除这份清单?删除后不可恢复。')) { return; } apiFetch('/quota-bill/' + id, { method: 'DELETE' }) .then(function () { toast('已删除', 'success'); openServerList(); }) .catch(function (e) { toast('删除失败:' + e.message, 'error'); }); } /* ---------------- 指定定额册 ---------------- */ function openQuotaBookPick() { var mask = document.getElementById('bookMask'); if (mask) { mask.classList.add('show'); } var el = document.getElementById('bookPickBody'); if (!ONLINE) { el.innerHTML = '
📡
未连接工具库(定额库在后端)
'; return; } el.innerHTML = '
读取中…
'; var p = apiFetch('/quota-lib/books').then(function (res) { BOOKS = (res && res.data) || []; var h = '
' + '' + ''; BOOKS.forEach(function (b) { h += '' + '' + '' + '' + '' + '' + '' + '' + ''; }); h += '
册编码省份年份专业册名称条数操作
' + esc(b.bookCode) + '' + esc(b.province) + '' + esc(b.pubYear) + '' + esc(b.bookType || '') + '' + esc(b.name) + '' + (b.itemCount || 0) + '
'; h += '
'; el.innerHTML = h; }); p.catch(function (e) { el.innerHTML = '
读取失败:' + esc(e.message) + '
'; }); } function pickBook(id) { var bk = null; (BOOKS || []).forEach(function (b) { if (b.id === id) { bk = b; } }); if (bk) { BILL.bookId = bk.id; BILL.bookCode = bk.bookCode; BILL.province = BILL.province || bk.province; BILL.pubYear = BILL.pubYear || bk.pubYear; toast('已指定定额册:' + bk.name, 'success'); } else { BILL.bookId = null; BILL.bookCode = ''; toast('已取消指定,套定额时按省份+年份过滤', 'info'); } fillForm(); saveLocal(); closeBookPick(); } function closeBookPick() { var mask = document.getElementById('bookMask'); if (mask) { mask.classList.remove('show'); } } /* ---------------- 清空 / 初始化 ---------------- */ function clearAll() { if (!confirm('清空当前清单的所有内容?\n(本机缓存会清掉;如果已经保存到工具库,那边不受影响)')) { return; } BILL = blankBill(); saveLocal(); renderAll(); toast('已清空', 'success'); } function probeOnline() { return apiFetch('/quota-lib/provinces').then(function (res) { ONLINE = true; setStatus('✅ 已连接工具库', 'success'); return apiFetch('/quota-lib/books').then(function (r2) { BOOKS = (r2 && r2.data) || []; fillForm(); }); }).catch(function () { ONLINE = false; setStatus('⚠️ 未连接工具库(数据仍存在本机)', 'warning'); }); } function initBill() { var b = loadLocal(); if (!b) { b = blankBill(); } loadBillObj(b); renderItems(); renderSummary(); fillForm(); probeOnline().then(function () { // 打开页面时如果本机这份清单还没进过工具库,给个提示即可,不自动写库 var h = document.getElementById('billHint'); if (h) { h.textContent = ONLINE ? '提示:先「保管好」这份清单 —— 点右上角「☁️ 保存到工具库」' : '提示:现在填的内容只存在本机浏览器,等后端连上后可以「保存到工具库」'; } }); // 关闭弹窗的通用操作 document.addEventListener('keydown', function (e) { if (e.key === 'Escape') { closeQuota(); closeList(); closeBookPick(); } }); ['quotaMask', 'listMask', 'bookMask'].forEach(function (id) { var m = document.getElementById(id); if (m) { m.addEventListener('click', function (e) { if (e.target === m) { if (id === 'quotaMask') { closeQuota(); } if (id === 'listMask') { closeList(); } if (id === 'bookMask') { closeBookPick(); } } }); } }); } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', initBill); } else { initBill(); }