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
export const TRANSFER_ITEM_REPORT_TITLE = '调拨明细报表'
export const TRANSFER_ITEM_REPORT_STYLE = {
  titleAlign: 'center',
  titleLevel: 'strong',
  orientation: 'landscape',
  density: 'compact',
  showSequence: true,
  showBorder: true
}
 
const STATUS_META = {
  1: { text: '正常', type: 'success', bool: true },
  0: { text: '冻结', type: 'danger', bool: false }
}
 
function normalizeText(value, fallback = '--') {
  if (value === null || value === undefined || value === '') {
    return fallback
  }
  const text = String(value).trim()
  return text || fallback
}
 
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 pushText(target, key, value) {
  const text = normalizeText(value, '')
  if (text) {
    target[key] = text
  }
}
 
function pushNumber(target, key, value) {
  const numericValue = normalizeNumber(value, void 0)
  if (numericValue !== void 0) {
    target[key] = numericValue
  }
}
 
function getStatusMeta(status, statusText) {
  const numericStatus = Number(status)
  return STATUS_META[numericStatus] || {
    text: normalizeText(statusText || status || '--'),
    type: 'info',
    bool: false
  }
}
 
export function createTransferItemSearchState() {
  return {
    condition: '',
    timeStart: '',
    timeEnd: '',
    transferId: '',
    transferCode: '',
    matnrId: '',
    maktx: '',
    matnrCode: '',
    unit: '',
    anfme: '',
    qty: '',
    workQty: '',
    batch: '',
    splrId: '',
    spec: '',
    model: '',
    fieldsIndex: '',
    platItemId: '',
    platOrderCode: '',
    platWorkCode: '',
    projectCode: '',
    memo: '',
    status: ''
  }
}
 
export function getTransferItemPaginationKey() {
  return {
    current: 'current',
    size: 'pageSize'
  }
}
 
export function getTransferItemStatusOptions() {
  return [
    { label: '正常', value: 1 },
    { label: '冻结', value: 0 }
  ]
}
 
export function getTransferItemStatusMeta(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 buildTransferItemSearchParams(params = {}) {
  const result = {}
 
  ;[
    'condition',
    'timeStart',
    'timeEnd',
    'transferCode',
    'maktx',
    'matnrCode',
    'unit',
    'batch',
    'spec',
    'model',
    'fieldsIndex',
    'platItemId',
    'platOrderCode',
    'platWorkCode',
    'projectCode',
    'memo'
  ].forEach((key) => pushText(result, key, params[key]))
 
  ;['transferId', 'matnrId', 'anfme', 'qty', 'workQty', 'splrId', 'status'].forEach((key) =>
    pushNumber(result, key, params[key])
  )
 
  return result
}
 
export function buildTransferItemPageQueryParams(params = {}) {
  return {
    current: params.current || 1,
    pageSize: params.pageSize || params.size || 20,
    ...buildTransferItemSearchParams(params)
  }
}
 
export function normalizeTransferItemRow(record = {}) {
  const statusMeta = getStatusMeta(record.statusBool ?? record.status, record['status$'] || record.statusText)
 
  return {
    ...record,
    id: record.id ?? null,
    transferId: normalizeNumber(record.transferId, '--'),
    transferCode: normalizeText(record.transferCode),
    matnrId: normalizeNumber(record.matnrId, '--'),
    maktx: normalizeText(record.maktx),
    matnrCode: normalizeText(record.matnrCode),
    unit: normalizeText(record.unit),
    anfme: normalizeNumber(record.anfme, '--'),
    qty: normalizeNumber(record.qty, '--'),
    workQty: normalizeNumber(record.workQty, '--'),
    batch: normalizeText(record.batch),
    splrId: normalizeNumber(record.splrId, '--'),
    splrCode: normalizeText(record.splrCode),
    splrName: normalizeText(record.splrName),
    spec: normalizeText(record.spec),
    model: normalizeText(record.model),
    fieldsIndex: normalizeText(record.fieldsIndex),
    platItemId: normalizeText(record.platItemId),
    platOrderCode: normalizeText(record.platOrderCode),
    platWorkCode: normalizeText(record.platWorkCode),
    projectCode: normalizeText(record.projectCode),
    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 buildTransferItemPrintRows(records = []) {
  if (!Array.isArray(records)) {
    return []
  }
  return records.map((record) => normalizeTransferItemRow(record))
}
 
export function buildTransferItemReportMeta({
  previewMeta = {},
  count = 0,
  orientation = TRANSFER_ITEM_REPORT_STYLE.orientation
} = {}) {
  return {
    reportTitle: TRANSFER_ITEM_REPORT_TITLE,
    reportDate: previewMeta.reportDate,
    printedAt: previewMeta.printedAt,
    operator: previewMeta.operator,
    count,
    reportStyle: {
      ...TRANSFER_ITEM_REPORT_STYLE,
      orientation
    }
  }
}