zhou zhou
23 小时以前 50e95b985a72fcec4a93a2470e9efdfb2620148a
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
152
153
154
155
156
157
158
159
import { $t } from '@/locales'
 
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 = [], t = $t) {
  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 ? t('common.status.normal') : t('common.status.frozen'),
      statusType: normalizeNumber(item?.status, 1) === 1 ? 'success' : 'danger',
      memo: normalizeText(item?.memo) || t('common.placeholder.empty'),
      children
    }
  })
}
 
export function normalizeWhMatRow(record = {}, t = $t) {
  const statusValue = normalizeNullableNumber(record?.status)
  return {
    ...record,
    code: normalizeText(record?.code) || t('common.placeholder.empty'),
    name: normalizeText(record?.name) || t('common.placeholder.empty'),
    groupName: normalizeText(record?.groupId$ || record?.groupCode) || t('common.placeholder.empty'),
    shipperName: normalizeText(record?.shipperId$ || record?.shipperName) || t('common.placeholder.empty'),
    barcode: normalizeText(record?.barcode) || t('common.placeholder.empty'),
    spec: normalizeText(record?.spec) || t('common.placeholder.empty'),
    model: normalizeText(record?.model) || t('common.placeholder.empty'),
    color: normalizeText(record?.color) || t('common.placeholder.empty'),
    size: normalizeText(record?.size) || t('common.placeholder.empty'),
    unit: normalizeText(record?.unit) || t('common.placeholder.empty'),
    purUnit: normalizeText(record?.purUnit) || t('common.placeholder.empty'),
    stockUnit: normalizeText(record?.stockUnit) || t('common.placeholder.empty'),
    stockLevelText: normalizeText(record?.stockLeval$) || t('common.placeholder.empty'),
    flagLabelManageText: normalizeText(record?.flagLabelMange$) || t('common.placeholder.empty'),
    flagCheckText:
      record?.flagCheck === 1 || record?.flagCheck === '1'
        ? t('common.status.yes')
        : record?.flagCheck === 0 || record?.flagCheck === '0'
          ? t('common.status.no')
          : t('common.placeholder.empty'),
    statusText:
      normalizeText(record?.status$) ||
      (statusValue === 1
        ? t('common.status.normal')
        : statusValue === 0
          ? t('common.status.frozen')
          : t('common.placeholder.empty')),
    statusType: statusValue === 1 ? 'success' : statusValue === 0 ? 'danger' : 'info',
    safeQty: record?.safeQty ?? t('common.placeholder.empty'),
    minQty: record?.minQty ?? t('common.placeholder.empty'),
    maxQty: record?.maxQty ?? t('common.placeholder.empty'),
    valid: record?.valid ?? t('common.placeholder.empty'),
    validWarn: record?.validWarn ?? t('common.placeholder.empty'),
    stagn: record?.stagn ?? t('common.placeholder.empty'),
    describle: normalizeText(record?.describle) || t('common.placeholder.empty'),
    baseUnit: normalizeText(record?.baseUnit) || t('common.placeholder.empty'),
    useOrgName: normalizeText(record?.useOrgName) || t('common.placeholder.empty'),
    erpClsId: normalizeText(record?.erpClsId) || t('common.placeholder.empty'),
    memo: normalizeText(record?.memo) || t('common.placeholder.empty'),
    updateByText: normalizeText(record?.updateBy$) || t('common.placeholder.empty'),
    createByText: normalizeText(record?.createBy$) || t('common.placeholder.empty'),
    updateTimeText: normalizeText(record?.updateTime$ || record?.updateTime) || t('common.placeholder.empty'),
    createTimeText: normalizeText(record?.createTime$ || record?.createTime) || t('common.placeholder.empty'),
    extendFields:
      record?.extendFields && typeof record.extendFields === 'object' && !Array.isArray(record.extendFields)
        ? record.extendFields
        : {}
  }
}
 
export function normalizeWhMatDetail(record = {}, t = $t) {
  return normalizeWhMatRow(record, t)
}
 
export function getWhMatTreeNodeLabel(node = {}) {
  const name = normalizeText(node?.name)
  const code = normalizeText(node?.code)
  return [name, code].filter(Boolean).join(' · ') || $t('common.placeholder.empty')
}
 
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