zhou zhou
13 小时以前 a49845f424ae5b1e43e391837a55c43ce07ea62d
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
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'].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,
    ...buildTransferSearchParams(params)
  }
}
 
export function buildTransferOrderPageParams(params = {}) {
  return {
    condition: normalizeText(params.code || params.condition),
    code: normalizeText(params.code || params.condition),
    current: params.current || 1,
    pageSize: params.pageSize || params.size || 20
  }
}
 
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 fetchTransferOrdersPage(params = {}) {
  return request.post({ url: '/transfer/orders/page', params: buildTransferOrderPageParams(params) })
}
 
export function fetchTransferPubOutStock(payload = {}) {
  return request.post({ url: '/transfer/pub/outStock', params: payload })
}
 
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)
  })
}