Commit 239d2312 by Lin

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

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