zhou zhou
昨天 c579731e0c206d6062f8442ec9df70ca781b26f6
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
const FLAG_META = {
  1: { text: '是', type: 'success', bool: true },
  0: { text: '否', type: 'danger', bool: false }
}
 
export const DEVICE_BIND_REPORT_TITLE = '设备绑定报表'
export const DEVICE_BIND_REPORT_STYLE = {
  titleAlign: 'center',
  titleLevel: 'strong',
  orientation: 'portrait',
  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 numberValue = Number(value)
  return Number.isNaN(numberValue) ? fallback : numberValue
}
 
function normalizeFlagValue(value, fallback = '0') {
  if (value === 1 || value === '1' || value === true) {
    return '1'
  }
  if (value === 0 || value === '0' || value === false) {
    return '0'
  }
  const text = normalizeText(value)
  return text || fallback
}
 
function normalizeFlagText(value) {
  if (value === 1 || value === '1' || value === true) {
    return FLAG_META[1].text
  }
  if (value === 0 || value === '0' || value === false) {
    return FLAG_META[0].text
  }
  return '--'
}
 
function splitStaList(value) {
  return normalizeText(value)
    .split(/[;,,\n\r]+/g)
    .map((item) => item.trim())
    .filter(Boolean)
}
 
export function createDeviceBindSearchState() {
  return {
    condition: '',
    currentRow: null,
    startRow: null,
    endRow: null,
    deviceQty: null,
    startDeviceNo: null,
    endDeviceNo: null,
    typeId: '',
    staList: '',
    beSimilar: '',
    emptySimilar: '',
    memo: '',
    timeStart: '',
    timeEnd: ''
  }
}
 
export function createDeviceBindFormState() {
  return {
    id: void 0,
    currentRow: void 0,
    startRow: void 0,
    endRow: void 0,
    deviceQty: void 0,
    startDeviceNo: void 0,
    endDeviceNo: void 0,
    staList: '',
    typeId: void 0,
    beSimilar: '0',
    emptySimilar: '0',
    memo: ''
  }
}
 
export function getDeviceBindPaginationKey() {
  return {
    current: 'current',
    size: 'pageSize'
  }
}
 
export function getDeviceBindFlagOptions() {
  return [
    { label: '是', value: '1' },
    { label: '否', value: '0' }
  ]
}
 
export function getDeviceBindFlagMeta(value) {
  if (value === true || Number(value) === 1) {
    return FLAG_META[1]
  }
  if (value === false || Number(value) === 0) {
    return FLAG_META[0]
  }
  return { text: '--', type: 'info', bool: void 0 }
}
 
export function resolveDeviceBindTypeOptions(records = []) {
  if (!Array.isArray(records)) {
    return []
  }
 
  return records
    .map((item) => {
      if (!item || typeof item !== 'object') {
        return null
      }
      const value = item.id ?? item.areaId ?? item.value
      if (value === void 0 || value === null || value === '') {
        return null
      }
      return {
        value: Number(value),
        label: normalizeText(item.name || item.areaName || item.code || item.areaCode || `库区 ${value}`)
      }
    })
    .filter(Boolean)
}
 
export function buildDeviceBindSearchParams(params = {}) {
  const searchParams = {
    condition: normalizeText(params.condition),
    currentRow: normalizeNumber(params.currentRow),
    startRow: normalizeNumber(params.startRow),
    endRow: normalizeNumber(params.endRow),
    deviceQty: normalizeNumber(params.deviceQty),
    startDeviceNo: normalizeNumber(params.startDeviceNo),
    endDeviceNo: normalizeNumber(params.endDeviceNo),
    typeId: normalizeNumber(params.typeId),
    staList: normalizeText(params.staList),
    beSimilar: normalizeText(params.beSimilar),
    emptySimilar: normalizeText(params.emptySimilar),
    memo: normalizeText(params.memo),
    timeStart: normalizeText(params.timeStart),
    timeEnd: normalizeText(params.timeEnd)
  }
 
  return Object.fromEntries(
    Object.entries(searchParams).filter(([, value]) => value !== '' && value !== void 0 && value !== null)
  )
}
 
export function buildDeviceBindPageQueryParams(params = {}) {
  return {
    current: params.current || 1,
    pageSize: params.pageSize || params.size || 20,
    ...buildDeviceBindSearchParams(params)
  }
}
 
export function buildDeviceBindSavePayload(formData = {}) {
  return {
    ...(formData.id !== void 0 && formData.id !== null && formData.id !== ''
      ? { id: Number(formData.id) }
      : {}),
    ...(formData.currentRow !== void 0 && formData.currentRow !== null && formData.currentRow !== ''
      ? { currentRow: Number(formData.currentRow) }
      : {}),
    ...(formData.startRow !== void 0 && formData.startRow !== null && formData.startRow !== ''
      ? { startRow: Number(formData.startRow) }
      : {}),
    ...(formData.endRow !== void 0 && formData.endRow !== null && formData.endRow !== ''
      ? { endRow: Number(formData.endRow) }
      : {}),
    ...(formData.deviceQty !== void 0 && formData.deviceQty !== null && formData.deviceQty !== ''
      ? { deviceQty: Number(formData.deviceQty) }
      : {}),
    ...(formData.startDeviceNo !== void 0 && formData.startDeviceNo !== null && formData.startDeviceNo !== ''
      ? { startDeviceNo: Number(formData.startDeviceNo) }
      : {}),
    ...(formData.endDeviceNo !== void 0 && formData.endDeviceNo !== null && formData.endDeviceNo !== ''
      ? { endDeviceNo: Number(formData.endDeviceNo) }
      : {}),
    staList: normalizeText(formData.staList) || '',
    ...(formData.typeId !== void 0 && formData.typeId !== null && formData.typeId !== ''
      ? { typeId: Number(formData.typeId) }
      : {}),
    beSimilar: normalizeFlagValue(formData.beSimilar),
    emptySimilar: normalizeFlagValue(formData.emptySimilar),
    memo: normalizeText(formData.memo) || ''
  }
}
 
export function buildDeviceBindDialogModel(record = {}) {
  return {
    ...createDeviceBindFormState(),
    ...(record.id !== void 0 && record.id !== null && record.id !== '' ? { id: Number(record.id) } : {}),
    currentRow:
      record.currentRow !== void 0 && record.currentRow !== null && record.currentRow !== ''
        ? Number(record.currentRow)
        : void 0,
    startRow:
      record.startRow !== void 0 && record.startRow !== null && record.startRow !== ''
        ? Number(record.startRow)
        : void 0,
    endRow:
      record.endRow !== void 0 && record.endRow !== null && record.endRow !== ''
        ? Number(record.endRow)
        : void 0,
    deviceQty:
      record.deviceQty !== void 0 && record.deviceQty !== null && record.deviceQty !== ''
        ? Number(record.deviceQty)
        : void 0,
    startDeviceNo:
      record.startDeviceNo !== void 0 && record.startDeviceNo !== null && record.startDeviceNo !== ''
        ? Number(record.startDeviceNo)
        : void 0,
    endDeviceNo:
      record.endDeviceNo !== void 0 && record.endDeviceNo !== null && record.endDeviceNo !== ''
        ? Number(record.endDeviceNo)
        : void 0,
    staList: normalizeText(record.staList || ''),
    typeId:
      record.typeId !== void 0 && record.typeId !== null && record.typeId !== ''
        ? Number(record.typeId)
        : void 0,
    beSimilar: normalizeFlagValue(record.beSimilar, '0'),
    emptySimilar: normalizeFlagValue(record.emptySimilar, '0'),
    memo: normalizeText(record.memo || '')
  }
}
 
export function normalizeDeviceBindDetailRecord(record = {}, resolveTypeLabel) {
  const beSimilarMeta = getDeviceBindFlagMeta(record.beSimilar)
  const emptySimilarMeta = getDeviceBindFlagMeta(record.emptySimilar)
 
  return {
    ...record,
    currentRow:
      record.currentRow !== void 0 && record.currentRow !== null && record.currentRow !== ''
        ? Number(record.currentRow)
        : void 0,
    startRow:
      record.startRow !== void 0 && record.startRow !== null && record.startRow !== ''
        ? Number(record.startRow)
        : void 0,
    endRow:
      record.endRow !== void 0 && record.endRow !== null && record.endRow !== ''
        ? Number(record.endRow)
        : void 0,
    deviceQty:
      record.deviceQty !== void 0 && record.deviceQty !== null && record.deviceQty !== ''
        ? Number(record.deviceQty)
        : void 0,
    startDeviceNo:
      record.startDeviceNo !== void 0 && record.startDeviceNo !== null && record.startDeviceNo !== ''
        ? Number(record.startDeviceNo)
        : void 0,
    endDeviceNo:
      record.endDeviceNo !== void 0 && record.endDeviceNo !== null && record.endDeviceNo !== ''
        ? Number(record.endDeviceNo)
        : void 0,
    staList: normalizeText(record.staList || ''),
    staListItems: splitStaList(record.staList),
    typeIdText:
      normalizeText(record.typeId$ || record.typeIdText || '') ||
      (typeof resolveTypeLabel === 'function' ? normalizeText(resolveTypeLabel(record.typeId)) : ''),
    beSimilarText: beSimilarMeta.text,
    beSimilarType: beSimilarMeta.type,
    emptySimilarText: emptySimilarMeta.text,
    emptySimilarType: emptySimilarMeta.type,
    memo: normalizeText(record.memo || ''),
    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 normalizeDeviceBindListRow(record = {}, resolveTypeLabel) {
  return normalizeDeviceBindDetailRecord(record, resolveTypeLabel)
}
 
export function buildDeviceBindPrintRows(records = [], resolveTypeLabel) {
  if (!Array.isArray(records)) {
    return []
  }
  return records.map((record) => normalizeDeviceBindListRow(record, resolveTypeLabel))
}
 
export function buildDeviceBindReportMeta({
  previewMeta = {},
  count = 0,
  orientation = DEVICE_BIND_REPORT_STYLE.orientation
} = {}) {
  return {
    reportTitle: DEVICE_BIND_REPORT_TITLE,
    reportDate: previewMeta.reportDate,
    printedAt: previewMeta.printedAt,
    operator: previewMeta.operator,
    count,
    reportStyle: {
      ...DEVICE_BIND_REPORT_STYLE,
      orientation
    }
  }
}