|
|
@ -378,7 +378,6 @@ export default { |
|
|
|
}, |
|
|
|
brandList: [], |
|
|
|
brandCache: {}, // 为每个商品缓存品牌信息 { productId: [brandList] } |
|
|
|
brandIndexList: ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'], |
|
|
|
currentLetter: 'A', |
|
|
|
scrollToView: '', |
|
|
|
brandSearch: '', |
|
|
@ -579,7 +578,18 @@ export default { |
|
|
|
max: maxExtra.toFixed(2), |
|
|
|
display: `${minExtra.toFixed(2)}-${maxExtra.toFixed(2)}元` |
|
|
|
}; |
|
|
|
} |
|
|
|
}, |
|
|
|
// 动态生成品牌字母索引,只显示有品牌的字母 |
|
|
|
brandIndexList() { |
|
|
|
const set = new Set() |
|
|
|
this.brandList.forEach(b => { |
|
|
|
if (b.letter && /^[A-Z]$/.test(b.letter)) set.add(b.letter) |
|
|
|
}) |
|
|
|
const arr = Array.from(set).sort() |
|
|
|
// 如果没有A-Z分组,兜底显示#分组 |
|
|
|
if (arr.length === 0 && this.brandList.length > 0) return ['#'] |
|
|
|
return arr |
|
|
|
}, |
|
|
|
}, |
|
|
|
methods: { |
|
|
|
showPriceInfoPopups() { |
|
|
@ -688,13 +698,23 @@ export default { |
|
|
|
} |
|
|
|
|
|
|
|
// 品牌商品且数量为0且加一时 |
|
|
|
if ((item.quantity || 0) === 0 && delta > 0) { |
|
|
|
if (item.isPin === 'Y' && (item.quantity || 0) === 0 && delta > 0) { |
|
|
|
this.pendingBrandIndex = index |
|
|
|
this.isWaitingForBrandSelection = true; |
|
|
|
this.showRules(item); // 先显示回收规则 |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
// 无品牌商品,数量为0且加一时,也弹规则,确认后再加数量 |
|
|
|
if (item.isPin !== 'Y' && (item.quantity || 0) === 0 && delta > 0) { |
|
|
|
this.pendingBrandIndex = index |
|
|
|
this.isWaitingForBrandSelection = false; // 标记为无品牌 |
|
|
|
this.showRules(item) |
|
|
|
return |
|
|
|
} |
|
|
|
// 其它情况直接加数量 |
|
|
|
let newQuantity = (item.quantity || 0) + delta |
|
|
|
if (newQuantity < 0) newQuantity = 0 |
|
|
|
this.$set(item, 'quantity', newQuantity) |
|
|
|
}, |
|
|
|
// 选择要减少的品牌 |
|
|
|
selectReduceBrand(brandInfo) { |
|
|
@ -739,27 +759,42 @@ export default { |
|
|
|
}, |
|
|
|
// 显示回收规则 |
|
|
|
showRules(item) { |
|
|
|
// 检查该商品是否已经查看过规则 |
|
|
|
if (this.viewedRuleItems.has(item.id)) { |
|
|
|
// 如果已经查看过,直接跳过规则弹窗,进入品牌选择 |
|
|
|
this.isWaitingForBrandSelection = false; |
|
|
|
this.getGoodsBrandList(item.id); |
|
|
|
this.showBrandPopup = true; |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// 重置滚动状态 |
|
|
|
this.hasScrolledToBottom = false; |
|
|
|
|
|
|
|
// 获取回收规则富文本 |
|
|
|
this.$api('getGoodsRecycleRule', { goodsId: item.id }, res => { |
|
|
|
if (res.code === 200 && res.result) { |
|
|
|
this.ruleHtml = res.result |
|
|
|
} else { |
|
|
|
this.ruleHtml = '<p>暂无回收规则</p>' |
|
|
|
// isPin=Y: 弹规则,读到底部后自动弹品牌;isPin=N: 只弹规则 |
|
|
|
if (item.isPin === 'Y') { |
|
|
|
// 检查该商品是否已经查看过规则 |
|
|
|
if (this.viewedRuleItems.has(item.id)) { |
|
|
|
// 如果已经查看过,直接跳过规则弹窗,进入品牌选择 |
|
|
|
this.isWaitingForBrandSelection = false; |
|
|
|
this.getGoodsBrandList(item.id); |
|
|
|
this.showBrandPopup = true; |
|
|
|
return; |
|
|
|
} |
|
|
|
this.showRulePopup = true |
|
|
|
}) |
|
|
|
// 重置滚动状态 |
|
|
|
this.hasScrolledToBottom = false; |
|
|
|
// 获取回收规则富文本 |
|
|
|
this.$api('getGoodsRecycleRule', { goodsId: item.id }, res => { |
|
|
|
if (res.code === 200 && res.result) { |
|
|
|
this.ruleHtml = res.result |
|
|
|
} else { |
|
|
|
this.ruleHtml = '<p>暂无回收规则</p>' |
|
|
|
} |
|
|
|
this.showRulePopup = true |
|
|
|
// 规则弹窗关闭后自动弹品牌弹窗逻辑在closeRulePopup已实现 |
|
|
|
}) |
|
|
|
} else { |
|
|
|
// isPin=N 只弹规则 |
|
|
|
this.hasScrolledToBottom = false; |
|
|
|
this.$api('getGoodsRecycleRule', { goodsId: item.id }, res => { |
|
|
|
if (res.code === 200 && res.result) { |
|
|
|
this.ruleHtml = res.result |
|
|
|
} else { |
|
|
|
this.ruleHtml = '<p>暂无回收规则</p>' |
|
|
|
} |
|
|
|
this.showRulePopup = true |
|
|
|
// 不弹品牌弹窗 |
|
|
|
this.isWaitingForBrandSelection = false; |
|
|
|
}) |
|
|
|
} |
|
|
|
}, |
|
|
|
showMore() { |
|
|
|
uni.showToast({ |
|
|
@ -980,6 +1015,15 @@ export default { |
|
|
|
|
|
|
|
this.getGoodsBrandList(item.id); |
|
|
|
this.showBrandPopup = true; // 打开品牌索引弹窗 |
|
|
|
} else if (this.pendingBrandIndex !== null) { |
|
|
|
// 无品牌商品,规则弹窗关闭后加数量 |
|
|
|
const categoryId = this.categories[this.currentCategory]?.id; |
|
|
|
const item = this.allProducts[categoryId]?.[this.pendingBrandIndex]; |
|
|
|
if (item) { |
|
|
|
let newQuantity = (item.quantity || 0) + 1 |
|
|
|
this.$set(item, 'quantity', newQuantity) |
|
|
|
} |
|
|
|
this.pendingBrandIndex = null |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
@ -1078,7 +1122,8 @@ export default { |
|
|
|
id: item.id, |
|
|
|
logo: item.image || '/static/brand/alexander.png', |
|
|
|
name: item.name, |
|
|
|
letter: firstChar |
|
|
|
letter: firstChar, |
|
|
|
isPin: item.isPin |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
@ -1103,12 +1148,10 @@ export default { |
|
|
|
return key.charAt(0).toUpperCase() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
let index = this.brandIndexList.indexOf(firstChar.toUpperCase()) |
|
|
|
if (index != -1) { |
|
|
|
return this.brandIndexList[index] |
|
|
|
// 英文首字母 |
|
|
|
if (/^[A-Za-z]$/.test(firstChar)) { |
|
|
|
return firstChar.toUpperCase() |
|
|
|
} |
|
|
|
|
|
|
|
return '#' |
|
|
|
}, |
|
|
|
|
|
|
|