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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
const STATUS_META = {
  1: { text: '正常', type: 'success', bool: true },
  0: { text: '冻结', type: 'danger', bool: false }
}
 
export const LOC_TYPE_REPORT_TITLE = '库位类型报表'
export const LOC_TYPE_REPORT_STYLE = {
  titleAlign: 'center',
  titleLevel: 'strong',
  orientation: 'portrait',
  density: 'compact',
  showSequence: true
}
 
function normalizeText(value) {
  return String(value ?? '').trim()
}
 
function normalizeNumber(value, fallback = void 0) {
  if (value === '' || value === null || value === undefined) {
    return fallback
  }
  const parsed = Number(value)
  return Number.isNaN(parsed) ? fallback : parsed
}
 
export function createLocTypeSearchState() {
  return {
    condition: '',
    uuid: '',
    code: '',
    name: '',
    regex: '',
    status: '',
    memo: ''
  }
}
 
export function createLocTypeFormState() {
  return {
    id: void 0,
    code: '',
    name: '',
    regex: '',
    status: 1,
    memo: ''
  }
}
 
export function getLocTypePaginationKey() {
  return {
    current: 'current',
    size: 'pageSize'
  }
}
 
export function getLocTypeStatusOptions() {
  return [
    { label: '正常', value: 1 },
    { label: '冻结', value: 0 }
  ]
}
 
export function getLocTypeStatusMeta(status) {
  if (status === true || Number(status) === 1) {
    return STATUS_META[1]
  }
  if (status === false || Number(status) === 0) {
    return STATUS_META[0]
  }
  return { text: '未知', type: 'info', bool: false }
}
 
export function buildLocTypeSearchParams(params = {}) {
  const searchParams = {
    condition: normalizeText(params.condition),
    uuid: normalizeText(params.uuid),
    code: normalizeText(params.code),
    name: normalizeText(params.name),
    regex: normalizeText(params.regex),
    status:
      params.status !== undefined && params.status !== null && params.status !== ''
        ? Number(params.status)
        : void 0,
    memo: normalizeText(params.memo)
  }
 
  return Object.fromEntries(
    Object.entries(searchParams).filter(([, value]) => value !== '' && value !== void 0 && value !== null)
  )
}
 
export function buildLocTypePageQueryParams(params = {}) {
  return {
    current: params.current || 1,
    pageSize: params.pageSize || params.size || 20,
    ...buildLocTypeSearchParams(params)
  }
}
 
export function buildLocTypeSavePayload(formData = {}) {
  return {
    ...(formData.id !== undefined && formData.id !== null && formData.id !== ''
      ? { id: Number(formData.id) }
      : {}),
    code: normalizeText(formData.code) || '',
    name: normalizeText(formData.name) || '',
    regex: normalizeText(formData.regex) || '',
    status:
      formData.status !== undefined && formData.status !== null && formData.status !== ''
        ? Number(formData.status)
        : 1,
    memo: normalizeText(formData.memo) || ''
  }
}
 
export function buildLocTypeDialogModel(record = {}) {
  return {
    ...createLocTypeFormState(),
    ...(record.id !== undefined && record.id !== null && record.id !== '' ? { id: Number(record.id) } : {}),
    code: normalizeText(record.code || ''),
    name: normalizeText(record.name || ''),
    regex: normalizeText(record.regex || ''),
    status: record.status !== undefined && record.status !== null ? Number(record.status) : 1,
    memo: normalizeText(record.memo || '')
  }
}
 
export function normalizeLocTypeDetailRecord(record = {}) {
  const statusMeta = getLocTypeStatusMeta(record.statusBool ?? record.status)
  return {
    ...record,
    uuid: normalizeText(record.uuid || ''),
    code: normalizeText(record.code || ''),
    name: normalizeText(record.name || ''),
    regex: normalizeText(record.regex || ''),
    memo: normalizeText(record.memo || ''),
    statusText: statusMeta.text,
    statusType: statusMeta.type,
    statusBool: record.statusBool !== void 0 ? Boolean(record.statusBool) : statusMeta.bool,
    createByText: normalizeText(record.createBy$ || record.createByText || ''),
    createTimeText: normalizeText(record.createTime$ || record.createTime || ''),
    updateByText: normalizeText(record.updateBy$ || record.updateByText || ''),
    updateTimeText: normalizeText(record.updateTime$ || record.updateTime || '')
  }
}
 
export function normalizeLocTypeListRow(record = {}) {
  return normalizeLocTypeDetailRecord(record)
}
 
export function buildLocTypePrintRows(records = []) {
  if (!Array.isArray(records)) {
    return []
  }
  return records.map((record) => normalizeLocTypeListRow(record))
}
 
export function buildLocTypeReportMeta({
  previewMeta = {},
  count = 0,
  orientation = LOC_TYPE_REPORT_STYLE.orientation
} = {}) {
  return {
    reportTitle: LOC_TYPE_REPORT_TITLE,
    reportDate: previewMeta.reportDate,
    printedAt: previewMeta.printedAt,
    operator: previewMeta.operator,
    count,
    reportStyle: {
      ...LOC_TYPE_REPORT_STYLE,
      orientation
    }
  }
}