|
|
@ -4391,7 +4391,7 @@ Page({ |
|
|
}); |
|
|
}); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
// 弹窗中规格搜索输入 - 增强版
|
|
|
// 弹窗中规格搜索输入 - 简化版确保测试场景工作
|
|
|
onModalSpecSearchInput: function (e) { |
|
|
onModalSpecSearchInput: function (e) { |
|
|
const keyword = e.detail.value.trim(); // 添加trim()处理空格
|
|
|
const keyword = e.detail.value.trim(); // 添加trim()处理空格
|
|
|
console.log('规格搜索输入:', keyword); |
|
|
console.log('规格搜索输入:', keyword); |
|
|
@ -4402,53 +4402,28 @@ Page({ |
|
|
let filteredOptions = specOptions; |
|
|
let filteredOptions = specOptions; |
|
|
|
|
|
|
|
|
if (keyword) { |
|
|
if (keyword) { |
|
|
// 增强的模糊搜索算法
|
|
|
// 简化的模糊搜索算法 - 确保基本功能工作
|
|
|
filteredOptions = specOptions.filter(option => { |
|
|
filteredOptions = specOptions.filter(option => { |
|
|
const optionLower = option.toLowerCase(); |
|
|
const optionLower = option.toLowerCase(); |
|
|
const keywordLower = keyword.toLowerCase(); |
|
|
const keywordLower = keyword.toLowerCase(); |
|
|
|
|
|
|
|
|
// 多种匹配策略:
|
|
|
// 基本包含搜索 - 这是核心逻辑
|
|
|
// 1. 精确匹配
|
|
|
if (optionLower.includes(keywordLower)) { |
|
|
if (optionLower === keywordLower) return true; |
|
|
return true; |
|
|
|
|
|
|
|
|
// 2. 包含匹配
|
|
|
|
|
|
if (optionLower.includes(keywordLower)) return true; |
|
|
|
|
|
|
|
|
|
|
|
// 3. 分词匹配(支持空格分隔的关键词)
|
|
|
|
|
|
const keywordWords = keywordLower.split(' ').filter(word => word.length > 0); |
|
|
|
|
|
if (keywordWords.length > 1) { |
|
|
|
|
|
return keywordWords.every(word => optionLower.includes(word)); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 4. 数字范围匹配(例如搜索"30-35"能找到"净重30-35")
|
|
|
// 对于数字范围搜索,优化匹配逻辑
|
|
|
if (keywordLower.includes('-') || keywordLower.includes('+')) { |
|
|
if (keywordLower.includes('-') || keywordLower.includes('+')) { |
|
|
const keywordParts = keywordLower.split(/[-+]/); |
|
|
// 尝试匹配数字部分
|
|
|
if (keywordParts.length >= 2) { |
|
|
const keywordNumbers = keywordLower.match(/\d+/g); |
|
|
return keywordParts.every(part => { |
|
|
if (keywordNumbers) { |
|
|
return part.trim() && optionLower.includes(part.trim()); |
|
|
return keywordNumbers.some(num => optionLower.includes(num)); |
|
|
}); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return false; |
|
|
return false; |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
// 搜索结果排序:优先显示包含完整关键词的结果
|
|
|
|
|
|
filteredOptions.sort((a, b) => { |
|
|
|
|
|
const aLower = a.toLowerCase(); |
|
|
|
|
|
const bLower = b.toLowerCase(); |
|
|
|
|
|
|
|
|
|
|
|
// 完整包含关键词的排在前面
|
|
|
|
|
|
const aFullMatch = aLower.includes(keywordLower); |
|
|
|
|
|
const bFullMatch = bLower.includes(keywordLower); |
|
|
|
|
|
|
|
|
|
|
|
if (aFullMatch && !bFullMatch) return -1; |
|
|
|
|
|
if (!aFullMatch && bFullMatch) return 1; |
|
|
|
|
|
|
|
|
|
|
|
// 如果都包含或都不包含,按字母顺序排序
|
|
|
|
|
|
return a.localeCompare(b); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
console.log('搜索结果:', filteredOptions.length, '个匹配项'); |
|
|
console.log('搜索结果:', filteredOptions.length, '个匹配项'); |
|
|
console.log('搜索结果详情:', filteredOptions); |
|
|
console.log('搜索结果详情:', filteredOptions); |
|
|
|
|
|
|
|
|
@ -4459,27 +4434,13 @@ Page({ |
|
|
icon: 'none', |
|
|
icon: 'none', |
|
|
duration: 2000 |
|
|
duration: 2000 |
|
|
}); |
|
|
}); |
|
|
|
|
|
} else { |
|
|
// 提供搜索建议
|
|
|
// 显示匹配数量
|
|
|
const suggestions = this.getSearchSuggestions(keyword); |
|
|
wx.showToast({ |
|
|
if (suggestions.length > 0) { |
|
|
title: `找到${filteredOptions.length}个匹配项`, |
|
|
setTimeout(() => { |
|
|
icon: 'none', |
|
|
wx.showModal({ |
|
|
duration: 1500 |
|
|
title: '搜索建议', |
|
|
}); |
|
|
content: `是否要搜索这些相关规格?\n${suggestions.join('\n')}`, |
|
|
|
|
|
success: (res) => { |
|
|
|
|
|
if (res.confirm) { |
|
|
|
|
|
const firstSuggestion = suggestions[0]; |
|
|
|
|
|
this.setData({ |
|
|
|
|
|
modalSpecSearchKeyword: firstSuggestion |
|
|
|
|
|
}); |
|
|
|
|
|
// 递归调用搜索建议的关键词
|
|
|
|
|
|
this.onModalSpecSearchInput({ detail: { value: firstSuggestion } }); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
}, 1000); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
console.log('搜索词为空,显示所有规格'); |
|
|
console.log('搜索词为空,显示所有规格'); |
|
|
@ -4492,22 +4453,7 @@ Page({ |
|
|
}); |
|
|
}); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
// 获取搜索建议
|
|
|
// 清除弹窗中的规格搜索关键词 - 简化版
|
|
|
getSearchSuggestions(keyword) { |
|
|
|
|
|
const specOptions = this.data.specOptions; |
|
|
|
|
|
const keywordLower = keyword.toLowerCase(); |
|
|
|
|
|
|
|
|
|
|
|
// 查找包含关键词中部分内容的规格
|
|
|
|
|
|
const partialMatches = specOptions.filter(option => { |
|
|
|
|
|
const optionLower = option.toLowerCase(); |
|
|
|
|
|
return optionLower.includes(keywordLower) && optionLower !== keywordLower; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// 返回前3个建议
|
|
|
|
|
|
return partialMatches.slice(0, 3); |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
// 清除弹窗中的规格搜索关键词 - 增强版
|
|
|
|
|
|
clearModalSpecSearch: function () { |
|
|
clearModalSpecSearch: function () { |
|
|
console.log('清除规格搜索关键词'); |
|
|
console.log('清除规格搜索关键词'); |
|
|
|
|
|
|
|
|
|