zhou zhou
昨天 aaf8a50511d77dbc209ca93bbba308c21179a8bc
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
function normalizeText(value) {
  return String(value ?? '').trim()
}
 
function normalizeNumber(value, fallback = 0) {
  if (value === '' || value === null || value === undefined) {
    return fallback
  }
  const numericValue = Number(value)
  return Number.isFinite(numericValue) ? numericValue : fallback
}
 
function normalizeNullableNumber(value) {
  if (value === '' || value === null || value === undefined) {
    return null
  }
  const numericValue = Number(value)
  return Number.isFinite(numericValue) ? numericValue : null
}
 
export function createWhMatSearchState() {
  return {
    condition: '',
    code: '',
    name: '',
    spec: '',
    model: '',
    barcode: ''
  }
}
 
export function buildWhMatPageQueryParams(params = {}) {
  const result = {
    current: params.current || 1,
    pageSize: params.pageSize || params.size || 20
  }
 
  ;['condition', 'code', 'name', 'spec', 'model', 'barcode'].forEach((key) => {
    const value = normalizeText(params[key])
    if (value) {
      result[key] = value
    }
  })
 
  if (params.groupId !== undefined && params.groupId !== null && params.groupId !== '') {
    result.groupId = String(params.groupId)
  }
 
  return result
}
 
export function buildWhMatGroupTreeQueryParams(params = {}) {
  return {
    condition: normalizeText(params.condition)
  }
}
 
export function normalizeWhMatGroupTreeRows(records = []) {
  if (!Array.isArray(records)) {
    return []
  }
 
  return records.map((item) => {
    const children = normalizeWhMatGroupTreeRows(item?.children || [])
    const id = normalizeNullableNumber(item?.id)
    const code = normalizeText(item?.code)
    const name = normalizeText(item?.name)
    const label = [name, code].filter(Boolean).join(' · ') || '-'
 
    return {
      ...item,
      id,
      parentId: normalizeNumber(item?.parentId, 0),
      code,
      name,
      label,
      displayLabel: label,
      status: normalizeNullableNumber(item?.status),
      statusText: normalizeNumber(item?.status, 1) === 1 ? '正常' : '冻结',
      statusType: normalizeNumber(item?.status, 1) === 1 ? 'success' : 'danger',
      memo: normalizeText(item?.memo) || '-',
      children
    }
  })
}
 
export function normalizeWhMatRow(record = {}) {
  const statusValue = normalizeNullableNumber(record?.status)
  return {
    ...record,
    code: normalizeText(record?.code) || '-',
    name: normalizeText(record?.name) || '-',
    groupName: normalizeText(record?.groupId$ || record?.groupCode) || '-',
    shipperName: normalizeText(record?.shipperId$ || record?.shipperName) || '-',
    barcode: normalizeText(record?.barcode) || '-',
    spec: normalizeText(record?.spec) || '-',
    model: normalizeText(record?.model) || '-',
    color: normalizeText(record?.color) || '-',
    size: normalizeText(record?.size) || '-',
    unit: normalizeText(record?.unit) || '-',
    purUnit: normalizeText(record?.purUnit) || '-',
    stockUnit: normalizeText(record?.stockUnit) || '-',
    stockLevelText: normalizeText(record?.stockLeval$) || '-',
    flagLabelManageText: normalizeText(record?.flagLabelMange$) || '-',
    flagCheckText:
      record?.flagCheck === 1 || record?.flagCheck === '1'
        ? '是'
        : record?.flagCheck === 0 || record?.flagCheck === '0'
          ? '否'
          : '-',
    statusText: normalizeText(record?.status$) || (statusValue === 1 ? '正常' : statusValue === 0 ? '冻结' : '-'),
    statusType: statusValue === 1 ? 'success' : statusValue === 0 ? 'danger' : 'info',
    safeQty: record?.safeQty ?? '-',
    minQty: record?.minQty ?? '-',
    maxQty: record?.maxQty ?? '-',
    valid: record?.valid ?? '-',
    validWarn: record?.validWarn ?? '-',
    stagn: record?.stagn ?? '-',
    describle: normalizeText(record?.describle) || '-',
    baseUnit: normalizeText(record?.baseUnit) || '-',
    useOrgName: normalizeText(record?.useOrgName) || '-',
    erpClsId: normalizeText(record?.erpClsId) || '-',
    memo: normalizeText(record?.memo) || '-',
    updateByText: normalizeText(record?.updateBy$) || '-',
    createByText: normalizeText(record?.createBy$) || '-',
    updateTimeText: normalizeText(record?.updateTime$ || record?.updateTime) || '-',
    createTimeText: normalizeText(record?.createTime$ || record?.createTime) || '-',
    extendFields:
      record?.extendFields && typeof record.extendFields === 'object' && !Array.isArray(record.extendFields)
        ? record.extendFields
        : {}
  }
}
 
export function normalizeWhMatDetail(record = {}) {
  return normalizeWhMatRow(record)
}
 
export function getWhMatTreeNodeLabel(node = {}) {
  const name = normalizeText(node?.name)
  const code = normalizeText(node?.code)
  return [name, code].filter(Boolean).join(' · ') || '-'
}
 
export const buildMatnrPageQueryParams = buildWhMatPageQueryParams
export const buildMatnrGroupTreeQueryParams = buildWhMatGroupTreeQueryParams
export const normalizeMatnrGroupTreeRows = normalizeWhMatGroupTreeRows
export const normalizeMatnrRow = normalizeWhMatRow
export const normalizeMatnrDetail = normalizeWhMatDetail
export const createMatnrSearchState = createWhMatSearchState
export const getMatnrTreeNodeLabel = getWhMatTreeNodeLabel