|
|
|
@@ -265,6 +265,8 @@ window.switchTenant = (tenant) => {
|
|
|
|
state.projectView = null;
|
|
|
|
state.projectView = null;
|
|
|
|
const label = tenant.replace("·无界", "");
|
|
|
|
const label = tenant.replace("·无界", "");
|
|
|
|
document.querySelector("#workspaceTitle").textContent = label + " OPC 工作台";
|
|
|
|
document.querySelector("#workspaceTitle").textContent = label + " OPC 工作台";
|
|
|
|
|
|
|
|
document.querySelector("#tenantSelect").value = tenant;
|
|
|
|
|
|
|
|
document.querySelectorAll(".workspace-nav-item").forEach(el => el.classList.toggle("active", el.dataset.tenant === tenant));
|
|
|
|
load();
|
|
|
|
load();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
@@ -461,7 +463,10 @@ function renderFinance() {
|
|
|
|
const gross = pf["gross_"+m.replace("-","_")] || 0;
|
|
|
|
const gross = pf["gross_"+m.replace("-","_")] || 0;
|
|
|
|
return `<td class="p-2 text-right whitespace-nowrap"><span class="${rev ? 'text-blue-700 font-medium' : 'text-slate-300'}">${rev ? money(rev) : '—'}</span><br><span class="text-xs ${gross ? 'text-green-600' : 'text-slate-300'}">${gross ? money(gross) : '—'}</span></td>`;
|
|
|
|
return `<td class="p-2 text-right whitespace-nowrap"><span class="${rev ? 'text-blue-700 font-medium' : 'text-slate-300'}">${rev ? money(rev) : '—'}</span><br><span class="text-xs ${gross ? 'text-green-600' : 'text-slate-300'}">${gross ? money(gross) : '—'}</span></td>`;
|
|
|
|
}).join("");
|
|
|
|
}).join("");
|
|
|
|
return `<tr class="border-b border-slate-100 hover:bg-slate-50 cursor-pointer" onclick="openPfEditModal(${pf.id})"><td class="p-2 text-sm font-medium">${pf.customer_name}</td><td class="p-2 text-sm">${pf.business_type}</td><td class="p-2 text-sm">${pf.status === "已签单" ? badge("已签") : badge(pf.status,"amber")}</td><td class="p-2 text-right text-sm">${money(pf.sign_amount)}</td>${mCols}<td class="p-2 text-sm text-slate-500">${pf.sales_person || ""}</td></tr>`;
|
|
|
|
const totalRev = months.reduce((s,m) => s + (pf["rev_"+m.replace("-","_")]||0), 0);
|
|
|
|
|
|
|
|
const totalGross = months.reduce((s,m) => s + (pf["gross_"+m.replace("-","_")]||0), 0);
|
|
|
|
|
|
|
|
const totalCol = `<td class="p-2 text-right whitespace-nowrap font-semibold"><span class="${totalRev ? 'text-blue-700' : 'text-slate-300'}">${totalRev ? money(totalRev) : '—'}</span><br><span class="text-xs ${totalGross ? 'text-green-600' : 'text-slate-300'}">${totalGross ? money(totalGross) : '—'}</span></td>`;
|
|
|
|
|
|
|
|
return `<tr class="border-b border-slate-100 hover:bg-slate-50 cursor-pointer" onclick="openPfEditModal(${pf.id})"><td class="p-2 text-sm font-medium">${pf.customer_name}</td><td class="p-2 text-sm">${pf.business_type}</td><td class="p-2 text-sm">${pf.status === "已签单" ? badge("已签") : badge(pf.status,"amber")}</td><td class="p-2 text-right text-sm">${money(pf.sign_amount)}</td>${mCols}${totalCol}<td class="p-2 text-sm text-slate-500">${pf.sales_person || ""}</td></tr>`;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
document.querySelector("#finance").innerHTML = `<div class="grid gap-4">
|
|
|
|
document.querySelector("#finance").innerHTML = `<div class="grid gap-4">
|
|
|
|
@@ -471,9 +476,9 @@ function renderFinance() {
|
|
|
|
${card(`<div class="flex items-center justify-between cursor-pointer" onclick="toggleFinanceChart()"><h2 class="text-lg font-bold text-slate-700">月度趋势</h2><i data-lucide="chevron-down" class="transition-transform rotate-90" id="financeChartIcon"></i></div><div id="financeChartWrap" class="hidden mt-4"><div style="position:relative;height:300px"><canvas id="financeChart2"></canvas></div></div>`, "p-5")}
|
|
|
|
${card(`<div class="flex items-center justify-between cursor-pointer" onclick="toggleFinanceChart()"><h2 class="text-lg font-bold text-slate-700">月度趋势</h2><i data-lucide="chevron-down" class="transition-transform rotate-90" id="financeChartIcon"></i></div><div id="financeChartWrap" class="hidden mt-4"><div style="position:relative;height:300px"><canvas id="financeChart2"></canvas></div></div>`, "p-5")}
|
|
|
|
|
|
|
|
|
|
|
|
<div class="flex justify-end"><button class="btn btn-primary btn-sm" onclick="openFinanceModal()"><i data-lucide="plus"></i>新增财务项目</button></div>
|
|
|
|
<div class="flex justify-end"><button class="btn btn-primary btn-sm" onclick="openFinanceModal()"><i data-lucide="plus"></i>新增财务项目</button></div>
|
|
|
|
<div id="financeModal" class="hidden fixed inset-0 z-50 flex items-center justify-center bg-black/40" onclick="closeFinanceModal()"><div class="bg-white rounded-2xl shadow-2xl w-full max-w-5xl mx-4 max-h-[92vh] overflow-y-auto" onclick="event.stopPropagation()"><div class="sticky top-0 z-10 bg-white/95 backdrop-blur border-b border-slate-100 px-8 py-5 flex items-center justify-between"><div><h3 class="text-xl font-bold text-slate-800" id="financeModalTitle">新增项目财务</h3><p class="text-xs text-slate-400 mt-0.5">填写项目财务信息,标记月度确收与毛利预估</p></div><button class="btn btn-ghost btn-sm rounded-full w-8 h-8 p-0" onclick="closeFinanceModal()"><i data-lucide="x"></i></button></div><form onsubmit="createFinance(event)" class="p-8 grid gap-6"><input type="hidden" name="pf_id" id="pf-id-input" value=""><div class="grid grid-cols-2 gap-6"><div class="bg-slate-50 rounded-xl p-5"><h4 class="text-sm font-semibold text-slate-500 mb-4 flex items-center gap-2"><i data-lucide="briefcase-business"></i>基本信息</h4><div class="grid gap-4"><label class="block"><span class="text-xs font-medium text-slate-500">项目</span><select name="project_id" class="mt-1 block w-full rounded-lg border border-slate-200 px-3 py-2.5 text-sm bg-white">${tenantOps.map(o => `<option value="${o.id}">${o.project_name}</option>`).join("")}</select></label><label class="block"><span class="text-xs font-medium text-slate-500">业务类型</span><select name="business_type" class="mt-1 block w-full rounded-lg border border-slate-200 px-3 py-2.5 text-sm bg-white">${fmTypes.map(t => `<option>${t}</option>`).join("")}</select></label><label class="block"><span class="text-xs font-medium text-slate-500">客户名称</span><input name="customer_name" class="mt-1 block w-full rounded-lg border border-slate-200 px-3 py-2.5 text-sm"></label></div></div><div class="bg-slate-50 rounded-xl p-5"><h4 class="text-sm font-semibold text-slate-500 mb-4 flex items-center gap-2"><i data-lucide="banknote"></i>签约信息</h4><div class="grid gap-4"><label class="block"><span class="text-xs font-medium text-slate-500">签约金额(万元)</span><input name="sign_amount" type="number" step="0.01" class="mt-1 block w-full rounded-lg border border-slate-200 px-3 py-2.5 text-sm" placeholder="0.00"></label><label class="block"><span class="text-xs font-medium text-slate-500">签约月份</span><input name="sign_month" class="mt-1 block w-full rounded-lg border border-slate-200 px-3 py-2.5 text-sm" placeholder="如 2026-06"></label><label class="block"><span class="text-xs font-medium text-slate-500">项目状态</span><select name="status" class="mt-1 block w-full rounded-lg border border-slate-200 px-3 py-2.5 text-sm bg-white"><option>已签单</option><option>待签</option></select></label></div></div></div><div class="bg-slate-50 rounded-xl p-5"><h4 class="text-sm font-semibold text-slate-500 mb-4 flex items-center gap-2"><i data-lucide="calendar"></i>月度确收 & 毛利预估(万元)</h4><div class="grid grid-cols-4 gap-3">${["06","07","08","09"].map(m => `<div class="bg-white rounded-lg border border-slate-200 p-3 text-center"><p class="text-xs font-semibold text-slate-400 mb-2">${m}月</p><div class="grid grid-cols-2 gap-2"><div><p class="text-[10px] text-slate-400 mb-0.5">确收</p><input name="rev_2026_${m}" type="number" step="0.01" class="w-full rounded-md border border-slate-200 px-2 py-1.5 text-sm text-center" placeholder="—"></div><div><p class="text-[10px] text-slate-400 mb-0.5">毛利</p><input name="gross_2026_${m}" type="number" step="0.01" class="w-full rounded-md border border-slate-200 px-2 py-1.5 text-sm text-center" placeholder="—"></div></div></div>`).join("")}</div></div><div class="flex justify-end gap-3 pt-2"><button type="button" class="btn btn-ghost btn-sm px-6" onclick="closeFinanceModal()">取消</button><button type="submit" class="btn btn-primary btn-sm px-8">保存</button></div></form></div></div>
|
|
|
|
<div id="financeModal" class="hidden fixed inset-0 z-50 flex items-center justify-center bg-black/40" onclick="closeFinanceModal()"><div class="bg-white rounded-2xl shadow-2xl w-full max-w-5xl mx-4 max-h-[92vh] overflow-y-auto" onclick="event.stopPropagation()"><div class="sticky top-0 z-10 bg-white/95 backdrop-blur border-b border-slate-100 px-8 py-5 flex items-center justify-between"><div><h3 class="text-xl font-bold text-slate-800" id="financeModalTitle">新增项目财务</h3><p class="text-xs text-slate-400 mt-0.5">填写项目财务信息,标记月度确收与毛利预估</p></div><button class="btn btn-ghost btn-sm rounded-full w-8 h-8 p-0" onclick="closeFinanceModal()"><i data-lucide="x"></i></button></div><form onsubmit="createFinance(event)" class="p-8 grid gap-6"><input type="hidden" name="pf_id" id="pf-id-input" value=""><div class="grid grid-cols-2 gap-6"><div class="bg-slate-50 rounded-xl p-5"><h4 class="text-sm font-semibold text-slate-500 mb-4 flex items-center gap-2"><i data-lucide="briefcase-business"></i>基本信息</h4><div class="grid gap-4"><label class="block"><span class="text-xs font-medium text-slate-500">项目</span><select name="project_id" class="mt-1 block w-full rounded-lg border border-slate-200 px-3 py-2.5 text-sm bg-white">${tenantOps.map(o => `<option value="${o.id}">${o.project_name}</option>`).join("")}</select></label><label class="block"><span class="text-xs font-medium text-slate-500">业务类型</span><select name="business_type" class="mt-1 block w-full rounded-lg border border-slate-200 px-3 py-2.5 text-sm bg-white">${fmTypes.map(t => `<option>${t}</option>`).join("")}</select></label><label class="block"><span class="text-xs font-medium text-slate-500">客户名称</span><input name="customer_name" class="mt-1 block w-full rounded-lg border border-slate-200 px-3 py-2.5 text-sm"></label></div></div><div class="bg-slate-50 rounded-xl p-5"><h4 class="text-sm font-semibold text-slate-500 mb-4 flex items-center gap-2"><i data-lucide="banknote"></i>签约信息</h4><div class="grid gap-4"><label class="block"><span class="text-xs font-medium text-slate-500">签约金额(万元)</span><input name="sign_amount" type="number" step="0.01" class="mt-1 block w-full rounded-lg border border-slate-200 px-3 py-2.5 text-sm" placeholder="0.00"></label><label class="block"><span class="text-xs font-medium text-slate-500">签约月份</span><input name="sign_month" class="mt-1 block w-full rounded-lg border border-slate-200 px-3 py-2.5 text-sm" placeholder="如 2026-06"></label><label class="block"><span class="text-xs font-medium text-slate-500">项目状态</span><select name="status" class="mt-1 block w-full rounded-lg border border-slate-200 px-3 py-2.5 text-sm bg-white"><option>已签单</option><option>待签</option></select></label></div></div></div><div class="bg-slate-50 rounded-xl p-5"><h4 class="text-sm font-semibold text-slate-500 mb-4 flex items-center gap-2"><i data-lucide="calendar"></i>月度确收 & 毛利预估(万元)</h4><div class="grid grid-cols-4 gap-3">${["06","07","08","09"].map(m => `<div class="bg-white rounded-lg border border-slate-200 p-3 text-center"><p class="text-xs font-semibold text-slate-400 mb-2">${m}月</p><div class="grid grid-cols-2 gap-2"><div><p class="text-[10px] text-slate-400 mb-0.5">确收</p><input name="rev_2026_${m}" type="number" step="0.01" class="w-full rounded-md border border-slate-200 px-2 py-1.5 text-sm text-center" placeholder="—"></div><div><p class="text-[10px] text-slate-400 mb-0.5">毛利</p><input name="gross_2026_${m}" type="number" step="0.01" class="w-full rounded-md border border-slate-200 px-2 py-1.5 text-sm text-center" placeholder="—"></div></div></div>`).join("")}</div><div class="grid grid-cols-2 gap-3 mt-3"><div class="bg-white rounded-lg border border-slate-200 p-3 text-center"><p class="text-xs font-semibold text-slate-400 mb-1">总确收</p><input name="total_rev" id="total-rev-display" class="w-full rounded-md border border-slate-200 px-2 py-1.5 text-sm text-center font-bold text-blue-700" readonly placeholder="自动计算"></div><div class="bg-white rounded-lg border border-slate-200 p-3 text-center"><p class="text-xs font-semibold text-slate-400 mb-1">总毛利</p><input name="total_gross" id="total-gross-display" class="w-full rounded-md border border-slate-200 px-2 py-1.5 text-sm text-center font-bold text-green-600" readonly placeholder="自动计算"></div></div></div><div class="flex justify-end gap-3 pt-2"><button type="button" class="btn btn-ghost btn-sm px-6" onclick="closeFinanceModal()">取消</button><button type="submit" class="btn btn-primary btn-sm px-8">保存</button></div></form></div></div>
|
|
|
|
|
|
|
|
|
|
|
|
${card(`<h3 class="font-bold text-slate-700 mb-3">项目明细 <span class="text-slate-400 font-normal">(${pfs.length})</span></h3><div class="flex gap-2 mb-3">${[["已签单","已签"],["待签","待签"]].map(([k,v]) => `<button class="btn btn-sm ${state.finFilter === k ? 'btn-primary' : 'btn-ghost'}" onclick="state.finFilter='${k}';renderFinance()">${v} (${pfs.filter(x=>x.status===k).length})</button>`).join("")}</div><div class="overflow-x-auto"><table class="w-full text-sm"><thead><tr class="bg-slate-50 border-b border-slate-200"><th class="p-2 text-left font-semibold">客户</th><th class="p-2 text-left font-semibold">类型</th><th class="p-2 text-left font-semibold">状态</th><th class="p-2 text-right font-semibold">签约金额</th>${monthLabels.map(l => `<th class="p-2 text-center font-semibold">${l}<br><span class="text-xs text-slate-400">确收/毛利</span></th>`).join("")}<th class="p-2 text-left font-semibold">销售</th></tr></thead><tbody>${pfs.filter(x => x.status === state.finFilter).map(renderPfRow).join("")}</tbody></table></div>`, "p-4")}
|
|
|
|
${card(`<h3 class="font-bold text-slate-700 mb-3">项目明细 <span class="text-slate-400 font-normal">(${pfs.length})</span></h3><div class="flex gap-2 mb-3">${[["已签单","已签"],["待签","待签"]].map(([k,v]) => `<button class="btn btn-sm ${state.finFilter === k ? 'btn-primary' : 'btn-ghost'}" onclick="state.finFilter='${k}';renderFinance()">${v} (${pfs.filter(x=>x.status===k).length})</button>`).join("")}</div><div class="overflow-x-auto"><table class="w-full text-sm"><thead><tr class="bg-slate-50 border-b border-slate-200"><th class="p-2 text-left font-semibold">客户</th><th class="p-2 text-left font-semibold">类型</th><th class="p-2 text-left font-semibold">状态</th><th class="p-2 text-right font-semibold">签约金额</th>${monthLabels.map(l => `<th class="p-2 text-center font-semibold">${l}<br><span class="text-xs text-slate-400">确收/毛利</span></th>`).join("")}<th class="p-2 text-center font-semibold">总计<br><span class="text-xs text-slate-400">确收/毛利</span></th><th class="p-2 text-left font-semibold">销售</th></tr></thead><tbody>${pfs.filter(x => x.status === state.finFilter).map(renderPfRow).join("")}</tbody></table></div>`, "p-4")}
|
|
|
|
</div>`;
|
|
|
|
</div>`;
|
|
|
|
if (window.lucide) window.lucide.createIcons();
|
|
|
|
if (window.lucide) window.lucide.createIcons();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -502,6 +507,11 @@ window.openPfEditModal = (pfId) => {
|
|
|
|
form.querySelector('[name="rev_2026_' + m + '"]').value = pf["rev_2026_" + m] || "";
|
|
|
|
form.querySelector('[name="rev_2026_' + m + '"]').value = pf["rev_2026_" + m] || "";
|
|
|
|
form.querySelector('[name="gross_2026_' + m + '"]').value = pf["gross_2026_" + m] || "";
|
|
|
|
form.querySelector('[name="gross_2026_' + m + '"]').value = pf["gross_2026_" + m] || "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate totals
|
|
|
|
|
|
|
|
const totalRev = (pf.rev_2026_06||0) + (pf.rev_2026_07||0) + (pf.rev_2026_08||0) + (pf.rev_2026_09||0);
|
|
|
|
|
|
|
|
const totalGross = (pf.gross_2026_06||0) + (pf.gross_2026_07||0) + (pf.gross_2026_08||0) + (pf.gross_2026_09||0);
|
|
|
|
|
|
|
|
document.querySelector("#total-rev-display").value = money(totalRev);
|
|
|
|
|
|
|
|
document.querySelector("#total-gross-display").value = money(totalGross);
|
|
|
|
openFinanceModal();
|
|
|
|
openFinanceModal();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
window.toggleFinanceChart = () => {
|
|
|
|
window.toggleFinanceChart = () => {
|
|
|
|
|