1
1 天以前 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
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
function translate(t, key, params) {
  if (typeof t === 'function') {
    return t(key, params)
  }
  return key
}
 
const OUT_STOCK_STATUS_META = {
  8: { key: 'pages.orders.outStock.status.cancelled', type: 'danger' },
  10: { key: 'pages.orders.outStock.status.initialized', type: 'info' },
  11: { key: 'pages.orders.outStock.status.pending', type: 'warning' },
  13: { key: 'pages.orders.outStock.status.generated', type: 'primary' },
  14: { key: 'pages.orders.outStock.status.running', type: 'warning' },
  15: { key: 'pages.orders.outStock.status.completed', type: 'success' }
}
 
const OUT_STOCK_RLE_STATUS_META = {
  0: { key: 'common.status.normal', type: 'success' },
  1: { key: 'pages.orders.outStock.status.released', type: 'warning' }
}
 
const OUT_STOCK_TYPE_META = {
  out: 'pages.orders.outStock.type.out'
}
 
export const OUT_STOCK_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(exceStatus, exceStatusText, t) {
  if (exceStatusText) {
    const fallback = OUT_STOCK_STATUS_META[Number(exceStatus)] || {
      text: exceStatusText,
      type: 'info'
    }
    if (fallback.key) {
      return {
        text: translate(t, fallback.key),
        type: fallback.type
      }
    }
    return fallback
  }
 
  const fallback = OUT_STOCK_STATUS_META[Number(exceStatus)]
  if (fallback?.key) {
    return {
      text: translate(t, fallback.key),
      type: fallback.type
    }
  }
 
  return {
    text: normalizeText(exceStatus) || translate(t, 'common.placeholder.empty'),
    type: 'info'
  }
}
 
function normalizeRleStatusMeta(rleStatus, rleStatusText, t) {
  if (rleStatusText) {
    const fallback = OUT_STOCK_RLE_STATUS_META[Number(rleStatus)] || {
      text: rleStatusText,
      type: 'info'
    }
    if (fallback.key) {
      return {
        text: translate(t, fallback.key),
        type: fallback.type
      }
    }
    return fallback
  }
 
  const fallback = OUT_STOCK_RLE_STATUS_META[Number(rleStatus)]
  if (fallback?.key) {
    return {
      text: translate(t, fallback.key),
      type: fallback.type
    }
  }
 
  return {
    text: normalizeText(rleStatus) || translate(t, 'common.placeholder.empty'),
    type: 'info'
  }
}
 
export function createOutStockSearchState() {
  return {
    condition: '',
    code: '',
    poCode: '',
    wkType: '',
    exceStatus: '',
    rleStatus: '',
    logisNo: '',
    customerName: '',
    saleOrgName: '',
    memo: ''
  }
}
 
export function buildOutStockSearchParams(params = {}) {
  const result = {
    type: 'out'
  }
 
  ;['condition', 'code', 'poCode', 'wkType', 'logisNo', 'customerName', 'saleOrgName', '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.rleStatus !== '' && params.rleStatus !== undefined && params.rleStatus !== null) {
    result.rleStatus = normalizeNumber(params.rleStatus)
  }
 
  return result
}
 
export function buildOutStockPageQueryParams(params = {}) {
  return {
    current: params.current || 1,
    pageSize: params.pageSize || params.size || 20,
    ...buildOutStockSearchParams(params)
  }
}
 
export function getOutStockReportTitle(t) {
  return translate(t, 'pages.orders.outStock.reportTitle')
}
 
export function normalizeOutStockRow(record = {}, t) {
  const statusMeta = normalizeStatusMeta(record.exceStatus, record['exceStatus$'] || record.exceStatusText, t)
  const rleStatusMeta = normalizeRleStatusMeta(record.rleStatus, record['rleStatus$'] || record.rleStatusText, t)
  const typeValue = normalizeText(record['type$'] || record.type)
 
  return {
    ...record,
    id: record.id ?? null,
    code: normalizeText(record.code) || translate(t, 'common.placeholder.empty'),
    poCode: normalizeText(record.poCode) || translate(t, 'common.placeholder.empty'),
    typeLabel: OUT_STOCK_TYPE_META[typeValue]
      ? translate(t, OUT_STOCK_TYPE_META[typeValue])
      : typeValue || translate(t, 'common.placeholder.empty'),
    wkTypeLabel: normalizeText(record['wkType$'] || record.wkType) || translate(t, 'common.placeholder.empty'),
    exceStatusText: statusMeta.text,
    exceStatusTagType: statusMeta.type,
    rleStatusText: rleStatusMeta.text,
    rleStatusTagType: rleStatusMeta.type,
    anfme: record.anfme ?? translate(t, 'common.placeholder.empty'),
    workQty: record.workQty ?? translate(t, 'common.placeholder.empty'),
    qty: record.qty ?? translate(t, 'common.placeholder.empty'),
    logisNo: normalizeText(record.logisNo) || translate(t, 'common.placeholder.empty'),
    saleOrgName: normalizeText(record.saleOrgName) || translate(t, 'common.placeholder.empty'),
    saleUserName: normalizeText(record.saleUserName) || translate(t, 'common.placeholder.empty'),
    businessTimeText:
      normalizeText(record['businessTime$'] || record.businessTimeText || record.businessTime) ||
      translate(t, 'common.placeholder.empty'),
    customerId: normalizeText(record.customerId) || translate(t, 'common.placeholder.empty'),
    customerName: normalizeText(record.customerName) || translate(t, 'common.placeholder.empty'),
    stockOrgName: normalizeText(record.stockOrgName) || translate(t, 'common.placeholder.empty'),
    createByText: normalizeText(record['createBy$'] || record.createByText) || translate(t, 'common.placeholder.empty'),
    createTimeText:
      normalizeText(record['createTime$'] || record.createTimeText || record.createTime) ||
      translate(t, 'common.placeholder.empty'),
    updateByText: normalizeText(record['updateBy$'] || record.updateByText) || translate(t, 'common.placeholder.empty'),
    updateTimeText:
      normalizeText(record['updateTime$'] || record.updateTimeText || record.updateTime) ||
      translate(t, 'common.placeholder.empty'),
    memo: normalizeText(record.memo) || translate(t, 'common.placeholder.empty'),
    canComplete: Number(record.exceStatus) !== 15,
    canCancel: Number(record.exceStatus) === 10,
    canDelete: Number(record.exceStatus) !== 15
  }
}
 
export function getOutStockActionList(row = {}, t) {
  const normalizedRow = normalizeOutStockRow(row, t)
  return [
    {
      key: 'view',
      label: translate(t, 'pages.orders.outStock.actions.view'),
      icon: 'ri:eye-line'
    },
    {
      key: 'items',
      label: translate(t, 'pages.orders.outStock.actions.items'),
      icon: 'ri:list-check-3'
    },
    {
      key: 'print',
      label: translate(t, 'pages.orders.outStock.actions.print'),
      icon: 'ri:printer-line'
    },
    {
      key: 'complete',
      label: translate(t, 'pages.orders.outStock.actions.complete'),
      icon: 'ri:check-line',
      color: 'var(--el-color-success)',
      disabled: !normalizedRow.canComplete
    },
    {
      key: 'cancel',
      label: translate(t, 'pages.orders.outStock.actions.cancel'),
      icon: 'ri:close-circle-line',
      color: 'var(--el-color-danger)',
      disabled: !normalizedRow.canCancel
    },
    {
      key: 'delete',
      label: translate(t, 'pages.orders.outStock.actions.delete'),
      icon: 'ri:delete-bin-6-line',
      color: 'var(--el-color-danger)',
      disabled: !normalizedRow.canDelete
    }
  ]
}
 
export function buildOutStockPrintRows(records = [], t) {
  if (!Array.isArray(records)) {
    return []
  }
  return records.map((record) => normalizeOutStockRow(record, t))
}
 
export function buildOutStockReportMeta({
  previewMeta = {},
  count = 0,
  orientation = OUT_STOCK_REPORT_STYLE.orientation,
  t
} = {}) {
  return {
    reportTitle: getOutStockReportTitle(t),
    reportDate: previewMeta.reportDate,
    printedAt: previewMeta.printedAt,
    operator: previewMeta.operator,
    count,
    reportStyle: {
      ...OUT_STOCK_REPORT_STYLE,
      orientation
    }
  }
}