zhou zhou
3 小时以前 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
export const ASN_ORDER_REPORT_TITLE = '入库通知单报表'
export const ASN_ORDER_REPORT_STYLE = {
  titleAlign: 'center',
  titleLevel: 'strong',
  orientation: 'landscape',
  density: 'compact',
  showSequence: true
}
 
const ASN_ORDER_STATUS_MAP = {
  0: { label: '未执行', tagType: 'info' },
  1: { label: '执行中', tagType: 'warning' },
  2: { label: '收货完成', tagType: 'success' },
  3: { label: '任务执行中', tagType: 'warning' },
  4: { label: '已完成', tagType: 'success' },
  8: { label: '取消', tagType: 'danger' },
  9: { label: '已关闭', tagType: 'info' }
}
 
function normalizeText(value) {
  return String(value ?? '').trim()
}
 
function normalizeNumber(value) {
  if (value === '' || value === null || value === undefined) {
    return 0
  }
  const numericValue = Number(value)
  return Number.isFinite(numericValue) ? numericValue : 0
}
 
function normalizeNullableNumber(value) {
  if (value === '' || value === null || value === undefined) {
    return '-'
  }
  const numericValue = Number(value)
  return Number.isFinite(numericValue) ? numericValue : '-'
}
 
function getStatusConfig(status, statusText) {
  const numericStatus = Number(status)
  const fallback = ASN_ORDER_STATUS_MAP[numericStatus] || {
    label: statusText || '-',
    tagType: 'info'
  }
  return {
    label: statusText || fallback.label,
    tagType: fallback.tagType
  }
}
 
export function createAsnOrderSearchState() {
  return {
    condition: '',
    code: '',
    poCode: '',
    wkType: '',
    exceStatus: '',
    supplierName: '',
    purchaseUserName: ''
  }
}
 
export function createPurchaseFilterSearchState() {
  return {
    condition: '',
    code: '',
    source: '',
    supplierName: ''
  }
}
 
export function buildAsnOrderSearchParams(params = {}) {
  const result = {}
  ;['condition', 'code', 'poCode', 'wkType', 'supplierName', 'purchaseUserName'].forEach((key) => {
    const value = normalizeText(params[key])
    if (value) {
      result[key] = value
    }
  })
 
  if (params.exceStatus !== '' && params.exceStatus !== undefined && params.exceStatus !== null) {
    result.exceStatus = Number(params.exceStatus)
  }
 
  return result
}
 
export function buildAsnOrderPageQueryParams(params = {}) {
  return {
    current: params.current || 1,
    pageSize: params.pageSize || params.size || 20,
    ...buildAsnOrderSearchParams(params)
  }
}
 
export function buildAsnOrderDetailQueryParams(params = {}) {
  return {
    orderId: params.orderId,
    current: params.current || 1,
    pageSize: params.pageSize || params.size || 20
  }
}
 
export function buildPurchaseFilterSearchParams(params = {}) {
  const result = {}
  ;['condition', 'code', 'source', 'supplierName'].forEach((key) => {
    const value = normalizeText(params[key])
    if (value) {
      result[key] = value
    }
  })
  return result
}
 
export function buildPurchaseFilterPageQueryParams(params = {}) {
  return {
    current: params.current || 1,
    pageSize: params.pageSize || params.size || 20,
    ...buildPurchaseFilterSearchParams(params)
  }
}
 
export function normalizeAsnOrderRow(record = {}) {
  const statusConfig = getStatusConfig(record.exceStatus, record['exceStatus$'])
  return {
    ...record,
    id: record.id ?? null,
    code: record.code || '-',
    poCode: record.poCode || '-',
    wkTypeLabel: record['wkType$'] || record.wkType || '-',
    orderTypeLabel: record['type$'] || record.type || '-',
    exceStatusText: statusConfig.label,
    exceStatusTagType: statusConfig.tagType,
    anfme: normalizeNumber(record.anfme),
    qty: normalizeNumber(record.qty),
    purchaseOrgName: record.purchaseOrgName || '-',
    purchaseUserName: record.purchaseUserName || '-',
    supplierId: record.supplierId || '-',
    supplierName: record.supplierName || '-',
    businessTimeText: record['businessTime$'] || record.businessTime || '-',
    updateByText: record['updateBy$'] || '-',
    updateTimeText: record['updateTime$'] || record.updateTime || '-',
    createByText: record['createBy$'] || '-',
    createTimeText: record['createTime$'] || record.createTime || '-',
    memo: record.memo || '-',
    canComplete: Number(record.exceStatus) === 1
  }
}
 
export function normalizeAsnOrderItemRow(record = {}) {
  return {
    ...record,
    id: record.id ?? null,
    orderCode: record.orderCode || '-',
    poCode: record.poCode || '-',
    matnrCode: record.matnrCode || '-',
    maktx: record.maktx || '-',
    platItemId: record.platItemId || '-',
    splrBatch: record.splrBatch || '-',
    splrCode: record.splrCode || '-',
    splrName: record.splrName || record.supplierName || '-',
    stockUnit: record.stockUnit || record.unit || '-',
    purUnit: record.purUnit || '-',
    anfme: normalizeNumber(record.anfme),
    qty: normalizeNumber(record.qty),
    memo: record.memo || '-',
    prodTimeText: record['prodTime$'] || record.prodTime || '-'
  }
}
 
export function normalizePurchaseRow(record = {}) {
  return {
    ...record,
    id: record.id ?? null,
    code: record.code || '-',
    source: record.source || '-',
    wkTypeLabel: record['wkType$'] || record.wkType || '-',
    typeLabel: record['type$'] || record.type || '-',
    supplierName: record.supplierName || '-',
    purchaseUserName: record.purchaseUserName || '-',
    anfme: normalizeNumber(record.anfme),
    qty: normalizeNumber(record.qty),
    remainingQty: Math.max(normalizeNumber(record.anfme) - normalizeNumber(record.qty), 0),
    exceStatusText: record['exceStatus$'] || '-',
    businessTimeText: record['businessTime$'] || record.businessTime || '-'
  }
}
 
export function normalizePurchaseItemRow(record = {}) {
  return {
    ...record,
    id: record.id ?? null,
    platItemId: record.platItemId || '-',
    matnrCode: record.matnrCode || '-',
    maktx: record.matnrName || record.maktx || '-',
    splrName: record.splrName || '-',
    splrCode: record.splrCode || '-',
    splrBatch: record.splrBatch || '-',
    unit: record.unit || record.stockUnit || '-',
    anfme: normalizeNumber(record.anfme),
    qty: normalizeNumber(record.qty),
    nromQty: normalizeNullableNumber(record.nromQty)
  }
}
 
export function buildAsnOrderPrintRows(records = []) {
  if (!Array.isArray(records)) {
    return []
  }
  return records.map((record) => normalizeAsnOrderRow(record))
}
 
export function buildAsnOrderReportMeta({
  previewMeta = {},
  count = 0,
  orientation = ASN_ORDER_REPORT_STYLE.orientation
} = {}) {
  return {
    reportTitle: ASN_ORDER_REPORT_TITLE,
    reportDate: previewMeta.reportDate,
    printedAt: previewMeta.printedAt,
    operator: previewMeta.operator,
    count,
    reportStyle: {
      ...ASN_ORDER_REPORT_STYLE,
      orientation
    }
  }
}
 
export function getAsnOrderStatusOptions() {
  return Object.entries(ASN_ORDER_STATUS_MAP).map(([value, item]) => ({
    label: item.label,
    value: Number(value)
  }))
}
 
export function getAsnOrderActionList(row = {}) {
  const normalizedRow = normalizeAsnOrderRow(row)
  return [
    {
      key: 'view',
      label: '查看详情',
      icon: 'ri:eye-line'
    },
    {
      key: 'print',
      label: '打印',
      icon: 'ri:printer-line'
    },
    {
      key: 'complete',
      label: '完成',
      icon: 'ri:check-line',
      color: 'var(--el-color-success)',
      disabled: !normalizedRow.canComplete
    }
  ]
}