merchantDetailMap.js
9.67 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
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
import NP from "number-precision";
/** 详情/历史接口人员 ID、姓名字段大小写不一致时的兜底读取 */
function pickStr(mi, ...keys) {
if (!mi || typeof mi !== "object") {
return "";
}
for (const k of keys) {
const v = mi[k];
if (v != null && String(v).trim() !== "") {
return String(v).trim();
}
}
return "";
}
function joinStaffIds(mi, listKey, ...idKeys) {
if (!mi || typeof mi !== "object") {
return "";
}
for (const idKey of idKeys) {
const str = mi[idKey];
if (str != null && str !== "") {
return String(str);
}
}
const list = mi[listKey];
if (Array.isArray(list) && list.length) {
return list.join(",");
}
return "";
}
/**
* 人员 uuid 列表:优先数组字段;否则从逗号或斜杠拼接的标量拆开(与 joinStaffIds / 上架保存 join('/') 一致)。
* listKeys / scalarKeys 可传多个别名(如 areaOpIdList / areaopIdList)。
*/
export function normalizeStaffIdListFromMi(mi, listKeys, scalarKeys) {
if (!mi || typeof mi !== "object") {
return [];
}
const lk = Array.isArray(listKeys) ? listKeys : [listKeys];
for (const key of lk) {
const rawList = mi[key];
if (Array.isArray(rawList) && rawList.length) {
return rawList.map(x => String(x).trim()).filter(Boolean);
}
}
const sk = Array.isArray(scalarKeys) ? scalarKeys : [scalarKeys];
for (const idKey of sk) {
const str = mi[idKey];
if (str != null && String(str).trim() !== "") {
return String(str)
.split(/[,/]+/)
.map(s => s.trim())
.filter(Boolean);
}
}
return [];
}
/** 场景列表接口可能返回 { list } 或裸数组,统一成数组 */
export function normalizeBaseSceneListResponse(res) {
if (Array.isArray(res)) {
return res;
}
if (res && typeof res === "object") {
const inner = res.list ?? res.records ?? res.data ?? res.rows ?? res.scenes;
if (Array.isArray(inner)) {
return inner;
}
}
return [];
}
/**
* 与 merchantManage.vue 列表 buildRelationRefPayload / parseFiniteSceneTypeFromRow 一致:
* 使用 getBaseSceneCodeList(normalizeBaseSceneListResponse)下发的项,
* 按 baseSceneCode 精确匹配取 sceneType;无效时返回 0。
*/
export function resolveSceneTypeFromBaseSceneFilterList(baseSceneCode, baseSceneList = []) {
if (baseSceneCode == null || baseSceneCode === "") {
return 0;
}
const codeStr = String(baseSceneCode).trim();
if (!codeStr) {
return 0;
}
const list = Array.isArray(baseSceneList) ? baseSceneList : [];
const hit = list.find(
item => item != null
&& String(item.baseSceneCode ?? "").trim() === codeStr,
) ?? null;
if (hit == null) {
return 0;
}
const v = hit.sceneType;
if (v === undefined || v === null || v === "") {
return 0;
}
const n = Number(v);
return Number.isFinite(n) ? n : 0;
}
function sceneRowMatchCodes(row) {
if (!row || typeof row !== "object") {
return [];
}
const keys = ["baseSceneCode", "sceneCode", "bizSceneCode", "code", "id", "sceneId"];
const out = [];
for (const k of keys) {
const v = row[k];
if (v != null && v !== "") {
out.push(String(v).trim());
}
}
return out;
}
/** 历史/详情里可能出现的场景编码字段(仅用于名称反查,不含 scene 大类枚举) */
export function pickSceneLookupCode(mi) {
if (!mi || typeof mi !== "object") {
return "";
}
const keys = ["baseSceneCode", "bizBaseSceneCode", "bizSceneCode", "sceneBizCode", "businessSceneCode"];
for (const k of keys) {
const v = mi[k];
if (v != null && v !== "") {
return v;
}
}
return "";
}
export function resolveSceneName(code, baseSceneList = []) {
if (code == null || code === "") {
return "";
}
const codeStr = String(code).trim();
if (!codeStr) {
return "";
}
const hit = baseSceneList.find(row => sceneRowMatchCodes(row).includes(codeStr));
if (hit) {
return hit.name ?? hit.sceneName ?? hit.label ?? hit.confLabel ?? codeStr;
}
return codeStr;
}
/**
* 仅当场景列表中存在对应 baseSceneCode(及相关别名字段)时返回展示名;未命中返回空串。
* 供头部「业务场景」等按 baseSceneCode 回显,避免无列表数据时把纯数字编码当作名称展示。
*/
export function getSceneDisplayNameFromList(code, baseSceneList = []) {
if (code == null || code === "") {
return "";
}
const codeStr = String(code).trim();
if (!codeStr) {
return "";
}
const hit = baseSceneList.find(row =>
sceneRowMatchCodes(row).includes(codeStr),
);
if (!hit) {
return "";
}
const n = hit.name ?? hit.sceneName ?? hit.label ?? hit.confLabel;
return n != null && String(n).trim() !== "" ? String(n).trim() : "";
}
/** 门店单台利润额:仅回显接口字段 storeProfitPerCar,不做推算 */
export function storeProfitPerCar(mi) {
if (!mi || typeof mi !== "object") {
return "";
}
const direct = mi.storeProfitPerCar;
if (direct == null || direct === "") {
return "";
}
const n = Number(direct);
if (!Number.isNaN(n)) {
return String(NP.round(n, 2));
}
return String(direct).trim();
}
/**
* 从详情/历史里的 otherServiceProviders(JSON 字符串或对象数组)解析多选 ID 与展示名。
* 元素结构约定:{ merchantNo, merchantName }(兼容 merchantId、name 等别名)
*/
export function parseOtherServiceProvidersFromMi(mi) {
const raw = mi?.otherServiceProviders;
if (raw == null || raw === "") {
return { ids: [], namesStr: "" };
}
let parsed = raw;
if (typeof raw === "string") {
try {
parsed = JSON.parse(raw);
} catch {
return { ids: [], namesStr: "" };
}
}
if (!Array.isArray(parsed)) {
return { ids: [], namesStr: "" };
}
const ids = [];
const names = [];
for (const item of parsed) {
if (item == null) {
continue;
}
if (typeof item === "number") {
if (!Number.isNaN(item)) {
ids.push(Number(item));
}
continue;
}
if (typeof item === "string") {
const n = Number(item);
if (!Number.isNaN(n)) {
ids.push(n);
}
continue;
}
if (typeof item === "object") {
const idRaw = item.merchantNo ?? item.merchantId ?? item.id ?? item.serviceProviderId;
const nameRaw = item.merchantName ?? item.name ?? "";
if (idRaw != null && idRaw !== "") {
const n = Number(idRaw);
if (!Number.isNaN(n)) {
ids.push(n);
}
}
if (nameRaw != null && String(nameRaw).trim() !== "") {
names.push(String(nameRaw).trim());
}
}
}
const namesStr = names.length ? names.join("/") : "";
return { ids, namesStr };
}
export function buildTrafficProviderData(mi, baseSceneList = []) {
const osp = parseOtherServiceProvidersFromMi(mi);
const nameFromMi = mi?.otherServiceProvidersName;
const areaOpIdListNorm = normalizeStaffIdListFromMi(mi, ["areaOpIdList", "areaopIdList"], ["areaOpId", "areaopId"]);
const onlineOpIdListNorm = normalizeStaffIdListFromMi(mi, ["onlineOpIdList", "onlineopIdList"], ["onlineOpId", "onlineopId"]);
const regionSupervisorIdListNorm = normalizeStaffIdListFromMi(mi, ["regionSupervisorIdList", "regionsupervisorIdList"], ["regionSupervisorId", "regionsupervisorId"]);
return {
trafficPartyName: mi.trafficPartyName || "",
parentName: mi.parentName || mi.parentMerchantName || "",
sceneTypeName: mi.sceneTypeName || mi.baseSceneName || resolveSceneName(pickSceneLookupCode(mi), baseSceneList) || "",
signingEntityId: mi.signingEntityId != null ? Number(mi.signingEntityId) : null,
signingEntity: mi.signingEntity || mi.signingEntityName || "",
businessMode: mi.businessMode != null ? Number(mi.businessMode) : null,
operationMode: mi.operationMode != null ? Number(mi.operationMode) : null,
serviceMerchant2fId: mi.serviceMerchant2fId != null ? Number(mi.serviceMerchant2fId) : null,
serviceMerchant2fName: mi.serviceMerchant2fName || "",
partnerId: mi.partnerId != null ? Number(mi.partnerId) : (mi.serviceProviderId != null ? Number(mi.serviceProviderId) : null),
partnerName: mi.partnerName || mi.serviceProviderName || "",
parentServiceMerchantName: mi.parentServiceMerchantName || "",
yqMerchantId: mi.yqMerchantId != null ? Number(mi.yqMerchantId) : (mi.parkingStoreId != null ? Number(mi.parkingStoreId) : null),
yqMerchantName: mi.yqMerchantName || mi.parkingStoreName || "",
areaOpIdList: areaOpIdListNorm,
onlineOpIdList: onlineOpIdListNorm,
regionSupervisorIdList: regionSupervisorIdListNorm,
areaOpId: areaOpIdListNorm.length ? areaOpIdListNorm.join(",") : joinStaffIds(mi, "areaOpIdList", "areaOpId", "areaopId"),
onlineOpId: onlineOpIdListNorm.length ? onlineOpIdListNorm.join(",") : joinStaffIds(mi, "onlineOpIdList", "onlineOpId", "onlineopId"),
regionSupervisorId: regionSupervisorIdListNorm.length ? regionSupervisorIdListNorm.join(",") : joinStaffIds(mi, "regionSupervisorIdList", "regionSupervisorId", "regionsupervisorId"),
areaOpName: pickStr(mi, "areaOpName", "areaopName"),
onlineOpName: pickStr(mi, "onlineOpName", "onlineopName"),
regionSupervisorName: pickStr(mi, "regionSupervisorName", "regionsupervisorName"),
otherServiceProvidersIdList: osp.ids,
otherServiceProvidersName:
nameFromMi != null && String(nameFromMi).trim() !== ""
? String(nameFromMi).trim()
: osp.namesStr,
estimatedDeliveryCountPerMonth: mi.estimatedDeliveryCountPerMonth,
personnelCostRate: mi.personnelCostRate,
renovationEquipmentCost: mi.renovationEquipmentCost,
estimatedGrossMargin: mi.estimatedGrossMargin,
hasGuarantee: mi.hasGuarantee,
monthlySettlementDate: mi.monthlySettlementDate,
otherCostPerMonth: mi.otherCostPerMonth,
// 兜底条件列表
guaranteeList: Array.isArray(mi.guaranteeList) ? mi.guaranteeList : [],
};
}
export function buildBusinessForm(mi) {
return {
deliveryCount: mi.deliveryCount,
customerTouchRate: mi.customerTouchRate,
personnelCost: mi.personnelCost,
rentCost: mi.rentCost,
depreciationCost: mi.depreciationCost,
otherCost: mi.otherCost,
storeProfitPerCar: storeProfitPerCar(mi),
};
}