Commit 7cf02fa6 by 李伟康

refactor(boutique): 重构商品展示组件的数据绑定和标签逻辑

- 在 GoodsBox 组件中添加 tabListId 属性并修改 changeCar 方法逻辑
- 为 Reception 组件添加 tabListId 数据属性并更新标签显示结构
- 修改 tabs 计算属性以支持对象数组格式并添加活动标识判断
- 优化 changeTab 方法并调整车型切换逻辑
- 在 Reception 组件中添加对活动状态的监听处理
- 修复预览跟踪数据为空时的错误处理
- 重构 SkuBox 组件的模板结构和样式布局
1 parent 83296dd7
const target = ['ip', 'dev', 'uat', 'prod', 'beta']
const index = 1
const index = 2
/**
*
0本地
......
......@@ -33,6 +33,7 @@ export default {
tabIndex: Number,
hasBeforeActivity: Boolean,
hasAfterActivity: Boolean,
tabListId: Number,
},
data() {
......@@ -89,8 +90,10 @@ export default {
},
changeCar(newval) {
this.goodsList = []
let { activityData, tabIndex } = this
let carSeriesList = activityData[tabIndex].carSeriesList,
let { activityData, tabListId } = this,
list = activityData.find(e => e.marketingStage == tabListId)
if(!list) return
let carSeriesList = list.carSeriesList,
data = carSeriesList.find(e => e.carSeriesId == newval)
if (data) {
this.goodsIndex = -1
......
......@@ -48,7 +48,7 @@
<view class="sku-box">
<goods-box :currentCar="currentCarId" :activityData="activityData"
:show="show && [0, 1].includes(tabIndex)" @changePreView="currentItem = $event" ref="goodsBox"
:tabIndex="tabIndex" @noActivity="setNoActivity" />
:tabIndex="tabIndex" @noActivity="setNoActivity" :tabListId="tabListId" />
</view>
</template>
<template v-else>
......@@ -67,7 +67,8 @@
<template v-if="tabs.length > 1">
<view class="tabs-box flex">
<template v-for="(i, index) in tabs">
<view :class="['tab flex', { active: index == tabIndex }]" :key="index" @click="changeTab(index)">{{ i
<view :class="['tab flex', { active: index == tabIndex }]" :key="index" @click="changeTab(index)">{{
i.name
}}</view>
</template>
<view :class="['block', `block-${tabIndex}`]"></view>
......@@ -115,7 +116,8 @@ export default {
isSelect: false,
currentCarId: '',
activityData: [],
noActivity: false
noActivity: false,
tabListId: 2
}
},
watch: {
......@@ -135,7 +137,7 @@ export default {
currentCarId: {
immediate: true,
handler(newval) {
if (!this.hasOptionals && this.tabIndex != 0) this.tabIndex = 0
if (this.tabIndex != 0) this.tabIndex = 0
if (this.show && newval && !this.isPreview && this.customerType == 1) {
uni.showLoading({
mask: true
......@@ -158,11 +160,16 @@ export default {
handler(newval) {
if (newval) {
this.isSelect = false
let index = 0
let index = 0,
tabListId = 2
if (this.hasBeforeActivity || this.hasAfterActivity) {
index = 1
tabListId = 1
}
if (this.hasBeforeActivity && this.hasAfterActivity) {
index = 2
tabListId = 0
}
if (this.hasBeforeActivity && this.hasAfterActivity) index = 2
if (newval && this.currentItem && this.tabIndex == index) this.changePreView(this.currentItem, false, false)
}
}
......@@ -175,6 +182,22 @@ export default {
if (newval.length) this.currentItem = null
}
},
hasBeforeActivity: {
immediate: true,
deep: true,
handler(newval) {
let { tabListId } = this
if (newval && tabListId != 0) this.changeTab(0, true)
}
},
hasAfterActivity: {
immediate: true,
deep: true,
handler(newval) {
let { tabListId, hasBeforeActivity } = this
if (newval && tabListId != 1 && !hasBeforeActivity) this.changeTab(0, true)
}
},
},
computed: {
......@@ -225,26 +248,38 @@ export default {
},
tabs() {
let { hasBeforeActivity, hasAfterActivity, hasOptionals } = this,
tabs = ['加装']
if (hasAfterActivity) tabs.unshift('售后钜惠')
if (hasBeforeActivity) tabs.unshift('新享特惠')
if (hasOptionals) tabs.push('选装')
tabs = [{
name: '加装',
id: 2
}]
if (hasAfterActivity) tabs.unshift({
name: '售后钜惠',
id: 1
})
if (hasBeforeActivity) tabs.unshift({
name: '新享特惠',
id: 0
})
if (hasOptionals) tabs.push({
name: '选装',
id: 3
})
return tabs
},
hasBeforeActivity() {
// let { currentCarId } = this,
// hasBeforeActivity = this.activityData.some(e => e.marketingStage == 0),
// hasCar = false
// this.activityData.forEach(e => {
// if (!hasCar) e.carSeriesList.some(e => e.carSeriesId == currentCarId)
// })
// return hasBeforeActivity && hasCar
return this.activityData.some(e => e.marketingStage == 0)
let { currentCarId } = this,
beforeActivityIndex = this.activityData.findIndex(e => e.marketingStage == 0),
hasCar = false
if (!hasCar && beforeActivityIndex > -1) hasCar = this.activityData[beforeActivityIndex].carSeriesList.some(e => e.carSeriesId == currentCarId)
return hasCar
},
hasAfterActivity() {
return this.activityData.some(e => e.marketingStage == 1)
}
let { currentCarId } = this,
afterActivityIndex = this.activityData.findIndex(e => e.marketingStage == 1),
hasCar = false
if (!hasCar && afterActivityIndex > -1) hasCar = this.activityData[afterActivityIndex].carSeriesList.some(e => e.carSeriesId == currentCarId)
return hasCar
},
},
methods: {
......@@ -318,6 +353,7 @@ export default {
if (this.isPreview) return
let key = `${currentItem.carModelName}_${currentItem.id}`,
value = this.receptionTrack[key]
if (!value) return
value.stayDuration += Number(Date.now() - value.entryTime)
this.$store.dispatch("setReceptionTrack", { key, value })
},
......@@ -327,19 +363,20 @@ export default {
clearCanvas() {
this.$refs.receptionCanvas.clearBoard()
},
changeTab(index) {
if (this.tabIndex == index) return
changeTab(index, force = false) {
if (this.tabIndex == index && !force) return
let skuIndex = 0
if (this.hasBeforeActivity || this.hasAfterActivity) skuIndex = 1
if (this.hasBeforeActivity && this.hasAfterActivity) skuIndex = 2
if (this.tabIndex == skuIndex) this.previewLeave(this.currentItem)
if (this.tabIndex == skuIndex && this.currentItem.carModelName) this.previewLeave(this.currentItem)
this.tabIndex = index
this.currentItem = null
this.$nextTick(() => {
if (skuIndex == 2 && index < 2) this.$refs.goodsBox.changeCar(this.currentCarId)
this.tabListId = this.tabs[index].id
setTimeout(() => {
if (this.$refs.goodsBox) this.$refs.goodsBox.changeCar(this.currentCarId)
if (index == skuIndex) this.$refs.sku.changeCar(this.currentCarId)
this.clearCanvas()
})
}, 100)
},
showSelect() {
if (this.carList.length == 1 || this.change_disabled) return
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!