fieldOptionProviders.js
5.13 KB
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
/**
* 字段选项 HTTP 封装 — 在职员工列表等
* @see packageDynamicForm/docs/field-options-api.md
*
* fetchStoreStaffListOptions:api.getEmployeeList,仅传 merchantId(不传 sceneList)
* 驻店由 adapter 传入 yqMerchantId;门店/洽谈 storeStaffList 同;4sStaffList 传 4S shopMerchantId
*/
const {
resolveBaseGoodsCodeList,
resolveCarBrandTypeFlag
} = require('../utils/order-list-params.js')
let employeeListApiModule = null
let orderListApiModule = null
/** 懒加载 getEmployeeList API 模块 */
function getEmployeeListApi() {
if (!employeeListApiModule) {
employeeListApiModule = require('../../api/api.js')
}
return employeeListApiModule
}
/** 测试注入:覆盖 getEmployeeList API 模块 */
function __setEmployeeListApi(api) {
employeeListApiModule = api
}
/** 懒加载订单列表 API 模块(与 getEmployeeList 同走 api/api.js) */
function getOrderListApi() {
if (!orderListApiModule) {
orderListApiModule = require('../../api/api.js')
}
return orderListApiModule
}
/** 测试注入:覆盖订单列表 API 模块 */
function __setOrderListApi(api) {
orderListApiModule = api
}
/**
* 将员工列表映射为 { label, value } 选项
* @param {Array} [list=[]] getEmployeeList 返回的数据
* @returns {Array<{label: string, value: string}>}
*/
function mapEmployeeListToOptions(list = []) {
if (!Array.isArray(list)) {
return []
}
return list
.map(item => {
const value = item?.uuid ?? item?.staffUuid ?? item?.userId ?? ''
const label = item?.staffName ?? item?.name ?? item?.employeeName ?? ''
const phone = item?.phone ?? item?.mobile ?? item?.staffPhone ?? ''
if (value === '' || label === '') {
return null
}
const option = {
label: String(label),
value: String(value),
id: String(value),
name: String(label)
}
if (phone !== '') {
option.phone = String(phone)
}
return option
})
.filter(Boolean)
}
/**
* 拉取在职员工选项(onTheJob.getByMerchantId)
* @param {Object} [options={}]
* @param {string|number} options.merchantId 商户 ID(驻店为园区店,门店/洽谈为 4S 店)
* @param {string} [options.name] 员工姓名关键词(对齐 Merchant-Seles getEmployeeList)
* @returns {Promise<{code: number, message: string, data: Array}>}
*/
async function fetchStoreStaffListOptions({ merchantId, name } = {}) {
if (!merchantId) {
return { code: -1, message: '缺少门店信息', data: [] }
}
const params = { merchantId }
if (name) {
params.name = name
}
const result = await getEmployeeListApi().getEmployeeList(params)
const code = result?.code ?? -1
if (code != 0) {
return {
code: code ?? -1,
message: result?.message || '获取驻店人员失败',
data: []
}
}
return {
code: 0,
message: 'ok',
data: mapEmployeeListToOptions(result?.data)
}
}
/**
* 将订单列表映射为 { label, value } 选项
* @param {Array} [list=[]]
* @returns {Array<{label: string, value: string}>}
*/
function mapOrderListToOptions(list = []) {
if (!Array.isArray(list)) {
return []
}
return list
.map(item => {
const value = item?.orderCode ?? item?.value ?? ''
const label =
item?.orderCode != null && item?.orderCode !== ''
? String(item.orderCode)
: item?.productName ?? item?.label ?? ''
if (value === '' || label === '') {
return null
}
return {
label: String(label),
value: String(value),
id: String(value),
name: String(label),
raw: item
}
})
.filter(Boolean)
}
/**
* 拉取洽谈订单选项(goodsOrder.product.outputValue.list)
* @param {Object} [options={}]
* @param {string|number} options.merchantId 4S 门店 ID
* @param {string} [options.staffUuid] 当前员工 UUID(sellerUserId)
* @param {string} [options.reportDate] 保留供 adapter 透传,不参与 saleDate 组装
* @param {string} [options.saleDate] 行内成交日期 F3-*-12(与 App 一致,无 reportDate 兜底)
* @param {Array} [options.sceneList] 门店 sceneList → baseGoodsCodeList
* @param {string} [options.carBrandTypeFlag] field.reqParams 字面量(优先)
* @param {Array} [options.groupBrandIds] 兜底推导 carBrandTypeFlag
* @returns {Promise<{code: number, message: string, data: Array}>}
*/
async function fetchOrderListOptions({
merchantId,
staffUuid,
reportDate,
saleDate,
sceneList,
carBrandTypeFlag,
groupBrandIds
} = {}) {
if (!merchantId) {
return { code: -1, message: '缺少门店信息', data: [] }
}
const params = {
merchantId,
sellerUserId: staffUuid || '',
// baseGoodsCodeList: resolveBaseGoodsCodeList(sceneList),
carBrandTypeFlag: carBrandTypeFlag ?? resolveCarBrandTypeFlag(groupBrandIds),
saleDate: saleDate || ''
}
const result = await getOrderListApi().getGoodsOrderOutputValueList(params)
const code = result?.code ?? -1
if (code != 0) {
return {
code: code ?? -1,
message: result?.message || '获取订单列表失败',
data: []
}
}
return {
code: 0,
message: 'ok',
data: mapOrderListToOptions(result?.data)
}
}
module.exports = {
mapEmployeeListToOptions,
mapOrderListToOptions,
fetchStoreStaffListOptions,
fetchOrderListOptions,
__setEmployeeListApi,
__setOrderListApi
}