|
|
|
|
@@ -2,6 +2,7 @@ const state = {
|
|
|
|
|
active: "home",
|
|
|
|
|
data: null,
|
|
|
|
|
opFilter: "all",
|
|
|
|
|
projectView: null,
|
|
|
|
|
chart: null,
|
|
|
|
|
chart2: null,
|
|
|
|
|
productPlatform: "all",
|
|
|
|
|
@@ -216,8 +217,6 @@ window.submitTaskForm = async (event, projectId) => {
|
|
|
|
|
await api("/api/tasks", { method: "POST", body: JSON.stringify({ data }) });
|
|
|
|
|
}
|
|
|
|
|
await load();
|
|
|
|
|
closeTaskDrawer(projectId);
|
|
|
|
|
showTaskModal(Number(projectId));
|
|
|
|
|
} catch (error) {
|
|
|
|
|
alert("保存失败:" + error.message);
|
|
|
|
|
}
|
|
|
|
|
@@ -226,6 +225,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>`,
|
|
|
|
|
@@ -233,7 +236,7 @@ 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-end">
|
|
|
|
|
@@ -251,6 +254,49 @@ function renderProjects() {
|
|
|
|
|
</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">
|
|
|
|
|
<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) {
|
|
|
|
|
@@ -384,11 +430,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>
|
|
|
|
|
@@ -402,14 +450,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",
|
|
|
|
|
@@ -421,7 +469,10 @@ function openDrawer(resource, id) {
|
|
|
|
|
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">
|
|
|
|
|
<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>
|
|
|
|
|
@@ -488,7 +539,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;
|
|
|
|
|
@@ -508,7 +559,9 @@ function bindDrawerAutosave(resource, id, item) {
|
|
|
|
|
setDrawerSaveStatus("保存失败", "danger");
|
|
|
|
|
alert(`自动保存失败:${error.message}`);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
field.addEventListener("blur", doSave);
|
|
|
|
|
if (field.tagName === "SELECT") field.addEventListener("change", doSave);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|