yyb
9 小时以前 352f7bbb74f1b6c57b3d3e576849d0565932fbd4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import {
  createEmptyForm,
  publishStatusLabel,
  PUBLISH_STATUS_OPTIONS,
} from "./enterpriseNewsUtils.js";
import { normalizeApprovalStatusKey } from "../../ApproveManage/approve-list/approveListConstants.js";
 
/** formPayload 中存放完整企业新闻业务数据的键 */
export const ENTERPRISE_NEWS_PAYLOAD_KEY = "enterpriseNews";
 
export function extractEnterpriseNewsFromRow(row) {
  const payload = row?.formPayload || {};
  const raw = payload[ENTERPRISE_NEWS_PAYLOAD_KEY];
  if (raw && typeof raw === "object") {
    return { ...createEmptyForm(), ...raw };
  }
  return {
    ...createEmptyForm(),
    title: payload.title || row?.title || "",
    summary: payload.summary || "",
    newsType: payload.newsType || "announcement",
    contentHtml: payload.contentHtml || "",
  };
}
 
/** 列表行增强:主表展示新闻字段 */
export function enrichEnterpriseNewsListRow(row) {
  const news = extractEnterpriseNewsFromRow(row);
  const publishStatus =
    news.publishStatus || mapApprovalStatusToPublishStatus(row?.approvalStatus);
  return {
    ...row,
    newsNo: news.newsNo || row.instanceNo || "—",
    title: news.title || row.title || "—",
    summary: news.summary,
    newsType: news.newsType,
    publisherName: news.publisherName || row.applicantName || "—",
    publishTime: news.publishTime || row.createTime || "",
    updateTime: news.updateTime || row.createTime || "",
    publishStatus,
    _news: news,
  };
}
 
function mapApprovalStatusToPublishStatus(approvalStatus) {
  const key = normalizeApprovalStatusKey(approvalStatus);
  if (key === "approved") return "published";
  if (key === "pending") return "pending_review";
  if (key === "rejected") return "draft";
  return "draft";
}
 
/** 企业新闻表单 → 审批实例 formPayload */
export function syncNewsFormToSubmitPayload(newsForm, submitForm) {
  const snapshot = JSON.parse(JSON.stringify(newsForm));
  submitForm.formPayload = {
    ...(submitForm.formPayload || {}),
    [ENTERPRISE_NEWS_PAYLOAD_KEY]: snapshot,
    title: snapshot.title,
    summary: snapshot.summary,
  };
}
 
export function buildEnterpriseNewsTableColumns(buildTableActions) {
  return [
    { label: "编号", prop: "newsNo", width: 150 },
    { label: "标题", prop: "title", minWidth: 180, showOverflowTooltip: true },
    {
      label: "分类",
      prop: "newsType",
      width: 100,
      dataType: "slot",
      slot: "newsType",
    },
    {
      label: "状态",
      prop: "publishStatus",
      width: 90,
      dataType: "tag",
      formatData: (v) => publishStatusLabel(v),
      formatType: (v) => {
        const hit = PUBLISH_STATUS_OPTIONS.find((x) => x.value === v);
        return hit?.tag || "info";
      },
    },
    { label: "发布人", prop: "publisherName", width: 110 },
    { label: "发布时间", prop: "publishTime", width: 170 },
    { label: "更新时间", prop: "updateTime", width: 170 },
    {
      dataType: "action",
      label: "操作",
      align: "center",
      fixed: "right",
      width: 220,
      operation: buildTableActions(),
    },
  ];
}