|
|
|
@ -51,7 +51,8 @@ Page({ |
|
|
|
small: ['何佳芹', '李真音'], // 小品种创建者
|
|
|
|
large: ['吴海燕', '陈骏', '刘琴', '汤敏'] // 大贸易创建者
|
|
|
|
}, |
|
|
|
total: 0 // 总数据条数
|
|
|
|
total: 0, // 总数据条数
|
|
|
|
searchTimer: null // 搜索防抖定时器
|
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
@ -125,12 +126,27 @@ Page({ |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* 处理搜索输入 |
|
|
|
* 处理搜索输入 - 添加防抖功能 |
|
|
|
*/ |
|
|
|
onSearchInput(e) { |
|
|
|
const keyword = e.detail.value; |
|
|
|
this.setData({ |
|
|
|
searchKeyword: e.detail.value |
|
|
|
}) |
|
|
|
searchKeyword: keyword |
|
|
|
}); |
|
|
|
|
|
|
|
// 清除之前的定时器
|
|
|
|
if (this.data.searchTimer) { |
|
|
|
clearTimeout(this.data.searchTimer); |
|
|
|
} |
|
|
|
|
|
|
|
// 设置新的定时器,300ms后执行搜索
|
|
|
|
const searchTimer = setTimeout(() => { |
|
|
|
this.searchGoods(); |
|
|
|
}, 300); |
|
|
|
|
|
|
|
this.setData({ |
|
|
|
searchTimer: searchTimer |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
@ -177,7 +193,7 @@ Page({ |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据搜索关键词过滤数据 |
|
|
|
* 根据搜索关键词过滤数据 - 完善搜索功能,支持搜索创建人信息 |
|
|
|
*/ |
|
|
|
searchGoodsList(goodsList, keyword) { |
|
|
|
if (!keyword || keyword.trim() === '') { |
|
|
|
@ -189,22 +205,45 @@ Page({ |
|
|
|
return goodsList.filter(item => { |
|
|
|
// 检查多个字段是否包含搜索关键词
|
|
|
|
const fieldsToCheck = [ |
|
|
|
// 产品基本信息
|
|
|
|
item.productName || item.name || '', // 产品名称
|
|
|
|
item.creatorName || '', // 创建人
|
|
|
|
item.specification || item.spec || '', // 规格
|
|
|
|
item.description || '', // 描述
|
|
|
|
item.region || '', // 地区
|
|
|
|
item.yolk || '', // 蛋黄
|
|
|
|
item.description || item.remark || '', // 描述
|
|
|
|
item.region || item.area || '', // 地区
|
|
|
|
item.yolk || item.variety || '', // 蛋黄
|
|
|
|
item.price || '', // 价格
|
|
|
|
item.costprice || '', // 采购价格
|
|
|
|
item.grossWeight || item.weight || '', // 重量
|
|
|
|
item.category || '', // 种类
|
|
|
|
item.formattedCreatedAt || item.created_at || '' // 创建时间
|
|
|
|
item.minOrder || item.quantity || '', // 最小起订量
|
|
|
|
|
|
|
|
// 创建时间
|
|
|
|
item.formattedCreatedAt || item.created_at || item.createdAt || '' // 创建时间
|
|
|
|
] |
|
|
|
|
|
|
|
// 检查是否有任何字段包含搜索关键词
|
|
|
|
return fieldsToCheck.some(field => { |
|
|
|
let hasMatch = fieldsToCheck.some(field => { |
|
|
|
return field.toLowerCase().includes(searchTerm) |
|
|
|
}) |
|
|
|
|
|
|
|
// 单独处理创建人信息,确保即使没有创建者信息也能正常搜索
|
|
|
|
if (!hasMatch) { |
|
|
|
// 检查创建人相关字段
|
|
|
|
const creatorFields = [ |
|
|
|
item.creatorName || '', // 已处理的创建人名称
|
|
|
|
// 检查seller对象中的创建人信息,确保seller是对象
|
|
|
|
typeof item.seller === 'object' && item.seller ? item.seller.nickName || '' : '', |
|
|
|
typeof item.seller === 'object' && item.seller ? item.seller.sellerNickName || '' : '', |
|
|
|
typeof item.seller === 'object' && item.seller ? item.seller.name || '' : '', |
|
|
|
item.sellerName || '' // 卖家名称备用字段
|
|
|
|
] |
|
|
|
|
|
|
|
hasMatch = creatorFields.some(field => { |
|
|
|
return field.toLowerCase().includes(searchTerm) |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
return hasMatch |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
@ -271,7 +310,7 @@ Page({ |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* 加载货源列表 |
|
|
|
* 加载货源列表 - 优化搜索功能,支持搜索创建人信息 |
|
|
|
*/ |
|
|
|
async loadGoodsList() { |
|
|
|
if (this.data.isLoading) return |
|
|
|
@ -322,15 +361,14 @@ Page({ |
|
|
|
console.log(`产品${index}的seller信息:`) |
|
|
|
console.log(`- seller对象:`, item.seller) |
|
|
|
console.log(`- seller.nickName:`, item.seller?.nickName) |
|
|
|
console.log(`- seller.sellerNickName:`, item.seller?.sellerNickName) |
|
|
|
console.log(`- seller.name:`, item.seller?.name) |
|
|
|
console.log(`- seller完整结构:`, JSON.stringify(item.seller)) |
|
|
|
|
|
|
|
// 确定creatorName - 只使用nickName和sellerNickName字段,不使用name字段
|
|
|
|
// 详细日志,查看seller对象的完整结构和各个字段值
|
|
|
|
console.log('seller对象完整结构:', JSON.stringify(item.seller)) |
|
|
|
console.log('seller.nickName:', item.seller?.nickName) |
|
|
|
console.log('seller.sellerNickName:', item.seller?.sellerNickName) |
|
|
|
const creatorName = item.seller?.nickName || item.seller?.sellerNickName || '未知' |
|
|
|
// 确定creatorName - 支持多种字段,确保能获取到创建人信息
|
|
|
|
// 从seller对象中获取创建人信息,优先使用nickName,其次使用sellerNickName,最后使用name
|
|
|
|
const sellerNickName = item.seller?.nickName || item.seller?.sellerNickName || item.seller?.name || '未知'; |
|
|
|
const creatorName = sellerNickName; |
|
|
|
console.log('creatorName获取结果:', creatorName) |
|
|
|
|
|
|
|
// 处理媒体URL,添加类型信息
|
|
|
|
@ -367,12 +405,17 @@ Page({ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 确保productName字段存在,优先使用productName,其次使用name
|
|
|
|
const productName = item.productName || item.name || '未命名商品'; |
|
|
|
|
|
|
|
return { |
|
|
|
...item, |
|
|
|
productName: productName, // 确保productName字段存在
|
|
|
|
name: productName, // 确保name字段存在
|
|
|
|
status: status, // 更新商品状态
|
|
|
|
price: processedPrice, // 更新为第一个规格的价格
|
|
|
|
formattedCreatedAt: this.formatDateTime(item.created_at || item.createTime), |
|
|
|
creatorName: creatorName, |
|
|
|
creatorName: creatorName, // 已处理的创建人名称
|
|
|
|
imageUrls: formattedImageUrls, |
|
|
|
mediaItems: mediaItems |
|
|
|
} |
|
|
|
@ -380,13 +423,13 @@ Page({ |
|
|
|
|
|
|
|
// 应用筛选条件和搜索过滤
|
|
|
|
const originalList = [...newGoodsList] |
|
|
|
// 先应用搜索过滤
|
|
|
|
let searchFilteredList = this.searchGoodsList(newGoodsList, this.data.searchKeyword) |
|
|
|
// 再应用筛选条件
|
|
|
|
let filteredList = this.filterGoodsList(searchFilteredList) |
|
|
|
// 先应用筛选条件
|
|
|
|
let filteredList = this.filterGoodsList(newGoodsList) |
|
|
|
// 再应用搜索过滤 - 在处理后的列表上进行搜索,确保能搜索到creatorName
|
|
|
|
let searchFilteredList = this.searchGoodsList(filteredList, this.data.searchKeyword) |
|
|
|
|
|
|
|
// 排序:已上架商品排在前面,售空商品排在后面
|
|
|
|
filteredList.sort((a, b) => { |
|
|
|
// 排序:已上架商品排在前面,售空商品排在后面 - 对搜索过滤后的列表进行排序
|
|
|
|
searchFilteredList.sort((a, b) => { |
|
|
|
if (a.status === 'published' && b.status === 'sold_out') { |
|
|
|
return -1 // 已上架排在前面
|
|
|
|
} else if (a.status === 'sold_out' && b.status === 'published') { |
|
|
|
@ -399,11 +442,11 @@ Page({ |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
console.log('处理并筛选后的产品列表:', filteredList) |
|
|
|
console.log('筛选前后数量对比:', originalList.length, '->', filteredList.length) |
|
|
|
console.log('处理并筛选后的产品列表:', searchFilteredList) |
|
|
|
console.log('筛选前后数量对比:', originalList.length, '->', searchFilteredList.length) |
|
|
|
|
|
|
|
// 处理分页逻辑
|
|
|
|
let updatedGoodsList = this.data.currentPage === 1 ? filteredList : [...this.data.goodsList, ...filteredList] |
|
|
|
// 处理分页逻辑 - 使用搜索过滤后的列表
|
|
|
|
let updatedGoodsList = this.data.currentPage === 1 ? searchFilteredList : [...this.data.goodsList, ...searchFilteredList] |
|
|
|
|
|
|
|
// 对整个列表进行排序,确保已上架商品始终在前面,售空商品在后面
|
|
|
|
updatedGoodsList.sort((a, b) => { |
|
|
|
|