zhou zhou
1 天以前 aaf8a50511d77dbc209ca93bbba308c21179a8bc
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
import request from '@/utils/http'
 
function normalizeText(value) {
  return typeof value === 'string' ? value.trim() : value
}
 
function normalizeNumber(value) {
  if (value === '' || value === null || value === undefined) {
    return void 0
  }
  const normalized = Number(value)
  return Number.isNaN(normalized) ? void 0 : normalized
}
 
function normalizeIds(ids) {
  if (Array.isArray(ids)) {
    return ids
      .map((id) => String(id).trim())
      .filter(Boolean)
      .join(',')
  }
  if (ids === null || ids === undefined) {
    return ''
  }
  return String(ids).trim()
}
 
function filterParams(params = {}, ignoredKeys = []) {
  return Object.fromEntries(
    Object.entries(params)
      .filter(([key, value]) => {
        if (ignoredKeys.includes(key)) return false
        if (value === undefined || value === null) return false
        if (typeof value === 'string' && value.trim() === '') return false
        return true
      })
      .map(([key, value]) => [key, typeof value === 'string' ? value.trim() : value])
  )
}
 
export function buildMatnrGroupPageParams(params = {}) {
  return {
    current: params.current || 1,
    pageSize: params.pageSize || params.size || 20,
    ...filterParams(params, ['current', 'pageSize', 'size'])
  }
}
 
export function buildMatnrGroupSearchParams(params = {}) {
  const searchParams = {
    condition: normalizeText(params.condition),
    code: normalizeText(params.code),
    name: normalizeText(params.name),
    parCode: normalizeText(params.parCode),
    memo: normalizeText(params.memo),
    sort: normalizeNumber(params.sort),
    status: normalizeNumber(params.status),
    parentId: normalizeNumber(params.parentId)
  }
 
  return Object.fromEntries(
    Object.entries(searchParams).filter(([, value]) => value !== '' && value !== void 0 && value !== null)
  )
}
 
export function buildMatnrGroupSavePayload(params = {}) {
  return {
    ...(params.id !== undefined && params.id !== null && params.id !== ''
      ? { id: Number(params.id) }
      : {}),
    parentId:
      params.parentId !== undefined && params.parentId !== null && params.parentId !== ''
        ? Number(params.parentId)
        : 0,
    parCode: normalizeText(params.parCode) || '',
    code: normalizeText(params.code) || '',
    name: normalizeText(params.name) || '',
    sort:
      params.sort !== undefined && params.sort !== null && params.sort !== ''
        ? Number(params.sort)
        : 0,
    status:
      params.status !== undefined && params.status !== null && params.status !== ''
        ? Number(params.status)
        : 1,
    memo: normalizeText(params.memo) || ''
  }
}
 
export function fetchMatnrGroupPage(params = {}) {
  return request.post({
    url: '/matnrGroup/page',
    params: buildMatnrGroupPageParams(params)
  })
}
 
export function fetchGetMatnrGroupDetail(id) {
  return request.get({
    url: `/matnrGroup/${id}`
  })
}
 
export function fetchGetMatnrGroupMany(ids) {
  return request.post({
    url: `/matnrGroup/many/${normalizeIds(ids)}`
  })
}
 
export function fetchSaveMatnrGroup(params = {}) {
  return request.post({
    url: '/matnrGroup/save',
    params: buildMatnrGroupSavePayload(params)
  })
}
 
export function fetchUpdateMatnrGroup(params = {}) {
  return request.post({
    url: '/matnrGroup/update',
    params: buildMatnrGroupSavePayload(params)
  })
}
 
export function fetchDeleteMatnrGroup(ids) {
  return request.post({
    url: `/matnrGroup/remove/${normalizeIds(ids)}`
  })
}
 
export function fetchMatnrGroupQuery(condition = '') {
  return request.post({
    url: '/matnrGroup/query',
    params: { condition: normalizeText(condition) }
  })
}
 
export function fetchMatnrGroupTree(params = {}) {
  return request.post({
    url: '/matnrGroup/tree',
    params: {
      condition: normalizeText(params.condition)
    }
  })
}
 
export async function fetchExportMatnrGroupReport(payload = {}, options = {}) {
  return fetch(`${import.meta.env.VITE_API_URL}/matnrGroup/export`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      ...(options.headers || {})
    },
    body: JSON.stringify(payload)
  })
}