zhou zhou
41 分钟以前 7c2bffa1a495cc4a3a263f654c08c231009c5c4e
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
const STATUS_META = {
  1: { text: '正常', type: 'success', bool: true },
  0: { text: '冻结', type: 'danger', bool: false }
}
 
export const LOC_AREA_REPORT_TITLE = '库区报表'
export const LOC_AREA_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 createLocAreaSearchState() {
  return {
    condition: '',
    areaId: '',
    name: '',
    code: '',
    status: '',
    memo: ''
  }
}
 
export function createLocAreaFormState() {
  return {
    id: void 0,
    areaId: void 0,
    name: '',
    code: '',
    status: 1,
    memo: ''
  }
}
 
export function getLocAreaPaginationKey() {
  return {
    current: 'current',
    size: 'pageSize'
  }
}
 
export function getLocAreaStatusOptions() {
  return [
    { label: '正常', value: 1 },
    { label: '冻结', value: 0 }
  ]
}
 
export function getLocAreaStatusMeta(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 buildLocAreaSearchParams(params = {}) {
  const searchParams = {
    condition: normalizeText(params.condition),
    areaId:
      params.areaId !== undefined && params.areaId !== null && params.areaId !== ''
        ? Number(params.areaId)
        : void 0,
    name: normalizeText(params.name),
    code: normalizeText(params.code),
    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 buildLocAreaPageQueryParams(params = {}) {
  return {
    current: params.current || 1,
    pageSize: params.pageSize || params.size || 20,
    ...buildLocAreaSearchParams(params)
  }
}
 
export function buildLocAreaSavePayload(formData = {}) {
  return {
    ...(formData.id !== undefined && formData.id !== null && formData.id !== ''
      ? { id: Number(formData.id) }
      : {}),
    ...(formData.areaId !== undefined && formData.areaId !== null && formData.areaId !== ''
      ? { areaId: Number(formData.areaId) }
      : {}),
    name: normalizeText(formData.name) || '',
    code: normalizeText(formData.code) || '',
    status:
      formData.status !== undefined && formData.status !== null && formData.status !== ''
        ? Number(formData.status)
        : 1,
    memo: normalizeText(formData.memo) || ''
  }
}
 
export function buildLocAreaDialogModel(record = {}) {
  return {
    ...createLocAreaFormState(),
    ...(record.id !== undefined && record.id !== null && record.id !== '' ? { id: Number(record.id) } : {}),
    areaId:
      record.areaId !== undefined && record.areaId !== null && record.areaId !== ''
        ? Number(record.areaId)
        : void 0,
    name: normalizeText(record.name || ''),
    code: normalizeText(record.code || ''),
    status: record.status !== undefined && record.status !== null ? Number(record.status) : 1,
    memo: normalizeText(record.memo || '')
  }
}
 
export function resolveLocAreaOptions(records = []) {
  if (!Array.isArray(records)) {
    return []
  }
 
  return records
    .map((item) => {
      if (!item || typeof item !== 'object') {
        return null
      }
      const value = item.id ?? item.value
      if (value === void 0 || value === null || value === '') {
        return null
      }
      return {
        value: Number(value),
        label: normalizeText(item.name || item.code || `库区 ${value}`)
      }
    })
    .filter(Boolean)
}
 
export function normalizeLocAreaDetailRecord(record = {}) {
  const statusMeta = getLocAreaStatusMeta(record.statusBool ?? record.status)
  return {
    ...record,
    areaName: normalizeText(record.areaId$ || record.areaName || ''),
    name: normalizeText(record.name || ''),
    code: normalizeText(record.code || ''),
    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 normalizeLocAreaListRow(record = {}) {
  return normalizeLocAreaDetailRecord(record)
}
 
export function buildLocAreaPrintRows(records = []) {
  if (!Array.isArray(records)) {
    return []
  }
  return records.map((record) => normalizeLocAreaListRow(record))
}
 
export function buildLocAreaReportMeta({
  previewMeta = {},
  count = 0,
  orientation = LOC_AREA_REPORT_STYLE.orientation
} = {}) {
  return {
    reportTitle: LOC_AREA_REPORT_TITLE,
    reportDate: previewMeta.reportDate,
    printedAt: previewMeta.printedAt,
    operator: previewMeta.operator,
    count,
    reportStyle: {
      ...LOC_AREA_REPORT_STYLE,
      orientation
    }
  }
}