1
14 小时以前 3a4a8c78098f41d3a7ce41f272cdefc35b572681
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
export const PURCHASE_ITEM_REPORT_TITLE = 'PO单明细报表'
export const PURCHASE_ITEM_REPORT_STYLE = {
  titleAlign: 'center',
  titleLevel: 'strong',
  orientation: 'landscape',
  density: 'compact',
  showSequence: 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 = '--') {
  if (value === '' || value === null || value === undefined) {
    return fallback
  }
  const parsed = Number(value)
  return Number.isNaN(parsed) ? fallback : parsed
}
 
function toSearchValue(value) {
  if (value === '' || value === null || value === undefined) {
    return void 0
  }
  const text = String(value).trim()
  return text || void 0
}
 
function toSearchNumber(value) {
  if (value === '' || value === null || value === undefined) {
    return void 0
  }
  const parsed = Number(value)
  return Number.isNaN(parsed) ? void 0 : parsed
}
 
export function createPurchaseItemSearchState() {
  return {
    condition: '',
    purchaseId: '',
    platItemId: '',
    matnrCode: '',
    matnrName: '',
    unit: '',
    anfme: '',
    qty: '',
    nromQty: '',
    asnQty: '',
    printQty: '',
    splrName: '',
    splrCode: '',
    splrBatch: '',
    memo: '',
    status: ''
  }
}
 
export function getPurchaseItemPaginationKey() {
  return {
    current: 'current',
    size: 'pageSize'
  }
}
 
export function getPurchaseItemStatusOptions() {
  return [
    { label: '正常', value: 1 },
    { label: '冻结', value: 0 }
  ]
}
 
export function getPurchaseItemStatusMeta(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 buildPurchaseItemSearchParams(params = {}) {
  const result = {}
 
  ;[
    'condition',
    'platItemId',
    'matnrCode',
    'matnrName',
    'unit',
    'splrName',
    'splrCode',
    'splrBatch',
    'memo'
  ].forEach((key) => {
    const value = toSearchValue(params[key])
    if (value) {
      result[key] = value
    }
  })
 
  ;['purchaseId', 'anfme', 'qty', 'nromQty', 'asnQty', 'printQty', 'status'].forEach((key) => {
    const value = toSearchNumber(params[key])
    if (value !== void 0) {
      result[key] = value
    }
  })
 
  return result
}
 
export function buildPurchaseItemPageQueryParams(params = {}) {
  return {
    current: params.current || 1,
    pageSize: params.pageSize || params.size || 20,
    ...buildPurchaseItemSearchParams(params)
  }
}
 
export function normalizePurchaseItemRow(record = {}) {
  const statusMeta = getPurchaseItemStatusMeta(record.statusBool ?? record.status)
 
  return {
    ...record,
    id: record.id ?? null,
    purchaseId: normalizeNumber(record.purchaseId),
    platItemId: normalizeText(record.platItemId),
    matnrCode: normalizeText(record.matnrCode),
    matnrName: normalizeText(record.matnrName),
    unit: normalizeText(record.unit),
    anfme: normalizeNumber(record.anfme),
    qty: normalizeNumber(record.qty),
    nromQty: normalizeNumber(record.nromQty),
    asnQty: normalizeNumber(record.asnQty),
    printQty: normalizeNumber(record.printQty),
    splrName: normalizeText(record.splrName),
    splrCode: normalizeText(record.splrCode),
    splrBatch: normalizeText(record.splrBatch),
    statusText: normalizeText(record['status$'] || record.statusText || statusMeta.text),
    statusType: statusMeta.type,
    statusBool: record.statusBool !== void 0 ? Boolean(record.statusBool) : statusMeta.bool,
    memo: normalizeText(record.memo),
    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 || '--')
  }
}
 
export function buildPurchaseItemPrintRows(records = []) {
  if (!Array.isArray(records)) {
    return []
  }
  return records.map((record) => normalizePurchaseItemRow(record))
}
 
export function buildPurchaseItemReportMeta({
  previewMeta = {},
  count = 0,
  orientation = PURCHASE_ITEM_REPORT_STYLE.orientation
} = {}) {
  return {
    reportTitle: PURCHASE_ITEM_REPORT_TITLE,
    reportDate: previewMeta.reportDate,
    printedAt: previewMeta.printedAt,
    operator: previewMeta.operator,
    count,
    reportStyle: {
      ...PURCHASE_ITEM_REPORT_STYLE,
      orientation
    }
  }
}