zhou zhou
9 天以前 28c6a76ead9b65a0b5861d70f0838ef2a46f5c45
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
import request from '@/utils/http'
 
function normalizeText(value) {
  return String(value ?? '').trim()
}
 
function normalizeIds(ids) {
  if (Array.isArray(ids)) {
    return ids
      .map((item) => Number(item))
      .filter((item) => Number.isFinite(item))
      .join(',')
  }
  return String(ids ?? '')
    .split(',')
    .map((item) => Number(item))
    .filter((item) => Number.isFinite(item))
    .join(',')
}
 
function normalizeIdList(ids) {
  if (Array.isArray(ids)) {
    return ids.map((item) => Number(item)).filter((item) => Number.isFinite(item))
  }
  return String(ids ?? '')
    .split(',')
    .map((item) => Number(item))
    .filter((item) => Number.isFinite(item))
}
 
function normalizeQueryParams(params = {}) {
  const allowKeys = new Set([
    'condition',
    'code',
    'name',
    'spec',
    'model',
    'color',
    'size',
    'barcode',
    'groupId',
    'unit',
    'status',
    'flagCheck',
    'validWarn'
  ])
  const result = {
    current: params.current || 1,
    pageSize: params.pageSize || params.size || 20,
    orderBy: normalizeText(params.orderBy) || 'create_time desc'
  }
 
  Array.from(allowKeys).forEach((key) => {
    const value = params[key]
    if (value === undefined || value === null || value === '') {
      return
    }
    if (typeof value === 'string') {
      const trimmed = normalizeText(value)
      if (trimmed) {
        result[key] = trimmed
      }
      return
    }
    result[key] = value
  })
 
  Object.entries(params).forEach(([key, value]) => {
    if (['current', 'pageSize', 'size', 'orderBy'].includes(key) || allowKeys.has(key)) {
      return
    }
    if (value === undefined || value === null || value === '') {
      return
    }
    if (typeof value === 'string') {
      const trimmed = normalizeText(value)
      if (trimmed) {
        result[key] = trimmed
      }
      return
    }
    if (Array.isArray(value)) {
      if (value.length) {
        result[key] = value
      }
      return
    }
    result[key] = value
  })
 
  return result
}
 
function normalizeGroupTreeParams(params = {}) {
  return {
    condition: normalizeText(params.condition)
  }
}
 
export function fetchMatnrPage(params = {}) {
  return request.post({
    url: '/matnr/page',
    params: normalizeQueryParams(params)
  })
}
 
export function fetchMatnrDetail(id) {
  return request.get({ url: `/matnr/${id}` })
}
 
export function fetchGetMatnrMany(ids) {
  return request.post({ url: `/matnr/many/${normalizeIds(ids)}` })
}
 
export function fetchEnabledFields() {
  return request.get({ url: '/fields/enable/list' })
}
 
export function fetchSaveMatnr(params = {}) {
  return request.post({ url: '/matnr/save', params })
}
 
export function fetchUpdateMatnr(params = {}) {
  return request.post({ url: '/matnr/update', params })
}
 
export function fetchDeleteMatnr(ids) {
  return request.post({ url: `/matnr/remove/${normalizeIds(ids)}` })
}
 
export function fetchBindMatnrGroup(payload = {}) {
  return request.post({
    url: '/matnr/group/bind',
    params: {
      ids: normalizeIdList(payload.ids),
      ...(payload.groupId !== undefined && payload.groupId !== null && payload.groupId !== ''
        ? { groupId: Number(payload.groupId) }
        : {})
    }
  })
}
 
export function fetchBatchUpdateMatnr(payload = {}) {
  const matnr = payload.matnr && typeof payload.matnr === 'object' ? payload.matnr : {}
  return request.post({
    url: '/matnr/batch/update',
    params: {
      ids: normalizeIdList(payload.ids),
      matnr: Object.fromEntries(
        Object.entries(matnr).filter(
          ([, value]) => value !== undefined && value !== null && value !== ''
        )
      )
    }
  })
}
 
export function fetchMatnrGroupTree(params = {}) {
  return request.post({
    url: '/matnrGroup/tree',
    params: normalizeGroupTreeParams(params)
  })
}
 
export async function fetchExportMatnrReport(payload = {}, options = {}) {
  return fetch(`${import.meta.env.VITE_API_URL}/matnr/export`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      ...(options.headers || {})
    },
    body: JSON.stringify(payload)
  })
}
 
export async function fetchDownloadMatnrTemplate(payload = {}, options = {}) {
  return fetch(`${import.meta.env.VITE_API_URL}/matnr/template/download`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      ...(options.headers || {})
    },
    body: JSON.stringify(payload)
  })
}
 
export function fetchImportMatnr(file) {
  const formData = new FormData()
  formData.append('file', file)
  return request.post({
    url: '/matnr/import',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}
 
export function fetchMatnrPrintTemplateList(params = {}) {
  return request.post({
    url: '/matnrPrintTemplate/list',
    params
  })
}
 
export function fetchGetMatnrPrintTemplateDetail(id) {
  return request.get({
    url: `/matnrPrintTemplate/${id}`
  })
}
 
export function fetchGetDefaultMatnrPrintTemplate() {
  return request.get({
    url: '/matnrPrintTemplate/default'
  })
}
 
export function fetchSaveMatnrPrintTemplate(params = {}) {
  return request.post({
    url: '/matnrPrintTemplate/save',
    params
  })
}
 
export function fetchUpdateMatnrPrintTemplate(params = {}) {
  return request.post({
    url: '/matnrPrintTemplate/update',
    params
  })
}
 
export function fetchRemoveMatnrPrintTemplate(ids) {
  return request.post({
    url: `/matnrPrintTemplate/remove/${normalizeIds(ids)}`
  })
}
 
export function fetchSetDefaultMatnrPrintTemplate(id) {
  return request.post({
    url: `/matnrPrintTemplate/default/${id}`
  })
}