Compare commits

...

5 Commits

View File

@@ -437,6 +437,13 @@ function renderProducts() {
function renderFinance() { function renderFinance() {
const pfs = state.data.projectFinances || []; const pfs = state.data.projectFinances || [];
const ops = state.data.operations || []; const ops = state.data.operations || [];
const fmTypesByTenant = {
"科普·无界": ["科普音频","科普视频","科普文章","全品类科普"],
"科研·无界": ["真实世界研究","调研问卷","病例征集","患者招募"],
"医患·无界": ["医患运营","患者管理","患教会","创新支付","电商","其他"],
};
const fmTypes = fmTypesByTenant[state.tenant] || fmTypesByTenant["科普·无界"];
const tenantOps = (state.data.operations || []).filter(o => (o.project_name || "").includes(state.tenant.replace("·无界","")) || o.tenant === state.tenant);
const months = ["2026-06","2026-07","2026-08","2026-09"]; const months = ["2026-06","2026-07","2026-08","2026-09"];
const monthLabels = ["6月","7月","8月","9月"]; const monthLabels = ["6月","7月","8月","9月"];
@@ -464,7 +471,7 @@ 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/30" onclick="closeFinanceModal()"><div class="bg-white rounded-xl shadow-xl w-full max-w-3xl mx-4 max-h-[90vh] overflow-y-auto" onclick="event.stopPropagation()"><div class="sticky top-0 bg-white border-b px-6 py-4 flex items-center justify-between"><h3 class="font-bold text-lg" id="financeModalTitle">新增项目财务</h3><button class="btn btn-ghost btn-sm" onclick="closeFinanceModal()"><i data-lucide="x"></i></button></div><form onsubmit="createFinance(event)" class="p-6 grid gap-3"><input type="hidden" name="pf_id" id="pf-id-input" value=""><div class="grid grid-cols-3 gap-3"><label class="text-xs">项目<select name="project_id" class="rounded border px-2 py-1.5 text-sm w-full">${ops.map(o => `<option value="${o.id}">${o.project_name}</option>`).join("")}</select></label><label class="text-xs">业务类型<select name="business_type" class="rounded border px-2 py-1.5 text-sm w-full">${["科普音频","科普视频","科普文章","真实世界研究","调研问卷","病例征集","患者招募","医患运营","患者管理","患教会","创新支付","电商","其他"].map(t => `<option>${t}</option>`).join("")}</select></label><label class="text-xs">客户名称<input name="customer_name" class="rounded border px-2 py-1.5 text-sm w-full"></label><label class="text-xs">签约金额/万<input name="sign_amount" type="number" step="0.01" class="rounded border px-2 py-1.5 text-sm w-full"></label><label class="text-xs">签约月份<input name="sign_month" class="rounded border px-2 py-1.5 text-sm w-full"></label><label class="text-xs">状态<select name="status" class="rounded border px-2 py-1.5 text-sm w-full"><option>已签单</option><option>待签</option></select></label></div><div class="grid grid-cols-4 gap-2">${["06","07","08","09"].map(m => `<div class="border rounded p-2"><p class="text-xs text-slate-400 mb-1">${m}月</p><label class="text-xs text-slate-500">确收<br><input name="rev_2026_${m}" type="number" step="0.01" class="w-full rounded border px-1 py-1 text-sm" placeholder=""></label><label class="text-xs text-slate-500 mt-1">毛利<br><input name="gross_2026_${m}" type="number" step="0.01" class="w-full rounded border px-1 py-1 text-sm" placeholder=""></label></div>`).join("")}</div><div class="flex justify-end gap-2 pt-3 border-t"><button type="button" class="btn btn-ghost btn-sm" onclick="closeFinanceModal()">取消</button><button type="submit" class="btn btn-primary btn-sm">确认新增</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><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-left font-semibold">销售</th></tr></thead><tbody>${pfs.filter(x => x.status === state.finFilter).map(renderPfRow).join("")}</tbody></table></div>`, "p-4")}
</div>`; </div>`;