zhou zhou
106 分钟以前 450c9d39c6eb3765642f977512202e3240ac9b03
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
export const LOC_REVISE_REPORT_TITLE = '库存调整报表'
export const LOC_REVISE_REPORT_STYLE = {
  titleAlign: 'center',
  titleLevel: 'strong',
  orientation: 'landscape',
  density: 'compact',
  showSequence: true
}
 
const TYPE_OPTIONS = [
  { label: '库存调整', value: 0 },
  { label: '盘点调整', value: 1 },
  { label: '其它调整', value: 2 }
]
 
const EXCE_STATUS_OPTIONS = [
  { label: '未执行', value: 0, tagType: 'info' },
  { label: '执行中', value: 1, tagType: 'warning' },
  { label: '执行完成', value: 2, tagType: 'success' }
]
 
function normalizeText(value) {
  return String(value ?? '').trim()
}
 
function normalizeNumber(value, fallback = 0) {
  if (value === '' || value === null || value === undefined) {
    return fallback
  }
  const numericValue = Number(value)
  return Number.isFinite(numericValue) ? numericValue : fallback
}
 
export function getLocReviseTypeOptions() {
  return TYPE_OPTIONS
}
 
export function getLocReviseExceStatusOptions() {
  return EXCE_STATUS_OPTIONS
}
 
export function createLocReviseSearchState() {
  return {
    condition: '',
    code: '',
    type: '',
    areaName: '',
    exceStatus: '',
    timeStart: '',
    timeEnd: ''
  }
}
 
export function createLocReviseFormState() {
  return {
    id: null,
    code: '',
    type: 0,
    areaId: '',
    exceTime: '',
    memo: '',
    status: 1
  }
}
 
export function buildLocReviseDialogModel(record = {}) {
  const model = createLocReviseFormState()
  return {
    ...model,
    ...record,
    id: record.id ?? null,
    code: record.code || '',
    type: record.type ?? 0,
    areaId: record.areaId ?? '',
    exceTime: record.exceTime || '',
    memo: record.memo || '',
    status: record.status ?? 1
  }
}
 
export function buildLocReviseSearchParams(params = {}) {
  const result = {}
  ;['condition', 'code', 'areaName', 'timeStart', 'timeEnd'].forEach((key) => {
    const value = normalizeText(params[key])
    if (value) {
      result[key] = value
    }
  })
 
  if (params.type !== '' && params.type !== null && params.type !== undefined) {
    result.type = normalizeNumber(params.type)
  }
  if (params.exceStatus !== '' && params.exceStatus !== null && params.exceStatus !== undefined) {
    result.exceStatus = normalizeNumber(params.exceStatus)
  }
 
  return result
}
 
export function buildLocRevisePageQueryParams(params = {}) {
  return {
    current: params.current || 1,
    pageSize: params.pageSize || params.size || 20,
    ...buildLocReviseSearchParams(params)
  }
}
 
export function buildReviseLogPageQueryParams(params = {}) {
  return {
    current: params.current || 1,
    pageSize: params.pageSize || params.size || 20,
    ...(params.reviseId !== undefined ? { reviseId: params.reviseId } : {})
  }
}
 
export function buildReviseLogItemPageQueryParams(params = {}) {
  return {
    current: params.current || 1,
    pageSize: params.pageSize || params.size || 20,
    ...(params.reviseLogId !== undefined ? { reviseLogId: params.reviseLogId } : {})
  }
}
 
export function buildLocReviseSavePayload(formData = {}) {
  return {
    ...(formData.id ? { id: formData.id } : {}),
    ...(formData.code ? { code: formData.code } : {}),
    type: normalizeNumber(formData.type),
    areaId: normalizeNumber(formData.areaId, null),
    ...(normalizeText(formData.exceTime) ? { exceTime: normalizeText(formData.exceTime) } : {}),
    ...(normalizeText(formData.memo) ? { memo: normalizeText(formData.memo) } : {}),
    status: formData.status === 0 ? 0 : 1
  }
}
 
export function resolveWarehouseAreaOptions(records = []) {
  if (!Array.isArray(records)) {
    return []
  }
  return records.map((record) => ({
    label: record.name || record.code || `库区${record.id}`,
    value: record.id
  }))
}
 
function resolveOptionLabel(options, value, fallback = '-') {
  const target = options.find((item) => Number(item.value) === Number(value))
  return target?.label || fallback
}
 
export function getLocReviseExceStatusMeta(value) {
  const target = EXCE_STATUS_OPTIONS.find((item) => Number(item.value) === Number(value))
  return target || { label: '-', value, tagType: 'info' }
}
 
export function normalizeLocReviseRow(record = {}) {
  const exceStatusMeta = getLocReviseExceStatusMeta(record.exceStatus)
  return {
    ...record,
    code: record.code || '-',
    typeLabel: record['type$'] || resolveOptionLabel(TYPE_OPTIONS, record.type),
    areaLabel: record.areaName || record['areaId$'] || '-',
    anfme: normalizeNumber(record.anfme),
    reviseQty: normalizeNumber(record.reviseQty),
    exceStatusText: record['exceStatus$'] || exceStatusMeta.label,
    exceStatusTagType: exceStatusMeta.tagType,
    updateByText: record['updateBy$'] || '-',
    updateTimeText: record['updateTime$'] || record.updateTime || '-',
    createByText: record['createBy$'] || '-',
    createTimeText: record['createTime$'] || record.createTime || '-',
    exceTimeText: record['exceTime$'] || record.exceTime || '-',
    memo: record.memo || '-'
  }
}
 
export function normalizeReviseLogRow(record = {}) {
  return {
    ...record,
    reviseCode: record.reviseCode || '-',
    locCode: record.locCode || record.barcode || '-',
    barcode: record.barcode || '-',
    typeLabel: record['type$'] || '-',
    useStatusLabel: record['useStatus$'] || record.useStatus || '-',
    updateByText: record['updateBy$'] || '-',
    updateTimeText: record['updateTime$'] || record.updateTime || '-'
  }
}
 
export function normalizeReviseLogItemRow(record = {}) {
  const diffQty = normalizeNumber(
    record.diffQty,
    normalizeNumber(record.reviseQty) - normalizeNumber(record.anfme)
  )
  return {
    ...record,
    locCode: record.locCode || '-',
    matnrCode: record.matnrCode || '-',
    maktx: record.maktx || '-',
    unit: record.unit || '-',
    anfme: normalizeNumber(record.anfme),
    reviseQty: normalizeNumber(record.reviseQty),
    diffQty,
    batch: record.batch || '-',
    spec: record.spec || '-',
    model: record.model || '-',
    updateTimeText: record['updateTime$'] || record.updateTime || '-'
  }
}
 
export function buildLocRevisePrintRows(records = []) {
  if (!Array.isArray(records)) {
    return []
  }
  return records.map((record) => normalizeLocReviseRow(record))
}
 
export function buildLocReviseReportMeta({
  previewMeta = {},
  count = 0,
  orientation = LOC_REVISE_REPORT_STYLE.orientation
} = {}) {
  return {
    reportTitle: LOC_REVISE_REPORT_TITLE,
    reportDate: previewMeta.reportDate,
    printedAt: previewMeta.printedAt,
    operator: previewMeta.operator,
    count,
    reportStyle: {
      ...LOC_REVISE_REPORT_STYLE,
      orientation
    }
  }
}