zhou zhou
10 小时以前 e12fb4e6e8e0a408e81ce05a269a15cc535d8c78
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
const STATUS_META = {
  1: { text: '正常', type: 'success', bool: true },
  0: { text: '冻结', type: 'danger', bool: false }
}
 
export const LOC_AREA_MAT_REPORT_TITLE = '库区物料报表'
export const LOC_AREA_MAT_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 numberValue = Number(value)
  return Number.isNaN(numberValue) ? fallback : numberValue
}
 
export function createLocAreaMatSearchState() {
  return {
    condition: '',
    code: '',
    warehouseId: '',
    areaId: '',
    depict: '',
    status: '',
    memo: '',
    timeStart: '',
    timeEnd: ''
  }
}
 
export function createLocAreaMatFormState() {
  return {
    id: void 0,
    code: '',
    warehouseId: '',
    areaId: '',
    depict: '',
    status: 1,
    memo: ''
  }
}
 
export function createLocAreaMatRelationBindMatnrState(areaMatId = void 0) {
  return {
    areaMatId,
    warehouseId: '',
    areaId: '',
    groupId: '',
    matnrId: [],
    typeId: []
  }
}
 
export function createLocAreaMatRelationBindLocState(areaMatId = void 0) {
  return {
    areaMatId,
    warehouseId: '',
    areaId: '',
    groupId: '',
    locId: [],
    typeId: []
  }
}
 
export function buildLocAreaMatRelationBindLocState(areaMatId = void 0) {
  return createLocAreaMatRelationBindLocState(areaMatId)
}
 
export function buildLocAreaMatRelationBindMatnrModel(record = {}) {
  return {
    ...createLocAreaMatRelationBindMatnrState(record.areaMatId),
    ...(record.areaMatId !== void 0 && record.areaMatId !== null && record.areaMatId !== ''
      ? { areaMatId: normalizeNumber(record.areaMatId) }
      : {}),
    warehouseId:
      record.warehouseId !== undefined && record.warehouseId !== null && record.warehouseId !== ''
        ? normalizeNumber(record.warehouseId)
        : '',
    areaId:
      record.areaId !== undefined && record.areaId !== null && record.areaId !== ''
        ? normalizeNumber(record.areaId)
        : '',
    groupId:
      record.groupId !== undefined && record.groupId !== null && record.groupId !== ''
        ? normalizeNumber(record.groupId)
        : '',
    matnrId: Array.isArray(record.matnrId) ? record.matnrId.map((item) => normalizeNumber(item)).filter(Boolean) : [],
    typeId: Array.isArray(record.typeId) ? record.typeId.map((item) => normalizeNumber(item)).filter(Boolean) : []
  }
}
 
export function buildLocAreaMatRelationBindLocModel(record = {}) {
  return {
    ...createLocAreaMatRelationBindLocState(record.areaMatId),
    ...(record.areaMatId !== void 0 && record.areaMatId !== null && record.areaMatId !== ''
      ? { areaMatId: normalizeNumber(record.areaMatId) }
      : {}),
    warehouseId:
      record.warehouseId !== undefined && record.warehouseId !== null && record.warehouseId !== ''
        ? normalizeNumber(record.warehouseId)
        : '',
    areaId:
      record.areaId !== undefined && record.areaId !== null && record.areaId !== ''
        ? normalizeNumber(record.areaId)
        : '',
    groupId:
      record.groupId !== undefined && record.groupId !== null && record.groupId !== ''
        ? normalizeNumber(record.groupId)
        : '',
    locId: Array.isArray(record.locId) ? record.locId.map((item) => normalizeNumber(item)).filter(Boolean) : [],
    typeId: Array.isArray(record.typeId) ? record.typeId.map((item) => normalizeNumber(item)).filter(Boolean) : []
  }
}
 
export function getLocAreaMatStatusOptions() {
  return [
    { label: '正常', value: 1 },
    { label: '冻结', value: 0 }
  ]
}
 
export function getLocAreaMatPaginationKey() {
  return {
    current: 'current',
    size: 'pageSize'
  }
}
 
export function getLocAreaMatStatusMeta(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 buildLocAreaMatSearchParams(params = {}) {
  const searchParams = {
    condition: normalizeText(params.condition),
    code: normalizeText(params.code),
    warehouseId:
      params.warehouseId !== undefined && params.warehouseId !== null && params.warehouseId !== ''
        ? normalizeNumber(params.warehouseId)
        : void 0,
    areaId:
      params.areaId !== undefined && params.areaId !== null && params.areaId !== ''
        ? normalizeNumber(params.areaId)
        : void 0,
    depict: normalizeText(params.depict),
    status:
      params.status !== undefined && params.status !== null && params.status !== ''
        ? normalizeNumber(params.status)
        : void 0,
    memo: normalizeText(params.memo),
    timeStart: normalizeText(params.timeStart),
    timeEnd: normalizeText(params.timeEnd)
  }
 
  return Object.fromEntries(
    Object.entries(searchParams).filter(([, value]) => value !== '' && value !== void 0 && value !== null)
  )
}
 
export function buildLocAreaMatPageQueryParams(params = {}) {
  return {
    current: params.current || 1,
    pageSize: params.pageSize || params.size || 20,
    ...buildLocAreaMatSearchParams(params)
  }
}
 
export function buildLocAreaMatSavePayload(formData = {}) {
  return {
    ...(formData.id !== void 0 && formData.id !== null && formData.id !== ''
      ? { id: normalizeNumber(formData.id) }
      : {}),
    code: normalizeText(formData.code) || '',
    warehouseId:
      formData.warehouseId !== undefined && formData.warehouseId !== null && formData.warehouseId !== ''
        ? normalizeNumber(formData.warehouseId)
        : void 0,
    areaId:
      formData.areaId !== undefined && formData.areaId !== null && formData.areaId !== ''
        ? normalizeNumber(formData.areaId)
        : void 0,
    depict: normalizeText(formData.depict) || '',
    status:
      formData.status !== undefined && formData.status !== null && formData.status !== ''
        ? normalizeNumber(formData.status)
        : 1,
    memo: normalizeText(formData.memo) || ''
  }
}
 
export function buildLocAreaMatDialogModel(record = {}) {
  return {
    ...createLocAreaMatFormState(),
    ...(record.id !== void 0 && record.id !== null && record.id !== '' ? { id: normalizeNumber(record.id) } : {}),
    code: normalizeText(record.code || ''),
    warehouseId:
      record.warehouseId !== undefined && record.warehouseId !== null && record.warehouseId !== ''
        ? normalizeNumber(record.warehouseId)
        : '',
    areaId:
      record.areaId !== undefined && record.areaId !== null && record.areaId !== ''
        ? normalizeNumber(record.areaId)
        : '',
    depict: normalizeText(record.depict || ''),
    status: record.status !== void 0 && record.status !== null ? normalizeNumber(record.status, 1) : 1,
    memo: normalizeText(record.memo || '')
  }
}
 
export function normalizeLocAreaMatListRow(record = {}) {
  const statusMeta = getLocAreaMatStatusMeta(record.statusBool ?? record.status)
  return {
    ...record,
    code: normalizeText(record.code || ''),
    depict: normalizeText(record.depict || ''),
    warehouseName: normalizeText(record.warehouseId$ || record.warehouseName || ''),
    areaName: normalizeText(record.areaId$ || record.areaName || ''),
    statusText: statusMeta.text,
    statusType: statusMeta.type,
    statusBool: record.statusBool !== void 0 ? Boolean(record.statusBool) : statusMeta.bool,
    memo: normalizeText(record.memo || ''),
    createByText: normalizeText(record.createBy$ || record.createByText || ''),
    updateByText: normalizeText(record.updateBy$ || record.updateByText || ''),
    createTimeText: normalizeText(record.createTime$ || record.createTime || ''),
    updateTimeText: normalizeText(record.updateTime$ || record.updateTime || ''),
    warehouseIdText: normalizeText(record.warehouseId$ || record.warehouseIdText || ''),
    areaIdText: normalizeText(record.areaId$ || record.areaIdText || '')
  }
}
 
export function normalizeLocAreaMatDetailRecord(record = {}) {
  return normalizeLocAreaMatListRow(record)
}
 
export function normalizeLocAreaMatRelationRow(record = {}) {
  const relationTypeText =
    record.matnrId !== void 0 ||
    record.matnrId$ !== void 0 ||
    record.typeId !== void 0 ||
    record.typeId$ !== void 0
    ? '物料绑定'
    : '库位绑定'
 
  return {
    ...record,
    warehouseIdText: normalizeText(record.warehouseId$ || record.warehouseIdText || ''),
    areaIdText: normalizeText(record.areaId$ || record.areaIdText || ''),
    matnrIdText: normalizeText(record.matnrId$ || record.matnrIdText || record.matnrCode || record.matnrName || ''),
    groupIdText: normalizeText(record.groupId$ || record.groupIdText || record.groupName || ''),
    locTypeIdText: normalizeText(record.locTypeId$ || record.locTypeIdText || record.typeName || record.typeText || ''),
    locIdText: normalizeText(record.locId$ || record.locIdText || record.locCode || record.code || ''),
    relationTypeText,
    statusText: getLocAreaMatStatusMeta(record.statusBool ?? record.status).text,
    createByText: normalizeText(record.createBy$ || record.createByText || ''),
    updateByText: normalizeText(record.updateBy$ || record.updateByText || ''),
    createTimeText: normalizeText(record.createTime$ || record.createTime || ''),
    updateTimeText: normalizeText(record.updateTime$ || record.updateTime || ''),
    memo: normalizeText(record.memo || '')
  }
}
 
export function buildLocAreaMatPrintRows(records = []) {
  if (!Array.isArray(records)) {
    return []
  }
  return records.map((record) => normalizeLocAreaMatListRow(record))
}
 
export function buildLocAreaMatReportMeta({
  previewMeta = {},
  count = 0,
  orientation = LOC_AREA_MAT_REPORT_STYLE.orientation
} = {}) {
  return {
    reportTitle: LOC_AREA_MAT_REPORT_TITLE,
    reportDate: previewMeta.reportDate,
    printedAt: previewMeta.printedAt,
    operator: previewMeta.operator,
    count,
    reportStyle: {
      ...LOC_AREA_MAT_REPORT_STYLE,
      orientation
    }
  }
}
 
function normalizeOptionText(item = {}, fallbackPrefix = '') {
  return normalizeText(item.name || item.code || item.label || item.codeText || `${fallbackPrefix}${item.id ?? item.value ?? ''}`) || '--'
}
 
function normalizeOptionId(item = {}) {
  const value = item.id ?? item.value
  if (value === void 0 || value === null || value === '') {
    return void 0
  }
  return normalizeNumber(value)
}
 
export function resolveLocAreaMatWarehouseOptions(records = []) {
  if (!Array.isArray(records)) {
    return []
  }
  return records
    .map((item) => {
      const value = normalizeOptionId(item)
      if (value === void 0) return null
      return {
        value,
        label: normalizeOptionText(item, '仓库 ')
      }
    })
    .filter(Boolean)
}
 
export function resolveLocAreaMatAreaOptions(records = []) {
  if (!Array.isArray(records)) {
    return []
  }
  return records
    .map((item) => {
      const value = normalizeOptionId(item)
      if (value === void 0) return null
      return {
        value,
        label: normalizeOptionText(item, '库区 '),
        warehouseId:
          item.warehouseId !== undefined && item.warehouseId !== null && item.warehouseId !== ''
            ? normalizeNumber(item.warehouseId)
            : void 0
      }
    })
    .filter(Boolean)
}
 
export function resolveLocAreaMatLocTypeOptions(records = []) {
  if (!Array.isArray(records)) {
    return []
  }
  return records
    .map((item) => {
      const value = normalizeOptionId(item)
      if (value === void 0) return null
      return {
        value,
        label: normalizeOptionText(item, '类型 ')
      }
    })
    .filter(Boolean)
}
 
export function resolveLocAreaMatMatnrOptions(records = []) {
  if (!Array.isArray(records)) {
    return []
  }
  return records
    .map((item) => {
      const value = normalizeOptionId(item)
      if (value === void 0) return null
      const label = normalizeText(item.name || item.code || item.maktx || item.barcode || `物料 ${value}`)
      return {
        value,
        label: label || `物料 ${value}`,
        groupId:
          item.groupId !== undefined && item.groupId !== null && item.groupId !== ''
            ? normalizeNumber(item.groupId)
            : void 0
      }
    })
    .filter(Boolean)
}
 
export function resolveLocAreaMatLocOptions(records = []) {
  if (!Array.isArray(records)) {
    return []
  }
  return records
    .map((item) => {
      const value = normalizeOptionId(item)
      if (value === void 0) return null
      const code = normalizeText(item.code || item.locCode || '')
      const label = [code, normalizeText(item.warehouseName || item.areaName || '')].filter(Boolean).join(' · ') || `库位 ${value}`
      return {
        value,
        label,
        warehouseId:
          item.warehouseId !== undefined && item.warehouseId !== null && item.warehouseId !== ''
            ? normalizeNumber(item.warehouseId)
            : void 0,
        areaId:
          item.areaId !== undefined && item.areaId !== null && item.areaId !== ''
            ? normalizeNumber(item.areaId)
            : void 0
      }
    })
    .filter(Boolean)
}
 
export function normalizeLocAreaMatGroupTreeOptions(records = []) {
  if (!Array.isArray(records)) {
    return []
  }
 
  const walk = (nodes = []) =>
    nodes
      .map((item) => {
        if (!item || typeof item !== 'object') {
          return null
        }
        const value = normalizeOptionId(item)
        const children = walk(item.children || [])
        if (value === void 0 && children.length === 0) {
          return null
        }
        return {
          id: value ?? 0,
          name: normalizeText(item.name || '顶级分组'),
          code: normalizeText(item.code || ''),
          displayLabel: [normalizeText(item.name || '顶级分组'), normalizeText(item.code || '')].filter(Boolean).join(' · ') || '顶级分组',
          children
        }
      })
      .filter(Boolean)
 
  return [
    {
      id: 0,
      name: '顶级分组',
      code: '',
      displayLabel: '顶级分组',
      children: walk(records)
    }
  ]
}