negotiation-summary-transform.js
1.66 KB
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
/**
* 洽谈明细表汇总 — jsonContent 转只读区块模型(按行 recordRows)
* 数据规则对齐 gl_tape negotiationList.getReportDetail;UI 对齐 form-group-repeater 只读
*/
import { getSectionRowFieldsList } from './app-subform-json.js'
function formatCellValue(value) {
if (value == null || value === '') {
return ''
}
if (typeof value === 'object') {
if (value.displayText) {
return String(value.displayText)
}
if (value.name) {
return String(value.name)
}
return ''
}
return String(value)
}
function parseJsonContentList(jsonContent) {
if (Array.isArray(jsonContent)) {
return jsonContent
}
if (typeof jsonContent !== 'string' || !jsonContent.trim()) {
return []
}
try {
const parsed = JSON.parse(jsonContent)
return Array.isArray(parsed) ? parsed : []
} catch {
return []
}
}
function mapRowToFields(childRow) {
return (childRow || [])
.filter(field => field?.key)
.map(field => ({
label: field.label || field.key || '',
value: formatCellValue(field.value)
}))
}
/**
* @param {string|Array} jsonContent detail.get 返回的 jsonContent
* @returns {Array<{ label: string, recordRows: Array<{ fields: Array<{ label: string, value: string }> }> }>}
*/
export function buildNegotiationSummaryTables(jsonContent) {
const list = parseJsonContentList(jsonContent)
return list
.filter(item => item?.type === 'subform')
.map(item => {
const children = getSectionRowFieldsList(item)
if (!children.length) {
return null
}
const recordRows = children.map(childRow => ({
fields: mapRowToFields(childRow)
}))
return {
label: item.label || '',
recordRows
}
})
.filter(Boolean)
}