zhou zhou
78 分钟以前 93723e70d32c2451c7984798ec5b4d9947437e37
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
const STATUS_META = {
  1: { text: '正常', type: 'success', bool: true },
  0: { text: '冻结', type: 'danger', bool: false }
}
 
export const WAREHOUSE_REPORT_TITLE = '仓库报表'
export const WAREHOUSE_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
}
 
export function createWarehouseSearchState() {
  return {
    condition: '',
    factory: '',
    code: '',
    name: '',
    address: '',
    status: '',
    memo: '',
    timeStart: '',
    timeEnd: ''
  }
}
 
export function createWarehouseFormState() {
  return {
    id: void 0,
    name: '',
    code: '',
    factory: '',
    address: '',
    status: 1,
    memo: ''
  }
}
 
export function getWarehouseStatusOptions() {
  return [
    { label: '正常', value: 1 },
    { label: '冻结', value: 0 }
  ]
}
 
export function getWarehousePaginationKey() {
  return {
    current: 'current',
    size: 'pageSize'
  }
}
 
export function getWarehouseStatusMeta(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 buildWarehouseSearchParams(params = {}) {
  const searchParams = {
    condition: normalizeText(params.condition),
    factory: normalizeText(params.factory),
    code: normalizeText(params.code),
    name: normalizeText(params.name),
    address: normalizeText(params.address),
    status:
      params.status !== undefined && params.status !== null && params.status !== ''
        ? Number(params.status)
        : void 0,
    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 buildWarehousePageQueryParams(params = {}) {
  return {
    current: params.current || 1,
    pageSize: params.pageSize || params.size || 20,
    ...buildWarehouseSearchParams(params)
  }
}
 
export function buildWarehouseSavePayload(formData = {}) {
  return {
    ...(formData.id !== void 0 && formData.id !== null && formData.id !== ''
      ? { id: Number(formData.id) }
      : {}),
    name: normalizeText(formData.name),
    code: normalizeText(formData.code),
    factory: normalizeText(formData.factory),
    address: normalizeText(formData.address),
    status:
      formData.status !== void 0 && formData.status !== null && formData.status !== ''
        ? Number(formData.status)
        : 1,
    memo: normalizeText(formData.memo)
  }
}
 
export function buildWarehouseDialogModel(record = {}) {
  return {
    ...createWarehouseFormState(),
    ...(record.id !== void 0 && record.id !== null && record.id !== '' ? { id: Number(record.id) } : {}),
    name: normalizeText(record.name || ''),
    code: normalizeText(record.code || ''),
    factory: normalizeText(record.factory || ''),
    address: normalizeText(record.address || ''),
    status: record.status !== void 0 && record.status !== null ? Number(record.status) : 1,
    memo: normalizeText(record.memo || '')
  }
}
 
export function normalizeWarehouseDetailRecord(record = {}) {
  const statusMeta = getWarehouseStatusMeta(record.statusBool ?? record.status)
  return {
    ...record,
    name: normalizeText(record.name || ''),
    code: normalizeText(record.code || ''),
    factory: normalizeText(record.factory || ''),
    address: normalizeText(record.address || ''),
    memo: normalizeText(record.memo || ''),
    statusText: statusMeta.text,
    statusType: statusMeta.type,
    statusBool: record.statusBool !== void 0 ? Boolean(record.statusBool) : statusMeta.bool,
    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 normalizeWarehouseListRow(record = {}) {
  return normalizeWarehouseDetailRecord(record)
}
 
export function buildWarehousePrintRows(records = []) {
  if (!Array.isArray(records)) {
    return []
  }
  return records.map((record) => normalizeWarehouseListRow(record))
}
 
export function buildWarehouseReportMeta({
  previewMeta = {},
  count = 0,
  orientation = WAREHOUSE_REPORT_STYLE.orientation
} = {}) {
  return {
    reportTitle: WAREHOUSE_REPORT_TITLE,
    reportDate: previewMeta.reportDate,
    printedAt: previewMeta.printedAt,
    operator: previewMeta.operator,
    count,
    reportStyle: {
      ...WAREHOUSE_REPORT_STYLE,
      orientation
    }
  }
}