orderListSceneMap.js
2.41 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
/**
* 场景行 → 订单列表子组件(与 orderList 中 components 注册名一致)
* 可按 baseSceneCode 增补映射;未知时按名称关键字或类目默认。
*/
export const BASE_SCENE_TAB_MAP = {
// 示例:NEW_CAR_DELIVERY: "Order",
}
function pickLightTabName(scene) {
const code = (scene && scene.baseSceneCode) ? String(scene.baseSceneCode).trim() : ""
if (code && BASE_SCENE_TAB_MAP[code]) {
return BASE_SCENE_TAB_MAP[code]
}
const text = `${scene?.name || ""}${scene?.subTypeName || ""}`
if (/众筹/.test(text)) return "CrowdFunding"
if (/次新车|升配/.test(text)) return "configUpgradation"
return "Order"
}
/**
* @param {object} scene - 接口返回的场景
* @param {'light'|'rights'|'renewal'} category
* @param {{ sceneBusinessTypeGroup?: number }} options - 权益拉列表时传入 1 / 2
*/
export function resolveSceneTabName(scene, category, options = {}) {
if (category === "renewal") return "integralShopping"
if (category === "rights") return "carDamage"
if (category === "light") return pickLightTabName(scene)
return "Order"
}
function stableSceneId(category, scene, businessTypeGroup) {
const base = scene?.id ?? scene?.baseSceneCode ?? scene?.num ?? "x"
const btSeg =
businessTypeGroup != null && businessTypeGroup !== ""
? `${businessTypeGroup}-`
: ""
return `${category}-${btSeg}${base}`
}
/**
* @returns {{ id: string, label: string, tabName: string, baseSceneCode?: string, sceneBusinessType?: number, raw?: object }}
*/
export function buildSceneLeafItem(scene, category, options = {}) {
const tabName = resolveSceneTabName(scene, category, options)
const btFromRow = scene?.businessType
const bt =
options.sceneBusinessTypeGroup != null
? Number(options.sceneBusinessTypeGroup)
: btFromRow != null && btFromRow !== ""
? Number(btFromRow)
: undefined
const id = stableSceneId(category, scene, options.sceneBusinessTypeGroup)
const label = scene?.name || scene?.subTypeName || scene?.num || "场景"
return {
id,
label,
tabName,
baseSceneCode: scene?.baseSceneCode || "",
sceneBusinessType: Number.isNaN(bt) ? undefined : bt,
raw: scene,
}
}
export function normalizeSceneResponse(res) {
if (Array.isArray(res)) return res
if (res?.list && Array.isArray(res.list)) return res.list
if (res?.data && Array.isArray(res.data)) return res.data
if (res?.records && Array.isArray(res.records)) return res.records
return []
}