zhou zhou
10 小时以前 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
const DELIVERY_STATUS_META = {
  1: { text: '正常', type: 'success', bool: true },
  0: { text: '禁用', type: 'danger', bool: false }
}
 
const DELIVERY_EXCE_STATUS_META = {
  0: { text: '未执行', type: 'info' },
  1: { text: '执行中', type: 'warning' },
  2: { text: '部分完成', type: 'primary' },
  3: { text: '已完成', type: 'success' }
}
 
export const DELIVERY_REPORT_TITLE = 'DO单报表'
export const DELIVERY_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 normalizeStatusMeta(status) {
  if (status === true || Number(status) === 1) {
    return DELIVERY_STATUS_META[1]
  }
  if (status === false || Number(status) === 0) {
    return DELIVERY_STATUS_META[0]
  }
  return { text: '未知', type: 'info', bool: false }
}
 
function normalizeExceStatusMeta(exceStatus, exceStatusText) {
  if (exceStatusText) {
    const numericValue = Number(exceStatus)
    const fallback = DELIVERY_EXCE_STATUS_META[numericValue] || {
      text: exceStatusText,
      type: 'info'
    }
    return fallback
  }
  return DELIVERY_EXCE_STATUS_META[Number(exceStatus)] || {
    text: normalizeText(exceStatus) || '--',
    type: 'info'
  }
}
 
export function createDeliverySearchState() {
  return {
    condition: '',
    code: '',
    platId: '',
    type: '',
    wkType: '',
    source: '',
    exceStatus: '',
    memo: ''
  }
}
 
export function getDeliveryPaginationKey() {
  return {
    current: 'current',
    size: 'pageSize'
  }
}
 
export function buildDeliverySearchParams(params = {}) {
  const result = {}
  ;['condition', 'code', 'platId', 'type', 'wkType', 'source', 'memo'].forEach((key) => {
    const value = normalizeText(params[key])
    if (value) {
      result[key] = value
    }
  })
 
  if (params.exceStatus !== '' && params.exceStatus !== undefined && params.exceStatus !== null) {
    result.exceStatus = normalizeNumber(params.exceStatus)
  }
 
  if (params.status !== '' && params.status !== undefined && params.status !== null) {
    result.status = normalizeNumber(params.status)
  }
 
  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 buildDeliveryPageQueryParams(params = {}) {
  return {
    current: params.current || 1,
    pageSize: params.pageSize || params.size || 20,
    ...buildDeliverySearchParams(params)
  }
}
 
export function buildDeliveryDetailQueryParams(params = {}) {
  return {
    deliveryId: params.deliveryId,
    current: params.current || 1,
    pageSize: params.pageSize || params.size || 20
  }
}
 
export function normalizeDeliveryRow(record = {}) {
  const statusMeta = normalizeStatusMeta(record.statusBool ?? record.status)
  const exceStatusMeta = normalizeExceStatusMeta(record.exceStatus, record['exceStatus$'] || record.exceStatusText)
  return {
    ...record,
    id: record.id ?? null,
    code: normalizeText(record.code) || '--',
    platId: normalizeText(record.platId) || '--',
    platCode: normalizeText(record.platCode) || '--',
    source: normalizeText(record.source) || '--',
    typeLabel: normalizeText(record['type$'] || record.type) || '--',
    wkTypeLabel: normalizeText(record['wkType$'] || record.wkType) || '--',
    statusText: statusMeta.text,
    statusType: statusMeta.type,
    statusBool: record.statusBool !== void 0 ? Boolean(record.statusBool) : statusMeta.bool,
    exceStatusText: normalizeText(record['exceStatus$'] || record.exceStatusText) || exceStatusMeta.text,
    exceStatusTagType: exceStatusMeta.type,
    anfme: record.anfme ?? '--',
    qty: record.qty ?? '--',
    workQty: record.workQty ?? '--',
    startTimeText: normalizeText(record['startTime$'] || record.startTimeText || record.startTime) || '--',
    endTimeText: normalizeText(record['endTime$'] || record.endTimeText || record.endTime) || '--',
    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 normalizeDeliveryItemRow(record = {}) {
  return {
    ...record,
    id: record.id ?? null,
    deliveryId: record.deliveryId ?? '--',
    deliveryCode: normalizeText(record.deliveryCode) || '--',
    platOrderCode: normalizeText(record.platOrderCode) || '--',
    platWorkCode: normalizeText(record.platWorkCode) || '--',
    projectCode: normalizeText(record.projectCode) || '--',
    platItemId: normalizeText(record.platItemId) || '--',
    matnrCode: normalizeText(record.matnrCode) || '--',
    matnrName: normalizeText(record.maktx || record.matnrName) || '--',
    maktx: normalizeText(record.maktx || record.matnrName) || '--',
    fieldsIndex: normalizeText(record.fieldsIndex) || '--',
    unit: normalizeText(record.unit) || '--',
    anfme: record.anfme ?? '--',
    workQty: record.workQty ?? '--',
    qty: record.qty ?? '--',
    nromQty: record.nromQty ?? '--',
    printQty: record.printQty ?? '--',
    splrName: normalizeText(record.splrName) || '--',
    splrCode: normalizeText(record.splrCode) || '--',
    splrBatch: normalizeText(record.splrBatch) || '--',
    batch: normalizeText(record.batch) || '--',
    trackCode: normalizeText(record.trackCode) || '--',
    packName: normalizeText(record.packName) || '--',
    prodTimeText: normalizeText(record['prodTime$'] || record.prodTimeText || record.prodTime) || '--',
    statusText: normalizeStatusMeta(record.statusBool ?? record.status).text,
    statusType: normalizeStatusMeta(record.statusBool ?? record.status).type,
    statusBool:
      record.statusBool !== void 0
        ? Boolean(record.statusBool)
        : normalizeStatusMeta(record.statusBool ?? record.status).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 buildDeliveryPrintRows(records = []) {
  if (!Array.isArray(records)) {
    return []
  }
  return records.map((record) => normalizeDeliveryRow(record))
}
 
export function buildDeliveryItemPrintRows(records = []) {
  if (!Array.isArray(records)) {
    return []
  }
  return records.map((record) => normalizeDeliveryItemRow(record))
}
 
export function buildDeliveryReportMeta({
  previewMeta = {},
  count = 0,
  orientation = DELIVERY_REPORT_STYLE.orientation
} = {}) {
  return {
    reportTitle: DELIVERY_REPORT_TITLE,
    reportDate: previewMeta.reportDate,
    printedAt: previewMeta.printedAt,
    operator: previewMeta.operator,
    count,
    reportStyle: {
      ...DELIVERY_REPORT_STYLE,
      orientation
    }
  }
}
 
export function buildDeliveryItemReportMeta({
  previewMeta = {},
  count = 0,
  orientation = DELIVERY_REPORT_STYLE.orientation
} = {}) {
  return {
    reportTitle: 'DO单明细报表',
    reportDate: previewMeta.reportDate,
    printedAt: previewMeta.printedAt,
    operator: previewMeta.operator,
    count,
    reportStyle: {
      ...DELIVERY_REPORT_STYLE,
      orientation
    }
  }
}
 
export function getDeliveryActionList(row = {}) {
  const normalizedRow = normalizeDeliveryRow(row)
  const actions = [
    {
      key: 'view',
      label: '查看详情',
      icon: 'ri:eye-line'
    }
  ]
 
  if (Number(normalizedRow.exceStatus) === 0) {
    actions.push({
      key: 'delete',
      label: '删除',
      icon: 'ri:delete-bin-5-line',
      color: 'var(--art-error)'
    })
  }
 
  return actions
}