zhou zhou
18 小时以前 a49845f424ae5b1e43e391837a55c43ce07ea62d
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
const STATUS_META = {
  1: { text: '正常', type: 'success', bool: true },
  0: { text: '冻结', type: 'danger', bool: false }
}
 
const USE_STATUS_META = {
  O: { text: '空库', type: 'success' },
  D: { text: '空板', type: 'info' },
  R: { text: '预约出库', type: 'warning' },
  S: { text: '预约入库', type: 'warning' },
  X: { text: '禁用', type: 'danger' },
  F: { text: '在库', type: 'primary' }
}
 
const LOC_ID_FIELDS = ['id', 'version', 'warehouseId', 'areaId']
const LOC_SIZE_FIELDS = ['length', 'height', 'width']
const LOC_POSITION_FIELDS = ['row', 'col', 'lev', 'channel']
const LOC_CAPACITY_FIELDS = ['maxParts', 'maxPack']
const LOC_OPTIONAL_NUMBER_FIELDS = [...LOC_ID_FIELDS, ...LOC_SIZE_FIELDS, ...LOC_POSITION_FIELDS, ...LOC_CAPACITY_FIELDS]
 
export const LOC_REPORT_TITLE = '库位报表'
export const LOC_REPORT_STYLE = {
  titleAlign: 'center',
  titleLevel: 'strong',
  orientation: 'portrait',
  density: 'compact',
  showSequence: true
}
 
function normalizeText(value) {
  return String(value ?? '').trim()
}
 
function hasValue(value) {
  return value !== '' && value !== null && value !== undefined
}
 
function normalizeNumber(value, fallback = void 0) {
  if (!hasValue(value)) {
    return fallback
  }
  const parsed = Number(value)
  return Number.isNaN(parsed) ? fallback : parsed
}
 
function toOptionalNumber(value) {
  return hasValue(value) ? Number(value) : void 0
}
 
function toNumberOr(value, fallback) {
  return hasValue(value) ? Number(value) : fallback
}
 
function buildNumberField(key, value) {
  return hasValue(value) ? { [key]: Number(value) } : {}
}
 
function buildOptionalNumberFields(source = {}, fields = []) {
  return Object.fromEntries(fields.map((field) => [field, toOptionalNumber(source[field])]).filter(([, value]) => hasValue(value)))
}
 
function normalizeFlagText(value) {
  if (value === 1 || value === '1' || value === true || value === '是') {
    return '是'
  }
  if (value === 0 || value === '0' || value === false || value === '否') {
    return '否'
  }
  return normalizeText(value) || '--'
}
 
function normalizeTypeIds(typeIds = []) {
  if (Array.isArray(typeIds)) {
    return typeIds.map((item) => normalizeNumber(item, void 0)).filter(hasValue)
  }
 
  if (typeof typeIds === 'string' && typeIds.trim()) {
    return typeIds.split(',').map((item) => normalizeNumber(item, void 0)).filter(hasValue)
  }
 
  return []
}
 
export function filterLocAreaOptionsByWarehouse(options = [], warehouseId) {
  if (!warehouseId) {
    return options
  }
 
  return options.filter((item) => {
    if (!hasValue(item?.warehouseId)) {
      return true
    }
    return Number(item.warehouseId) === Number(warehouseId)
  })
}
 
export function createLocSearchState() {
  return {
    condition: '',
    warehouseId: '',
    areaId: '',
    code: '',
    useStatus: '',
    row: '',
    col: '',
    lev: '',
    channel: '',
    status: '',
    barcode: '',
    memo: ''
  }
}
 
export function createLocFormState() {
  return {
    id: void 0,
    version: void 0,
    warehouseId: void 0,
    areaId: void 0,
    code: '',
    typeIds: [],
    flagLogic: 0,
    fucAtrrs: '',
    barcode: '',
    unit: '',
    length: void 0,
    height: void 0,
    width: void 0,
    row: void 0,
    col: void 0,
    lev: void 0,
    channel: void 0,
    maxParts: void 0,
    maxPack: void 0,
    useStatus: 'O',
    flagLabelMange: 0,
    locAttrs: '',
    status: 1,
    memo: ''
  }
}
 
export function getLocPaginationKey() {
  return {
    current: 'current',
    size: 'pageSize'
  }
}
 
export function getLocStatusOptions() {
  return [
    { label: '正常', value: 1 },
    { label: '冻结', value: 0 }
  ]
}
 
export function getLocUseStatusOptions() {
  return [
    { label: '空库', value: 'O' },
    { label: '空板', value: 'D' },
    { label: '预约出库', value: 'R' },
    { label: '预约入库', value: 'S' },
    { label: '禁用', value: 'X' },
    { label: '在库', value: 'F' }
  ]
}
 
export function getLocBinaryOptions() {
  return [
    { label: '否', value: 0 },
    { label: '是', value: 1 }
  ]
}
 
export function getLocStatusMeta(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 getLocUseStatusMeta(useStatus) {
  if (!useStatus) {
    return { text: '未知', type: 'info' }
  }
  return USE_STATUS_META[String(useStatus).trim()] || { text: String(useStatus), type: 'info' }
}
 
export function buildLocSearchParams(params = {}) {
  const searchParams = {
    condition: normalizeText(params.condition),
    warehouseId: toOptionalNumber(params.warehouseId),
    areaId: toOptionalNumber(params.areaId),
    code: normalizeText(params.code),
    useStatus: normalizeText(params.useStatus),
    row: toOptionalNumber(params.row),
    col: toOptionalNumber(params.col),
    lev: toOptionalNumber(params.lev),
    channel: toOptionalNumber(params.channel),
    status: toOptionalNumber(params.status),
    barcode: normalizeText(params.barcode),
    memo: normalizeText(params.memo)
  }
 
  return Object.fromEntries(Object.entries(searchParams).filter(([, value]) => hasValue(value)))
}
 
export function buildLocPageQueryParams(params = {}) {
  return {
    current: params.current || 1,
    pageSize: params.pageSize || params.size || 20,
    ...buildLocSearchParams(params)
  }
}
 
export function buildLocSavePayload(formData = {}) {
  return {
    ...buildOptionalNumberFields(formData, LOC_ID_FIELDS),
    code: normalizeText(formData.code) || '',
    typeIds: normalizeTypeIds(formData.typeIds),
    ...buildNumberField('flagLogic', formData.flagLogic),
    fucAtrrs: normalizeText(formData.fucAtrrs) || '',
    barcode: normalizeText(formData.barcode) || '',
    unit: normalizeText(formData.unit) || '',
    ...buildOptionalNumberFields(formData, [...LOC_SIZE_FIELDS, ...LOC_POSITION_FIELDS, ...LOC_CAPACITY_FIELDS]),
    useStatus: normalizeText(formData.useStatus) || 'O',
    ...buildNumberField('flagLabelMange', formData.flagLabelMange),
    locAttrs: normalizeText(formData.locAttrs) || '',
    status: toNumberOr(formData.status, 1),
    memo: normalizeText(formData.memo) || ''
  }
}
 
export function buildLocDialogModel(record = {}) {
  return {
    ...createLocFormState(),
    ...buildOptionalNumberFields(record, LOC_OPTIONAL_NUMBER_FIELDS),
    code: normalizeText(record.code || ''),
    typeIds: normalizeTypeIds(record.typeIds ?? record.type ?? ''),
    flagLogic: toNumberOr(record.flagLogic, 0),
    fucAtrrs: normalizeText(record.fucAtrrs || ''),
    barcode: normalizeText(record.barcode || ''),
    unit: normalizeText(record.unit || ''),
    useStatus: normalizeText(record.useStatus || 'O') || 'O',
    flagLabelMange: toNumberOr(record.flagLabelMange, 0),
    locAttrs: normalizeText(record.locAttrs || ''),
    status: toNumberOr(record.status, 1),
    memo: normalizeText(record.memo || '')
  }
}
 
export function normalizeLocDetailRecord(record = {}) {
  const statusMeta = getLocStatusMeta(record.statusBool ?? record.status)
  const useStatusMeta = getLocUseStatusMeta(record.useStatus)
  const typeIds = normalizeTypeIds(record.typeIds ?? record.type ?? '')
  return {
    ...record,
    ...buildOptionalNumberFields(record, [...LOC_SIZE_FIELDS, ...LOC_POSITION_FIELDS, ...LOC_CAPACITY_FIELDS]),
    warehouseName: normalizeText(record.warehouseId$ || record.warehouseName || ''),
    areaName: normalizeText(record.areaId$ || record.areaName || ''),
    typeIds,
    typeIdsText: normalizeText(record.typeIds$ || record.type$ || record.typeText || record.type || ''),
    code: normalizeText(record.code || ''),
    barcode: normalizeText(record.barcode || ''),
    unit: normalizeText(record.unit || ''),
    fucAtrrs: normalizeText(record.fucAtrrs || ''),
    locAttrs: normalizeText(record.locAttrs || ''),
    memo: normalizeText(record.memo || ''),
    flagLogicText: normalizeFlagText(record.flagLogic),
    flagLabelMangeText: normalizeFlagText(record.flagLabelMange),
    useStatusText: useStatusMeta.text,
    useStatusType: useStatusMeta.type,
    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 normalizeLocListRow(record = {}) {
  return normalizeLocDetailRecord(record)
}
 
export function buildLocPrintRows(records = []) {
  if (!Array.isArray(records)) {
    return []
  }
  return records.map((record) => normalizeLocListRow(record))
}
 
export function buildLocReportMeta({
  previewMeta = {},
  count = 0,
  orientation = LOC_REPORT_STYLE.orientation
} = {}) {
  return {
    reportTitle: LOC_REPORT_TITLE,
    reportDate: previewMeta.reportDate,
    printedAt: previewMeta.printedAt,
    operator: previewMeta.operator,
    count,
    reportStyle: {
      ...LOC_REPORT_STYLE,
      orientation
    }
  }
}
 
export function resolveLocWarehouseOptions(records = []) {
  if (!Array.isArray(records)) {
    return []
  }
 
  return records
    .map((item) => {
      if (!item || typeof item !== 'object') {
        return null
      }
      const value = item.id ?? item.value
      if (!hasValue(value)) {
        return null
      }
      return {
        value: Number(value),
        label: normalizeText(item.name || item.code || `仓库 ${value}`)
      }
    })
    .filter(Boolean)
}
 
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 (!hasValue(value)) {
        return null
      }
      return {
        value: Number(value),
        label: normalizeText(item.name || item.code || `库区 ${value}`),
        warehouseId: toOptionalNumber(item.warehouseId)
      }
    })
    .filter(Boolean)
}
 
export function resolveLocTypeOptions(records = []) {
  if (!Array.isArray(records)) {
    return []
  }
 
  return records
    .map((item) => {
      if (!item || typeof item !== 'object') {
        return null
      }
      const value = item.id ?? item.value
      if (!hasValue(value)) {
        return null
      }
      return {
        value: Number(value),
        label: normalizeText(item.name || item.code || item.label || `类型 ${value}`)
      }
    })
    .filter(Boolean)
}