Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e21d41b218 | ||
|
|
a57cba8043 | ||
|
|
fdb16d053a | ||
|
|
61ba9c4c5d | ||
|
|
eba4945fba | ||
|
|
2445dea4dd | ||
|
|
d2ea5d0d5d | ||
|
|
e233c294b0 | ||
|
|
6d30b8b891 | ||
|
|
666f35931c |
@@ -65,7 +65,7 @@ def monthly_finance(conn, tenant="科普·无界"):
|
|||||||
_year = date.today().year
|
_year = date.today().year
|
||||||
months = [f"{_year}-{m:02d}" for m in range(1, 13)]
|
months = [f"{_year}-{m:02d}" for m in range(1, 13)]
|
||||||
pfs = rows(conn,
|
pfs = rows(conn,
|
||||||
"SELECT sign_amount, sign_month, status, budget_data, expense_data FROM project_finances WHERE tenant=? AND status='已签约'",
|
"SELECT sign_amount, sign_month, budget_data, expense_data FROM project_finances WHERE tenant=?",
|
||||||
[tenant])
|
[tenant])
|
||||||
|
|
||||||
parsed_budgets = []
|
parsed_budgets = []
|
||||||
@@ -104,7 +104,7 @@ def monthly_finance(conn, tenant="科普·无界"):
|
|||||||
key = month.replace("-", "_")
|
key = month.replace("-", "_")
|
||||||
revenue = gross = payment = cost = paid = sign = 0
|
revenue = gross = payment = cost = paid = sign = 0
|
||||||
for pf, budget_map in parsed_budgets:
|
for pf, budget_map in parsed_budgets:
|
||||||
if pf["status"] == "已签约" and (pf.get("sign_month") or "") == month:
|
if (pf.get("sign_month") or "") == month:
|
||||||
sign += float(pf["sign_amount"] or 0)
|
sign += float(pf["sign_amount"] or 0)
|
||||||
b = budget_map.get(key)
|
b = budget_map.get(key)
|
||||||
if b:
|
if b:
|
||||||
|
|||||||
@@ -114,5 +114,20 @@ def migrate_add_columns():
|
|||||||
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
print("[migrate] 加列迁移完成")
|
print("[migrate] 加列迁移完成")
|
||||||
|
|
||||||
|
# 删除 plan_finances.status 列(计划模块不再需要状态字段)
|
||||||
|
cur = conn.cursor()
|
||||||
|
cur.execute("SHOW COLUMNS FROM plan_finances LIKE 'status'")
|
||||||
|
if cur.fetchone():
|
||||||
|
cur.execute("ALTER TABLE plan_finances DROP COLUMN status")
|
||||||
|
conn.commit()
|
||||||
|
print("[migrate] plan_finances.status 列已删除")
|
||||||
|
# 删除 project_finances.status 列(实际模块不再需要状态字段)
|
||||||
|
cur.execute("SHOW COLUMNS FROM project_finances LIKE 'status'")
|
||||||
|
if cur.fetchone():
|
||||||
|
cur.execute("ALTER TABLE project_finances DROP COLUMN status")
|
||||||
|
conn.commit()
|
||||||
|
print("[migrate] project_finances.status 列已删除")
|
||||||
|
cur.close()
|
||||||
finally:
|
finally:
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|||||||
@@ -112,3 +112,5 @@ def migrate_fix_expense_status():
|
|||||||
print(f"[migrate] expense_records: {affected} 条记录 status 修正为 '计入费用'")
|
print(f"[migrate] expense_records: {affected} 条记录 status 修正为 '计入费用'")
|
||||||
finally:
|
finally:
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ def make_budget_data(sign_amount, signed_month, status):
|
|||||||
"""生成12个月的预算数据"""
|
"""生成12个月的预算数据"""
|
||||||
months = []
|
months = []
|
||||||
start_m = int(signed_month.split("-")[1]) if signed_month else 1
|
start_m = int(signed_month.split("-")[1]) if signed_month else 1
|
||||||
rev_total = sign_amount if status == "已签约" else int(sign_amount * random.uniform(0.3, 0.7))
|
rev_total = sign_amount
|
||||||
gross_rate = random.uniform(0.25, 0.55)
|
gross_rate = random.uniform(0.25, 0.55)
|
||||||
payment_rate = random.uniform(0.7, 0.95)
|
payment_rate = random.uniform(0.7, 0.95)
|
||||||
|
|
||||||
@@ -135,17 +135,17 @@ def seed_db():
|
|||||||
cust_idx += i % 3
|
cust_idx += i % 3
|
||||||
|
|
||||||
# 70% 已签约, 30% 待签约
|
# 70% 已签约, 30% 待签约
|
||||||
status = "已签约" if random.random() < 0.7 else "待签约"
|
status = "已签约"
|
||||||
sign_month = f"2026-{random.randint(1, 6):02d}" if status == "已签约" else ""
|
sign_month = f"2026-{random.randint(1, 6):02d}"
|
||||||
project_code = f"{tenant[:2]}-2026-{i+1:03d}"
|
project_code = f"{tenant[:2]}-2026-{i+1:03d}"
|
||||||
business_type = random.choice(["学术推广", "医生教育", "患者管理", "科研合作", "科普内容"])
|
business_type = random.choice(["学术推广", "医生教育", "患者管理", "科研合作", "科普内容"])
|
||||||
|
|
||||||
# 如果签约,总额 = 签约额;否则为0
|
# 如果签约,总额 = 签约额;否则为0
|
||||||
total_rev = int(sign_amount * random.uniform(0.8, 1.0)) if status == "已签约" else 0
|
total_rev = int(sign_amount * random.uniform(0.8, 1.0))
|
||||||
total_gross = int(total_rev * random.uniform(0.25, 0.5)) if status == "已签约" else 0
|
total_gross = int(total_rev * random.uniform(0.25, 0.5))
|
||||||
total_payment = int(total_rev * random.uniform(0.7, 0.9)) if status == "已签约" else 0
|
total_payment = int(total_rev * random.uniform(0.7, 0.9))
|
||||||
total_cost = int(total_rev * random.uniform(0.3, 0.5)) if status == "已签约" else 0
|
total_cost = int(total_rev * random.uniform(0.3, 0.5))
|
||||||
total_paid = int(total_cost * random.uniform(0.7, 0.95)) if status == "已签约" else 0
|
total_paid = int(total_cost * random.uniform(0.7, 0.95))
|
||||||
|
|
||||||
budget_data = make_budget_data(sign_amount, sign_month, status)
|
budget_data = make_budget_data(sign_amount, sign_month, status)
|
||||||
expense_data = make_expense_data() if status == "已签约" else "[]"
|
expense_data = make_expense_data() if status == "已签约" else "[]"
|
||||||
@@ -157,16 +157,16 @@ def seed_db():
|
|||||||
|
|
||||||
cur = _exec(conn, """
|
cur = _exec(conn, """
|
||||||
INSERT INTO project_finances
|
INSERT INTO project_finances
|
||||||
(tenant, project_id, business_type, customer_name, sign_amount, sign_month, status,
|
(tenant, project_id, business_type, customer_name, sign_amount, sign_month,
|
||||||
sales_person, total_rev, total_gross, total_payment, total_cost, total_paid,
|
sales_person, total_rev, total_gross, total_payment, total_cost, total_paid,
|
||||||
budget_data, expense_data, task_data,
|
budget_data, expense_data, task_data,
|
||||||
project_code, start_date, end_date, task_type, task_count,
|
project_code, start_date, end_date, task_type, task_count,
|
||||||
service_fee_standard, project_manager, contact_name, contact_phone, other_info,
|
service_fee_standard, project_manager, contact_name, contact_phone, other_info,
|
||||||
created_at, updated_at)
|
created_at, updated_at)
|
||||||
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
|
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
|
||||||
""", (
|
""", (
|
||||||
tenant, f"PF-{tenant[:2]}-{i+1:04d}", business_type, cust_name,
|
tenant, f"PF-{tenant[:2]}-{i+1:04d}", business_type, cust_name,
|
||||||
sign_amount, sign_month, status,
|
sign_amount, sign_month,
|
||||||
f"销售{random.choice(['A','B','C','D'])}", total_rev, total_gross,
|
f"销售{random.choice(['A','B','C','D'])}", total_rev, total_gross,
|
||||||
total_payment, total_cost, total_paid,
|
total_payment, total_cost, total_paid,
|
||||||
budget_data, expense_data, task_data,
|
budget_data, expense_data, task_data,
|
||||||
@@ -178,7 +178,7 @@ def seed_db():
|
|||||||
today, today,
|
today, today,
|
||||||
))
|
))
|
||||||
# Store for later use
|
# Store for later use
|
||||||
pf_ids.setdefault(tenant, []).append((cur.lastrowid, proj_name, cust_name, status))
|
pf_ids.setdefault(tenant, []).append((cur.lastrowid, proj_name, cust_name))
|
||||||
|
|
||||||
# operation_projects: 每个工作台 3-5 个
|
# operation_projects: 每个工作台 3-5 个
|
||||||
op_count = random.randint(3, 5)
|
op_count = random.randint(3, 5)
|
||||||
|
|||||||
@@ -158,6 +158,8 @@ def migrate_create_tables():
|
|||||||
created_at VARCHAR(30) NOT NULL DEFAULT '',
|
created_at VARCHAR(30) NOT NULL DEFAULT '',
|
||||||
updated_at VARCHAR(30) NOT NULL DEFAULT ''
|
updated_at VARCHAR(30) NOT NULL DEFAULT ''
|
||||||
)""",
|
)""",
|
||||||
|
"""CREATE TABLE IF NOT EXISTS plan_finances LIKE project_finances""",
|
||||||
|
"""CREATE TABLE IF NOT EXISTS plan_expense_records LIKE expense_records""",
|
||||||
]
|
]
|
||||||
|
|
||||||
for ddl in tables:
|
for ddl in tables:
|
||||||
|
|||||||
@@ -23,8 +23,10 @@ TABLES = {
|
|||||||
"products": ("product_versions", ["product_name", "version", "version_goal", "priority", "start_date", "plan_date", "dev_done_date", "test_date", "launch_date", "status", "notes", "tenant"]),
|
"products": ("product_versions", ["product_name", "version", "version_goal", "priority", "start_date", "plan_date", "dev_done_date", "test_date", "launch_date", "status", "notes", "tenant"]),
|
||||||
"finance": ("finance_records", ["month", "project_name", "record_type", "category", "amount", "occurred_date", "notes", "tenant"]),
|
"finance": ("finance_records", ["month", "project_name", "record_type", "category", "amount", "occurred_date", "notes", "tenant"]),
|
||||||
"tasks": ("project_tasks", ["project_id", "phase", "milestone", "task", "owner", "due_date", "blockers", "notes", "status", "sort_order", "priority", "tenant"]),
|
"tasks": ("project_tasks", ["project_id", "phase", "milestone", "task", "owner", "due_date", "blockers", "notes", "status", "sort_order", "priority", "tenant"]),
|
||||||
"projectFinances": ("project_finances", ["project_id", "tenant", "business_type", "customer_name", "sign_amount", "sign_month", "status", "sales_person", "owner", "total_rev", "total_gross", "total_payment", "total_cost", "total_paid", "budget_data", "expense_data", "start_date", "end_date", "task_type", "task_count", "service_fee_standard", "project_manager", "task_data", "project_code", "contact_name", "contact_phone", "other_info"]),
|
"projectFinances": ("project_finances", ["project_id", "tenant", "business_type", "customer_name", "sign_amount", "sign_month", "sales_person", "owner", "total_rev", "total_gross", "total_payment", "total_cost", "total_paid", "budget_data", "expense_data", "start_date", "end_date", "task_type", "task_count", "service_fee_standard", "project_manager", "task_data", "project_code", "contact_name", "contact_phone", "other_info"]),
|
||||||
"expense": ("expense_records", ["expense_type", "expense_month", "amount", "incurred_amount", "notes", "status", "tenant"]),
|
"expense": ("expense_records", ["expense_type", "expense_month", "amount", "incurred_amount", "notes", "status", "tenant"]),
|
||||||
|
"planFinances": ("plan_finances", ["project_id", "tenant", "business_type", "customer_name", "sign_amount", "sign_month", "sales_person", "owner", "total_rev", "total_gross", "total_payment", "total_cost", "total_paid", "budget_data", "expense_data", "start_date", "end_date", "task_type", "task_count", "service_fee_standard", "project_manager", "task_data", "project_code", "contact_name", "contact_phone", "other_info"]),
|
||||||
|
"planExpense": ("plan_expense_records", ["expense_type", "expense_month", "amount", "incurred_amount", "notes", "status", "tenant"]),
|
||||||
}
|
}
|
||||||
|
|
||||||
# ---------- 鉴权装饰器 ----------
|
# ---------- 鉴权装饰器 ----------
|
||||||
@@ -92,6 +94,30 @@ def auth_logout():
|
|||||||
return jsonify({"ok": True})
|
return jsonify({"ok": True})
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route("/api/auth/change-password", methods=["POST"])
|
||||||
|
@login_required
|
||||||
|
def auth_change_password():
|
||||||
|
data = request.get_json(force=True) or {}
|
||||||
|
old_password = data.get("old_password", "")
|
||||||
|
new_password = data.get("new_password", "")
|
||||||
|
if not old_password or not new_password:
|
||||||
|
return jsonify({"error": "旧密码和新密码不能为空"}), 400
|
||||||
|
if len(new_password) < 6:
|
||||||
|
return jsonify({"error": "新密码至少需要6位"}), 400
|
||||||
|
user_id = session.get("user_id")
|
||||||
|
conn = db()
|
||||||
|
try:
|
||||||
|
user = one(conn, "SELECT * FROM users WHERE id=?", (user_id,))
|
||||||
|
if not user or not check_password_hash(user["password_hash"], old_password):
|
||||||
|
return jsonify({"error": "旧密码错误"}), 401
|
||||||
|
new_hash = generate_password_hash(new_password)
|
||||||
|
_exec(conn, "UPDATE users SET password_hash=? WHERE id=?", (new_hash, user_id))
|
||||||
|
conn.commit()
|
||||||
|
return jsonify({"ok": True})
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
@bp.route("/api/auth/me")
|
@bp.route("/api/auth/me")
|
||||||
def auth_me():
|
def auth_me():
|
||||||
if "user_id" not in session:
|
if "user_id" not in session:
|
||||||
@@ -250,7 +276,7 @@ def bootstrap():
|
|||||||
t_products = attach_common(conn, "products", rows(conn, "SELECT * FROM product_versions WHERE tenant=? ORDER BY id DESC", [t]))
|
t_products = attach_common(conn, "products", rows(conn, "SELECT * FROM product_versions WHERE tenant=? ORDER BY id DESC", [t]))
|
||||||
t_expense = rows(conn, "SELECT * FROM expense_records WHERE tenant=?", [t])
|
t_expense = rows(conn, "SELECT * FROM expense_records WHERE tenant=?", [t])
|
||||||
t_proposals = attach_common(conn, "proposals", rows(conn, "SELECT * FROM business_proposals WHERE tenant=? ORDER BY id DESC", [t]))
|
t_proposals = attach_common(conn, "proposals", rows(conn, "SELECT * FROM business_proposals WHERE tenant=? ORDER BY id DESC", [t]))
|
||||||
t_signed_pfs = [x for x in t_pfs if x["status"] == "已签约"]
|
t_signed_pfs = t_pfs
|
||||||
def t_parse_budget(pf):
|
def t_parse_budget(pf):
|
||||||
try:
|
try:
|
||||||
budget = json.loads(pf.get("budget_data") or "[]")
|
budget = json.loads(pf.get("budget_data") or "[]")
|
||||||
@@ -300,12 +326,12 @@ def bootstrap():
|
|||||||
"total_proposals": len(t_ops),
|
"total_proposals": len(t_ops),
|
||||||
"total_products": len(t_proposals),
|
"total_products": len(t_proposals),
|
||||||
"upcoming_products": len(t_products),
|
"upcoming_products": len(t_products),
|
||||||
"signed_amount": sum(x["sign_amount"] or 0 for x in t_pfs if x["status"] == "已签约"),
|
"signed_amount": sum(x["sign_amount"] or 0 for x in t_pfs),
|
||||||
"signed_annual": sum(x["sign_amount"] or 0 for x in t_pfs if x["status"] == "已签约"),
|
"signed_annual": sum(x["sign_amount"] or 0 for x in t_pfs),
|
||||||
"signed_q2": sum(x["sign_amount"] or 0 for x in t_pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] in _q_months),
|
"signed_q2": sum(x["sign_amount"] or 0 for x in t_pfs if (x.get("sign_month") or "")[:7] in _q_months),
|
||||||
"signed_month": sum(x["sign_amount"] or 0 for x in t_pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] == f"{_year}-{_now_month:02d}"),
|
"signed_month": sum(x["sign_amount"] or 0 for x in t_pfs if (x.get("sign_month") or "")[:7] == f"{_year}-{_now_month:02d}"),
|
||||||
"signed_prev_q": sum(x["sign_amount"] or 0 for x in t_pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] in _prev_q_months),
|
"signed_prev_q": sum(x["sign_amount"] or 0 for x in t_pfs if (x.get("sign_month") or "")[:7] in _prev_q_months),
|
||||||
"signed_prev_month": sum(x["sign_amount"] or 0 for x in t_pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] == f"{_year}-{_prev_month:02d}") if _prev_month else 0,
|
"signed_prev_month": sum(x["sign_amount"] or 0 for x in t_pfs if (x.get("sign_month") or "")[:7] == f"{_year}-{_prev_month:02d}") if _prev_month else 0,
|
||||||
"revenue_annual": t_sum_budget("rev", range(1, 13)),
|
"revenue_annual": t_sum_budget("rev", range(1, 13)),
|
||||||
"revenue_q2": t_sum_budget("rev", _q_range),
|
"revenue_q2": t_sum_budget("rev", _q_range),
|
||||||
"monthly_revenue": t_sum_budget("rev", [_now_month]),
|
"monthly_revenue": t_sum_budget("rev", [_now_month]),
|
||||||
@@ -402,7 +428,7 @@ def bootstrap():
|
|||||||
"recent": sorted(all_recent, key=lambda x: x.get("id", 0), reverse=True)[:8],
|
"recent": sorted(all_recent, key=lambda x: x.get("id", 0), reverse=True)[:8],
|
||||||
"risks": [],
|
"risks": [],
|
||||||
}
|
}
|
||||||
return jsonify({"summary": summary, "sales": [], "proposals": [], "operations": [], "products": [], "finance": [], "projectFinances": [], "financeMonthly": merged_monthly, "tasks": [], "expense": [], "tenant": tenant, "tenants": allowed})
|
return jsonify({"summary": summary, "sales": [], "proposals": [], "operations": [], "products": [], "finance": [], "projectFinances": [], "financeMonthly": merged_monthly, "tasks": [], "expense": [], "planFinances": [], "planExpense": [], "tenant": tenant, "tenants": allowed})
|
||||||
|
|
||||||
def q(sql, *args):
|
def q(sql, *args):
|
||||||
return rows(conn, sql, args)
|
return rows(conn, sql, args)
|
||||||
@@ -414,7 +440,9 @@ def bootstrap():
|
|||||||
tasks = q("SELECT * FROM project_tasks WHERE tenant=? ORDER BY phase, sort_order, id", tenant)
|
tasks = q("SELECT * FROM project_tasks WHERE tenant=? ORDER BY phase, sort_order, id", tenant)
|
||||||
pfs = q("SELECT * FROM project_finances WHERE tenant=? ORDER BY id DESC", tenant)
|
pfs = q("SELECT * FROM project_finances WHERE tenant=? ORDER BY id DESC", tenant)
|
||||||
expense = q("SELECT * FROM expense_records WHERE tenant=? ORDER BY id DESC", tenant)
|
expense = q("SELECT * FROM expense_records WHERE tenant=? ORDER BY id DESC", tenant)
|
||||||
signed_pfs = [x for x in pfs if x["status"] == "已签约"]
|
planPfs = q("SELECT * FROM plan_finances WHERE tenant=? ORDER BY id DESC", tenant)
|
||||||
|
planExpense = q("SELECT * FROM plan_expense_records WHERE tenant=? ORDER BY id DESC", tenant)
|
||||||
|
signed_pfs = pfs
|
||||||
|
|
||||||
def parse_budget(pf):
|
def parse_budget(pf):
|
||||||
try:
|
try:
|
||||||
@@ -535,16 +563,14 @@ def bootstrap():
|
|||||||
profit_month = gross_month - proj_expense_month
|
profit_month = gross_month - proj_expense_month
|
||||||
profit_prev_q = gross_prev_q - proj_expense_prev_q
|
profit_prev_q = gross_prev_q - proj_expense_prev_q
|
||||||
profit_prev_month = gross_prev_month - proj_expense_prev_month
|
profit_prev_month = gross_prev_month - proj_expense_prev_month
|
||||||
def pf_status_sum(status):
|
signed_amount = sum(x["sign_amount"] or 0 for x in pfs)
|
||||||
return sum(x["sign_amount"] or 0 for x in pfs if x["status"] == status)
|
signed_annual = sum(x["sign_amount"] or 0 for x in pfs)
|
||||||
signed_amount = pf_status_sum("已签约")
|
|
||||||
signed_annual = sum(x["sign_amount"] or 0 for x in pfs if x["status"] == "已签约")
|
|
||||||
_q_months = [f"{_year}-{m:02d}" for m in _q_range]
|
_q_months = [f"{_year}-{m:02d}" for m in _q_range]
|
||||||
signed_q2 = sum(x["sign_amount"] or 0 for x in pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] in _q_months)
|
signed_q2 = sum(x["sign_amount"] or 0 for x in pfs if (x.get("sign_month") or "")[:7] in _q_months)
|
||||||
signed_month = sum(x["sign_amount"] or 0 for x in pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] == f"{_year}-{_now_month:02d}")
|
signed_month = sum(x["sign_amount"] or 0 for x in pfs if (x.get("sign_month") or "")[:7] == f"{_year}-{_now_month:02d}")
|
||||||
_prev_q_months = [f"{_year}-{m:02d}" for m in _prev_q_range]
|
_prev_q_months = [f"{_year}-{m:02d}" for m in _prev_q_range]
|
||||||
signed_prev_q = sum(x["sign_amount"] or 0 for x in pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] in _prev_q_months)
|
signed_prev_q = sum(x["sign_amount"] or 0 for x in pfs if (x.get("sign_month") or "")[:7] in _prev_q_months)
|
||||||
signed_prev_month = sum(x["sign_amount"] or 0 for x in pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] == f"{_year}-{_prev_month:02d}") if _prev_month else 0
|
signed_prev_month = sum(x["sign_amount"] or 0 for x in pfs if (x.get("sign_month") or "")[:7] == f"{_year}-{_prev_month:02d}") if _prev_month else 0
|
||||||
pipeline_amount = sum(x["expected_contract_amount"] or 0 for x in operations if x["project_status"] not in ["已签约","已丢单","已归档","已完成"])
|
pipeline_amount = sum(x["expected_contract_amount"] or 0 for x in operations if x["project_status"] not in ["已签约","已丢单","已归档","已完成"])
|
||||||
signed_not_executed = sum(x["expected_contract_amount"] or 0 for x in operations if x["project_type"] == "execution" and x["execution_progress"] < 100)
|
signed_not_executed = sum(x["expected_contract_amount"] or 0 for x in operations if x["project_type"] == "execution" and x["execution_progress"] < 100)
|
||||||
summary = {
|
summary = {
|
||||||
@@ -626,7 +652,7 @@ def bootstrap():
|
|||||||
"recent": q("SELECT * FROM follow_up_records WHERE tenant=? ORDER BY id DESC LIMIT 8", tenant),
|
"recent": q("SELECT * FROM follow_up_records WHERE tenant=? ORDER BY id DESC LIMIT 8", tenant),
|
||||||
"risks": [{"title": "执行提醒", "content": x["next_action"]} for x in operations if x["next_action"]][:5],
|
"risks": [{"title": "执行提醒", "content": x["next_action"]} for x in operations if x["next_action"]][:5],
|
||||||
}
|
}
|
||||||
return jsonify({"summary": summary, "sales": sales, "proposals": proposals, "operations": operations, "products": products, "finance": finance, "projectFinances": pfs, "financeMonthly": monthly_finance(conn, tenant), "tasks": tasks, "expense": expense, "tenant": tenant, "tenants": allowed})
|
return jsonify({"summary": summary, "sales": sales, "proposals": proposals, "operations": operations, "products": products, "finance": finance, "projectFinances": pfs, "financeMonthly": monthly_finance(conn, tenant), "tasks": tasks, "expense": expense, "planFinances": planPfs, "planExpense": planExpense, "tenant": tenant, "tenants": allowed})
|
||||||
finally:
|
finally:
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|||||||
@@ -166,3 +166,89 @@ window.deleteUser = async (uid, username) => {
|
|||||||
toast("删除失败:" + e.message, "error");
|
toast("删除失败:" + e.message, "error");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 修改密码弹窗
|
||||||
|
window.openChangePwdModal = () => {
|
||||||
|
const overlay = document.createElement("div");
|
||||||
|
overlay.id = "changePwdOverlay";
|
||||||
|
overlay.className = "fixed inset-0 bg-black/40 z-[9999] flex items-center justify-center p-4";
|
||||||
|
overlay.innerHTML = `
|
||||||
|
<div class="bg-white rounded-xl shadow-2xl w-full max-w-sm">
|
||||||
|
<div class="flex items-center justify-between px-6 py-4 border-b border-slate-200">
|
||||||
|
<h2 class="text-lg font-semibold text-slate-800">修改密码</h2>
|
||||||
|
<button class="text-slate-400 hover:text-slate-700" onclick="closeChangePwdModal()"><i data-lucide="x"></i></button>
|
||||||
|
</div>
|
||||||
|
<form class="p-6 grid gap-4" onsubmit="doChangePwd(event)" novalidate>
|
||||||
|
<label class="block">
|
||||||
|
<span class="text-sm text-slate-500 mb-1 block">旧密码</span>
|
||||||
|
<div class="relative">
|
||||||
|
<input type="password" name="old_password" required class="form-ctrl pr-10" placeholder="输入旧密码">
|
||||||
|
<button type="button" class="absolute right-2 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600 p-1" onclick="togglePwdEye(this)"><i data-lucide="eye-off" style="width:16px;height:16px"></i></button>
|
||||||
|
</div>
|
||||||
|
</label>
|
||||||
|
<label class="block">
|
||||||
|
<span class="text-sm text-slate-500 mb-1 block">新密码</span>
|
||||||
|
<div class="relative">
|
||||||
|
<input type="password" name="new_password" required minlength="6" class="form-ctrl pr-10" placeholder="至少6位">
|
||||||
|
<button type="button" class="absolute right-2 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600 p-1" onclick="togglePwdEye(this)"><i data-lucide="eye-off" style="width:16px;height:16px"></i></button>
|
||||||
|
</div>
|
||||||
|
</label>
|
||||||
|
<label class="block">
|
||||||
|
<span class="text-sm text-slate-500 mb-1 block">确认新密码</span>
|
||||||
|
<div class="relative">
|
||||||
|
<input type="password" name="confirm_password" required minlength="6" class="form-ctrl pr-10" placeholder="再次输入新密码">
|
||||||
|
<button type="button" class="absolute right-2 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600 p-1" onclick="togglePwdEye(this)"><i data-lucide="eye-off" style="width:16px;height:16px"></i></button>
|
||||||
|
</div>
|
||||||
|
</label>
|
||||||
|
<div class="flex justify-end gap-3 pt-2">
|
||||||
|
<button type="button" class="btn btn-ghost btn-sm px-6" onclick="closeChangePwdModal()">取消</button>
|
||||||
|
<button type="submit" class="btn btn-primary btn-sm px-8">确认修改</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>`;
|
||||||
|
overlay.addEventListener("click", (e) => { if (e.target === overlay) closeChangePwdModal(); });
|
||||||
|
document.body.appendChild(overlay);
|
||||||
|
if (window.lucide) lucide.createIcons();
|
||||||
|
};
|
||||||
|
|
||||||
|
window.togglePwdEye = (btn) => {
|
||||||
|
const input = btn.parentElement.querySelector("input");
|
||||||
|
const icon = btn.querySelector("i");
|
||||||
|
if (input.type === "password") {
|
||||||
|
input.type = "text";
|
||||||
|
icon.setAttribute("data-lucide", "eye");
|
||||||
|
} else {
|
||||||
|
input.type = "password";
|
||||||
|
icon.setAttribute("data-lucide", "eye-off");
|
||||||
|
}
|
||||||
|
if (window.lucide) lucide.createIcons({ elements: [icon] });
|
||||||
|
};
|
||||||
|
|
||||||
|
window.closeChangePwdModal = () => {
|
||||||
|
const el = document.getElementById("changePwdOverlay");
|
||||||
|
if (el) el.remove();
|
||||||
|
};
|
||||||
|
|
||||||
|
window.doChangePwd = async (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
const form = e.target;
|
||||||
|
const fd = new FormData(form);
|
||||||
|
const oldPwd = fd.get("old_password");
|
||||||
|
const newPwd = fd.get("new_password");
|
||||||
|
const confirmPwd = fd.get("confirm_password");
|
||||||
|
if (newPwd !== confirmPwd) { toast("两次输入的新密码不一致", "error"); return; }
|
||||||
|
if (newPwd.length < 6) { toast("新密码至少需要6位", "error"); return; }
|
||||||
|
try {
|
||||||
|
const resp = await fetch("/api/auth/change-password", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({ old_password: oldPwd, new_password: newPwd }),
|
||||||
|
});
|
||||||
|
const data = await resp.json();
|
||||||
|
if (!resp.ok) { toast(data.error || "修改失败", "error"); return; }
|
||||||
|
closeChangePwdModal();
|
||||||
|
toast("密码修改成功", "success");
|
||||||
|
} catch (err) {
|
||||||
|
toast("请求失败:" + err.message, "error");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ function renderFinance() {
|
|||||||
const months = displayMonths.map(d => d.key);
|
const months = displayMonths.map(d => d.key);
|
||||||
const monthLabels = displayMonths.map(d => d.label);
|
const monthLabels = displayMonths.map(d => d.label);
|
||||||
|
|
||||||
const signed = pfs.filter(x => x.status === "已签约");
|
const signed = pfs;
|
||||||
const pending = pfs.filter(x => x.status === "待签约");
|
const pending = pfs;
|
||||||
const sumSign = Math.round(signed.reduce((s,x) => s + (x.sign_amount||0), 0));
|
const sumSign = Math.round(signed.reduce((s,x) => s + (x.sign_amount||0), 0));
|
||||||
const sumPending = Math.round(pending.reduce((s,x) => s + (x.sign_amount||0), 0));
|
const sumPending = Math.round(pending.reduce((s,x) => s + (x.sign_amount||0), 0));
|
||||||
|
|
||||||
@@ -116,7 +116,7 @@ function renderFinance() {
|
|||||||
const finHeaderBase = `<span class="text-sm text-slate-500">视图:</span><select onchange="setFinView(this.value)" class="text-sm font-medium py-1 px-2.5 cursor-pointer" style="appearance:none;-webkit-appearance:none;background-color:transparent;border:0;outline:none;background:url('data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%2212%22 height=%2212%22 viewBox=%220 0 24 24%22 fill=%22none%22 stroke=%22%236b7280%22 stroke-width=%222%22 stroke-linecap=%22round%22 stroke-linejoin=%22round%22%3E%3Cpolyline points=%226 9 12 15 18 9%22%3E%3C/polyline%3E%3C/svg%3E') no-repeat right 4px center;padding-right:22px;min-height:30px"><option value="overview" ${state.finView==='overview'?'selected':''}>总视图</option><option value="quarterly" ${state.finView==='quarterly'?'selected':''}>季度视图</option><option value="monthly" ${state.finView==='monthly'?'selected':''}>月度视图</option></select>${toolDateSelect}`;
|
const finHeaderBase = `<span class="text-sm text-slate-500">视图:</span><select onchange="setFinView(this.value)" class="text-sm font-medium py-1 px-2.5 cursor-pointer" style="appearance:none;-webkit-appearance:none;background-color:transparent;border:0;outline:none;background:url('data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%2212%22 height=%2212%22 viewBox=%220 0 24 24%22 fill=%22none%22 stroke=%22%236b7280%22 stroke-width=%222%22 stroke-linecap=%22round%22 stroke-linejoin=%22round%22%3E%3Cpolyline points=%226 9 12 15 18 9%22%3E%3C/polyline%3E%3C/svg%3E') no-repeat right 4px center;padding-right:22px;min-height:30px"><option value="overview" ${state.finView==='overview'?'selected':''}>总视图</option><option value="quarterly" ${state.finView==='quarterly'?'selected':''}>季度视图</option><option value="monthly" ${state.finView==='monthly'?'selected':''}>月度视图</option></select>${toolDateSelect}`;
|
||||||
const finAddBtn = `<button class="btn btn-primary btn-sm" onclick="openFinanceModal()">新增财务项目</button>`;
|
const finAddBtn = `<button class="btn btn-primary btn-sm" onclick="openFinanceModal()">新增财务项目</button>`;
|
||||||
|
|
||||||
const finFilterTabs = `<div class="finance-tabs" style="padding:0;border-bottom:1px solid #e2e8f0;margin-bottom:0"><button onclick="switchFinFilter('overview')" class="finance-tab${state.finFilter==='overview'?' active':''}" style="font-size:14px;font-weight:600">总览</button><button onclick="switchFinFilter('已签约')" class="finance-tab${state.finFilter==='已签约'?' active':''}" style="font-size:14px;font-weight:600">已签约 (${pfs.filter(x=>x.status==='已签约').length})</button><button onclick="switchFinFilter('待签约')" class="finance-tab${state.finFilter==='待签约'?' active':''}" style="font-size:14px;font-weight:600">待签约 (${pfs.filter(x=>x.status==='待签约').length})</button><button onclick="switchFinFilter('expense')" class="finance-tab${state.finFilter==='expense'?' active':''}" style="font-size:14px;font-weight:600">平台费用</button></div>`;
|
const finFilterTabs = `<div class="finance-tabs" style="padding:0;border-bottom:1px solid #e2e8f0;margin-bottom:0"><button onclick="switchFinFilter('overview')" class="finance-tab${state.finFilter==='overview'?' active':''}" style="font-size:14px;font-weight:600">总览</button><button onclick="switchFinFilter('projects')" class="finance-tab${state.finFilter==='projects'?' active':''}" style="font-size:14px;font-weight:600">项目 (${pfs.length})</button><button onclick="switchFinFilter('expense')" class="finance-tab${state.finFilter==='expense'?' active':''}" style="font-size:14px;font-weight:600">平台费用</button></div>`;
|
||||||
|
|
||||||
document.querySelector("#finance").innerHTML = `<div class="grid gap-4">
|
document.querySelector("#finance").innerHTML = `<div class="grid gap-4">
|
||||||
${finFilterTabs}
|
${finFilterTabs}
|
||||||
@@ -142,7 +142,7 @@ function renderFinance() {
|
|||||||
<div class="grid grid-cols-3 gap-3">
|
<div class="grid grid-cols-3 gap-3">
|
||||||
<label class="block"><span class="fin-label">签约金额(元) <span class="text-red-500">*</span></span><input name="sign_amount" class="form-ctrl" placeholder="必须大于 0"></label>
|
<label class="block"><span class="fin-label">签约金额(元) <span class="text-red-500">*</span></span><input name="sign_amount" class="form-ctrl" placeholder="必须大于 0"></label>
|
||||||
<label class="block"><span class="fin-label">签约月份 <span class="text-red-500">*</span></span><select name="sign_month" required class="form-ctrl bg-white"><option value="">选择</option>${monthOptions('')}</select></label>
|
<label class="block"><span class="fin-label">签约月份 <span class="text-red-500">*</span></span><select name="sign_month" required class="form-ctrl bg-white"><option value="">选择</option>${monthOptions('')}</select></label>
|
||||||
<label class="block"><span class="fin-label">项目状态</span><select name="status" class="form-ctrl bg-white"><option>已签约</option><option>待签约</option></select></label>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="grid grid-cols-3 gap-3">
|
<div class="grid grid-cols-3 gap-3">
|
||||||
<label class="block"><span class="fin-label">商务负责人 <span class="text-red-500">*</span></span><input name="sales_person" required class="form-ctrl" placeholder="请输入商务负责人"></label>
|
<label class="block"><span class="fin-label">商务负责人 <span class="text-red-500">*</span></span><input name="sales_person" required class="form-ctrl" placeholder="请输入商务负责人"></label>
|
||||||
@@ -245,7 +245,7 @@ function renderFinance() {
|
|||||||
setTimeout(() => renderExpense(), 10);
|
setTimeout(() => renderExpense(), 10);
|
||||||
return `<div id="financeExpense"></div>`;
|
return `<div id="financeExpense"></div>`;
|
||||||
}
|
}
|
||||||
const isUnsigned = state.finFilter === '待签约';
|
const isUnsigned = false;
|
||||||
const METRIC_CARDS = [
|
const METRIC_CARDS = [
|
||||||
{ label: '签约金额', value: ctx => moneyWan(ctx.signTotal), color: 'text-slate-700' },
|
{ label: '签约金额', value: ctx => moneyWan(ctx.signTotal), color: 'text-slate-700' },
|
||||||
{ label: '已确收', hideUnsigned: true, value: ctx => moneyWan(ctx.sumRev), color: 'text-blue-700' },
|
{ label: '已确收', hideUnsigned: true, value: ctx => moneyWan(ctx.sumRev), color: 'text-blue-700' },
|
||||||
@@ -259,7 +259,43 @@ function renderFinance() {
|
|||||||
{ label: '毛利率', hideUnsigned: true, value: ctx => ctx.sumRev && ctx.sumGross ? Math.round(ctx.sumGross / ctx.sumRev * 100) + '%' : '—', color: 'text-slate-500' },
|
{ label: '毛利率', hideUnsigned: true, value: ctx => ctx.sumRev && ctx.sumGross ? Math.round(ctx.sumGross / ctx.sumRev * 100) + '%' : '—', color: 'text-slate-500' },
|
||||||
{ label: '回款率', hideUnsigned: true, value: ctx => ctx.sumRev && ctx.sumPay ? Math.round(ctx.sumPay / ctx.sumRev * 100) + '%' : '—', color: 'text-slate-500' },
|
{ label: '回款率', hideUnsigned: true, value: ctx => ctx.sumRev && ctx.sumPay ? Math.round(ctx.sumPay / ctx.sumRev * 100) + '%' : '—', color: 'text-slate-500' },
|
||||||
{ label: '付款率', hideUnsigned: true, value: ctx => ctx.sumCost && ctx.sumPaid ? Math.round(ctx.sumPaid / ctx.sumCost * 100) + '%' : '—', color: 'text-slate-500' },
|
{ label: '付款率', hideUnsigned: true, value: ctx => ctx.sumCost && ctx.sumPaid ? Math.round(ctx.sumPaid / ctx.sumCost * 100) + '%' : '—', color: 'text-slate-500' },
|
||||||
].filter(c => state.finFilter !== '待签约' || !c.hideUnsigned);
|
].filter(c => true);
|
||||||
|
|
||||||
|
// 列排序
|
||||||
|
if (!state.finSort) state.finSort = { key: null, asc: true };
|
||||||
|
const sortData = (data, key) => {
|
||||||
|
if (!key || !state.finSort.key) return data;
|
||||||
|
var asc = state.finSort.asc ? 1 : -1;
|
||||||
|
return data.slice().sort(function(a, b) {
|
||||||
|
var va = a[key], vb = b[key];
|
||||||
|
if (typeof va === 'string') va = va || '', vb = vb || '';
|
||||||
|
else { va = parseFloat(va) || 0; vb = parseFloat(vb) || 0; }
|
||||||
|
if (va < vb) return -1 * asc;
|
||||||
|
if (va > vb) return 1 * asc;
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
const buildThead = (cols, sortKey) => {
|
||||||
|
var h = '<thead><tr class="bg-slate-50 border-b border-slate-200">';
|
||||||
|
cols.forEach(function(c) {
|
||||||
|
var arrow = sortKey ? (sortKey === c.key ? (state.finSort.asc ? ' ↑' : ' ↓') : '') : '';
|
||||||
|
h += '<th class="p-2 text-center font-semibold align-middle cursor-pointer select-none" onclick="setFinSort(\'' + sortKey + '|' + c.key + '\')">' + c.label + arrow + '</th>';
|
||||||
|
});
|
||||||
|
h += '</tr></thead>';
|
||||||
|
return h;
|
||||||
|
};
|
||||||
|
const SIGNED_COLS = [
|
||||||
|
{ key: 'customer_name', label: '项目名称' }, { key: 'sign_amount', label: '签约金额' },
|
||||||
|
{ key: 'rev', label: '已确收' }, { key: 'gross', label: '毛利' }, { key: 'cost', label: '成本' },
|
||||||
|
{ key: 'profit', label: '项目利润' }, { key: 'payment', label: '已回款' }, { key: 'paid', label: '已付' },
|
||||||
|
{ key: 'cashflow', label: '现金流' }, { key: 'exe_rate', label: '执行率' }, { key: 'gross_rate', label: '毛利率' },
|
||||||
|
{ key: 'pay_rate', label: '回款率' }, { key: 'paid_rate', label: '付款率' },
|
||||||
|
];
|
||||||
|
const UNSIGNED_COLS = [
|
||||||
|
{ key: 'customer_name', label: '项目名称' }, { key: 'sign_amount', label: '签约金额' },
|
||||||
|
{ key: 'sign_month', label: '签约月份' }, { key: 'gross', label: '毛利' }, { key: 'cost', label: '成本' },
|
||||||
|
{ key: 'profit', label: '项目利润' },
|
||||||
|
];
|
||||||
|
|
||||||
const renderView = (rows, sumRev, sumPay, sumCost, sumPaid, sumGross, signTotal, signCnt, emptyText) => {
|
const renderView = (rows, sumRev, sumPay, sumCost, sumPaid, sumGross, signTotal, signCnt, emptyText) => {
|
||||||
const ctx = { sumRev, sumPay, sumCost, sumPaid, sumGross, signTotal, signCnt };
|
const ctx = { sumRev, sumPay, sumCost, sumPaid, sumGross, signTotal, signCnt };
|
||||||
@@ -267,33 +303,8 @@ function renderFinance() {
|
|||||||
const v = c.value(ctx);
|
const v = c.value(ctx);
|
||||||
return typeof v === 'object' ? [c.label, v.val, v.cls] : [c.label, v, c.color];
|
return typeof v === 'object' ? [c.label, v.val, v.cls] : [c.label, v, c.color];
|
||||||
});
|
});
|
||||||
const thead = isUnsigned
|
const thead = isUnsigned ? buildThead(UNSIGNED_COLS, 'uns') : buildThead(SIGNED_COLS, 'sig');
|
||||||
? '<thead><tr class="bg-slate-50 border-b border-slate-200">' +
|
const theadCols = isUnsigned ? 6 : 13;
|
||||||
'<th class="p-2 text-center font-semibold align-middle">项目名称</th>' +
|
|
||||||
'<th class="p-2 text-center font-semibold align-middle">状态</th>' +
|
|
||||||
'<th class="p-2 text-center font-semibold align-middle">签约金额</th>' +
|
|
||||||
'<th class="p-2 text-center font-semibold align-middle">签约月份</th>' +
|
|
||||||
'<th class="p-2 text-center font-semibold align-middle">毛利</th>' +
|
|
||||||
'<th class="p-2 text-center font-semibold align-middle text-rose-600">成本</th>' +
|
|
||||||
'<th class="p-2 text-center font-semibold align-middle">项目利润</th>' +
|
|
||||||
'</tr></thead>'
|
|
||||||
: '<thead><tr class="bg-slate-50 border-b border-slate-200">' +
|
|
||||||
'<th class="p-2 text-center font-semibold align-middle">项目名称</th>' +
|
|
||||||
'<th class="p-2 text-center font-semibold align-middle">状态</th>' +
|
|
||||||
'<th class="p-2 text-center font-semibold align-middle">签约金额</th>' +
|
|
||||||
'<th class="p-2 text-center font-semibold align-middle text-blue-600">已确收</th>' +
|
|
||||||
'<th class="p-2 text-center font-semibold align-middle">毛利</th>' +
|
|
||||||
'<th class="p-2 text-center font-semibold align-middle text-rose-600">成本</th>' +
|
|
||||||
'<th class="p-2 text-center font-semibold align-middle">项目利润</th>' +
|
|
||||||
'<th class="p-2 text-center font-semibold align-middle text-amber-600">已回款</th>' +
|
|
||||||
'<th class="p-2 text-center font-semibold align-middle text-purple-600">已付</th>' +
|
|
||||||
'<th class="p-2 text-center font-semibold align-middle text-slate-700">现金流</th>' +
|
|
||||||
'<th class="p-2 text-center font-semibold align-middle">执行率</th>' +
|
|
||||||
'<th class="p-2 text-center font-semibold align-middle">毛利率</th>' +
|
|
||||||
'<th class="p-2 text-center font-semibold align-middle">回款率</th>' +
|
|
||||||
'<th class="p-2 text-center font-semibold align-middle">付款率</th>' +
|
|
||||||
'</tr></thead>';
|
|
||||||
const theadCols = isUnsigned ? 7 : 14;
|
|
||||||
const tbody = rows.length ? `<tbody>${rows.join("")}</tbody>` : `<tr><td colspan="${theadCols}" class="p-6 text-center text-slate-400">${emptyText}</td></tr>`;
|
const tbody = rows.length ? `<tbody>${rows.join("")}</tbody>` : `<tr><td colspan="${theadCols}" class="p-6 text-center text-slate-400">${emptyText}</td></tr>`;
|
||||||
|
|
||||||
const cardGrid = isUnsigned ? 'grid-cols-4' : 'grid-cols-6';
|
const cardGrid = isUnsigned ? 'grid-cols-4' : 'grid-cols-6';
|
||||||
@@ -313,31 +324,28 @@ function renderFinance() {
|
|||||||
const payR = payRVal !== null ? '<span class="' + payRCls + ' font-semibold">' + payRVal + '%</span>' : '<span class="text-slate-300">—</span>';
|
const payR = payRVal !== null ? '<span class="' + payRCls + ' font-semibold">' + payRVal + '%</span>' : '<span class="text-slate-300">—</span>';
|
||||||
const paidR = cost && paid ? Math.round(paid / cost * 100) + '%' : '<span class="text-slate-300">—</span>';
|
const paidR = cost && paid ? Math.round(paid / cost * 100) + '%' : '<span class="text-slate-300">—</span>';
|
||||||
const grossR = rev && gross ? Math.round(gross / rev * 100) + '%' : '<span class="text-slate-300">—</span>';
|
const grossR = rev && gross ? Math.round(gross / rev * 100) + '%' : '<span class="text-slate-300">—</span>';
|
||||||
const st = pf.status === '已签约' ? '<span class="text-green-600">已签约</span>' : '<span class="text-amber-600">待签约</span>';
|
const cf = cashflow ? money(cashflow) : '<span class="text-slate-300">—</span>';
|
||||||
const cf = cashflow ? money(cashflow) : '<span class="text-slate-300">—</span>';
|
|
||||||
const cfCls = cashflow >= 0 ? 'text-green-600' : 'text-red-600';
|
const cfCls = cashflow >= 0 ? 'text-green-600' : 'text-red-600';
|
||||||
const profit = gross;
|
const profit = gross;
|
||||||
const pfCls = profit >= 0 ? 'text-green-600' : 'text-red-600';
|
const pfCls = profit >= 0 ? 'text-green-600' : 'text-red-600';
|
||||||
const pfVal = profit ? money(profit) : '<span class="text-slate-300">—</span>';
|
const pfVal = profit ? money(profit) : '<span class="text-slate-300">—</span>';
|
||||||
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 text-center align-middle truncate" style="min-width:300px;max-width:300px;width:300px" title="${esc(pf.customer_name)}">${esc(pf.customer_name)}</td><td class="p-2 text-center align-middle text-sm">${st}</td><td class="p-2 text-center align-middle text-sm font-medium">${money(pf.sign_amount)}</td><td class="p-2 text-center text-blue-700 align-middle">${fmtNoUnit(rev)}</td><td class="p-2 text-center align-middle text-sm font-medium">${fmtNoUnit(gross)}</td><td class="p-2 text-center text-rose-700 align-middle">${fmtNoUnit(cost)}</td><td class="p-2 text-center font-semibold align-middle ${pfCls}">${pfVal}</td><td class="p-2 text-center text-amber-700 align-middle">${fmtNoUnit(payment)}</td><td class="p-2 text-center text-purple-700 align-middle">${fmtNoUnit(paid)}</td><td class="p-2 text-center font-semibold align-middle ${cfCls}">${cf}</td><td class="p-2 text-center align-middle text-sm">${exe}</td><td class="p-2 text-center align-middle text-sm">${grossR}</td><td class="p-2 text-center align-middle text-sm">${payR}</td><td class="p-2 text-center align-middle text-sm">${paidR}</td></tr>`;
|
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 text-center align-middle truncate" style="min-width:300px;max-width:300px;width:300px" title="${esc(pf.customer_name)}">${esc(pf.customer_name)}</td><td class="p-2 text-center align-middle text-sm font-medium">${money(pf.sign_amount)}</td><td class="p-2 text-center text-blue-700 align-middle">${fmtNoUnit(rev)}</td><td class="p-2 text-center align-middle text-sm font-medium">${fmtNoUnit(gross)}</td><td class="p-2 text-center text-rose-700 align-middle">${fmtNoUnit(cost)}</td><td class="p-2 text-center font-semibold align-middle ${pfCls}">${pfVal}</td><td class="p-2 text-center text-amber-700 align-middle">${fmtNoUnit(payment)}</td><td class="p-2 text-center text-purple-700 align-middle">${fmtNoUnit(paid)}</td><td class="p-2 text-center font-semibold align-middle ${cfCls}">${cf}</td><td class="p-2 text-center align-middle text-sm">${exe}</td><td class="p-2 text-center align-middle text-sm">${grossR}</td><td class="p-2 text-center align-middle text-sm">${payR}</td><td class="p-2 text-center align-middle text-sm">${paidR}</td></tr>`;
|
||||||
};
|
};
|
||||||
// 待签约简版行
|
// 待签约简版行
|
||||||
const tdRowUnsigned = (pf, cost, gross) => {
|
const tdRowUnsigned = (pf, cost, gross) => {
|
||||||
const st = pf.status === '待签约' ? '<span class="text-amber-600">待签约</span>' : '<span class="text-green-600">已签约</span>';
|
const profit = gross;
|
||||||
const profit = gross;
|
|
||||||
const pfCls = profit >= 0 ? 'text-green-600' : 'text-red-600';
|
const pfCls = profit >= 0 ? 'text-green-600' : 'text-red-600';
|
||||||
const pfVal = profit ? money(profit) : '<span class="text-slate-300">—</span>';
|
const pfVal = profit ? money(profit) : '<span class="text-slate-300">—</span>';
|
||||||
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 text-center align-middle truncate" style="min-width:300px;max-width:300px;width:300px" title="${esc(pf.customer_name)}">${esc(pf.customer_name)}</td><td class="p-2 text-center align-middle text-sm">${st}</td><td class="p-2 text-center align-middle text-sm font-medium">${money(pf.sign_amount)}</td><td class="p-2 text-center align-middle text-sm">${pf.sign_month || '—'}</td><td class="p-2 text-center align-middle text-sm font-medium">${fmtNoUnit(gross)}</td><td class="p-2 text-center text-rose-700 align-middle">${fmtNoUnit(cost)}</td><td class="p-2 text-center font-semibold align-middle ${pfCls}">${pfVal}</td></tr>`;
|
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 text-center align-middle truncate" style="min-width:300px;max-width:300px;width:300px" title="${esc(pf.customer_name)}">${esc(pf.customer_name)}</td><td class="p-2 text-center align-middle text-sm font-medium">${money(pf.sign_amount)}</td><td class="p-2 text-center align-middle text-sm">${pf.sign_month || '—'}</td><td class="p-2 text-center align-middle text-sm font-medium">${fmtNoUnit(gross)}</td><td class="p-2 text-center text-rose-700 align-middle">${fmtNoUnit(cost)}</td><td class="p-2 text-center font-semibold align-middle ${pfCls}">${pfVal}</td></tr>`;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (state.finView === 'monthly') {
|
if (state.finView === 'monthly') {
|
||||||
const allPfs = pfs.filter(x => x.status === state.finFilter);
|
const allPfs = pfs;
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const defaultMonth = now.getFullYear() + "-" + String(now.getMonth() + 1).padStart(2, "0");
|
const defaultMonth = now.getFullYear() + "-" + String(now.getMonth() + 1).padStart(2, "0");
|
||||||
if (!state.finMonth) state.finMonth = defaultMonth;
|
if (!state.finMonth) state.finMonth = defaultMonth;
|
||||||
const selMonth = state.finMonth;
|
const selMonth = state.finMonth;
|
||||||
const rows = [];
|
var dataItems = [];
|
||||||
let sumRev = 0, sumPay = 0, sumCost = 0, sumPaid = 0, sumGross = 0;
|
|
||||||
allPfs.forEach(pf => {
|
allPfs.forEach(pf => {
|
||||||
let bd = []; try { bd = JSON.parse(pf.budget_data || "[]"); } catch (e) {}
|
let bd = []; try { bd = JSON.parse(pf.budget_data || "[]"); } catch (e) {}
|
||||||
let ed = []; try { ed = JSON.parse(pf.expense_data || "[]"); } catch (e) {}
|
let ed = []; try { ed = JSON.parse(pf.expense_data || "[]"); } catch (e) {}
|
||||||
@@ -349,16 +357,31 @@ function renderFinance() {
|
|||||||
const cost = Math.round(parseFloat(e.cost || 0) || 0);
|
const cost = Math.round(parseFloat(e.cost || 0) || 0);
|
||||||
const paid = Math.round(parseFloat(e.paid || 0) || 0);
|
const paid = Math.round(parseFloat(e.paid || 0) || 0);
|
||||||
if (!rev && !payment && !cost && !paid && !gross) return;
|
if (!rev && !payment && !cost && !paid && !gross) return;
|
||||||
sumRev += rev; sumPay += payment; sumCost += cost; sumPaid += paid; sumGross += gross;
|
dataItems.push({
|
||||||
rows.push(isUnsigned ? tdRowUnsigned(pf, cost, gross) : tdRow(pf, rev, payment, cost, paid, gross));
|
pf: pf, customer_name: pf.customer_name || '', sign_amount: pf.sign_amount || 0, sign_month: pf.sign_month || '',
|
||||||
|
rev: rev, gross: gross, cost: cost, profit: gross, payment: payment, paid: paid,
|
||||||
|
cashflow: payment - paid,
|
||||||
|
exe_rate: rev && pf.sign_amount ? Math.round(rev / pf.sign_amount * 100) : 0,
|
||||||
|
gross_rate: rev && gross ? Math.round(gross / rev * 100) : 0,
|
||||||
|
pay_rate: rev && payment ? Math.round(payment / rev * 100) : 0,
|
||||||
|
paid_rate: cost && paid ? Math.round(paid / cost * 100) : 0,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
var sortK = state.finSort && state.finSort.key ? state.finSort.key.split('|')[1] : null;
|
||||||
|
dataItems = sortData(dataItems, sortK);
|
||||||
|
const rows = [];
|
||||||
|
let sumRev = 0, sumPay = 0, sumCost = 0, sumPaid = 0, sumGross = 0;
|
||||||
|
dataItems.forEach(d => {
|
||||||
|
sumRev += d.rev; sumPay += d.payment; sumCost += d.cost; sumPaid += d.paid; sumGross += d.gross;
|
||||||
|
rows.push(isUnsigned ? tdRowUnsigned(d.pf, d.cost, d.gross) : tdRow(d.pf, d.rev, d.payment, d.cost, d.paid, d.gross));
|
||||||
});
|
});
|
||||||
const signTotal = Math.round(allPfs.filter(x => (x.sign_month || "").substring(0, 7) === selMonth).reduce((a, p) => a + (p.sign_amount || 0), 0));
|
const signTotal = Math.round(allPfs.filter(x => (x.sign_month || "").substring(0, 7) === selMonth).reduce((a, p) => a + (p.sign_amount || 0), 0));
|
||||||
const signCnt = allPfs.filter(x => x.status === "已签约" && (x.sign_month || "").substring(0, 7) === selMonth).length;
|
const signCnt = allPfs.filter(x => (x.sign_month || "").substring(0, 7) === selMonth).length;
|
||||||
return renderView(rows, sumRev, sumPay, sumCost, sumPaid, sumGross, signTotal, signCnt, '该月份暂无数据');
|
return renderView(rows, sumRev, sumPay, sumCost, sumPaid, sumGross, signTotal, signCnt, '该月份暂无数据');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.finView === 'quarterly') {
|
if (state.finView === 'quarterly') {
|
||||||
const allPfs = pfs.filter(x => x.status === state.finFilter);
|
const allPfs = pfs;
|
||||||
const qRanges = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]];
|
const qRanges = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]];
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
if (state.finQuarter === undefined) {
|
if (state.finQuarter === undefined) {
|
||||||
@@ -377,8 +400,7 @@ function renderFinance() {
|
|||||||
try { JSON.parse(pf.expense_data || "[]").forEach(e => { const m = parseInt((e.month || "").substring(5)) || 0; if (qRange.includes(m)) total += parseFloat(e[field] || 0); }); } catch (e) {}
|
try { JSON.parse(pf.expense_data || "[]").forEach(e => { const m = parseInt((e.month || "").substring(5)) || 0; if (qRange.includes(m)) total += parseFloat(e[field] || 0); }); } catch (e) {}
|
||||||
return total;
|
return total;
|
||||||
};
|
};
|
||||||
let sumRev = 0, sumPay = 0, sumCost = 0, sumPaid = 0, sumGross = 0;
|
var dataItems = [];
|
||||||
const rows = [];
|
|
||||||
allPfs.forEach(pf => {
|
allPfs.forEach(pf => {
|
||||||
const rev = sumBudget(pf, "rev");
|
const rev = sumBudget(pf, "rev");
|
||||||
const payment = sumBudget(pf, "payment");
|
const payment = sumBudget(pf, "payment");
|
||||||
@@ -386,11 +408,26 @@ function renderFinance() {
|
|||||||
const cost = sumExpense(pf, "cost");
|
const cost = sumExpense(pf, "cost");
|
||||||
const paid = sumExpense(pf, "paid");
|
const paid = sumExpense(pf, "paid");
|
||||||
if (!rev && !payment && !cost && !paid && !gross) return;
|
if (!rev && !payment && !cost && !paid && !gross) return;
|
||||||
sumRev += rev; sumPay += payment; sumCost += cost; sumPaid += paid; sumGross += gross;
|
dataItems.push({
|
||||||
rows.push(isUnsigned ? tdRowUnsigned(pf, cost, gross) : tdRow(pf, rev, payment, cost, paid, gross));
|
pf: pf, customer_name: pf.customer_name || '', sign_amount: pf.sign_amount || 0, sign_month: pf.sign_month || '',
|
||||||
|
rev: rev, gross: gross, cost: cost, profit: gross, payment: payment, paid: paid,
|
||||||
|
cashflow: payment - paid,
|
||||||
|
exe_rate: rev && pf.sign_amount ? Math.round(rev / pf.sign_amount * 100) : 0,
|
||||||
|
gross_rate: rev && gross ? Math.round(gross / rev * 100) : 0,
|
||||||
|
pay_rate: rev && payment ? Math.round(payment / rev * 100) : 0,
|
||||||
|
paid_rate: cost && paid ? Math.round(paid / cost * 100) : 0,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
var sortK = state.finSort && state.finSort.key ? state.finSort.key.split('|')[1] : null;
|
||||||
|
dataItems = sortData(dataItems, sortK);
|
||||||
|
let sumRev = 0, sumPay = 0, sumCost = 0, sumPaid = 0, sumGross = 0;
|
||||||
|
const rows = [];
|
||||||
|
dataItems.forEach(d => {
|
||||||
|
sumRev += d.rev; sumPay += d.payment; sumCost += d.cost; sumPaid += d.paid; sumGross += d.gross;
|
||||||
|
rows.push(isUnsigned ? tdRowUnsigned(d.pf, d.cost, d.gross) : tdRow(d.pf, d.rev, d.payment, d.cost, d.paid, d.gross));
|
||||||
});
|
});
|
||||||
const signTotal = Math.round(allPfs.filter(x => { const m = parseInt((x.sign_month || "0").substring(5)) || 0; return qRange.includes(m); }).reduce((a, p) => a + (p.sign_amount || 0), 0));
|
const signTotal = Math.round(allPfs.filter(x => { const m = parseInt((x.sign_month || "0").substring(5)) || 0; return qRange.includes(m); }).reduce((a, p) => a + (p.sign_amount || 0), 0));
|
||||||
const signCnt = allPfs.filter(x => x.status === "已签约" && qRange.includes(parseInt((x.sign_month || "0").substring(5)) || 0)).length;
|
const signCnt = allPfs.filter(x => qRange.includes(parseInt((x.sign_month || "0").substring(5)) || 0)).length;
|
||||||
return renderView(rows, sumRev, sumPay, sumCost, sumPaid, sumGross, signTotal, signCnt, '该季度暂无数据');
|
return renderView(rows, sumRev, sumPay, sumCost, sumPaid, sumGross, signTotal, signCnt, '该季度暂无数据');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -404,16 +441,29 @@ function renderFinance() {
|
|||||||
expense.forEach(e => { cost += parseFloat(e.cost || 0) || 0; paid += parseFloat(e.paid || 0) || 0; });
|
expense.forEach(e => { cost += parseFloat(e.cost || 0) || 0; paid += parseFloat(e.paid || 0) || 0; });
|
||||||
return { rev: Math.round(rev), payment: Math.round(payment), cost: Math.round(cost), paid: Math.round(paid), gross: Math.round(gross) };
|
return { rev: Math.round(rev), payment: Math.round(payment), cost: Math.round(cost), paid: Math.round(paid), gross: Math.round(gross) };
|
||||||
};
|
};
|
||||||
const allPfs = pfs.filter(x => x.status === state.finFilter);
|
const allPfs = pfs;
|
||||||
|
var dataItems = allPfs.map(pf => {
|
||||||
|
var t = calcTotals(pf);
|
||||||
|
return {
|
||||||
|
pf: pf, customer_name: pf.customer_name || '', sign_amount: pf.sign_amount || 0, sign_month: pf.sign_month || '',
|
||||||
|
rev: t.rev, gross: t.gross, cost: t.cost, profit: t.gross,
|
||||||
|
payment: t.payment, paid: t.paid, cashflow: t.payment - t.paid,
|
||||||
|
exe_rate: t.rev && pf.sign_amount ? Math.round(t.rev / pf.sign_amount * 100) : 0,
|
||||||
|
gross_rate: t.rev && t.gross ? Math.round(t.gross / t.rev * 100) : 0,
|
||||||
|
pay_rate: t.rev && t.payment ? Math.round(t.payment / t.rev * 100) : 0,
|
||||||
|
paid_rate: t.cost && t.paid ? Math.round(t.paid / t.cost * 100) : 0,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
var sortK = state.finSort && state.finSort.key ? state.finSort.key.split('|')[1] : null;
|
||||||
|
dataItems = sortData(dataItems, sortK);
|
||||||
let sumRev = 0, sumPay = 0, sumCost = 0, sumPaid = 0, sumGross = 0;
|
let sumRev = 0, sumPay = 0, sumCost = 0, sumPaid = 0, sumGross = 0;
|
||||||
const rows = [];
|
const rows = [];
|
||||||
allPfs.forEach(pf => {
|
dataItems.forEach(d => {
|
||||||
const t = calcTotals(pf);
|
sumRev += d.rev; sumPay += d.payment; sumCost += d.cost; sumPaid += d.paid; sumGross += d.gross;
|
||||||
sumRev += t.rev; sumPay += t.payment; sumCost += t.cost; sumPaid += t.paid; sumGross += t.gross;
|
rows.push(isUnsigned ? tdRowUnsigned(d.pf, d.cost, d.gross) : tdRow(d.pf, d.rev, d.payment, d.cost, d.paid, d.gross));
|
||||||
rows.push(isUnsigned ? tdRowUnsigned(pf, t.cost, t.gross) : tdRow(pf, t.rev, t.payment, t.cost, t.paid, t.gross));
|
|
||||||
});
|
});
|
||||||
const signTotal = Math.round(allPfs.reduce((a, p) => a + (p.sign_amount || 0), 0));
|
const signTotal = Math.round(allPfs.reduce((a, p) => a + (p.sign_amount || 0), 0));
|
||||||
const signCnt = allPfs.filter(x => x.status === "已签约").length;
|
const signCnt = allPfs.length;
|
||||||
return renderView(rows, sumRev, sumPay, sumCost, sumPaid, sumGross, signTotal, signCnt, '暂无数据');
|
return renderView(rows, sumRev, sumPay, sumCost, sumPaid, sumGross, signTotal, signCnt, '暂无数据');
|
||||||
})()}
|
})()}
|
||||||
</div>`;
|
</div>`;
|
||||||
@@ -734,7 +784,6 @@ window.openPfEditModal = (pfId) => {
|
|||||||
signMonthEl.innerHTML = monthOptions(signMonthValue);
|
signMonthEl.innerHTML = monthOptions(signMonthValue);
|
||||||
signMonthEl.value = signMonthValue;
|
signMonthEl.value = signMonthValue;
|
||||||
}
|
}
|
||||||
form.querySelector('[name="status"]').value = pf.status || "待签约";
|
|
||||||
form.querySelector('[name="sales_person"]').value = pf.sales_person || "";
|
form.querySelector('[name="sales_person"]').value = pf.sales_person || "";
|
||||||
form.querySelector('[name="owner"]').value = pf.owner || "";
|
form.querySelector('[name="owner"]').value = pf.owner || "";
|
||||||
setVal("start_date", pf.start_date);
|
setVal("start_date", pf.start_date);
|
||||||
|
|||||||
@@ -168,17 +168,9 @@ function renderHome() {
|
|||||||
};
|
};
|
||||||
return buildDeptTable('部门经营情况', d.slice(0, 3)) + buildDeptTable('部门现金流', d.slice(3, 6));
|
return buildDeptTable('部门经营情况', d.slice(0, 3)) + buildDeptTable('部门现金流', d.slice(3, 6));
|
||||||
})()}
|
})()}
|
||||||
${card(`<h3 class="text-sm font-bold text-slate-700">业务(项目)财务概览</h3><p class="text-xs text-slate-400 mb-3">合同 → 确收 → 毛利 → 成本 → 项目利润 → 回款 → 已付 → 现金流</p><div class="overflow-x-auto"><table class="w-full text-sm"><thead>${thead}</thead><tbody>${tbody}</tbody></table></div>`, "p-4")}
|
|
||||||
<div class="grid grid-cols-4 gap-5">
|
|
||||||
${card(`<div class="mb-3 flex items-center justify-between"><h2 class="text-sm font-bold text-slate-600">月度签约趋势</h2><span class="text-xs text-slate-400">2026</span></div><div style="position:relative;height:200px"><canvas id="chartSign"></canvas></div>`, "p-4")}
|
|
||||||
${card(`<div class="mb-3 flex items-center justify-between"><h2 class="text-sm font-bold text-slate-600">月度确收与毛利</h2><span class="text-xs text-slate-400">2026</span></div><div style="position:relative;height:200px"><canvas id="chartRev"></canvas></div>`, "p-4")}
|
|
||||||
${card(`<div class="mb-3 flex items-center justify-between"><h2 class="text-sm font-bold text-slate-600">月度回款与已付</h2><span class="text-xs text-slate-400">2026</span></div><div style="position:relative;height:200px"><canvas id="chartCash"></canvas></div>`, "p-4")}
|
|
||||||
${card(`<div class="mb-3 flex items-center justify-between"><h2 class="text-sm font-bold text-slate-600">月度项目利润</h2><span class="text-xs text-slate-400">2026</span></div><div style="position:relative;height:200px"><canvas id="chartProfit"></canvas></div>`, "p-4")}
|
|
||||||
</div>
|
|
||||||
${card(`<h2 class="text-lg font-bold">近期动态</h2><div class="mt-4 grid gap-2">${summary.recent.map((r) => `<div class="flex items-start justify-between rounded-md bg-slate-50 px-3 py-2 text-sm group"><span class="break-words">${r.content}</span><div class="flex items-center gap-2 flex-shrink-0 ml-2"><span class="text-xs text-slate-400">${r.followed_at}</span><button class="btn btn-ghost btn-sm text-red-400 opacity-0 group-hover:opacity-100 p-0 w-5 h-5" onclick="event.preventDefault();deleteActivity(${r.id})" title="删除动态"><i data-lucide="trash-2" style="width:14px;height:14px"></i></button></div></div>`).join("")}</div>`, "p-5")}
|
${card(`<h2 class="text-lg font-bold">近期动态</h2><div class="mt-4 grid gap-2">${summary.recent.map((r) => `<div class="flex items-start justify-between rounded-md bg-slate-50 px-3 py-2 text-sm group"><span class="break-words">${r.content}</span><div class="flex items-center gap-2 flex-shrink-0 ml-2"><span class="text-xs text-slate-400">${r.followed_at}</span><button class="btn btn-ghost btn-sm text-red-400 opacity-0 group-hover:opacity-100 p-0 w-5 h-5" onclick="event.preventDefault();deleteActivity(${r.id})" title="删除动态"><i data-lucide="trash-2" style="width:14px;height:14px"></i></button></div></div>`).join("")}</div>`, "p-5")}
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
renderCharts(financeMonthly);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function chartOptions(yCallback) {
|
function chartOptions(yCallback) {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ window.renderPerformance = () => {
|
|||||||
const qRange = qRanges[q];
|
const qRange = qRanges[q];
|
||||||
const storageKey = 'opc-performance-Q' + (q + 1);
|
const storageKey = 'opc-performance-Q' + (q + 1);
|
||||||
|
|
||||||
const pfs = (data.projectFinances || []).filter(p => p.status === '已签约');
|
const pfs = (data.projectFinances || []);
|
||||||
|
|
||||||
const sumQ = (field) => {
|
const sumQ = (field) => {
|
||||||
let total = 0;
|
let total = 0;
|
||||||
|
|||||||
1051
static/modules/plan.js
Normal file
1051
static/modules/plan.js
Normal file
File diff suppressed because it is too large
Load Diff
219
static/modules/plan_expense.js
Normal file
219
static/modules/plan_expense.js
Normal file
@@ -0,0 +1,219 @@
|
|||||||
|
// expense.js — 费用管理模块
|
||||||
|
|
||||||
|
function renderPlanExpense() {
|
||||||
|
var records = state.data.planExpense || [];
|
||||||
|
var money = function(v) { return '¥ ' + (Number(v || 0)).toLocaleString('zh-CN', { minimumFractionDigits: 0, maximumFractionDigits: 2 }); };
|
||||||
|
var esc = function(s) { return (s || '').replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"'); };
|
||||||
|
var EXPENSE_TYPES = ['通用费用','平台采购','人力成本','研发费用','奖金','其他'];
|
||||||
|
var STATUS_OPTIONS = ['计入费用','暂不计入'];
|
||||||
|
|
||||||
|
// 排序状态
|
||||||
|
if (!state.planExpSort) state.planExpSort = { key: 'expense_month', asc: true };
|
||||||
|
var sortKey = state.planExpSort.key;
|
||||||
|
var sortAsc = state.planExpSort.asc ? 1 : -1;
|
||||||
|
|
||||||
|
// 筛选状态
|
||||||
|
var view = state.planExpView || 'total';
|
||||||
|
var typeFilter = state.planExpFilter || '全部';
|
||||||
|
var filtered = typeFilter === '全部' ? records : records.filter(function(r) { return r.expense_type === typeFilter; });
|
||||||
|
|
||||||
|
// 视图数据预处理
|
||||||
|
var now = new Date();
|
||||||
|
var thisYear = now.getFullYear();
|
||||||
|
var defaultMonth = thisYear + '-' + String(now.getMonth() + 1).padStart(2, '0');
|
||||||
|
|
||||||
|
if (!state.planExpMonth) state.planExpMonth = defaultMonth;
|
||||||
|
if (state.planExpQuarter === '') state.planExpQuarter = String(Math.floor(now.getMonth() / 3));
|
||||||
|
|
||||||
|
// 月度筛选
|
||||||
|
if (view === 'monthly') {
|
||||||
|
filtered = filtered.filter(function(r) { return r.expense_month === state.planExpMonth; });
|
||||||
|
}
|
||||||
|
|
||||||
|
// 季度筛选
|
||||||
|
if (view === 'quarterly') {
|
||||||
|
var q = parseInt(state.planExpQuarter) || 0;
|
||||||
|
var qRanges = [[1,2,3],[4,5,6],[7,8,9],[10,11,12]];
|
||||||
|
var qRange = qRanges[q];
|
||||||
|
filtered = filtered.filter(function(r) {
|
||||||
|
var m = parseInt((r.expense_month || '0').substring(5)) || 0;
|
||||||
|
return qRange.indexOf(m) >= 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 排序
|
||||||
|
filtered.sort(function(a, b) {
|
||||||
|
var va = a[sortKey] || '', vb = b[sortKey] || '';
|
||||||
|
if (sortKey === 'amount' || sortKey === 'incurred_amount') {
|
||||||
|
va = parseFloat(va) || 0; vb = parseFloat(vb) || 0;
|
||||||
|
}
|
||||||
|
if (va < vb) return -1 * sortAsc;
|
||||||
|
if (va > vb) return 1 * sortAsc;
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
var totalAmount = filtered.reduce(function(s, r) { return s + (r.amount || 0); }, 0);
|
||||||
|
var totalIncurred = filtered.reduce(function(s, r) { return s + (r.incurred_amount || 0); }, 0);
|
||||||
|
|
||||||
|
// 月份下拉选项(去年/今年/明年)
|
||||||
|
var monthOpts = '';
|
||||||
|
for (var yr = thisYear - 1; yr <= thisYear + 1; yr++)
|
||||||
|
for (var m = 1; m <= 12; m++) {
|
||||||
|
var mv = yr + '-' + String(m).padStart(2, '0');
|
||||||
|
monthOpts += '<option value="' + mv + '">' + mv + '</option>';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 季度下拉
|
||||||
|
var qLabels = ['Q1 (1-3月)','Q2 (4-6月)','Q3 (7-9月)','Q4 (10-12月)'];
|
||||||
|
var quarterOpts = '';
|
||||||
|
for (var qi = 0; qi < 4; qi++) {
|
||||||
|
quarterOpts += '<option value="' + qi + '">' + qLabels[qi] + '</option>';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 月份/季度日期选择器
|
||||||
|
var dateSelect = '';
|
||||||
|
if (view === 'monthly') {
|
||||||
|
dateSelect = '<span class="text-sm text-slate-500 ml-2">月份:</span><select onchange="setPlanExpMonth(this.value)" class="text-sm font-medium py-1 px-2.5 cursor-pointer" style="appearance:none;-webkit-appearance:none;background-color:transparent;border:0;outline:none;background:url('data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%2212%22 height=%2212%22 viewBox=%220 0 24 24%22 fill=%22none%22 stroke=%22%236b7280%22 stroke-width=%222%22 stroke-linecap=%22round%22 stroke-linejoin=%22round%22%3E%3Cpolyline points=%226 9 12 15 18 9%22%3E%3C/polyline%3E%3C/svg%3E') no-repeat right 4px center;padding-right:22px;min-height:30px"><option value=""' + (!state.planExpMonth?' selected':'') + '>请选择</option>' + monthOpts.replace('value="' + state.planExpMonth + '"', 'value="' + state.planExpMonth + '" selected') + '</select>';
|
||||||
|
} else if (view === 'quarterly') {
|
||||||
|
dateSelect = '<span class="text-sm text-slate-500 ml-2">季度:</span><select onchange="setPlanExpQuarter(this.value)" class="text-sm font-medium py-1 px-2.5 cursor-pointer" style="appearance:none;-webkit-appearance:none;background-color:transparent;border:0;outline:none;background:url('data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%2212%22 height=%2212%22 viewBox=%220 0 24 24%22 fill=%22none%22 stroke=%22%236b7280%22 stroke-width=%222%22 stroke-linecap=%22round%22 stroke-linejoin=%22round%22%3E%3Cpolyline points=%226 9 12 15 18 9%22%3E%3C/polyline%3E%3C/svg%3E') no-repeat right 4px center;padding-right:22px;min-height:30px">' + quarterOpts.replace('value="' + state.planExpQuarter + '"', 'value="' + state.planExpQuarter + '" selected') + '</select>';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Toolbar
|
||||||
|
var toolbar = '<span class="text-sm text-slate-500">视图:</span><select onchange="setPlanExpView(this.value)" class="text-sm font-medium py-1 px-2.5 cursor-pointer" style="appearance:none;-webkit-appearance:none;background-color:transparent;border:0;outline:none;background:url('data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%2212%22 height=%2212%22 viewBox=%220 0 24 24%22 fill=%22none%22 stroke=%22%236b7280%22 stroke-width=%222%22 stroke-linecap=%22round%22 stroke-linejoin=%22round%22%3E%3Cpolyline points=%226 9 12 15 18 9%22%3E%3C/polyline%3E%3C/svg%3E') no-repeat right 4px center;padding-right:22px;min-height:30px"><option value="total"' + (view==='total'?' selected':'') + '>总视图</option><option value="quarterly"' + (view==='quarterly'?' selected':'') + '>季度视图</option><option value="monthly"' + (view==='monthly'?' selected':'') + '>月度视图</option></select><span class="text-sm text-slate-500 ml-3">类型:</span><select onchange="setPlanExpFilter(this.value)" class="text-sm font-medium py-1 px-2.5 cursor-pointer" style="appearance:none;-webkit-appearance:none;background-color:transparent;border:0;outline:none;background:url('data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%2212%22 height=%2212%22 viewBox=%220 0 24 24%22 fill=%22none%22 stroke=%22%236b7280%22 stroke-width=%222%22 stroke-linecap=%22round%22 stroke-linejoin=%22round%22%3E%3Cpolyline points=%226 9 12 15 18 9%22%3E%3C/polyline%3E%3C/svg%3E') no-repeat right 4px center;padding-right:22px;min-height:30px"><option value="全部"' + (typeFilter==='全部'?' selected':'') + '>全部 (' + records.length + ')</option>';
|
||||||
|
EXPENSE_TYPES.forEach(function(t) {
|
||||||
|
toolbar += '<option value="' + t + '"' + (typeFilter===t?' selected':'') + '>' + t + ' (' + records.filter(function(r){return r.expense_type===t}).length + ')</option>';
|
||||||
|
});
|
||||||
|
toolbar += '</select>' + dateSelect;
|
||||||
|
|
||||||
|
// 排序箭头
|
||||||
|
var sortArrow = function(key) {
|
||||||
|
var arrow = key === sortKey ? (sortAsc === 1 ? ' ↑' : ' ↓') : '';
|
||||||
|
return '<span class="text-slate-400 text-xs cursor-pointer" onclick="togglePlanExpSort(\'' + key + '\')">' + arrow + '</span>';
|
||||||
|
};
|
||||||
|
|
||||||
|
// 表格行
|
||||||
|
var tableRows = '';
|
||||||
|
if (filtered.length) {
|
||||||
|
filtered.forEach(function(r) {
|
||||||
|
var statusCls = r.status === '暂不计入' ? 'text-amber-600' : 'text-green-600';
|
||||||
|
tableRows += '<tr class="border-b border-slate-100 hover:bg-slate-50 cursor-pointer" onclick="openPlanExpEdit(' + r.id + ')"><td class="p-2 text-center align-middle font-medium">' + (r.expense_month || '—') + '</td><td class="p-2 font-medium text-center align-middle">' + esc(r.expense_type) + '</td><td class="p-2 text-center align-middle font-semibold ' + statusCls + '">' + esc(r.status || '计入费用') + '</td><td class="p-2 text-center align-middle font-medium">' + money(r.amount) + '</td><td class="p-2 text-center align-middle font-medium">' + money(r.incurred_amount) + '</td><td class="p-2 text-center align-middle text-slate-500">' + (esc(r.notes) || '—') + '</td></tr>';
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
var emptyMsg = view === 'monthly' ? '该月份暂无费用记录' : view === 'quarterly' ? '该季度暂无费用记录' : '暂无费用记录';
|
||||||
|
tableRows = '<tr><td colspan="6" class="p-6 text-center text-slate-400">' + emptyMsg + '</td></tr>';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 模态框 monthOpts for form (with current value preselected)
|
||||||
|
var modalMonthOpts = '<option value="">请选择</option>';
|
||||||
|
for (var yr2 = thisYear - 1; yr2 <= thisYear + 1; yr2++)
|
||||||
|
for (var m2 = 1; m2 <= 12; m2++) {
|
||||||
|
var mv2 = yr2 + '-' + String(m2).padStart(2, '0');
|
||||||
|
modalMonthOpts += '<option value="' + mv2 + '">' + mv2 + '</option>';
|
||||||
|
}
|
||||||
|
var statusOpts = STATUS_OPTIONS.map(function(s) { return '<option value="' + s + '">' + s + '</option>'; }).join('');
|
||||||
|
|
||||||
|
var modal = '<div id="planExpenseModal" class="hidden fixed inset-0 z-50 flex items-center justify-center bg-black/40" onclick="closePlanExpModal()"><div class="bg-white rounded-2xl shadow-2xl w-full max-w-lg mx-4" onclick="event.stopPropagation()"><div class="sticky top-0 z-10 bg-white/95 backdrop-blur border-b border-slate-100 px-6 py-4 flex items-center justify-between"><h3 class="text-lg font-bold text-slate-800" id="planExpenseModalTitle">新增费用</h3><div class="flex items-center gap-2"><button class="btn btn-ghost btn-sm text-red-600 hidden" id="planExpDeleteBtn" onclick="deletePlanExpItem()">删除</button><button class="btn btn-ghost btn-sm rounded-full w-8 h-8 p-0" onclick="closePlanExpModal()"><i data-lucide="x"></i></button></div></div><form onsubmit="savePlanExpense(event)" class="p-6 grid gap-4" novalidate><input type="hidden" name="expense_id" value=""><div class="grid grid-cols-2 gap-3"><label class="block"><span class="text-sm text-slate-500 mb-1 block">费用类型 <span class="text-red-500">*</span></span><select name="expense_type" required class="form-ctrl bg-white"><option value="">请选择</option>';
|
||||||
|
EXPENSE_TYPES.forEach(function(t) { modal += '<option>' + t + '</option>'; });
|
||||||
|
modal += '</select></label><label class="block"><span class="text-sm text-slate-500 mb-1 block">月份 <span class="text-red-500">*</span></span><select name="expense_month" required class="form-ctrl bg-white">' + modalMonthOpts + '</select></label></div><div class="grid grid-cols-2 gap-3"><label class="block"><span class="text-sm text-slate-500 mb-1 block">金额(元)</span><input name="amount" type="number" step="0.01" class="form-ctrl" placeholder="0.00"></label><label class="block"><span class="text-sm text-slate-500 mb-1 block">已发生金额(元)</span><input name="incurred_amount" type="number" step="0.01" class="form-ctrl" placeholder="0.00"></label></div><label class="block"><span class="text-sm text-slate-500 mb-1 block">状态</span><select name="status" class="form-ctrl bg-white">' + statusOpts + '</select></label><label class="block"><span class="text-sm text-slate-500 mb-1 block">费用说明</span><textarea name="notes" class="form-ctrl" rows="3" placeholder="备注信息"></textarea></label><div class="flex justify-end gap-3 pt-2"><button type="button" class="btn btn-ghost btn-sm px-6" onclick="closePlanExpModal()">取消</button><button type="submit" class="btn btn-primary btn-sm px-8">保存</button></div></form></div></div>';
|
||||||
|
|
||||||
|
var target = document.querySelector("#planExpenseModule") || document.querySelector("#planExpenseModule") || document.querySelector("#planExpenseContent");
|
||||||
|
if (!target) return;
|
||||||
|
target.innerHTML = '<div class="grid gap-4">' +
|
||||||
|
'<div class="card p-3"><div class="flex justify-between items-center"><div class="flex items-center gap-2">' + toolbar + '</div><button class="btn btn-primary btn-sm" onclick="openPlanExpModal()">新增费用</button></div></div>' +
|
||||||
|
'<div class="grid grid-cols-3 gap-3">' +
|
||||||
|
'<div class="metric-card p-3"><span class="flex items-center gap-2 text-sm text-slate-500">费用记录</span><strong class="mt-2 block text-xl">' + filtered.length + '</strong></div>' +
|
||||||
|
'<div class="metric-card p-3"><span class="flex items-center gap-2 text-sm text-slate-500">总费用</span><strong class="mt-2 block text-xl">' + money(totalAmount) + '</strong></div>' +
|
||||||
|
'<div class="metric-card p-3"><span class="flex items-center gap-2 text-sm text-slate-500">已发生金额</span><strong class="mt-2 block text-xl">' + money(totalIncurred) + '</strong></div>' +
|
||||||
|
'</div>' +
|
||||||
|
modal +
|
||||||
|
'<div class="card p-4"><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-center font-semibold cursor-pointer select-none" onclick="togglePlanExpSort(\'expense_month\')">月份' + sortArrow('expense_month') + '</th><th class="p-2 text-center font-semibold cursor-pointer select-none" onclick="togglePlanExpSort(\'expense_type\')">费用类型' + sortArrow('expense_type') + '</th><th class="p-2 text-center font-semibold cursor-pointer select-none" onclick="togglePlanExpSort(\'status\')">状态' + sortArrow('status') + '</th><th class="p-2 text-center font-semibold cursor-pointer select-none" onclick="togglePlanExpSort(\'amount\')">金额' + sortArrow('amount') + '</th><th class="p-2 text-center font-semibold cursor-pointer select-none" onclick="togglePlanExpSort(\'incurred_amount\')">已发生金额' + sortArrow('incurred_amount') + '</th><th class="p-2 text-center font-semibold">费用说明</th></tr></thead><tbody>' + tableRows + '</tbody></table></div></div>' +
|
||||||
|
'</div>';
|
||||||
|
|
||||||
|
if (window.lucide) window.lucide.createIcons();
|
||||||
|
}
|
||||||
|
|
||||||
|
window.togglePlanExpSort = function(key) {
|
||||||
|
var cur = state.planExpSort || {};
|
||||||
|
if (cur.key === key) { cur.asc = !cur.asc; }
|
||||||
|
else { cur.key = key; cur.asc = true; }
|
||||||
|
state.planExpSort = cur;
|
||||||
|
renderPlanExpense();
|
||||||
|
};
|
||||||
|
|
||||||
|
window.setPlanExpView = function(v) { state.planExpView = v; renderPlanExpense(); };
|
||||||
|
window.setPlanExpFilter = function(v) { state.planExpFilter = v; renderPlanExpense(); };
|
||||||
|
window.setPlanExpMonth = function(v) { state.planExpMonth = v; renderPlanExpense(); };
|
||||||
|
window.setPlanExpQuarter = function(v) { state.planExpQuarter = v; renderPlanExpense(); };
|
||||||
|
|
||||||
|
window.openPlanExpModal = function() {
|
||||||
|
var form = document.querySelector("#planExpenseModal form");
|
||||||
|
form.reset();
|
||||||
|
form.querySelector('[name="expense_id"]').value = "";
|
||||||
|
form.querySelector('[name="status"]').value = "计入费用";
|
||||||
|
document.querySelector("#planExpenseModalTitle").textContent = "新增费用";
|
||||||
|
document.querySelector("#planExpDeleteBtn").classList.add("hidden");
|
||||||
|
document.querySelector("#planExpenseModal").classList.remove("hidden");
|
||||||
|
};
|
||||||
|
|
||||||
|
window.closePlanExpModal = function() {
|
||||||
|
document.querySelector("#planExpenseModal").classList.add("hidden");
|
||||||
|
};
|
||||||
|
|
||||||
|
window.openPlanExpEdit = function(id) {
|
||||||
|
var r = (state.data.planExpense || []).find(function(x) { return x.id === id; });
|
||||||
|
if (!r) return;
|
||||||
|
var form = document.querySelector("#planExpenseModal form");
|
||||||
|
form.reset();
|
||||||
|
var setVal = function(name, val) { var el = form.querySelector('[name="' + name + '"]'); if (el) el.value = val || ""; };
|
||||||
|
setVal("expense_id", r.id);
|
||||||
|
setVal("expense_type", r.expense_type);
|
||||||
|
setVal("expense_month", r.expense_month);
|
||||||
|
setVal("amount", r.amount);
|
||||||
|
setVal("incurred_amount", r.incurred_amount);
|
||||||
|
setVal("notes", r.notes);
|
||||||
|
setVal("status", r.status || "计入费用");
|
||||||
|
document.querySelector("#planExpenseModalTitle").textContent = "编辑费用";
|
||||||
|
document.querySelector("#planExpDeleteBtn").classList.remove("hidden");
|
||||||
|
document.querySelector("#planExpenseModal").classList.remove("hidden");
|
||||||
|
};
|
||||||
|
|
||||||
|
window.savePlanExpense = async function(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
var form = event.target;
|
||||||
|
var data = Object.fromEntries(new FormData(form).entries());
|
||||||
|
if (data.amount === '' || data.amount === undefined) data.amount = 0;
|
||||||
|
if (data.incurred_amount === '' || data.incurred_amount === undefined) data.incurred_amount = 0;
|
||||||
|
if (!data.status) data.status = '计入费用';
|
||||||
|
var isEdit = !!data.expense_id;
|
||||||
|
delete data.expense_id;
|
||||||
|
|
||||||
|
var id = form.querySelector('[name="expense_id"]').value;
|
||||||
|
var url = isEdit ? "/api/planExpense/" + id : "/api/planExpense";
|
||||||
|
var method = isEdit ? "PUT" : "POST";
|
||||||
|
|
||||||
|
var resp = await fetch(url, { method: method, headers: { "Content-Type": "application/json" }, body: JSON.stringify({ data: Object.assign({}, data, { tenant: state.tenant }) }) });
|
||||||
|
if (!resp.ok) { var err = await resp.text(); alert("保存失败:" + err); return; }
|
||||||
|
|
||||||
|
var bResp = await fetch("/api/bootstrap?tenant=" + encodeURIComponent(state.tenant));
|
||||||
|
if (bResp.ok) {
|
||||||
|
var bd = await bResp.json();
|
||||||
|
state.data = bd;
|
||||||
|
applyUserTenants();
|
||||||
|
renderPlanExpense();
|
||||||
|
}
|
||||||
|
closePlanExpModal();
|
||||||
|
};
|
||||||
|
|
||||||
|
window.deletePlanExpItem = async function() {
|
||||||
|
var id = document.querySelector("#planExpenseModal form [name='expense_id']").value;
|
||||||
|
if (!id || !confirm("确定删除?")) return;
|
||||||
|
var resp = await fetch("/api/planExpense/" + id, { method: "DELETE" });
|
||||||
|
if (!resp.ok) { alert("删除失败"); return; }
|
||||||
|
var bResp = await fetch("/api/bootstrap?tenant=" + encodeURIComponent(state.tenant));
|
||||||
|
if (bResp.ok) {
|
||||||
|
var bd = await bResp.json();
|
||||||
|
state.data = bd;
|
||||||
|
applyUserTenants();
|
||||||
|
renderPlanExpense();
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -82,6 +82,9 @@ window.toggleUserMenu = (user) => {
|
|||||||
${user.role === 'admin' ? `<button class="w-full text-left px-4 py-2 text-sm text-slate-700 hover:bg-slate-50 transition-colors flex items-center gap-2" onclick="closeUserMenu();openAdminUsers()">
|
${user.role === 'admin' ? `<button class="w-full text-left px-4 py-2 text-sm text-slate-700 hover:bg-slate-50 transition-colors flex items-center gap-2" onclick="closeUserMenu();openAdminUsers()">
|
||||||
<i data-lucide="users" style="width:14px;height:14px"></i>账号管理
|
<i data-lucide="users" style="width:14px;height:14px"></i>账号管理
|
||||||
</button>` : ''}
|
</button>` : ''}
|
||||||
|
<button class="w-full text-left px-4 py-2 text-sm text-slate-700 hover:bg-slate-50 transition-colors flex items-center gap-2" onclick="closeUserMenu();openChangePwdModal()">
|
||||||
|
<i data-lucide="lock" style="width:14px;height:14px"></i>修改密码
|
||||||
|
</button>
|
||||||
<button class="w-full text-left px-4 py-2 text-sm text-red-600 hover:bg-red-50 transition-colors flex items-center gap-2" onclick="doLogout()">
|
<button class="w-full text-left px-4 py-2 text-sm text-red-600 hover:bg-red-50 transition-colors flex items-center gap-2" onclick="doLogout()">
|
||||||
<i data-lucide="log-out" style="width:14px;height:14px"></i>退出登录
|
<i data-lucide="log-out" style="width:14px;height:14px"></i>退出登录
|
||||||
</button>`;
|
</button>`;
|
||||||
|
|||||||
@@ -5,11 +5,15 @@ const state = {
|
|||||||
data: null,
|
data: null,
|
||||||
tenant: "科普·无界",
|
tenant: "科普·无界",
|
||||||
opFilter: "all",
|
opFilter: "all",
|
||||||
finFilter: "已签约",
|
finFilter: "projects",
|
||||||
selectedProject: null,
|
selectedProject: null,
|
||||||
taskQuery: "",
|
taskQuery: "",
|
||||||
taskView: localStorage.getItem("opc-task-view") || "detail",
|
taskView: localStorage.getItem("opc-task-view") || "detail",
|
||||||
finView: "overview",
|
finView: "overview",
|
||||||
|
finSort: null, // { key: 'col', asc: true }
|
||||||
|
planFilter: "projects",
|
||||||
|
planView: "overview",
|
||||||
|
planSort: null,
|
||||||
proposalTab: "standard",
|
proposalTab: "standard",
|
||||||
chart: null,
|
chart: null,
|
||||||
chart2: null,
|
chart2: null,
|
||||||
@@ -132,7 +136,7 @@ function switchTab(tab) {
|
|||||||
document.querySelectorAll(".panel").forEach((panel) => panel.classList.toggle("active", panel.id === tab));
|
document.querySelectorAll(".panel").forEach((panel) => panel.classList.toggle("active", panel.id === tab));
|
||||||
|
|
||||||
// 更新顶部标题
|
// 更新顶部标题
|
||||||
const titles = { home: 'OPC 工作台', finance: '业务管理', projects: '重点工作台账', proposals: '业务方案', products: '版本与运营', performance: '季度绩效考核' };
|
const titles = { home: 'OPC 工作台', finance: '实际管理', plan: '计划管理', projects: '重点工作台账', proposals: '业务方案', products: '版本与运营', performance: '季度绩效考核' };
|
||||||
const titleEl = document.querySelector('#workspaceTitle');
|
const titleEl = document.querySelector('#workspaceTitle');
|
||||||
if (titleEl) titleEl.textContent = titles[tab] || state.tenant + ' OPC 工作台';
|
if (titleEl) titleEl.textContent = titles[tab] || state.tenant + ' OPC 工作台';
|
||||||
|
|
||||||
@@ -159,6 +163,7 @@ function render() {
|
|||||||
renderProducts();
|
renderProducts();
|
||||||
renderPerformance();
|
renderPerformance();
|
||||||
renderFinance();
|
renderFinance();
|
||||||
|
renderPlan();
|
||||||
if (window.lucide) window.lucide.createIcons();
|
if (window.lucide) window.lucide.createIcons();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,6 +176,7 @@ function renderActive() {
|
|||||||
else if (tab === "products") renderProducts();
|
else if (tab === "products") renderProducts();
|
||||||
else if (tab === "performance") renderPerformance();
|
else if (tab === "performance") renderPerformance();
|
||||||
else if (tab === "finance") renderFinance();
|
else if (tab === "finance") renderFinance();
|
||||||
|
else if (tab === "plan") renderPlan();
|
||||||
if (window.lucide) window.lucide.createIcons();
|
if (window.lucide) window.lucide.createIcons();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,8 +206,31 @@ window.setFinView = (view) => {
|
|||||||
};
|
};
|
||||||
window.switchFinFilter = (filter) => {
|
window.switchFinFilter = (filter) => {
|
||||||
state.finFilter = filter;
|
state.finFilter = filter;
|
||||||
|
state.finSort = null;
|
||||||
renderFinance();
|
renderFinance();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
window.setFinSort = (key) => {
|
||||||
|
if (!state.finSort) state.finSort = { key: null, asc: true };
|
||||||
|
if (state.finSort.key === key) { state.finSort.asc = !state.finSort.asc; }
|
||||||
|
else { state.finSort.key = key; state.finSort.asc = true; }
|
||||||
|
renderFinance();
|
||||||
|
};
|
||||||
|
window.setPlanView = (view) => {
|
||||||
|
state.planView = view;
|
||||||
|
renderPlan();
|
||||||
|
};
|
||||||
|
window.switchPlanFilter = (filter) => {
|
||||||
|
state.planFilter = filter;
|
||||||
|
state.planSort = null;
|
||||||
|
renderPlan();
|
||||||
|
};
|
||||||
|
window.setPlanSort = (key) => {
|
||||||
|
if (!state.planSort) state.planSort = { key: null, asc: true };
|
||||||
|
if (state.planSort.key === key) { state.planSort.asc = !state.planSort.asc; }
|
||||||
|
else { state.planSort.key = key; state.planSort.asc = true; }
|
||||||
|
renderPlan();
|
||||||
|
};
|
||||||
window.switchTenant = (tenant) => {
|
window.switchTenant = (tenant) => {
|
||||||
state.tenant = tenant;
|
state.tenant = tenant;
|
||||||
state.selectedProject = null;
|
state.selectedProject = null;
|
||||||
|
|||||||
@@ -96,26 +96,26 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 详情弹窗固定高度,tab 切换不抖动 */
|
/* 详情弹窗固定高度,tab 切换不抖动 */
|
||||||
#financeModal > div {
|
#financeModal > div, #planModal > div {
|
||||||
height: 650px;
|
height: 650px;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
#financeModal .finance-tabs { flex-shrink: 0; }
|
#financeModal .finance-tabs, #planModal .finance-tabs { flex-shrink: 0; }
|
||||||
#financeModal form {
|
#financeModal form, #planModal form {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
min-height: 0;
|
min-height: 0;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
#financeModal .finance-tab-body {
|
#financeModal .finance-tab-body, #planModal .finance-tab-body {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
min-height: 0;
|
min-height: 0;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
padding: 32px;
|
padding: 32px;
|
||||||
}
|
}
|
||||||
#financeModal .finance-form-actions {
|
#financeModal .finance-form-actions, #planModal .finance-form-actions {
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
background: #fff;
|
background: #fff;
|
||||||
padding: 12px 32px 8px;
|
padding: 12px 32px 8px;
|
||||||
|
|||||||
@@ -45,13 +45,17 @@
|
|||||||
<div class="w-8 h-px bg-slate-700 my-2"></div>
|
<div class="w-8 h-px bg-slate-700 my-2"></div>
|
||||||
<!-- 导航 Tab 图标 -->
|
<!-- 导航 Tab 图标 -->
|
||||||
<div class="flex flex-col items-center gap-1 w-14" id="sidebarTabs">
|
<div class="flex flex-col items-center gap-1 w-14" id="sidebarTabs">
|
||||||
<div class="sidebar-tab active" data-tab="home" onclick="switchTab('home')" title="首页">
|
<div class="sidebar-tab active" data-tab="home" onclick="switchTab('home')" title="部门">
|
||||||
<i data-lucide="home" style="width:20px;height:20px"></i>
|
<i data-lucide="trending-up" style="width:20px;height:20px"></i>
|
||||||
<span class="text-[10px] mt-1">首页</span>
|
<span class="text-[10px] mt-1">部门</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="sidebar-tab" data-tab="finance" onclick="switchTab('finance')" title="业务">
|
<div class="sidebar-tab" data-tab="plan" onclick="switchTab('plan')" title="计划">
|
||||||
|
<i data-lucide="calendar-range" style="width:20px;height:20px"></i>
|
||||||
|
<span class="text-[10px] mt-1">计划</span>
|
||||||
|
</div>
|
||||||
|
<div class="sidebar-tab" data-tab="finance" onclick="switchTab('finance')" title="实际">
|
||||||
<i data-lucide="folder-open-dot" style="width:20px;height:20px"></i>
|
<i data-lucide="folder-open-dot" style="width:20px;height:20px"></i>
|
||||||
<span class="text-[10px] mt-1">业务</span>
|
<span class="text-[10px] mt-1">实际</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="sidebar-tab" data-tab="projects" onclick="switchTab('projects')" title="Focus">
|
<div class="sidebar-tab" data-tab="projects" onclick="switchTab('projects')" title="Focus">
|
||||||
<i data-lucide="file-text" style="width:20px;height:20px"></i>
|
<i data-lucide="file-text" style="width:20px;height:20px"></i>
|
||||||
@@ -76,7 +80,7 @@
|
|||||||
<header class="topbar border-b border-slate-200 bg-white px-8 py-5">
|
<header class="topbar border-b border-slate-200 bg-white px-8 py-5">
|
||||||
<div class="flex items-center gap-3 w-full">
|
<div class="flex items-center gap-3 w-full">
|
||||||
<div class="flex-1">
|
<div class="flex-1">
|
||||||
<p class="eyebrow text-xs font-semibold uppercase tracking-[0.18em] text-blue-700">OPC Manager <span class="ml-2 text-xs font-normal text-slate-400 tracking-normal">v1.0.0.13</span></p>
|
<p class="eyebrow text-xs font-semibold uppercase tracking-[0.18em] text-blue-700">OPC Manager <span class="ml-2 text-xs font-normal text-slate-400 tracking-normal">v1.0.0.23</span></p>
|
||||||
<div class="flex items-center gap-4 mt-1">
|
<div class="flex items-center gap-4 mt-1">
|
||||||
<h1 class="text-2xl font-semibold" id="workspaceTitle">科普 OPC 工作台</h1>
|
<h1 class="text-2xl font-semibold" id="workspaceTitle">科普 OPC 工作台</h1>
|
||||||
<div class="hidden sm:flex items-center gap-1.5 bg-gradient-to-r from-blue-50 to-indigo-50 border border-blue-100 rounded-full px-4 py-1.5">
|
<div class="hidden sm:flex items-center gap-1.5 bg-gradient-to-r from-blue-50 to-indigo-50 border border-blue-100 rounded-full px-4 py-1.5">
|
||||||
@@ -99,6 +103,7 @@
|
|||||||
<section id="performance" class="panel"></section>
|
<section id="performance" class="panel"></section>
|
||||||
<section id="performance" class="panel"></section>
|
<section id="performance" class="panel"></section>
|
||||||
<section id="finance" class="panel"></section>
|
<section id="finance" class="panel"></section>
|
||||||
|
<section id="plan" class="panel"></section>
|
||||||
</main>
|
</main>
|
||||||
</div><!-- 关闭主内容区 -->
|
</div><!-- 关闭主内容区 -->
|
||||||
</div><!-- 关闭 flex 容器 -->
|
</div><!-- 关闭 flex 容器 -->
|
||||||
@@ -129,6 +134,8 @@
|
|||||||
<script src="{{ url_for('static', filename='modules/performance.js') }}"></script>
|
<script src="{{ url_for('static', filename='modules/performance.js') }}"></script>
|
||||||
<script src="{{ url_for('static', filename='modules/finance.js') }}"></script>
|
<script src="{{ url_for('static', filename='modules/finance.js') }}"></script>
|
||||||
<script src="{{ url_for('static', filename='modules/expense.js') }}"></script>
|
<script src="{{ url_for('static', filename='modules/expense.js') }}"></script>
|
||||||
|
<script src="{{ url_for('static', filename='modules/plan.js') }}"></script>
|
||||||
|
<script src="{{ url_for('static', filename='modules/plan_expense.js') }}"></script>
|
||||||
<script src="{{ url_for('static', filename='modules/drawer.js') }}"></script>
|
<script src="{{ url_for('static', filename='modules/drawer.js') }}"></script>
|
||||||
<script src="{{ url_for('static', filename='modules/admin.js') }}"></script>
|
<script src="{{ url_for('static', filename='modules/admin.js') }}"></script>
|
||||||
<script src="{{ url_for('static', filename='app.js') }}"></script>
|
<script src="{{ url_for('static', filename='app.js') }}"></script>
|
||||||
|
|||||||
Reference in New Issue
Block a user