zhou zhou
5 小时以前 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
const TRANSFER_SOURCE_META = {
  1: { text: 'ERP系统', type: 'info' },
  2: { text: 'WMS系统生成', type: 'primary' },
  3: { text: 'EXCEL导入', type: 'warning' },
  4: { text: 'QMS系统', type: 'success' }
}
 
const TRANSFER_EXCE_STATUS_META = {
  0: { text: '未执行', type: 'info' },
  1: { text: '执行中', type: 'warning' },
  2: { text: '执行完成', type: 'success' }
}
 
const TRANSFER_STATUS_META = {
  1: { text: '正常', type: 'success', bool: true },
  0: { text: '冻结', type: 'danger', bool: false }
}
 
export const TRANSFER_REPORT_TITLE = '调拨单报表'
export const TRANSFER_REPORT_STYLE = {
  titleAlign: 'center',
  titleLevel: 'strong',
  orientation: 'landscape',
  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
}
 
function metaByValue(value, metaMap, fallbackText = '--') {
  const numericValue = Number(value)
  return metaMap[numericValue] || { text: normalizeText(value) || fallbackText, type: 'info' }
}
 
export function createTransferSearchState() {
  return {
    condition: '',
    code: '',
    type: '',
    source: '',
    exceStatus: '',
    orgWareName: '',
    tarWareName: '',
    orgAreaName: '',
    tarAreaName: '',
    memo: '',
    status: '',
    timeStart: '',
    timeEnd: ''
  }
}
 
export function createTransferFormState() {
  return {
    id: void 0,
    code: '',
    type: '',
    source: 2,
    exceStatus: 0,
    orgAreaId: void 0,
    tarAreaId: void 0,
    status: 1,
    memo: ''
  }
}
 
export function buildTransferDialogModel(record = {}) {
  return {
    ...createTransferFormState(),
    ...(record.id !== undefined && record.id !== null && record.id !== '' ? { id: Number(record.id) } : {}),
    code: normalizeText(record.code || ''),
    type: record.type !== undefined && record.type !== null && record.type !== '' ? Number(record.type) : '',
    source: record.source !== undefined && record.source !== null && record.source !== '' ? Number(record.source) : 2,
    exceStatus:
      record.exceStatus !== undefined && record.exceStatus !== null && record.exceStatus !== ''
        ? Number(record.exceStatus)
        : 0,
    orgAreaId:
      record.orgAreaId !== undefined && record.orgAreaId !== null && record.orgAreaId !== ''
        ? Number(record.orgAreaId)
        : void 0,
    tarAreaId:
      record.tarAreaId !== undefined && record.tarAreaId !== null && record.tarAreaId !== ''
        ? Number(record.tarAreaId)
        : void 0,
    status: record.status !== undefined && record.status !== null ? Number(record.status) : 1,
    memo: normalizeText(record.memo || '')
  }
}
 
export function getTransferPaginationKey() {
  return { current: 'current', size: 'pageSize' }
}
 
export function getTransferSourceOptions() {
  return [
    { label: 'ERP系统', value: 1 },
    { label: 'WMS系统生成', value: 2 },
    { label: 'EXCEL导入', value: 3 },
    { label: 'QMS系统', value: 4 }
  ]
}
 
export function getTransferStatusOptions() {
  return [
    { label: '正常', value: 1 },
    { label: '冻结', value: 0 }
  ]
}
 
export function getTransferExceStatusOptions() {
  return [
    { label: '未执行', value: 0 },
    { label: '执行中', value: 1 },
    { label: '执行完成', value: 2 }
  ]
}
 
export function buildTransferSearchParams(params = {}) {
  const result = {}
  ;['condition', 'code', 'orgWareName', 'tarWareName', 'orgAreaName', 'tarAreaName', 'memo'].forEach((key) => {
    const value = normalizeText(params[key])
    if (value) result[key] = value
  })
  ;['type', 'source', 'exceStatus', 'status', 'orgWareId', 'tarWareId', 'orgAreaId', 'tarAreaId'].forEach((key) => {
    if (params[key] !== '' && params[key] !== undefined && params[key] !== null) {
      result[key] = normalizeNumber(params[key])
    }
  })
  if (params.timeStart !== '' && params.timeStart !== undefined && params.timeStart !== null) {
    result.timeStart = normalizeText(params.timeStart)
  }
  if (params.timeEnd !== '' && params.timeEnd !== undefined && params.timeEnd !== null) {
    result.timeEnd = normalizeText(params.timeEnd)
  }
  return result
}
 
export function buildTransferPageQueryParams(params = {}) {
  return {
    current: params.current || 1,
    pageSize: params.pageSize || params.size || 20,
    ...buildTransferSearchParams(params)
  }
}
 
export function buildTransferDetailOrderQueryParams(params = {}) {
  return {
    condition: normalizeText(params.code || params.condition),
    code: normalizeText(params.code || params.condition),
    current: params.current || 1,
    pageSize: params.pageSize || params.size || 20
  }
}
 
export function buildTransferSavePayload(formData = {}, areaOptions = []) {
  const optionMap = new Map(
    (Array.isArray(areaOptions) ? areaOptions : [])
      .map((item) => {
        const value = normalizeNumber(item?.value ?? item?.id, void 0)
        if (value === void 0) return null
        return [value, item?.raw || item]
      })
      .filter(Boolean)
  )
 
  const orgAreaId = normalizeNumber(formData.orgAreaId, void 0)
  const tarAreaId = normalizeNumber(formData.tarAreaId, void 0)
  const orgArea = optionMap.get(orgAreaId) || {}
  const tarArea = optionMap.get(tarAreaId) || {}
  const orgWareId = normalizeNumber(orgArea.warehouseId ?? orgArea.warehouse_id ?? orgArea.warehouseIdValue, void 0)
  const tarWareId = normalizeNumber(tarArea.warehouseId ?? tarArea.warehouse_id ?? tarArea.warehouseIdValue, void 0)
 
  return {
    ...(formData.id !== undefined && formData.id !== null && formData.id !== ''
      ? { id: normalizeNumber(formData.id) }
      : {}),
    ...(normalizeText(formData.code) ? { code: normalizeText(formData.code) } : {}),
    ...(formData.type !== undefined && formData.type !== null && formData.type !== ''
      ? { type: normalizeNumber(formData.type) }
      : {}),
    ...(formData.source !== undefined && formData.source !== null && formData.source !== ''
      ? { source: normalizeNumber(formData.source) }
      : {}),
    ...(formData.exceStatus !== undefined && formData.exceStatus !== null && formData.exceStatus !== ''
      ? { exceStatus: normalizeNumber(formData.exceStatus) }
      : {}),
    ...(orgAreaId !== void 0 ? { orgAreaId } : {}),
    ...(tarAreaId !== void 0 ? { tarAreaId } : {}),
    ...(orgWareId !== void 0 ? { orgWareId } : {}),
    ...(tarWareId !== void 0 ? { tarWareId } : {}),
    ...(normalizeText(orgArea.name || orgArea.areaName) ? { orgAreaName: normalizeText(orgArea.name || orgArea.areaName) } : {}),
    ...(normalizeText(tarArea.name || tarArea.areaName) ? { tarAreaName: normalizeText(tarArea.name || tarArea.areaName) } : {}),
    ...(normalizeText(orgArea.warehouseId$ || orgArea.warehouseName) ? { orgWareName: normalizeText(orgArea.warehouseId$ || orgArea.warehouseName) } : {}),
    ...(normalizeText(tarArea.warehouseId$ || tarArea.warehouseName) ? { tarWareName: normalizeText(tarArea.warehouseId$ || tarArea.warehouseName) } : {}),
    ...(formData.status !== undefined && formData.status !== null && formData.status !== ''
      ? { status: normalizeNumber(formData.status) }
      : { status: 1 }),
    memo: normalizeText(formData.memo) || ''
  }
}
 
function resolveAreaText(record = {}, key) {
  return normalizeText(record[`${key}AreaName$`] || record[`${key}AreaName`] || record[`${key}AreaId$`] || record[`${key}AreaId`])
}
 
function resolveWarehouseText(record = {}, key) {
  return normalizeText(record[`${key}WareName$`] || record[`${key}WareName`] || record[`${key}WareId$`] || record[`${key}WareId`])
}
 
export function normalizeTransferRow(record = {}) {
  const statusMeta = metaByValue(record.statusBool ?? record.status, TRANSFER_STATUS_META, '未知')
  const exceStatusMeta = metaByValue(record.exceStatus, TRANSFER_EXCE_STATUS_META, record.exceStatusText)
  const sourceMeta = metaByValue(record.source, TRANSFER_SOURCE_META, record.sourceText)
  return {
    ...record,
    id: record.id ?? null,
    code: normalizeText(record.code) || '--',
    typeLabel: normalizeText(record['type$'] || record.type) || '--',
    sourceText: sourceMeta.text,
    sourceTagType: sourceMeta.type,
    exceStatusText: normalizeText(record['exceStatus$'] || record.exceStatusText) || exceStatusMeta.text,
    exceStatusTagType: exceStatusMeta.type,
    orgWareName: resolveWarehouseText(record, 'org') || '--',
    tarWareName: resolveWarehouseText(record, 'tar') || '--',
    orgAreaName: resolveAreaText(record, 'org') || '--',
    tarAreaName: resolveAreaText(record, 'tar') || '--',
    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.createTimeText || record.createTime) || '--',
    updateByText: normalizeText(record['updateBy$'] || record.updateByText) || '--',
    updateTimeText: normalizeText(record['updateTime$'] || record.updateTimeText || record.updateTime) || '--',
    memo: normalizeText(record.memo) || '--'
  }
}
 
export function normalizeTransferDetailRecord(record = {}) {
  return normalizeTransferRow(record)
}
 
export function normalizeTransferOrderRow(record = {}) {
  const statusMeta = metaByValue(record.statusBool ?? record.status, TRANSFER_STATUS_META, '未知')
  const exceStatusMeta = metaByValue(record.exceStatus, TRANSFER_EXCE_STATUS_META, record.exceStatusText)
  return {
    ...record,
    id: record.id ?? null,
    code: normalizeText(record.code) || '--',
    poCode: normalizeText(record.poCode) || '--',
    typeLabel: normalizeText(record['type$'] || record.type) || '--',
    wkTypeLabel: normalizeText(record['wkType$'] || record.wkType) || '--',
    exceStatusText: normalizeText(record['exceStatus$'] || record.exceStatusText) || exceStatusMeta.text,
    exceStatusTagType: exceStatusMeta.type,
    statusText: statusMeta.text,
    statusType: statusMeta.type,
    statusBool: record.statusBool !== void 0 ? Boolean(record.statusBool) : statusMeta.bool,
    anfme: record.anfme ?? '--',
    workQty: record.workQty ?? '--',
    qty: record.qty ?? '--',
    stationId: normalizeText(record.stationId) || '--',
    businessTimeText: normalizeText(record['businessTime$'] || record.businessTimeText || record.businessTime) || '--',
    createByText: normalizeText(record['createBy$'] || record.createByText) || '--',
    createTimeText: normalizeText(record['createTime$'] || record.createTimeText || record.createTime) || '--',
    updateByText: normalizeText(record['updateBy$'] || record.updateByText) || '--',
    updateTimeText: normalizeText(record['updateTime$'] || record.updateTimeText || record.updateTime) || '--',
    memo: normalizeText(record.memo) || '--'
  }
}
 
export function buildTransferPrintRows(records = []) {
  return Array.isArray(records) ? records.map((record) => normalizeTransferRow(record)) : []
}
 
export function buildTransferOrderPrintRows(records = []) {
  return Array.isArray(records) ? records.map((record) => normalizeTransferOrderRow(record)) : []
}
 
export function buildTransferReportMeta({
  previewMeta = {},
  count = 0,
  orientation = TRANSFER_REPORT_STYLE.orientation
} = {}) {
  return {
    reportTitle: TRANSFER_REPORT_TITLE,
    reportDate: previewMeta.reportDate,
    printedAt: previewMeta.printedAt,
    operator: previewMeta.operator,
    count,
    reportStyle: {
      ...TRANSFER_REPORT_STYLE,
      orientation
    }
  }
}
 
export function getTransferActionList(row = {}) {
  const normalizedRow = normalizeTransferRow(row)
  const actions = [
    { key: 'view', label: '查看详情', icon: 'ri:eye-line' },
    { key: 'edit', label: '编辑', icon: 'ri:pencil-line' }
  ]
  if (Number(normalizedRow.exceStatus) === 0) {
    actions.push({ key: 'publish', label: '下发执行', icon: 'ri:send-plane-line' })
    actions.push({ key: 'delete', label: '删除', icon: 'ri:delete-bin-5-line', color: 'var(--art-error)' })
  }
  return actions
}
 
export function resolveTransferAreaOptions(records = []) {
  if (!Array.isArray(records)) return []
  return records
    .map((item) => {
      if (!item || typeof item !== 'object') return null
      const value = normalizeNumber(item.id ?? item.value, void 0)
      if (value === void 0) return null
      return {
        value,
        label: normalizeText(item.name || item.areaName || item.code || item.warehouseId$ || item.warehouseName || `库区 ${value}`),
        raw: item
      }
    })
    .filter(Boolean)
}
 
export function resolveTransferTypeOptions(records = []) {
  if (!Array.isArray(records)) return []
  return records
    .map((item) => {
      if (!item || typeof item !== 'object') return null
      const value = normalizeNumber(item.value ?? item.id, void 0)
      if (value === void 0) return null
      return {
        value,
        label: normalizeText(item.label || item.name || item.dictLabel || `类型 ${value}`)
      }
    })
    .filter(Boolean)
}