Commit 239d2312 by Lin

refactor(HomeFrame): 优化策略数据查询逻辑

- 重构 getStrategyStatus 和 getActivityProductList 方法,增加对 merchantId 的有效性检查。
- 在查询失败时,添加错误处理逻辑,确保数据状态的正确性。
- 移除不必要的 console.log 调试信息,提升代码整洁性。
1 parent 38ce3bee
...@@ -520,7 +520,6 @@ export default { ...@@ -520,7 +520,6 @@ export default {
methods: { methods: {
handleHomeContentTabClick(index) { handleHomeContentTabClick(index) {
this.homeContentTabIndex = index this.homeContentTabIndex = index
console.log('当前选中标签:', this.currentHomeContentTab)
}, },
_syncShowFloatLog() { _syncShowFloatLog() {
this.showFloatLog = FloatLogConfig.isLogBallVisible() this.showFloatLog = FloatLogConfig.isLogBallVisible()
...@@ -730,46 +729,73 @@ export default { ...@@ -730,46 +729,73 @@ export default {
* 查询策略首页数据状态(营销活动和客户列表是否有数据) * 查询策略首页数据状态(营销活动和客户列表是否有数据)
*/ */
async getStrategyStatus() { async getStrategyStatus() {
this.$store.state.boutique.boutiqueActivityData = [] // 清空 boutiqueActivityData const { shopMerchantId: merchantId } = uni.$storage.get('userInfo') || {}
const res = await uni.$api.activityApi.getActivityStatusAPI({merchantId: uni.$storage.get('userInfo').shopMerchantId}) if (!merchantId) return
console.log('%c查询策略首页数据状态(营销活动和客户列表是否有数据):', 'color: green;', res)
if (!res) return try {
const res = await uni.$api.activityApi.getActivityStatusAPI({ merchantId })
this.marketingActivityHasData = !!res.marketingActivityHasData if (!res) {
this.customerListHasData = !!res.customerListHasData this.marketingActivityHasData = false
this.homeContentTabIndex = 0 this.customerListHasData = false
this.activityProductList = []
// 仅「限时产品活动」Tab 展示时才需拉取营销活动商品列表 this.$store.state.boutique.boutiqueActivityData = []
if (this.marketingActivityHasData || this.customerListHasData) { return
this.getActivityProductList() }
this.marketingActivityHasData = !!res.marketingActivityHasData
this.customerListHasData = !!res.customerListHasData
this.homeContentTabIndex = 0
// 仅「限时产品活动」Tab 展示时才需拉取营销活动商品列表
if (this.marketingActivityHasData) {
await this.getActivityProductList()
} else {
this.activityProductList = []
this.$store.state.boutique.boutiqueActivityData = []
}
} catch (error) {
console.error('查询策略首页数据状态失败:', error)
} }
}, },
/** /**
* 查询当前进行中的营销活动商品列表 * 查询当前进行中的营销活动商品列表
*/ */
async getActivityProductList() { async getActivityProductList() {
const { shopMerchantId } = uni.$storage.get('userInfo') const { shopMerchantId: merchantId } = uni.$storage.get('userInfo') || {}
console.log('**&&merchantId**', shopMerchantId) if (!merchantId) {
const res = await uni.$api.activityApi.getActivityProductListAPI({merchantId: shopMerchantId}) this.activityProductList = []
console.log('查询当前进行中的营销活动商品列表:', res) this.$store.state.boutique.boutiqueActivityData = []
this.activityProductList = res return
// console.log('查询当前进行中的营销活动商品列表:', res) }
this.$store.state.boutique.boutiqueActivityData = res
try {
const res = await uni.$api.activityApi.getActivityProductListAPI({ merchantId })
const list = Array.isArray(res) ? res : []
this.activityProductList = list
this.$store.state.boutique.boutiqueActivityData = list
} catch (error) {
console.error('查询营销活动商品列表失败:', error)
this.activityProductList = []
this.$store.state.boutique.boutiqueActivityData = []
}
}, },
/** /**
* 查询客户建档分页查询-月按天分组 * 查询客户建档分页查询-月按天分组
*/ */
async getCustomerProfileGroupInfo() { async getCustomerProfileGroupInfo() {
let shopMerchantId = uni.$storage.get('userInfo').shopMerchantId const { shopMerchantId: merchantId } = uni.$storage.get('userInfo') || {}
console.log('getCustomerProfileGroupInfo***merchantId:', uni.$storage.get('userInfo')) if (!merchantId) {
let requestParams = { this.customerProfileList = []
merchantId: shopMerchantId return
} }
const res = await uni.$api.customerApi.getCustomerProfileGroupInfoAPI(requestParams)
console.log('getCustomerProfileGroupInfoAPI-月按天分组:', res) try {
if (res) { const res = await uni.$api.customerApi.getCustomerProfileGroupInfoAPI({ merchantId })
this.customerProfileList = res this.customerProfileList = Array.isArray(res) ? res : []
} catch (error) {
console.error('查询客户建档分组信息失败:', error)
this.customerProfileList = []
} }
}, },
/** /**
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!