orderList.vue
11 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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
<template>
<div class="order-list-wrap">
<div class="header" style="background: #e7eaec">
<el-tabs v-model="activeCategory" @tab-click="onCategoryTabClick">
<el-tab-pane label="轻改类" name="light" />
<el-tab-pane label="权益类" name="rights" />
<el-tab-pane label="续保积分" name="renewal" />
</el-tabs>
<div v-loading="scenesLoading" class="sub-nav">
<el-radio-group
v-model="activeLeaf"
size="small"
@change="onSubLeafChange"
>
<el-radio-button
v-for="s in currentSubList"
:key="s.id"
:label="s.id"
>{{ s.label }}</el-radio-button>
</el-radio-group>
</div>
<component
:is="tabName"
:key="leafComponentKey"
v-bind="childExtraProps"
/>
</div>
</div>
</template>
<script>
import Order from "./order.vue"
import CrowdFunding from "./crowdfunding.vue"
import carDamage from "./carDamage.vue"
import configUpgradation from "./configUpgradation.vue"
import integralShopping from "./integralShopping.vue"
import { sceneListWithOrder } from "@/api/order"
import {
buildSceneLeafItem,
normalizeSceneResponse
} from "./orderListSceneMap.js"
import { shouldReapplyRouteParams } from "./utils/orderListRouteGuard.js"
import { computeRouteParamPatch } from "./utils/orderListRouteParams.js"
/** 接口失败或无数据时的二级兜底(与原先静态一致) */
const FALLBACK_LIGHT = [
{
id: "l-1-1",
label: "1.1 轻改精品升级",
tabName: "Order",
baseSceneCode: "",
sceneBusinessType: undefined
},
{
id: "l-1-2",
label: "1.2 轻改次新车升配",
tabName: "configUpgradation",
baseSceneCode: "",
sceneBusinessType: undefined
},
{
id: "l-1-3",
label: "1.3 轻改售后众筹",
tabName: "CrowdFunding",
baseSceneCode: "",
sceneBusinessType: undefined
}
]
const FALLBACK_RIGHTS = [
{
id: "l-2-1",
label: "2.1 会员权益升级",
tabName: "carDamage",
baseSceneCode: "",
sceneBusinessType: 1
},
{
id: "l-2-3",
label: "2.3 延保",
tabName: "carDamage",
baseSceneCode: "",
sceneBusinessType: 2
}
]
const RENEWAL_SUB = [
{
id: "l-3-1",
label: "积分商城",
tabName: "integralShopping",
baseSceneCode: "",
sceneBusinessType: undefined
}
]
/** 旧路由 leaf -> 匹配子项用的规则 */
const LEGACY_LEAF_MATCH = {
"l-1-1": { tabName: "Order" },
"l-1-2": { tabName: "configUpgradation" },
"l-1-3": { tabName: "CrowdFunding" },
"l-2-1": { tabName: "carDamage", sceneBusinessType: 1 },
"l-2-3": { tabName: "carDamage", sceneBusinessType: 2 },
"l-3-1": { tabName: "integralShopping" }
}
export default {
// 需与路由 name 一致,d2admin keep-alive include 按路由名匹配
name: "orderList",
components: {
Order,
CrowdFunding,
carDamage,
configUpgradation,
integralShopping
},
data() {
return {
activeCategory: "light",
activeLeaf: "",
rightsFromLegacyTab4: false,
isApplyingRoute: false,
scenesLoading: false,
/** 权益类场景由子页 d2-search 下拉里选择;此处只拉取列表数据传入 carDamage */
rightsScenesLoading: false,
rightsScenesForEquity: [],
rightsScenesForWarranty: [],
sceneSubs: {
light: []
},
/** 路由带入:匹配完成后清空 */
pendingLegacyLeaf: null
}
},
computed: {
/** 权益类二级固定为 2.1 / 2.3,不用接口行替换 */
currentSubList() {
if (this.activeCategory === "renewal") {
return RENEWAL_SUB
}
if (this.activeCategory === "rights") {
return FALLBACK_RIGHTS
}
const list = this.sceneSubs[this.activeCategory]
return Array.isArray(list) ? list : []
},
/** 传给 carDamage 搜索区「场景」下拉的 options(2.1=权益 2.3=延保) */
rightsSceneListForSearch() {
let raw = []
if (this.activeLeaf === "l-2-1") {
raw = this.rightsScenesForEquity
} else if (this.activeLeaf === "l-2-3") {
raw = this.rightsScenesForWarranty
}
return (raw || []).filter(
(o) => o && String(o.baseSceneCode || "").trim() !== ""
)
},
tabName() {
const item = this.currentSubList.find(s => s.id === this.activeLeaf)
return item?.tabName || "Order"
},
/** 切换场景时强制子组件重建(除仅改 query 外) */
leafComponentKey() {
const item = this.currentSubList.find(s => s.id === this.activeLeaf)
// 权益类:场景在子页 search 中切换,不纳入 key,避免改下拉就整表重建
const scenePart =
this.activeCategory === "rights" ? "" : (item?.baseSceneCode || "")
const parts = [
this.activeLeaf,
scenePart,
item?.sceneBusinessType != null ? String(item.sceneBusinessType) : ""
]
return parts.join("|")
},
carDamageRightsNavPreset() {
if (this.tabName !== "carDamage") return null
const item = this.currentSubList.find(s => s.id === this.activeLeaf)
if (item?.sceneBusinessType !== undefined && item.sceneBusinessType !== "") {
const bt = Number(item.sceneBusinessType)
if (bt === 2) return "extended"
if (bt === 1) {
return this.rightsFromLegacyTab4 ? "all" : "equity"
}
}
if (this.activeLeaf === "l-2-3") return "extended"
if (this.activeLeaf === "l-2-1") {
return this.rightsFromLegacyTab4 ? "all" : "equity"
}
return "all"
},
childExtraProps() {
const item = this.currentSubList.find(s => s.id === this.activeLeaf)
const base = {}
if (this.activeCategory === "rights" && this.tabName === "carDamage") {
base.rightsSceneListForSearch = this.rightsSceneListForSearch
base.rightsScenesSearchLoading = this.rightsScenesLoading
if (item?.sceneBusinessType !== undefined && item.sceneBusinessType !== "") {
base.sceneBusinessType = Number(item.sceneBusinessType)
}
} else if (item?.baseSceneCode) {
base.baseSceneCode = item.baseSceneCode
if (item?.sceneBusinessType !== undefined && item.sceneBusinessType !== "") {
base.sceneBusinessType = Number(item.sceneBusinessType)
}
}
if (this.tabName === "carDamage" && this.carDamageRightsNavPreset) {
base.rightsNavPreset = this.carDamageRightsNavPreset
}
const { customerName, customerPhone } = this.$route.query
if (customerName || customerPhone) {
base.customerFilter = {
customerName: customerName || "",
customerPhone: customerPhone || "",
}
}
return base
}
},
watch: {
$route: {
async handler(to, from) {
if (!shouldReapplyRouteParams(to, from)) {
return
}
this.applyRouteParams(to.params)
await this.loadScenesForCategory(this.activeCategory)
this.pickLeafAfterLoad()
}
}
},
async mounted() {
this.applyRouteParams(this.$route.params)
await this.loadScenesForCategory(this.activeCategory)
this.pickLeafAfterLoad()
},
methods: {
matchLegacyLeafId(leafKey) {
const rule = LEGACY_LEAF_MATCH[leafKey]
if (!rule) return null
const subs = this.currentSubList
const found = subs.find((s) => {
if (s.tabName !== rule.tabName) return false
if (rule.sceneBusinessType != null) {
return Number(s.sceneBusinessType) === Number(rule.sceneBusinessType)
}
return true
})
return found?.id || null
},
pickLeafAfterLoad() {
const subs = this.currentSubList
if (!subs.length) return
if (this.pendingLegacyLeaf) {
const id =
this.matchLegacyLeafId(this.pendingLegacyLeaf) || subs[0].id
this.activeLeaf = id
this.pendingLegacyLeaf = null
return
}
if (!subs.some(s => s.id === this.activeLeaf)) {
this.activeLeaf = subs[0].id
}
if (!this.activeLeaf) {
this.activeLeaf = subs[0].id
}
},
async loadScenesForCategory(category) {
if (category === "renewal") {
return
}
this.scenesLoading = category === "light"
this.rightsScenesLoading = category === "rights"
try {
if (category === "light") {
const res = await sceneListWithOrder({ bizTypeCode: "1" })
const arr = normalizeSceneResponse(res)
const mapped = arr.map(s => buildSceneLeafItem(s, "light"))
this.sceneSubs.light = mapped.length ? mapped : [...FALLBACK_LIGHT]
} else if (category === "rights") {
const [res1, res2] = await Promise.all([
sceneListWithOrder({ bizTypeCode: "2", businessType: 1 }),
sceneListWithOrder({ bizTypeCode: "2", businessType: 2 })
])
this.rightsScenesForEquity = normalizeSceneResponse(res1)
this.rightsScenesForWarranty = normalizeSceneResponse(res2)
}
} catch (e) {
if (category === "light") {
this.sceneSubs.light = [...FALLBACK_LIGHT]
} else {
this.rightsScenesForEquity = []
this.rightsScenesForWarranty = []
}
} finally {
this.scenesLoading = false
this.rightsScenesLoading = false
}
},
ensureLeafInCategory() {
const subs = this.currentSubList
if (subs.length && !subs.some(s => s.id === this.activeLeaf)) {
this.activeLeaf = subs[0].id
}
},
async onCategoryTabClick() {
await this.loadScenesForCategory(this.activeCategory)
this.$nextTick(() => {
this.ensureLeafInCategory()
if (!this.activeLeaf && this.currentSubList.length) {
this.activeLeaf = this.currentSubList[0].id
}
})
},
onSubLeafChange() {
if (this.isApplyingRoute) return
this.rightsFromLegacyTab4 = false
},
applyRouteParams(params) {
const patch = computeRouteParamPatch(params)
if (!patch) {
return
}
this.activeCategory = patch.activeCategory
this.pendingLegacyLeaf = patch.pendingLegacyLeaf
this.rightsFromLegacyTab4 = patch.rightsFromLegacyTab4
this.isApplyingRoute = patch.isApplyingRoute
this.$nextTick(() => {
this.isApplyingRoute = false
})
}
}
}
</script>
<style lang="scss" scoped>
.order-list-wrap {
padding: 0px 24px 0 20px;
.header {
::v-deep .el-tabs__header {
margin: 0;
padding: 0 20px;
}
/* 只保留一级 tab 的头部,不展示空内容区;列表下移由各子页 m-t-94 与原先 m-t-40 同逻辑 */
::v-deep .el-tabs__content {
display: none;
}
}
.sub-nav {
margin: 0;
padding: 12px 20px 16px;
border-top: none;
background: #fff;
::v-deep .el-radio-button {
margin-right: 8px;
}
::v-deep .el-radio-button__inner {
border-radius: 4px;
}
::v-deep .el-radio-button:not(:first-child):not(.is-active) .el-radio-button__inner {
border-left: 1px solid #dcdfe6;
}
}
}
</style>