|
|
|
|
@@ -2,6 +2,7 @@ const state = {
|
|
|
|
|
active: "home",
|
|
|
|
|
data: null,
|
|
|
|
|
opFilter: "all",
|
|
|
|
|
projectView: null,
|
|
|
|
|
chart: null,
|
|
|
|
|
chart2: null,
|
|
|
|
|
productPlatform: "all",
|
|
|
|
|
@@ -93,30 +94,38 @@ function render() {
|
|
|
|
|
function renderHome() {
|
|
|
|
|
const { summary, financeMonthly } = state.data;
|
|
|
|
|
const m = summary.metrics;
|
|
|
|
|
const rows1 = [
|
|
|
|
|
["年度累计签约", money(m.signed_annual || m.signed_amount)],
|
|
|
|
|
["Q2 累计签约", money(m.signed_q2 || 0)],
|
|
|
|
|
["本月新增签约", money(m.signed_month || 0)],
|
|
|
|
|
["合同流程中", money(m.pipeline_amount)],
|
|
|
|
|
];
|
|
|
|
|
const rows2 = [
|
|
|
|
|
["年度累计确收", money(m.revenue_annual)],
|
|
|
|
|
["Q2 累计确收", money(m.revenue_q2)],
|
|
|
|
|
["本月新增确收", money(m.monthly_revenue)],
|
|
|
|
|
["已签约未执行", money(m.signed_not_executed)],
|
|
|
|
|
];
|
|
|
|
|
const rows3 = [
|
|
|
|
|
["年度累计毛利", money(m.gross_annual)],
|
|
|
|
|
["Q2 累计毛利", money(m.gross_q2)],
|
|
|
|
|
["本月新增毛利", money(m.monthly_net_profit)],
|
|
|
|
|
["合同毛利率", m.revenue_annual ? Math.round(m.gross_annual / m.revenue_annual * 100) + "%" : "—"],
|
|
|
|
|
];
|
|
|
|
|
const tblCard = (title, rows) => card(`<h3 class="text-sm font-bold text-slate-700 mb-3">${title}</h3><table class="w-full text-sm"><tbody>${rows.map(([label, value]) => `<tr class="border-b border-slate-100 last:border-0"><td class="py-2 pr-4 text-slate-500">${label}</td><td class="py-2 text-right font-semibold text-slate-800">${value}</td></tr>`).join("")}</tbody></table>`, "p-4");
|
|
|
|
|
document.querySelector("#home").innerHTML = `
|
|
|
|
|
<div class="grid gap-5">
|
|
|
|
|
<div class="grid grid-cols-4 gap-3">
|
|
|
|
|
<div class="grid grid-cols-6 gap-3">
|
|
|
|
|
${[
|
|
|
|
|
["P0 客户数", m.p0_customers, "projects"],
|
|
|
|
|
["跟进中销售机会", m.active_sales, "projects"],
|
|
|
|
|
["已签约执行项目", m.execution_projects, "projects"],
|
|
|
|
|
["有风险项目", m.risk_projects, "projects"],
|
|
|
|
|
["本月收入", money(m.monthly_revenue), "finance"],
|
|
|
|
|
["重点项目", m.total_projects, "projects"],
|
|
|
|
|
["业务方案", m.total_proposals, "proposals"],
|
|
|
|
|
["产品版本", m.total_products, "products"],
|
|
|
|
|
["本月确收", money(m.monthly_revenue), "finance"],
|
|
|
|
|
["本月毛利", money(m.monthly_gross || m.monthly_net_profit), "finance"],
|
|
|
|
|
["本月净利", money(m.monthly_net_profit), "finance"],
|
|
|
|
|
["即将上线版本", m.upcoming_products, "products"],
|
|
|
|
|
["已签约未执行", money(m.signed_not_executed), "finance"],
|
|
|
|
|
].map(([label, value, tab]) => `<button class="metric-card" onclick="switchTab('${tab}')"><span class="flex items-center gap-2 text-xs text-slate-500"><i data-lucide="gauge"></i>${label}</span><strong class="mt-2 block text-2xl">${value}</strong></button>`).join("")}
|
|
|
|
|
</div>
|
|
|
|
|
<div class="grid grid-cols-4 gap-3">
|
|
|
|
|
${[
|
|
|
|
|
["已签约合同总额", money(m.signed_amount), "projects"],
|
|
|
|
|
["合同流程中", money(m.pipeline_amount), "projects"],
|
|
|
|
|
["年度累计确收", money(m.revenue_annual), "finance"],
|
|
|
|
|
["Q2 累计确收", money(m.revenue_q2), "finance"],
|
|
|
|
|
["年度累计毛利", money(m.gross_annual), "finance"],
|
|
|
|
|
["Q2 累计毛利", money(m.gross_q2), "finance"],
|
|
|
|
|
].map(([label, value, tab]) => `<button class="metric-card" onclick="switchTab('${tab}')"><span class="flex items-center gap-2 text-xs text-slate-500"><i data-lucide="trending-up"></i>${label}</span><strong class="mt-2 block text-2xl">${value}</strong></button>`).join("")}
|
|
|
|
|
</div>
|
|
|
|
|
<div class="grid grid-cols-3 gap-5">${tblCard("合同金额", rows1)}${tblCard("确收金额", rows2)}${tblCard("确收毛利", rows3)}</div>
|
|
|
|
|
<div class="grid grid-cols-2 gap-5">
|
|
|
|
|
${card(`<div class="mb-3 flex items-center justify-between"><h2 class="text-sm font-bold text-slate-600">财务趋势</h2>${badge("YYYY-MM")}</div><div style="position:relative;height:140px"><canvas id="financeChart"></canvas></div>`, "p-4")}
|
|
|
|
|
${card(`<h2 class="text-lg font-bold">风险提醒</h2><div class="mt-3 grid gap-2">${(summary.risks.length ? summary.risks : [{ title: "暂无高风险", content: "当前无明确阻塞,按周更新即可。" }]).map((r) => `<div class="rounded-md border border-amber-200 bg-amber-50 p-3"><p class="font-bold text-amber-900">${r.title}</p><p class="mt-1 text-sm text-amber-800 break-words">${r.content}</p></div>`).join("")}</div>`, "p-5")}
|
|
|
|
|
@@ -172,38 +181,41 @@ window.createOperation = (event) => createResource(event, "operations");
|
|
|
|
|
window.createProduct = (event) => createResource(event, "products");
|
|
|
|
|
|
|
|
|
|
window.openTaskForm = (projectId, taskId) => {
|
|
|
|
|
const form = document.querySelector(`#task-form-${projectId}`);
|
|
|
|
|
form.classList.remove("hidden");
|
|
|
|
|
const drawer = document.querySelector(`#task-drawer-${projectId}`);
|
|
|
|
|
const titleEl = drawer.querySelector(".task-drawer-title");
|
|
|
|
|
if (taskId === null) {
|
|
|
|
|
// new task
|
|
|
|
|
document.querySelector(`#task-id-${projectId}`).value = "";
|
|
|
|
|
document.querySelector(`#task-name-${projectId}`).value = "";
|
|
|
|
|
document.querySelector(`#task-phase-${projectId}`).value = "项目准备";
|
|
|
|
|
document.querySelector(`#task-phase-${projectId}`).value = "商务洽谈";
|
|
|
|
|
document.querySelector(`#task-owner-${projectId}`).value = "";
|
|
|
|
|
document.querySelector(`#task-due-${projectId}`).value = "";
|
|
|
|
|
document.querySelector(`#task-notes-${projectId}`).value = "";
|
|
|
|
|
document.querySelector(`#task-blockers-${projectId}`).value = "";
|
|
|
|
|
document.querySelector(`#task-submit-btn-${projectId}`).textContent = "确认新增";
|
|
|
|
|
if (titleEl) titleEl.textContent = "新增任务";
|
|
|
|
|
} else {
|
|
|
|
|
// edit task
|
|
|
|
|
const task = (state.data.tasks || []).find((t) => t.id === taskId);
|
|
|
|
|
if (!task) return;
|
|
|
|
|
document.querySelector(`#task-id-${projectId}`).value = task.id;
|
|
|
|
|
document.querySelector(`#task-name-${projectId}`).value = task.task || "";
|
|
|
|
|
document.querySelector(`#task-phase-${projectId}`).value = task.phase || "项目准备";
|
|
|
|
|
document.querySelector(`#task-phase-${projectId}`).value = task.phase || "商务洽谈";
|
|
|
|
|
document.querySelector(`#task-owner-${projectId}`).value = task.owner || "";
|
|
|
|
|
document.querySelector(`#task-due-${projectId}`).value = task.due_date || "";
|
|
|
|
|
document.querySelector(`#task-notes-${projectId}`).value = task.notes || "";
|
|
|
|
|
document.querySelector(`#task-blockers-${projectId}`).value = task.blockers || "";
|
|
|
|
|
document.querySelector(`#task-submit-btn-${projectId}`).textContent = "保存修改";
|
|
|
|
|
if (titleEl) titleEl.textContent = "编辑任务";
|
|
|
|
|
}
|
|
|
|
|
form.scrollIntoView({ behavior: "smooth" });
|
|
|
|
|
drawer.classList.add("open");
|
|
|
|
|
};
|
|
|
|
|
window.closeTaskDrawer = (projectId) => {
|
|
|
|
|
document.querySelector(`#task-drawer-${projectId}`).classList.remove("open");
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
window.submitTaskForm = async (event, projectId) => {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
const form = event.currentTarget;
|
|
|
|
|
const data = Object.fromEntries(new FormData(form).entries());
|
|
|
|
|
data.project_id = projectId;
|
|
|
|
|
const data = Object.fromEntries(new FormData(event.currentTarget).entries());
|
|
|
|
|
data.project_id = Number(projectId);
|
|
|
|
|
const taskId = data.task_id;
|
|
|
|
|
delete data.task_id;
|
|
|
|
|
try {
|
|
|
|
|
@@ -212,10 +224,7 @@ window.submitTaskForm = async (event, projectId) => {
|
|
|
|
|
} else {
|
|
|
|
|
await api("/api/tasks", { method: "POST", body: JSON.stringify({ data }) });
|
|
|
|
|
}
|
|
|
|
|
form.reset();
|
|
|
|
|
form.classList.add("hidden");
|
|
|
|
|
await load();
|
|
|
|
|
showTaskModal(projectId);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
alert("保存失败:" + error.message);
|
|
|
|
|
}
|
|
|
|
|
@@ -224,6 +233,10 @@ window.createFinance = (event) => createResource(event, "finance");
|
|
|
|
|
window.switchTab = switchTab;
|
|
|
|
|
|
|
|
|
|
function renderProjects() {
|
|
|
|
|
// 二级页面:项目任务详情
|
|
|
|
|
if (state.projectView) {
|
|
|
|
|
return renderProjectTasks(state.projectView);
|
|
|
|
|
}
|
|
|
|
|
const items = state.data.operations;
|
|
|
|
|
const rows = items.map((x) => [
|
|
|
|
|
`<strong>${x.project_name}</strong>`,
|
|
|
|
|
@@ -231,13 +244,10 @@ function renderProjects() {
|
|
|
|
|
badge(x.current_stage || x.project_status),
|
|
|
|
|
x.expected_contract_amount ? money(x.expected_contract_amount) : "—",
|
|
|
|
|
text(x.owner || "—"),
|
|
|
|
|
`<button class="btn btn-ghost btn-sm text-blue-600" onclick="event.stopPropagation(); showTaskModal(${x.id})"><i data-lucide="eye"></i>查看</button>`
|
|
|
|
|
`<button class="btn btn-ghost btn-sm text-blue-600" onclick="event.stopPropagation(); state.projectView=${x.id}; renderProjects()"><i data-lucide="eye"></i>查看</button>`
|
|
|
|
|
]);
|
|
|
|
|
document.querySelector("#projects").innerHTML = `<div class="grid gap-4">
|
|
|
|
|
<div class="flex items-center justify-between">
|
|
|
|
|
<div class="flex gap-2">
|
|
|
|
|
${[["all","全部"],["项目准备","准备"],["项目执行","执行"],["项目验收","验收"],["验收完毕","完毕"]].map(([k,v]) => `<button class="btn ${state.opFilter === k ? "btn-primary" : "btn-ghost"} btn-sm" onclick="state.opFilter='${k}'; renderProjects()">${v}</button>`).join("")}
|
|
|
|
|
</div>
|
|
|
|
|
<div class="flex items-center justify-end">
|
|
|
|
|
<button class="btn btn-primary" onclick="document.querySelector('#project-form').classList.toggle('hidden')">
|
|
|
|
|
<i data-lucide="plus"></i>新增项目
|
|
|
|
|
</button>
|
|
|
|
|
@@ -245,40 +255,87 @@ function renderProjects() {
|
|
|
|
|
<div id="project-form" class="hidden">
|
|
|
|
|
${card(formHtml([
|
|
|
|
|
{ label: "项目名称", input: `<input name="project_name" required>` },
|
|
|
|
|
{ label: "当前阶段", input: `<select name="current_stage"><option>项目准备</option><option>项目执行</option><option>项目验收</option><option>验收完毕</option></select>` },
|
|
|
|
|
{ label: "当前阶段", input: `<select name="current_stage"><option>商务洽谈</option><option>系统上线</option><option>团队分工</option><option>项目交付</option><option>上线推广</option><option>结项验收</option></select>` },
|
|
|
|
|
{ label: "项目金额", input: `<input name="expected_contract_amount" type="number" step="0.01" placeholder="万元">` },
|
|
|
|
|
{ label: "负责人", input: `<input name="owner">` },
|
|
|
|
|
], { handler: "createOperation", text: "确认新增" }), "p-4")}
|
|
|
|
|
</div>
|
|
|
|
|
${renderTable(["项目", "项目说明", "当前阶段", "项目金额", "负责人", "进展"], rows, items.map((x) => ({ resource: "operations", id: x.id })))}
|
|
|
|
|
</div>`;
|
|
|
|
|
if (window.lucide) window.lucide.createIcons();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function renderProjectTasks(projectId) {
|
|
|
|
|
const project = state.data.operations.find((x) => x.id === projectId);
|
|
|
|
|
if (!project) { state.projectView = null; renderProjects(); return; }
|
|
|
|
|
const tasks = (state.data.tasks || []).filter((t) => t.project_id === projectId);
|
|
|
|
|
const phases = ["商务洽谈", "系统上线", "团队分工", "项目交付", "上线推广", "结项验收"];
|
|
|
|
|
document.querySelector("#projects").innerHTML = `<div class="grid gap-4">
|
|
|
|
|
<div class="flex items-center justify-between px-5">
|
|
|
|
|
<button class="btn btn-ghost btn-sm" onclick="state.projectView=null;renderProjects()"><i data-lucide="arrow-left"></i>返回项目列表</button>
|
|
|
|
|
<div class="flex items-center gap-3">
|
|
|
|
|
<span class="text-sm font-semibold text-slate-700">${project.project_name}</span>
|
|
|
|
|
<button class="btn btn-primary btn-sm" onclick="openTaskForm(${projectId}, null)"><i data-lucide="plus"></i>新增任务</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="task-page-wrap">
|
|
|
|
|
<div class="task-body">
|
|
|
|
|
${phases.map((phase) => {
|
|
|
|
|
const pt = tasks.filter((t) => t.phase === phase);
|
|
|
|
|
if (!pt.length) return "";
|
|
|
|
|
return `<div class="task-group"><div class="task-group-hd"><span class="task-group-icon"><i data-lucide="layers"></i></span><span class="task-group-label">${phase}</span><span class="task-group-n">${pt.length}</span></div><div class="task-group-list">${pt.map((t) => `<div class="task-row" data-id="${t.id}" onclick="openTaskForm(${projectId}, ${t.id})"><span class="task-dot"><i data-lucide="${t.status === 'done' ? 'check-circle' : 'circle'}"></i></span><div class="task-main"><span class="task-name">${t.task}</span>${t.notes ? `<span class="task-desc">${t.notes}</span>` : ""}${t.blockers ? `<span class="task-blocker">⚠ ${t.blockers}</span>` : ""}</div><span class="task-col">${t.owner || ""}</span><span class="task-col-badge">${t.due_date || ""}</span></div>`).join("")}</div></div>`;
|
|
|
|
|
}).join("")}
|
|
|
|
|
</div>
|
|
|
|
|
<div id="task-drawer-${projectId}" class="task-drawer">
|
|
|
|
|
<div class="task-drawer-hd"><span class="task-drawer-title">编辑任务</span><button class="task-close" onclick="closeTaskDrawer(${projectId})"><i data-lucide="x"></i></button></div>
|
|
|
|
|
<form class="task-drawer-form" onsubmit="submitTaskForm(event, ${projectId})">
|
|
|
|
|
<input type="hidden" name="task_id" id="task-id-${projectId}" value="">
|
|
|
|
|
<label class="task-field"><span>任务名称</span><input name="task" required id="task-name-${projectId}"></label>
|
|
|
|
|
<label class="task-field"><span>任务阶段</span><select name="phase" id="task-phase-${projectId}">${phases.map((p) => `<option>${p}</option>`).join("")}</select></label>
|
|
|
|
|
<label class="task-field"><span>负责人</span><input name="owner" id="task-owner-${projectId}"></label>
|
|
|
|
|
<label class="task-field"><span>截止时间</span><input name="due_date" type="date" id="task-due-${projectId}"></label>
|
|
|
|
|
<label class="task-field"><span>任务说明</span><textarea name="notes" rows="3" id="task-notes-${projectId}"></textarea></label>
|
|
|
|
|
<label class="task-field"><span>卡点&备注</span><textarea name="blockers" rows="2" id="task-blockers-${projectId}" placeholder="风险卡点、依赖项等"></textarea></label>
|
|
|
|
|
<div class="flex justify-end gap-2 mt-4 pt-3 border-t border-slate-100">
|
|
|
|
|
<button type="button" class="btn btn-ghost btn-sm" onclick="closeTaskDrawer(${projectId})">取消</button>
|
|
|
|
|
<button type="submit" class="btn btn-primary btn-sm" id="task-submit-btn-${projectId}">确认新增</button>
|
|
|
|
|
</div>
|
|
|
|
|
</form>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>`;
|
|
|
|
|
if (window.lucide) window.lucide.createIcons();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showTaskModal(projectId) {
|
|
|
|
|
const project = state.data.operations.find((x) => x.id === projectId);
|
|
|
|
|
const tasks = (state.data.tasks || []).filter((t) => t.project_id === projectId);
|
|
|
|
|
const phases = ["项目准备", "项目执行", "项目验收", "验收完毕"];
|
|
|
|
|
document.querySelector("#taskModal").innerHTML = `<div class="task-overlay" onclick="closeTaskModal()"><div class="task-panel" onclick="event.stopPropagation()"><div class="task-header"><h2 class="task-title">${project.project_name} · 任务清单</h2><div class="flex items-center gap-3"><button class="btn btn-primary btn-sm" onclick="event.stopPropagation(); openTaskForm(${projectId}, null)"><i data-lucide="plus"></i>新增任务</button><button class="task-close" onclick="closeTaskModal()"><i data-lucide="x"></i></button></div></div><div class="task-body">
|
|
|
|
|
<form id="task-form-${projectId}" class="hidden task-form" onsubmit="submitTaskForm(event, ${projectId})">
|
|
|
|
|
<input type="hidden" name="task_id" id="task-id-${projectId}" value="">
|
|
|
|
|
<div class="grid grid-cols-2 gap-3">
|
|
|
|
|
<label class="task-field"><span>任务名称</span><input name="task" required id="task-name-${projectId}"></label>
|
|
|
|
|
<label class="task-field"><span>任务阶段</span><select name="phase" id="task-phase-${projectId}">${phases.map((p) => `<option>${p}</option>`).join("")}</select></label>
|
|
|
|
|
<label class="task-field"><span>负责人</span><input name="owner" id="task-owner-${projectId}"></label>
|
|
|
|
|
<label class="task-field"><span>截止时间</span><input name="due_date" type="date" id="task-due-${projectId}"></label>
|
|
|
|
|
<label class="task-field col-span-2"><span>任务说明</span><textarea name="notes" rows="2" id="task-notes-${projectId}"></textarea></label>
|
|
|
|
|
<label class="task-field col-span-2"><span>卡点&备注</span><textarea name="blockers" rows="2" id="task-blockers-${projectId}" placeholder="风险卡点、依赖项等"></textarea></label>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="flex justify-end gap-2 mt-3">
|
|
|
|
|
<button type="button" class="btn btn-ghost btn-sm" onclick="document.querySelector('#task-form-${projectId}').classList.add('hidden')">取消</button>
|
|
|
|
|
<button type="submit" class="btn btn-primary btn-sm" id="task-submit-btn-${projectId}">确认新增</button>
|
|
|
|
|
</div>
|
|
|
|
|
</form>
|
|
|
|
|
const phases = ["商务洽谈", "系统上线", "团队分工", "项目交付", "上线推广", "结项验收"];
|
|
|
|
|
document.querySelector("#taskModal").innerHTML = `<div class="task-overlay" onclick="closeTaskModal()"><div class="task-panel" onclick="event.stopPropagation()"><div class="task-header"><h2 class="task-title">${project.project_name} · 任务清单</h2><div class="flex items-center gap-3"><button class="btn btn-primary btn-sm" onclick="event.stopPropagation(); openTaskForm(${projectId}, null)"><i data-lucide="plus"></i>新增任务</button><button class="task-close" onclick="closeTaskModal()"><i data-lucide="x"></i></button></div></div><div class="task-body-wrap">
|
|
|
|
|
<div class="task-body">
|
|
|
|
|
${phases.map((phase) => {
|
|
|
|
|
const pt = tasks.filter((t) => t.phase === phase);
|
|
|
|
|
if (!pt.length) return "";
|
|
|
|
|
return `<div class="task-group"><div class="task-group-hd"><span class="task-group-icon"><i data-lucide="layers"></i></span><span class="task-group-label">${phase}</span><span class="task-group-n">${pt.length}</span></div><div class="task-group-list">${pt.map((t) => `<div class="task-row" data-id="${t.id}" onclick="event.stopPropagation(); openTaskForm(${projectId}, ${t.id})"><span class="task-dot"><i data-lucide="${t.status === 'done' ? 'check-circle' : 'circle'}"></i></span><div class="task-main"><span class="task-name">${t.task}</span>${t.notes ? `<span class="task-desc">${t.notes}</span>` : ""}${t.blockers ? `<span class="task-blocker">⚠ ${t.blockers}</span>` : ""}</div><span class="task-col">${t.owner || ""}</span><span class="task-col-badge">${t.due_date || ""}</span></div>`).join("")}</div></div>`;
|
|
|
|
|
}).join("")}</div></div></div>`;
|
|
|
|
|
}).join("")}
|
|
|
|
|
</div>
|
|
|
|
|
<div id="task-drawer-${projectId}" class="task-drawer">
|
|
|
|
|
<div class="task-drawer-hd"><span class="task-drawer-title">编辑任务</span><button class="task-close" onclick="closeTaskDrawer(${projectId})"><i data-lucide="x"></i></button></div>
|
|
|
|
|
<form class="task-drawer-form" onsubmit="submitTaskForm(event, ${projectId})">
|
|
|
|
|
<input type="hidden" name="task_id" id="task-id-${projectId}" value="">
|
|
|
|
|
<label class="task-field"><span>任务名称</span><input name="task" required id="task-name-${projectId}"></label>
|
|
|
|
|
<label class="task-field"><span>任务阶段</span><select name="phase" id="task-phase-${projectId}">${phases.map((p) => `<option>${p}</option>`).join("")}</select></label>
|
|
|
|
|
<label class="task-field"><span>负责人</span><input name="owner" id="task-owner-${projectId}"></label>
|
|
|
|
|
<label class="task-field"><span>截止时间</span><input name="due_date" type="date" id="task-due-${projectId}"></label>
|
|
|
|
|
<label class="task-field"><span>任务说明</span><textarea name="notes" rows="3" id="task-notes-${projectId}"></textarea></label>
|
|
|
|
|
<label class="task-field"><span>卡点&备注</span><textarea name="blockers" rows="2" id="task-blockers-${projectId}" placeholder="风险卡点、依赖项等"></textarea></label>
|
|
|
|
|
<div class="flex justify-end gap-2 mt-4 pt-3 border-t border-slate-100">
|
|
|
|
|
<button type="button" class="btn btn-ghost btn-sm" onclick="closeTaskDrawer(${projectId})">取消</button>
|
|
|
|
|
<button type="submit" class="btn btn-primary btn-sm" id="task-submit-btn-${projectId}">确认新增</button>
|
|
|
|
|
</div>
|
|
|
|
|
</form>
|
|
|
|
|
</div>
|
|
|
|
|
</div></div></div>`;
|
|
|
|
|
document.querySelector("#taskModal").classList.add("active");
|
|
|
|
|
if (window.lucide) window.lucide.createIcons();
|
|
|
|
|
}
|
|
|
|
|
@@ -381,11 +438,13 @@ function renderChartOn(id, data) {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function drawerField(icon, label, name, value, multiline = false) {
|
|
|
|
|
function drawerField(icon, label, name, value, multiline = false, customControl = null) {
|
|
|
|
|
const initialValue = text(value);
|
|
|
|
|
const control = multiline
|
|
|
|
|
? `<textarea name="${name}" rows="2" class="drawer-value drawer-textarea" data-original="${initialValue}">${initialValue}</textarea>`
|
|
|
|
|
: `<input name="${name}" value="${initialValue}" class="drawer-value" data-original="${initialValue}">`;
|
|
|
|
|
const control = customControl
|
|
|
|
|
? customControl
|
|
|
|
|
: multiline
|
|
|
|
|
? `<textarea name="${name}" rows="2" class="drawer-value drawer-textarea" data-original="${initialValue}">${initialValue}</textarea>`
|
|
|
|
|
: `<input name="${name}" value="${initialValue}" class="drawer-value" data-original="${initialValue}">`;
|
|
|
|
|
return `<div class="drawer-field">
|
|
|
|
|
<div class="drawer-field-label"><i data-lucide="${icon}"></i><span>${label}</span></div>
|
|
|
|
|
<div class="drawer-field-control">${control}</div>
|
|
|
|
|
@@ -399,14 +458,14 @@ function openDrawer(resource, id) {
|
|
|
|
|
const fields = resource === "sales"
|
|
|
|
|
? [["target_customer","业务机会"],["priority","优先级"],["status","状态"]]
|
|
|
|
|
: resource === "operations"
|
|
|
|
|
? [["project_name","项目名称"],["project_version","项目版本"],["project_status","项目状态"],["current_stage","当前阶段"],["target_customer","业务机会"],["customer_need","客户需求"],["expected_contract_amount","预计签约金额"],["expected_sign_date","预计签约时间"],["sign_probability","签约概率"],["sop_stage","SOP 阶段"],["execution_progress","执行进度"],["current_deliverable","当前交付物"],["risks","风险与阻塞"],["next_action","下一步动作"]]
|
|
|
|
|
? [["project_name","项目名称"],["owner","负责人"],["expected_sign_date","截止时间"],["expected_contract_amount","金额"],["notes","项目说明"]]
|
|
|
|
|
: resource === "proposals"
|
|
|
|
|
? [["customer_or_project_name","客户/项目"],["version","版本号"],["description","版本说明"],["created_date","创建日期"],["status","状态"]]
|
|
|
|
|
: [["product_name","产品名称"],["version","版本号"],["version_goal","版本目标"],["feature_list","核心功能清单"],["platform","平台"],["launch_date","上线日期"],["status","当前状态"],["notes","备注"]];
|
|
|
|
|
const fieldIcons = {
|
|
|
|
|
target_customer: "user", priority: "flag", status: "circle-dot",
|
|
|
|
|
project_name: "briefcase-business", project_version: "git-branch", project_status: "circle-dot", current_stage: "map-pin",
|
|
|
|
|
customer_need: "file-text", expected_contract_amount: "banknote", expected_sign_date: "calendar",
|
|
|
|
|
owner: "user", customer_need: "file-text", expected_contract_amount: "banknote", expected_sign_date: "calendar",
|
|
|
|
|
sign_probability: "percent", sop_stage: "list-checks", execution_progress: "activity",
|
|
|
|
|
current_deliverable: "package", risks: "alert-triangle", next_action: "arrow-right",
|
|
|
|
|
product_name: "box", version: "tag", version_goal: "target", feature_list: "list", platform: "layers",
|
|
|
|
|
@@ -415,10 +474,13 @@ function openDrawer(resource, id) {
|
|
|
|
|
const multilineFields = ["customer_need", "current_deliverable", "risks", "next_action", "version_goal", "feature_list", "notes"];
|
|
|
|
|
const followupTarget = resource === "sales" ? "sales" : resource === "proposals" ? "proposal" : resource === "operations" ? "operation" : resource === "products" ? "product" : "";
|
|
|
|
|
const title = item.target_customer || item.project_name || item.customer_or_project_name || item.product_name;
|
|
|
|
|
drawer.innerHTML = `<div class="drawer-panel"><div class="sticky top-0 z-10 flex items-center justify-between border-b border-slate-200 bg-white/95 px-5 py-3 backdrop-blur"><div><p class="text-[10px] font-semibold uppercase tracking-[0.18em] text-slate-400">Detail Drawer</p><div class="flex items-center gap-2"><h2 class="drawer-title text-[17px] font-semibold leading-6 text-slate-900">${title}</h2><span id="drawerSaveStatus" class="save-status"></span></div></div><button class="btn btn-ghost btn-sm" onclick="closeDrawer()">关闭</button></div><div class="grid gap-5 p-5">
|
|
|
|
|
drawer.innerHTML = `<div class="drawer-panel"><div class="sticky top-0 z-10 flex items-center justify-between border-b border-slate-200 bg-white/95 px-5 py-3 backdrop-blur"><div><p class="text-[10px] font-semibold uppercase tracking-[0.18em] text-slate-400">Detail Drawer</p><div class="flex items-center gap-2"><h2 class="drawer-title text-[17px] font-semibold leading-6 text-slate-900">${title}</h2><span id="drawerSaveStatus" class="save-status"></span></div></div><div class="flex items-center gap-2"><button class="btn btn-ghost btn-sm text-red-600 hover:bg-red-50" onclick="deleteOperation(${id})"><i data-lucide="trash-2"></i>删除</button><button class="btn btn-ghost btn-sm" onclick="closeDrawer()">关闭</button></div></div><div class="grid gap-5 p-5">
|
|
|
|
|
<section>
|
|
|
|
|
<h3 class="drawer-section-title">属性</h3>
|
|
|
|
|
<form id="drawerForm" class="drawer-fields">${fields.map(([key,label]) => drawerField(fieldIcons[key] || "circle", label, key, item[key], multilineFields.includes(key))).join("")}</form>
|
|
|
|
|
<form id="drawerForm" class="drawer-fields">
|
|
|
|
|
${drawerField("map-pin", "当前阶段", "current_stage", "", false, `<select name="current_stage" class="drawer-value" onchange="saveDrawerField(this,'${resource}',${id})">${["商务洽谈","系统上线","团队分工","项目交付","上线推广","结项验收"].map((s) => `<option ${s === item.current_stage ? "selected" : ""}>${s}</option>`).join("")}</select>`)}
|
|
|
|
|
${fields.map(([key,label]) => drawerField(fieldIcons[key] || "circle", label, key, item[key], multilineFields.includes(key))).join("")}
|
|
|
|
|
</form>
|
|
|
|
|
</section>
|
|
|
|
|
${resource === "proposals" ? `<section><h3 class="drawer-section-title">方案文件</h3><div class="grid gap-2">${["方案","成本","SOP","财务流程"].map((cat) => fileGroup("proposal", item.id, item.version, cat, item.files.filter((f) => f.file_category === cat))).join("")}</div></section>` : ""}
|
|
|
|
|
${followupTarget ? `<section>
|
|
|
|
|
@@ -485,7 +547,7 @@ function bindDrawerAutosave(resource, id, item) {
|
|
|
|
|
field.addEventListener("keydown", (event) => {
|
|
|
|
|
if (event.key === "Enter" && field.tagName !== "TEXTAREA") field.blur();
|
|
|
|
|
});
|
|
|
|
|
field.addEventListener("blur", async () => {
|
|
|
|
|
const doSave = async () => {
|
|
|
|
|
const value = field.value;
|
|
|
|
|
if (value === field.dataset.original) return;
|
|
|
|
|
const previous = field.dataset.original;
|
|
|
|
|
@@ -505,13 +567,25 @@ function bindDrawerAutosave(resource, id, item) {
|
|
|
|
|
setDrawerSaveStatus("保存失败", "danger");
|
|
|
|
|
alert(`自动保存失败:${error.message}`);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
field.addEventListener("blur", doSave);
|
|
|
|
|
if (field.tagName === "SELECT") field.addEventListener("change", doSave);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
window.openDrawer = openDrawer;
|
|
|
|
|
window.deleteOperation = async (id) => {
|
|
|
|
|
if (!confirm("确认删除该项目?此操作不可撤销。")) return;
|
|
|
|
|
try {
|
|
|
|
|
await api(`/api/operations/${id}`, { method: "DELETE" });
|
|
|
|
|
closeDrawer();
|
|
|
|
|
await load();
|
|
|
|
|
} catch (error) {
|
|
|
|
|
alert("删除失败:" + error.message);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
window.closeDrawer = () => document.querySelector("#drawer").classList.remove("open");
|
|
|
|
|
window.squireInstances = {};
|
|
|
|
|
window.squireCmd = (cmd) => {
|
|
|
|
|
|