zhou zhou
2 小时以前 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
export const WAVE_ITEM_REPORT_TITLE = '波次明细报表'
export const WAVE_ITEM_REPORT_STYLE = {
  titleAlign: 'center',
  titleLevel: 'strong',
  orientation: 'landscape',
  density: 'compact',
  showSequence: true
}
 
function normalizeText(value) {
  return String(value ?? '').trim()
}
 
function normalizeNumber(value) {
  if (value === '' || value === null || value === undefined) {
    return 0
  }
  const numericValue = Number(value)
  return Number.isFinite(numericValue) ? numericValue : 0
}
 
const WAVE_ITEM_STATUS_MAP = {
  0: { label: '未执行', tagType: 'info' },
  1: { label: '执行中', tagType: 'warning' },
  2: { label: '暂停', tagType: 'warning' },
  3: { label: '已下发', tagType: 'primary' },
  4: { label: '任务完成', tagType: 'success' }
}
 
function getItemStatusConfig(status, statusText) {
  const fallback = WAVE_ITEM_STATUS_MAP[Number(status)] || {
    label: statusText || '-',
    tagType: 'info'
  }
  return {
    label: statusText || fallback.label,
    tagType: fallback.tagType
  }
}
 
function normalizeStockLocs(stockLocs) {
  if (!stockLocs) {
    return '[]'
  }
  if (typeof stockLocs === 'string') {
    return stockLocs
  }
  try {
    return JSON.stringify(stockLocs)
  } catch {
    return '[]'
  }
}
 
export function createWaveItemSearchState() {
  return {
    condition: '',
    waveId: '',
    waveCode: '',
    orderCode: '',
    matnrCode: '',
    maktx: '',
    batch: '',
    splrBatch: '',
    unit: '',
    fieldsIndex: '',
    status: '',
    exceStatus: '',
    timeStart: '',
    timeEnd: ''
  }
}
 
export function buildWaveItemSearchParams(params = {}) {
  const result = {}
  ;[
    'condition',
    'waveCode',
    'orderCode',
    'matnrCode',
    'maktx',
    'batch',
    'splrBatch',
    'unit',
    'fieldsIndex',
    'timeStart',
    'timeEnd'
  ].forEach((key) => {
    const value = normalizeText(params[key])
    if (value) {
      result[key] = value
    }
  })
 
  if (params.waveId !== '' && params.waveId !== undefined && params.waveId !== null) {
    result.waveId = Number(params.waveId)
  }
 
  if (params.status !== '' && params.status !== undefined && params.status !== null) {
    result.status = Number(params.status)
  }
 
  if (params.exceStatus !== '' && params.exceStatus !== undefined && params.exceStatus !== null) {
    result.exceStatus = Number(params.exceStatus)
  }
 
  return result
}
 
export function buildWaveItemPageQueryParams(params = {}) {
  return {
    current: params.current || 1,
    pageSize: params.pageSize || params.size || 20,
    ...buildWaveItemSearchParams(params)
  }
}
 
export function normalizeWaveItemRow(record = {}) {
  const statusConfig = getItemStatusConfig(record.exceStatus, record['exceStatus$'])
  return {
    ...record,
    waveCode: record.waveCode || '-',
    orderCode: record.orderCode || '-',
    matnrCode: record.matnrCode || '-',
    maktx: record.maktx || '-',
    batch: record.batch || '-',
    splrBatch: record.splrBatch || '-',
    unit: record.unit || '-',
    fieldsIndex: record.fieldsIndex || '-',
    anfme: normalizeNumber(record.anfme),
    workQty: normalizeNumber(record.workQty),
    qty: normalizeNumber(record.qty),
    stockQty: normalizeNumber(record.stockQty),
    stockLocsText: normalizeStockLocs(record.stockLocs),
    exceStatusText: statusConfig.label,
    exceStatusTagType: statusConfig.tagType,
    createTimeText: record['createTime$'] || record.createTime || '-',
    updateTimeText: record['updateTime$'] || record.updateTime || '-'
  }
}
 
export function buildWaveItemPrintRows(records = []) {
  if (!Array.isArray(records)) {
    return []
  }
  return records.map((record) => normalizeWaveItemRow(record))
}
 
export function buildWaveItemReportMeta({
  previewMeta = {},
  count = 0,
  orientation = WAVE_ITEM_REPORT_STYLE.orientation
} = {}) {
  return {
    reportTitle: WAVE_ITEM_REPORT_TITLE,
    reportDate: previewMeta.reportDate,
    printedAt: previewMeta.printedAt,
    operator: previewMeta.operator,
    count,
    reportStyle: {
      ...WAVE_ITEM_REPORT_STYLE,
      orientation
    }
  }
}