yyb
13 小时以前 a1df9699594b0a0e46d26a0394eafb1eb030c68b
src/views/officeProcessAutomation/ApproveManage/approve-list/approveListConstants.js
@@ -33,6 +33,7 @@
/** 列表查询:审批状态(与后端 status 枚举一致) */
export const APPROVAL_STATUS_SEARCH_OPTIONS = [
  { value: "DRAFT", label: "草稿" },
  { value: "PENDING", label: "待审批" },
  { value: "APPROVED", label: "已通过" },
  { value: "REJECTED", label: "已驳回" },
@@ -40,34 +41,105 @@
/**
 * 审批状态展示(与后端 status 枚举一致)
 * PENDING → 待审批/进行中  APPROVED → 已通过/已完成  REJECTED → 已驳回
 * DRAFT→草稿 PENDING→待审批/进行中 APPROVED→已通过/已完成 REJECTED→已驳回
 */
export const APPROVAL_STATUS_OPTIONS = [
  { value: "draft", api: "DRAFT", label: "草稿" },
  { value: "pending", api: "PENDING", label: "待审批" },
  { value: "approved", api: "APPROVED", label: "已通过" },
  { value: "rejected", api: "REJECTED", label: "已驳回" },
  { value: "cancelled", api: "CANCELLED", label: "已撤销" },
];
/** 数字状态码(部分后端用 0/1/2) */
const STATUS_NUMERIC_MAP = {
  0: "pending",
  1: "approved",
  2: "rejected",
  3: "cancelled",
  4: "cancelled",
};
/** 后端 status / 页面 approvalStatus → 统一页面 key(pending | approved | rejected | cancelled) */
export function normalizeApprovalStatusKey(v) {
  const s = String(v ?? "").trim();
  if (v == null || v === "") return "pending";
  if (typeof v === "number" || (typeof v === "string" && /^\d+$/.test(v.trim()))) {
    const numKey = STATUS_NUMERIC_MAP[Number(v)];
    if (numKey) return numKey;
  }
  const s = String(v).trim();
  if (!s) return "pending";
  const upper = s.toUpperCase();
  if (upper === "APPROVED" || upper === "APPROVE" || upper === "PASS") return "approved";
  if (upper === "REJECTED" || upper === "REJECT" || upper === "REFUSE") return "rejected";
  if (upper === "CANCELLED" || upper === "CANCEL") return "cancelled";
  if (upper === "DRAFT") return "draft";
  if (upper === "PUBLISHED") return "approved";
  if (upper === "OFFLINE") return "cancelled";
  if (upper === "APPROVED" || upper === "APPROVE" || upper === "PASS" || upper === "AGREE") {
    return "approved";
  }
  if (
    upper === "REJECTED" ||
    upper === "REJECT" ||
    upper === "REFUSE" ||
    upper === "REFUSED" ||
    upper === "DENIED"
  ) {
    return "rejected";
  }
  if (upper === "CANCELLED" || upper === "CANCEL" || upper === "REVOKED") return "cancelled";
  if (
    upper === "PENDING" ||
    upper === "IN_PROGRESS" ||
    upper === "PROCESSING" ||
    upper === "RUNNING"
    upper === "RUNNING" ||
    upper === "WAIT" ||
    upper === "WAITING"
  ) {
    return "pending";
  }
  if (s.includes("草稿")) return "draft";
  if (s.includes("驳回") || s.includes("拒绝")) return "rejected";
  if (s.includes("下线")) return "cancelled";
  if (s.includes("撤销")) return "cancelled";
  if (s.includes("发布") || s.includes("通过") || s.includes("完成")) return "approved";
  if (s.includes("待审") || s.includes("进行中") || s.includes("审批中")) return "pending";
  const lower = s.toLowerCase();
  if (["pending", "approved", "rejected", "cancelled"].includes(lower)) return lower;
  if (["draft", "pending", "approved", "rejected", "cancelled"].includes(lower)) return lower;
  return "pending";
}
/** 从列表/详情行解析后端原始状态(兼容多字段命名) */
export function resolveInstanceStatusRaw(row) {
  if (!row || typeof row !== "object") return "";
  const candidates = [
    row.status,
    row.statusRaw,
    row.approvalStatus,
    row.statusName,
    row.statusLabel,
    row.approvalStatusName,
    row.statusDesc,
    row.instanceStatus,
    row.approvalInstanceStatus,
    row.approveStatus,
    row.auditStatus,
    row.approvalInstance?.status,
    row.approvalInstanceVo?.status,
  ];
  for (const c of candidates) {
    if (c != null && c !== "") return c;
  }
  const tasks = row.tasks;
  if (Array.isArray(tasks) && tasks.length) {
    const rejected = tasks.some((t) =>
      normalizeApprovalStatusKey(t?.status ?? t?.taskStatus) === "rejected"
    );
    if (rejected) return "REJECTED";
    const allApproved = tasks.every((t) =>
      normalizeApprovalStatusKey(t?.status ?? t?.taskStatus) === "approved"
    );
    if (allApproved) return "APPROVED";
  }
  return "";
}
/** 提交弹窗:模板卡片(来自后端列表) */
@@ -322,12 +394,15 @@
    dto.id = existingRow?.id ?? submitForm?.instanceId;
    dto.instanceNo = existingRow?.instanceNo ?? submitForm?.instanceNo ?? "";
    dto.status =
      existingRow?.statusRaw || mapInstanceStatusToApi(existingRow?.approvalStatus) || "PENDING";
      submitForm?.saveStatusApi ||
      existingRow?.statusRaw ||
      mapInstanceStatusToApi(existingRow?.approvalStatus) ||
      "PENDING";
    dto.currentLevel = existingRow?.currentLevel ?? submitForm?.currentLevel ?? 1;
    dto.applicantId = existingRow?.applicantId ?? existingRow?.applicantNo;
    dto.applicantName = existingRow?.applicantName || "";
  } else {
    dto.status = "PENDING";
    dto.status = submitForm?.saveStatusApi || "PENDING";
    dto.currentLevel = 1;
    dto.applicantId = userStore?.id;
    dto.applicantName = userStore?.nickName || userStore?.name || "";
@@ -352,6 +427,12 @@
  return normalizeApprovalStatusKey(status);
}
/** 列表/详情行 → 页面 approvalStatus key */
export function mapInstanceApprovalStatusFromRow(row) {
  const raw = resolveInstanceStatusRaw(row);
  return normalizeApprovalStatusKey(raw);
}
/** 页面 approvalStatus → 后端 status */
export function mapInstanceStatusToApi(approvalStatus) {
  const key = normalizeApprovalStatusKey(approvalStatus);
@@ -370,7 +451,8 @@
/** 分页列表项 → 表格行 */
export function mapInstanceFromApi(row) {
  if (!row) return {};
  const approvalStatus = mapInstanceStatusFromApi(row.status);
  const statusRaw = resolveInstanceStatusRaw(row);
  const approvalStatus = normalizeApprovalStatusKey(statusRaw);
  const createTime = formatDisplayTime(row.createTime ?? row.applyTime ?? "");
  const applyTime = formatDisplayTime(row.applyTime ?? "");
  const finishTime = formatDisplayTime(row.finishTime ?? "");
@@ -397,7 +479,7 @@
    unread: Boolean(row.isApprove) && approvalStatus === "pending",
    isApprove: Boolean(row.isApprove),
    approvalStatus,
    statusRaw: row.status,
    statusRaw: statusRaw || row.status,
    createTime,
    applyTime: applyTime === "—" ? "" : applyTime,
    finishTime: finishTime === "—" ? "" : finishTime,
@@ -439,10 +521,16 @@
}
export function buildApprovalInstanceListParams({ page, searchForm, businessType, extraParams }) {
  const extra = { ...(extraParams && typeof extraParams === "object" ? extraParams : {}) };
  if (extra.createTime != null && extra.createTimeStart == null) {
    extra.createTimeStart = extra.createTime;
  }
  delete extra.createTime;
  const params = {
    current: page.current,
    size: page.size,
    ...(extraParams && typeof extraParams === "object" ? extraParams : {}),
    ...extra,
  };
  const bizType = businessType ?? searchForm?.businessType;
  if (bizType != null && bizType !== "") {
@@ -451,9 +539,12 @@
  if (searchForm?.status) {
    params.status = searchForm.status;
  }
  const range = searchForm?.createTimeRange;
  const range =
    searchForm?.createTimeRange ??
    searchForm?.applyDateRange ??
    searchForm?.transferDateRange;
  if (Array.isArray(range) && range[0]) {
    params.createTime = range[0];
    params.createTimeStart = range[0];
  }
  if (Array.isArray(range) && range[1]) {
    params.createTimeEnd = range[1];
@@ -483,6 +574,7 @@
/** 业务申请页状态文案:PENDING→进行中 APPROVED→已完成 REJECTED→已驳回 */
export function businessApprovalStatusLabel(v) {
  const key = normalizeApprovalStatusKey(v);
  if (key === "draft") return "草稿";
  if (key === "pending") return "进行中";
  if (key === "approved") return "已完成";
  if (key === "rejected") return "已驳回";
@@ -503,6 +595,7 @@
export function businessApprovalStatusTagType(v) {
  const key = normalizeApprovalStatusKey(v);
  if (key === "draft") return "info";
  if (key === "approved") return "success";
  if (key === "rejected") return "danger";
  if (key === "cancelled") return "info";
@@ -511,6 +604,7 @@
export function approvalStatusTagType(v) {
  const key = normalizeApprovalStatusKey(v);
  if (key === "draft") return "info";
  if (key === "approved") return "success";
  if (key === "rejected") return "danger";
  if (key === "cancelled") return "info";