zhou zhou
昨天 d4e039545c9e97347223eb415fbba85ee01bc263
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
import request from '@/utils/http'
 
function normalizeText(value) {
  return typeof value === 'string' ? value.trim() : value
}
 
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 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()
}
 
export function buildTransferSearchParams(params = {}) {
  const result = {}
  ;[
    'condition',
    'code',
    'orgWareName',
    'tarWareName',
    'orgAreaName',
    'tarAreaName',
    'memo',
    'timeStart',
    'timeEnd',
    'orderBy'
  ].forEach((key) => {
    const value = normalizeText(params[key])
    if (value) result[key] = value
  })
  ;[
    'type',
    'source',
    'exceStatus',
    'status',
    'orgWareId',
    'tarWareId',
    'orgAreaId',
    'tarAreaId'
  ].forEach((key) => {
    if (params[key] !== '' && params[key] !== undefined && params[key] !== null) {
      result[key] = normalizeNumber(params[key])
    }
  })
  return result
}
 
export function buildTransferPageParams(params = {}) {
  return {
    current: params.current || 1,
    pageSize: params.pageSize || params.size || 20,
    orderBy: normalizeText(params.orderBy) || 'create_time desc',
    ...buildTransferSearchParams(params)
  }
}
 
export function buildTransferLocsItemPageParams(params = {}) {
  return {
    orgAreaId: normalizeNumber(params.orgAreaId, void 0),
    matnrCode: normalizeText(params.matnrCode || params.code || ''),
    maktx: normalizeText(params.maktx || params.name || ''),
    current: params.current || 1,
    pageSize: params.pageSize || params.size || 20
  }
}
 
export function buildTransferOrderPageParams(params = {}) {
  return {
    ...(normalizeNumber(params.id, void 0) !== void 0
      ? { id: normalizeNumber(params.id, void 0) }
      : {}),
    condition: normalizeText(params.code || params.condition),
    code: normalizeText(params.code || params.condition),
    current: params.current || 1,
    pageSize: params.pageSize || params.size || 20,
    orderBy: normalizeText(params.orderBy) || 'create_time desc'
  }
}
 
export function buildTransferSavePayload(formData = {}, areaOptions = []) {
  const optionMap = new Map(
    (Array.isArray(areaOptions) ? areaOptions : [])
      .map((item) => {
        const value = normalizeNumber(item?.value ?? item?.id, void 0)
        if (value === void 0) return null
        return [value, item?.raw || item]
      })
      .filter(Boolean)
  )
 
  const orgAreaId = normalizeNumber(formData.orgAreaId, void 0)
  const tarAreaId = normalizeNumber(formData.tarAreaId, void 0)
  const orgArea = optionMap.get(orgAreaId) || {}
  const tarArea = optionMap.get(tarAreaId) || {}
  const orgWareId = normalizeNumber(
    orgArea.warehouseId ?? orgArea.warehouse_id ?? orgArea.warehouseIdValue,
    void 0
  )
  const tarWareId = normalizeNumber(
    tarArea.warehouseId ?? tarArea.warehouse_id ?? tarArea.warehouseIdValue,
    void 0
  )
 
  return {
    ...(formData.id !== undefined && formData.id !== null && formData.id !== ''
      ? { id: normalizeNumber(formData.id) }
      : {}),
    ...(normalizeText(formData.code) ? { code: normalizeText(formData.code) } : {}),
    ...(formData.type !== undefined && formData.type !== null && formData.type !== ''
      ? { type: normalizeNumber(formData.type) }
      : {}),
    ...(orgAreaId !== void 0 ? { orgAreaId } : {}),
    ...(tarAreaId !== void 0 ? { tarAreaId } : {}),
    ...(orgWareId !== void 0 ? { orgWareId } : {}),
    ...(tarWareId !== void 0 ? { tarWareId } : {}),
    ...(normalizeText(orgArea.name || orgArea.areaName)
      ? { orgAreaName: normalizeText(orgArea.name || orgArea.areaName) }
      : {}),
    ...(normalizeText(tarArea.name || tarArea.areaName)
      ? { tarAreaName: normalizeText(tarArea.name || tarArea.areaName) }
      : {}),
    ...(normalizeText(orgArea.warehouseId$ || orgArea.warehouseName)
      ? { orgWareName: normalizeText(orgArea.warehouseId$ || orgArea.warehouseName) }
      : {}),
    ...(normalizeText(tarArea.warehouseId$ || tarArea.warehouseName)
      ? { tarWareName: normalizeText(tarArea.warehouseId$ || tarArea.warehouseName) }
      : {}),
    ...(formData.status !== undefined && formData.status !== null && formData.status !== ''
      ? { status: normalizeNumber(formData.status) }
      : { status: 1 }),
    memo: normalizeText(formData.memo) || ''
  }
}
 
export function fetchTransferPage(params = {}) {
  return request.post({ url: '/transfer/page', params: buildTransferPageParams(params) })
}
 
export function fetchTransferDetail(id) {
  return request.get({ url: `/transfer/${id}` })
}
 
export function fetchTransferMany(ids) {
  return request.post({ url: `/transfer/many/${normalizeIds(ids)}` })
}
 
export function fetchDeleteTransfer(ids) {
  return request.post({ url: `/transfer/remove/${normalizeIds(ids)}` })
}
 
export function fetchSaveTransfer(payload = {}) {
  return request.post({ url: '/transfer/save', params: payload })
}
 
export function fetchUpdateTransfer(payload = {}) {
  return request.post({ url: '/transfer/update', params: payload })
}
 
export function fetchSaveTransferItems(payload = {}) {
  return request.post({ url: '/transfer/items/save', params: payload })
}
 
export function fetchUpdateTransferItems(payload = {}) {
  return request.post({ url: '/transfer/items/update', params: payload })
}
 
export function fetchTransferOrdersPage(params = {}) {
  return request.post({
    url: '/transfer/orders/page',
    params: buildTransferOrderPageParams(params)
  })
}
 
export function fetchTransferLocsItemsPage(params = {}) {
  return request.post({
    url: '/transfer/locs/items',
    params: buildTransferLocsItemPageParams(params)
  })
}
 
export function fetchTransferPubOutStock(payload = {}) {
  return request.post({ url: '/transfer/pub/outStock', params: payload })
}
 
export function fetchEnabledTransferFields() {
  return request.get({ url: '/fields/enable/list' })
}
 
export async function fetchExportTransferReport(payload = {}, options = {}) {
  return fetch(`${import.meta.env.VITE_API_URL}/transfer/export`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      ...(options.headers || {})
    },
    body: JSON.stringify(payload)
  })
}