Commit 23e6a946 by Lin

重构(ActivityTime):简化汽车模型标签处理并移除未使用的常量

- 移除了虚拟的“全部车型”标签,并调整了车型标签逻辑,直接使用API数据。
- 优化了所选车型和商品列表的处理方式,以简化数据管理。
- 确保在数据更新时默认选择能够正确重置。
1 parent 267bbcf0
......@@ -21,7 +21,7 @@
<view class="car-list-inner">
<view
v-for="(item, index) in carModelTabs"
:key="item.carSeriesId || 'all'"
:key="item.carSeriesId"
:class="['car-item', { active: carModelIndex === index }]"
@click="handleCarModelClick(index)"
>
......@@ -81,12 +81,6 @@ import Entrance from '@/components/Entrance.vue'
const GOODS_COVER = require('@/assets/images/common/goods-activity-cover.png')
/** 前端虚拟 Tab:接口 carSeriesList 不含此项,仅用于 UI 展示「全部车型」 */
const ALL_CAR_SERIES_TAB = {
carSeriesId: '__ALL__',
carSeriesName: '全部车型'
}
export default {
name: 'ActivityTime',
components: {
......@@ -119,7 +113,7 @@ export default {
}
],
activityTypeIndex: 0,
carModelIndex: 0, // 0 对应「全部车型」,切换活动类型或数据刷新时重置至此
carModelIndex: 0,
goodsIndex: 0
}
},
......@@ -138,26 +132,15 @@ export default {
}
})
},
// 当前活动类型下的原始车型列表(接口数据,不含虚拟 Tab)
carSeriesList() {
return this.activityProductList[this.activityTypeIndex]?.carSeriesList ?? []
},
// 车型标签栏:首位注入「全部车型」,无车型数据时不展示标签栏
// 车型标签栏,无车型数据时不展示
carModelTabs() {
if (!this.carSeriesList.length) return []
return [ALL_CAR_SERIES_TAB, ...this.carSeriesList]
return this.activityProductList[this.activityTypeIndex]?.carSeriesList ?? []
},
selectedCarTab() {
return this.carModelTabs[this.carModelIndex] ?? null
},
isAllCarModelSelected() {
return this.selectedCarTab?.carSeriesId === ALL_CAR_SERIES_TAB.carSeriesId
},
// 全部车型:合并当前活动类型下所有 productList;具体车型:取选中项 productList
goodsList() {
const productList = this.isAllCarModelSelected
? this.carSeriesList.flatMap(series => series.productList ?? [])
: (this.selectedCarTab?.productList ?? [])
const productList = this.selectedCarTab?.productList ?? []
return productList.map(product => this.mapProductItem(product))
},
selectedGoods() {
......@@ -174,7 +157,7 @@ export default {
}
},
watch: {
// 接口数据更新时重置选中态,默认回到首个活动类型 + 全部车型
// 接口数据更新时重置选中态,默认回到首个活动类型 + 首个车型
activityProductList() {
this.resetTabSelection()
},
......@@ -188,7 +171,7 @@ export default {
methods: {
resetTabSelection() {
this.activityTypeIndex = 0
this.carModelIndex = 0 // 重置为「全部车型」
this.carModelIndex = 0
this.goodsIndex = 0
},
formatPrice(value) {
......@@ -223,7 +206,7 @@ export default {
handleActivityTypeClick(index) {
if (this.activityTypeIndex === index) return
this.activityTypeIndex = index
this.carModelIndex = 0 // 切换活动类型后默认选中「全部车型」
this.carModelIndex = 0
this.goodsIndex = 0
},
handleCarModelClick(index) {
......@@ -242,7 +225,7 @@ export default {
const payload = {
...goods,
activityTypeLabel: this.activityTypeList[this.activityTypeIndex]?.label || '',
carSeriesName: this.isAllCarModelSelected ? '全部车型' : (this.selectedCarTab?.carSeriesName || '')
carSeriesName: this.selectedCarTab?.carSeriesName || ''
}
uni.navigateTo({
url: `/pages/common/actuvityDetail?row=${encodeURIComponent(JSON.stringify(payload))}`,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!