Browse Source

fix: 显示下架商品并修复商品更新页WXML错误

pull/11/head
SwTt29 2 months ago
parent
commit
95460ad05e
  1. 2
      pages/goods-update/goods-update.wxml
  2. 462
      pages/index/index.js

2
pages/goods-update/goods-update.wxml

@ -192,7 +192,7 @@
class="bottom-button" class="bottom-button"
bindtap="prepareUnpublishSupply" bindtap="prepareUnpublishSupply"
disabled="{{goodsDetail.status == 'sold_out'}}" disabled="{{goodsDetail.status == 'sold_out'}}"
style="background-color: {{goodsDetail.status == 'sold_out' ? '#d9d9d9' : '#52c41a'}}; color: {{goodsDetail.status == 'sold_out' ? '#999999' : '#ffffff'}}; border: 2px solid {{goodsDetail.status == 'sold_out' ? '#d9d9d9' : '#52c41a'}}; box-shadow: {{goodsDetail.status == 'sold_out' ? 'none' : '0 2px 8px rgba(82, 196, 26, 0.2)'}}; opacity: {{goodsDetail.status == 'sold_out' ? '0.8' : '1'}};" style="background-color: {{goodsDetail.status == 'sold_out' ? '#d9d9d9' : '#52c41a'}}; color: {{goodsDetail.status == 'sold_out' ? '#999999' : '#ffffff'}}; border: 2px solid {{goodsDetail.status == 'sold_out' ? '#d9d9d9' : '#52c41a'}}; box-shadow: {{goodsDetail.status == 'sold_out' ? 'none' : '0 2px 8px rgba(82, 196, 26, 0.2)'}}; opacity: {{goodsDetail.status == 'sold_out' ? '0.8' : '1'}}"
> >
{{goodsDetail.status == 'sold_out' ? '已下架' : '下架'}} {{goodsDetail.status == 'sold_out' ? '已下架' : '下架'}}
</button> </button>

462
pages/index/index.js

@ -124,10 +124,10 @@ Page({
navigateToChat() { navigateToChat() {
wx.navigateTo({ wx.navigateTo({
url: '/pages/chat/index', url: '/pages/chat/index',
success: function() { success: function () {
console.log('成功跳转到聊天页面'); console.log('成功跳转到聊天页面');
}, },
fail: function(error) { fail: function (error) {
console.error('跳转到聊天页面失败:', error); console.error('跳转到聊天页面失败:', error);
wx.showToast({ wx.showToast({
title: '跳转失败,请稍后重试', title: '跳转失败,请稍后重试',
@ -143,10 +143,10 @@ Page({
const userType = e.currentTarget.dataset.type; const userType = e.currentTarget.dataset.type;
wx.navigateTo({ wx.navigateTo({
url: `/pages/customer-service/index?type=${userType}`, url: `/pages/customer-service/index?type=${userType}`,
success: function() { success: function () {
console.log('成功跳转到客服列表页面,类型:', userType); console.log('成功跳转到客服列表页面,类型:', userType);
}, },
fail: function(error) { fail: function (error) {
console.error('跳转到客服列表页面失败:', error); console.error('跳转到客服列表页面失败:', error);
wx.showToast({ wx.showToast({
title: '跳转失败,请稍后重试', title: '跳转失败,请稍后重试',
@ -160,10 +160,10 @@ Page({
navigateToSettlement() { navigateToSettlement() {
wx.navigateTo({ wx.navigateTo({
url: '/pages/settlement/index', url: '/pages/settlement/index',
success: function() { success: function () {
console.log('成功跳转到我要卖蛋页面'); console.log('成功跳转到我要卖蛋页面');
}, },
fail: function(error) { fail: function (error) {
console.error('跳转到我要卖蛋页面失败:', error); console.error('跳转到我要卖蛋页面失败:', error);
wx.showToast({ wx.showToast({
title: '跳转失败,请稍后重试', title: '跳转失败,请稍后重试',
@ -366,13 +366,13 @@ Page({
this.setData({ this.setData({
goods: updatedGoods goods: updatedGoods
}, () => { }, () => {
// 重新应用筛选条件,确保显示的商品收藏状态也更新 // 重新应用筛选条件,确保显示的商品收藏状态也更新
const filteredGoods = this.applyFilters(this.data.goods, false); const filteredGoods = this.applyFilters(this.data.goods, false);
this.setData({ this.setData({
filteredGoods: filteredGoods, filteredGoods: filteredGoods,
});
}); });
});
}; };
app.eventBus.on('favoriteChanged', this.favoriteChangedHandler); app.eventBus.on('favoriteChanged', this.favoriteChangedHandler);
}, },
@ -421,17 +421,17 @@ Page({
} }
}, },
onPullDownRefresh: function() { onPullDownRefresh: function () {
this.onRefresh() this.onRefresh()
}, },
onRestore: function() { onRestore: function () {
this.setData({ this.setData({
isRefreshing: false isRefreshing: false
}) })
}, },
onRefresh: function() { onRefresh: function () {
if (this.data.isRefreshing) { if (this.data.isRefreshing) {
return return
} }
@ -463,8 +463,8 @@ Page({
lastDataTimestamp: 0 lastDataTimestamp: 0
}); });
// 优先查询published状态的商品,如果有搜索关键词则同时查询sold_out状态 // 查询published和sold_out状态的商品
const statusList = currentKeyword ? ['published', 'sold_out'] : ['published']; const statusList = ['published', 'sold_out'];
const apiParams = { const apiParams = {
timestamp: timestamp, timestamp: timestamp,
viewMode: 'shopping', viewMode: 'shopping',
@ -477,81 +477,81 @@ Page({
apiParams.category = currentCategory apiParams.category = currentCategory
} }
API.getProductList(statusList, apiParams) API.getProductList(statusList, apiParams)
.then(res => { .then(res => {
this.setData({ isRefreshing: false }) this.setData({ isRefreshing: false })
if (res.success && res.products) { if (res.success && res.products) {
this.processRefreshData(res.products, existingGoods) this.processRefreshData(res.products, existingGoods)
wx.showToast({ wx.showToast({
title: '刷新成功', title: '刷新成功',
icon: 'success', icon: 'success',
duration: 1500 duration: 1500
}) })
} else if (res.products.length === 0) { } else if (res.products.length === 0) {
// 如果published状态没有商品,则查询sold_out状态 // 如果published状态没有商品,则查询sold_out状态
console.log('没有published状态的商品,查询sold_out状态的商品'); console.log('没有published状态的商品,查询sold_out状态的商品');
const apiParams = { const apiParams = {
timestamp: timestamp, timestamp: timestamp,
viewMode: 'shopping', viewMode: 'shopping',
page: 1, page: 1,
pageSize: pageSize, pageSize: pageSize,
keyword: currentKeyword keyword: currentKeyword
} }
// 只有非全部分类时才传递category参数 // 只有非全部分类时才传递category参数
if (currentCategory) { if (currentCategory) {
apiParams.category = currentCategory apiParams.category = currentCategory
} }
API.getProductList(['sold_out'], apiParams) API.getProductList(['sold_out'], apiParams)
.then(soldOutRes => { .then(soldOutRes => {
this.setData({ isRefreshing: false }); this.setData({ isRefreshing: false });
if (soldOutRes.success && soldOutRes.products && soldOutRes.products.length > 0) { if (soldOutRes.success && soldOutRes.products && soldOutRes.products.length > 0) {
this.processRefreshData(soldOutRes.products, existingGoods); this.processRefreshData(soldOutRes.products, existingGoods);
wx.showToast({
title: '刷新成功',
icon: 'success',
duration: 1500
});
} else {
this.setData({
isLoading: false,
loadingMore: false
});
}
})
.catch(err => {
this.setData({ isRefreshing: false });
console.error('刷新sold_out商品数据失败:', err);
wx.showToast({ wx.showToast({
title: '刷新成功', title: '刷新失败,请稍后重试',
icon: 'success', icon: 'none',
duration: 1500 duration: 2000
});
} else {
this.setData({
isLoading: false,
loadingMore: false
}); });
} });
} else {
this.setData({
isLoading: false,
loadingMore: false
}) })
.catch(err => { }
this.setData({ isRefreshing: false }); })
console.error('刷新sold_out商品数据失败:', err); .catch(err => {
wx.showToast({ this.setData({ isRefreshing: false })
title: '刷新失败,请稍后重试', console.error('刷新商品数据失败:', err)
icon: 'none', wx.showToast({
duration: 2000 title: '刷新失败,请稍后重试',
}); icon: 'none',
}); duration: 2000
} else {
this.setData({
isLoading: false,
loadingMore: false
}) })
}
})
.catch(err => {
this.setData({ isRefreshing: false })
console.error('刷新商品数据失败:', err)
wx.showToast({
title: '刷新失败,请稍后重试',
icon: 'none',
duration: 2000
}) })
})
}, },
onReachBottom: function() { onReachBottom: function () {
this.loadGoods(true) this.loadGoods(true)
}, },
// 格式化毛重显示的辅助函数 // 格式化毛重显示的辅助函数
formatGrossWeight: function(grossWeight, weight) { formatGrossWeight: function (grossWeight, weight) {
if (grossWeight !== null && grossWeight !== undefined && grossWeight !== '') { if (grossWeight !== null && grossWeight !== undefined && grossWeight !== '') {
return grossWeight; return grossWeight;
} }
@ -562,7 +562,7 @@ Page({
}, },
// 提取地区中的省份信息 // 提取地区中的省份信息
extractProvince: function(region) { extractProvince: function (region) {
if (!region || typeof region !== 'string') { if (!region || typeof region !== 'string') {
return region; return region;
} }
@ -586,7 +586,7 @@ Page({
}, },
// 格式化商品规格显示 - 只显示前两个,后面加... // 格式化商品规格显示 - 只显示前两个,后面加...
formatSpecification: function(spec, yolk) { formatSpecification: function (spec, yolk) {
if (!spec || spec === '无') { if (!spec || spec === '无') {
return { return {
displaySpec: '无', displaySpec: '无',
@ -625,7 +625,7 @@ Page({
}, },
// 处理商品数据 - 淘宝风格 // 处理商品数据 - 淘宝风格
processGoodsData: function(products, isLoadMore = false) { processGoodsData: function (products, isLoadMore = false) {
let newGoods = products.map(product => { let newGoods = products.map(product => {
const imageUrls = product.imageUrls || product.images || []; const imageUrls = product.imageUrls || product.images || [];
const formattedImageUrls = Array.isArray(imageUrls) ? imageUrls : [imageUrls]; const formattedImageUrls = Array.isArray(imageUrls) ? imageUrls : [imageUrls];
@ -780,7 +780,7 @@ Page({
}, },
// 处理刷新数据 - 查重并保持原有商品 // 处理刷新数据 - 查重并保持原有商品
processRefreshData: function(newProducts, existingGoods) { processRefreshData: function (newProducts, existingGoods) {
let newGoods = newProducts.map(product => { let newGoods = newProducts.map(product => {
const imageUrls = product.imageUrls || product.images || []; const imageUrls = product.imageUrls || product.images || [];
const formattedImageUrls = Array.isArray(imageUrls) ? imageUrls : [imageUrls]; const formattedImageUrls = Array.isArray(imageUrls) ? imageUrls : [imageUrls];
@ -859,7 +859,7 @@ Page({
}, },
// 插入广告位数据 // 插入广告位数据
insertAdSlots: function(goods) { insertAdSlots: function (goods) {
if (!goods || goods.length === 0) return goods if (!goods || goods.length === 0) return goods
const adSlot1 = { const adSlot1 = {
@ -884,7 +884,7 @@ Page({
}, },
// 广告点击事件处理 // 广告点击事件处理
onAdClick: function(e) { onAdClick: function (e) {
const adSlot = e.currentTarget.dataset.ad; const adSlot = e.currentTarget.dataset.ad;
let imageSrc = e.currentTarget.dataset.src; let imageSrc = e.currentTarget.dataset.src;
@ -916,7 +916,7 @@ Page({
}, },
// 加载商品分类列表 // 加载商品分类列表
loadCategories: function() { loadCategories: function () {
API.getProductCategories().then(categories => { API.getProductCategories().then(categories => {
if (categories && categories.length > 0) { if (categories && categories.length > 0) {
this.setData({ this.setData({
@ -929,7 +929,7 @@ Page({
}, },
// 加载商品数据 - 优化版带缓存,支持状态优先级 // 加载商品数据 - 优化版带缓存,支持状态优先级
loadGoods: function(isLoadMore = false, forceRefresh = false) { loadGoods: function (isLoadMore = false, forceRefresh = false) {
if (isLoadMore && !this.data.hasMoreData) { if (isLoadMore && !this.data.hasMoreData) {
return return
} }
@ -952,8 +952,8 @@ Page({
// 只有非加载更多模式才使用缓存 // 只有非加载更多模式才使用缓存
if (!isLoadMore && !forceRefresh && if (!isLoadMore && !forceRefresh &&
this.data.categoryQueryCache[cacheKey] && this.data.categoryQueryCache[cacheKey] &&
(now - this.data.lastDataTimestamp) < this.data.cacheValidDuration) { (now - this.data.lastDataTimestamp) < this.data.cacheValidDuration) {
// 使用缓存数据 // 使用缓存数据
const cachedGoods = this.data.categoryQueryCache[cacheKey]; const cachedGoods = this.data.categoryQueryCache[cacheKey];
this.setData({ lastDataTimestamp: now }); this.setData({ lastDataTimestamp: now });
@ -986,96 +986,96 @@ Page({
console.log('loadGoods - API请求参数:', apiParams); console.log('loadGoods - API请求参数:', apiParams);
// 在搜索时同时查询published和sold_out状态的商品,否则只查询published // 查询published和sold_out状态的商品
const statusList = this.data.searchKeyword ? ['published', 'sold_out'] : ['published']; const statusList = ['published', 'sold_out'];
console.log('loadGoods - 查询状态列表:', statusList); console.log('loadGoods - 查询状态列表:', statusList);
API.getProductList(statusList, apiParams) API.getProductList(statusList, apiParams)
.then(res => { .then(res => {
wx.hideLoading(); wx.hideLoading();
console.log(`===== ${statusList.join(', ')}状态查询结果 =====`);
console.log('res.success:', res.success);
console.log('res.products:', res.products);
console.log('res.products.length:', res.products ? res.products.length : 'undefined');
console.log('page:', page);
// 如果有published商品,直接处理
if (res.success && res.products && res.products.length > 0) {
console.log('有published商品,处理商品数据');
const totalGoods = res.total || 0;
const totalPages = res.totalPages || Math.ceil(totalGoods / pageSize);
// 只需要判断是否还有下一页,不需要检查当前页数据量是否等于pageSize
const publishedHasMore = page < totalPages;
// 当published商品没有更多数据时,查询sold_out商品
const shouldQuerySoldOut = !publishedHasMore;
// 更新缓存(加载更多时追加数据)
const updatedCache = { ...this.data.categoryQueryCache };
if (isLoadMore && updatedCache[cacheKey]) {
// 追加新数据到缓存
const existingIds = new Set(updatedCache[cacheKey].map(item => item.id));
const newProducts = res.products.filter(item => !existingIds.has(item.id));
updatedCache[cacheKey] = [...updatedCache[cacheKey], ...newProducts];
} else {
// 首次加载或刷新时替换缓存
updatedCache[cacheKey] = res.products;
}
// 计算sold_out起始页码和每页数量 console.log(`===== ${statusList.join(', ')}状态查询结果 =====`);
let soldOutPageNum = 1; console.log('res.success:', res.success);
let soldOutPageSize = pageSize; console.log('res.products:', res.products);
if (shouldQuerySoldOut || (!publishedHasMore && isLoadMore)) { console.log('res.products.length:', res.products ? res.products.length : 'undefined');
// 如果published已无更多数据,查询sold_out商品 console.log('page:', page);
soldOutPageNum = isLoadMore ? this.data.soldOutPage + 1 : 1;
soldOutPageSize = pageSize; // 如果有published商品,直接处理
} if (res.success && res.products && res.products.length > 0) {
console.log('有published商品,处理商品数据');
const totalGoods = res.total || 0;
const totalPages = res.totalPages || Math.ceil(totalGoods / pageSize);
// 只需要判断是否还有下一页,不需要检查当前页数据量是否等于pageSize
const publishedHasMore = page < totalPages;
// 当published商品没有更多数据时,查询sold_out商品
const shouldQuerySoldOut = !publishedHasMore;
// 更新缓存(加载更多时追加数据)
const updatedCache = { ...this.data.categoryQueryCache };
if (isLoadMore && updatedCache[cacheKey]) {
// 追加新数据到缓存
const existingIds = new Set(updatedCache[cacheKey].map(item => item.id));
const newProducts = res.products.filter(item => !existingIds.has(item.id));
updatedCache[cacheKey] = [...updatedCache[cacheKey], ...newProducts];
} else {
// 首次加载或刷新时替换缓存
updatedCache[cacheKey] = res.products;
}
this.setData({ // 计算sold_out起始页码和每页数量
hasMoreData: publishedHasMore || (shouldQuerySoldOut || this.data.isQueryingSoldOut), let soldOutPageNum = 1;
isQueryingSoldOut: shouldQuerySoldOut || (!publishedHasMore && isLoadMore), let soldOutPageSize = pageSize;
publishedHasMore: publishedHasMore, if (shouldQuerySoldOut || (!publishedHasMore && isLoadMore)) {
soldOutPage: soldOutPageNum, // 如果published已无更多数据,查询sold_out商品
soldOutPageSize: soldOutPageSize, soldOutPageNum = isLoadMore ? this.data.soldOutPage + 1 : 1;
categoryQueryCache: updatedCache, soldOutPageSize = pageSize;
lastDataTimestamp: now, }
goodsCache: updatedCache[cacheKey]
});
this.processGoodsData(res.products, isLoadMore); this.setData({
hasMoreData: publishedHasMore || (shouldQuerySoldOut || this.data.isQueryingSoldOut),
isQueryingSoldOut: shouldQuerySoldOut || (!publishedHasMore && isLoadMore),
publishedHasMore: publishedHasMore,
soldOutPage: soldOutPageNum,
soldOutPageSize: soldOutPageSize,
categoryQueryCache: updatedCache,
lastDataTimestamp: now,
goodsCache: updatedCache[cacheKey]
});
// 如果需要查询sold_out this.processGoodsData(res.products, isLoadMore);
if (this.data.isQueryingSoldOut) {
this.loadSoldOutData(cacheKey, currentKeyword, currentCategory, timestamp, isLoadMore);
}
return; // 如果需要查询sold_out
} if (this.data.isQueryingSoldOut) {
this.loadSoldOutData(cacheKey, currentKeyword, currentCategory, timestamp, isLoadMore);
}
// 如果没有published商品,查询sold_out状态 return;
if (page === 1) { }
console.log('没有published商品,查询sold_out状态');
console.log('查询参数 - page:', page, 'pageSize:', pageSize, 'keyword:', currentKeyword, 'category:', currentCategory); // 如果没有published商品,查询sold_out状态
this.setData({ isQueryingSoldOut: true, soldOutPage: 1, soldOutPageSize: pageSize }); if (page === 1) {
this.loadSoldOutData(cacheKey, currentKeyword, currentCategory, timestamp, isLoadMore); console.log('没有published商品,查询sold_out状态');
return; console.log('查询参数 - page:', page, 'pageSize:', pageSize, 'keyword:', currentKeyword, 'category:', currentCategory);
} else { this.setData({ isQueryingSoldOut: true, soldOutPage: 1, soldOutPageSize: pageSize });
this.setData({ loadingMore: false, isLoading: false }); this.loadSoldOutData(cacheKey, currentKeyword, currentCategory, timestamp, isLoadMore);
} return;
}) } else {
.catch(err => { this.setData({ loadingMore: false, isLoading: false });
console.error('加载商品数据失败:', err); }
this.setData({ })
loadingMore: false, .catch(err => {
isLoading: false, console.error('加载商品数据失败:', err);
isRefreshing: false this.setData({
}); loadingMore: false,
}) isLoading: false,
isRefreshing: false
});
})
}, },
// 加载sold_out数据 // 加载sold_out数据
loadSoldOutData: function(cacheKey, currentKeyword, currentCategory, timestamp, isLoadMore) { loadSoldOutData: function (cacheKey, currentKeyword, currentCategory, timestamp, isLoadMore) {
const pageSize = this.data.soldOutPageSize || 8; const pageSize = this.data.soldOutPageSize || 8;
const soldOutPageNum = this.data.soldOutPage || 1; const soldOutPageNum = this.data.soldOutPage || 1;
@ -1094,59 +1094,59 @@ Page({
apiParams.category = currentCategory apiParams.category = currentCategory
} }
API.getProductList(['sold_out'], apiParams) API.getProductList(['sold_out'], apiParams)
.then(soldOutRes => { .then(soldOutRes => {
console.log('===== sold_out状态查询结果 ====='); console.log('===== sold_out状态查询结果 =====');
console.log('soldOutRes.success:', soldOutRes.success); console.log('soldOutRes.success:', soldOutRes.success);
console.log('soldOutRes.products:', soldOutRes.products); console.log('soldOutRes.products:', soldOutRes.products);
console.log('soldOutRes.products.length:', soldOutRes.products ? soldOutRes.products.length : 'undefined'); console.log('soldOutRes.products.length:', soldOutRes.products ? soldOutRes.products.length : 'undefined');
if (soldOutRes.success && soldOutRes.products && soldOutRes.products.length > 0) { if (soldOutRes.success && soldOutRes.products && soldOutRes.products.length > 0) {
const soldOutTotal = soldOutRes.total || 0; const soldOutTotal = soldOutRes.total || 0;
const soldOutTotalPages = soldOutRes.totalPages || Math.ceil(soldOutTotal / pageSize); const soldOutTotalPages = soldOutRes.totalPages || Math.ceil(soldOutTotal / pageSize);
const soldOutHasMore = soldOutPageNum < soldOutTotalPages && soldOutRes.products.length >= pageSize; const soldOutHasMore = soldOutPageNum < soldOutTotalPages && soldOutRes.products.length >= pageSize;
// 更新缓存 // 更新缓存
const updatedCache = { ...this.data.categoryQueryCache }; const updatedCache = { ...this.data.categoryQueryCache };
const existingCache = updatedCache[cacheKey] || []; const existingCache = updatedCache[cacheKey] || [];
const existingIds = new Set(existingCache.map(item => item.id)); const existingIds = new Set(existingCache.map(item => item.id));
const uniqueSoldOutProducts = soldOutRes.products.filter(item => !existingIds.has(item.id)); const uniqueSoldOutProducts = soldOutRes.products.filter(item => !existingIds.has(item.id));
updatedCache[cacheKey] = [...existingCache, ...uniqueSoldOutProducts]; updatedCache[cacheKey] = [...existingCache, ...uniqueSoldOutProducts];
this.setData({ this.setData({
hasMoreData: soldOutHasMore, hasMoreData: soldOutHasMore,
isQueryingSoldOut: soldOutHasMore, isQueryingSoldOut: soldOutHasMore,
soldOutPage: soldOutPageNum + 1, soldOutPage: soldOutPageNum + 1,
categoryQueryCache: updatedCache, categoryQueryCache: updatedCache,
lastDataTimestamp: new Date().getTime(), lastDataTimestamp: new Date().getTime(),
goodsCache: updatedCache[cacheKey] goodsCache: updatedCache[cacheKey]
}); });
this.processGoodsData(updatedCache[cacheKey], isLoadMore); this.processGoodsData(updatedCache[cacheKey], isLoadMore);
console.log('sold_out数据加载完成,总商品数:', updatedCache[cacheKey].length, 'hasMoreData:', soldOutHasMore); console.log('sold_out数据加载完成,总商品数:', updatedCache[cacheKey].length, 'hasMoreData:', soldOutHasMore);
} else { } else {
console.log('没有找到更多sold_out商品'); console.log('没有找到更多sold_out商品');
this.setData({
isQueryingSoldOut: false,
hasMoreData: false,
loadingMore: false,
isLoading: false
});
}
})
.catch(err => {
console.error('加载sold_out数据失败:', err);
this.setData({ this.setData({
isQueryingSoldOut: false, isQueryingSoldOut: false,
hasMoreData: false,
loadingMore: false, loadingMore: false,
isLoading: false isLoading: false,
isRefreshing: false
}); });
}
})
.catch(err => {
console.error('加载sold_out数据失败:', err);
this.setData({
isQueryingSoldOut: false,
loadingMore: false,
isLoading: false,
isRefreshing: false
}); });
});
}, },
// 处理缓存的商品数据 // 处理缓存的商品数据
processCachedGoods: function(cachedGoods, isLoadMore) { processCachedGoods: function (cachedGoods, isLoadMore) {
// 处理商品数据格式并去重 // 处理商品数据格式并去重
@ -1249,7 +1249,7 @@ Page({
}, },
// 刷新商品列表 - 强制刷新机制 // 刷新商品列表 - 强制刷新机制
refreshGoodsList: function() { refreshGoodsList: function () {
this.setData({ this.setData({
page: 1, page: 1,
hasMoreData: true, hasMoreData: true,
@ -1267,7 +1267,7 @@ Page({
}, },
// 统一字段长度 // 统一字段长度
normalizeFieldLength: function(item) { normalizeFieldLength: function (item) {
const normalized = { ...item } const normalized = { ...item }
// 统一 name 字段长度为 20 字符 // 统一 name 字段长度为 20 字符
@ -1295,7 +1295,7 @@ Page({
}, },
// 应用筛选条件 // 应用筛选条件
applyFilters: function(goods, shouldSort = true) { applyFilters: function (goods, shouldSort = true) {
let filtered = [...goods] let filtered = [...goods]
console.log('applyFilters - 开始过滤,原始商品数量:', goods.length, '关键词:', this.data.searchKeyword); console.log('applyFilters - 开始过滤,原始商品数量:', goods.length, '关键词:', this.data.searchKeyword);
@ -1410,7 +1410,7 @@ Page({
}, },
// 瀑布流布局 - 淘宝风格左右交替 // 瀑布流布局 - 淘宝风格左右交替
distributeToColumns: function(goods) { distributeToColumns: function (goods) {
if (!goods || goods.length === 0) { if (!goods || goods.length === 0) {
return { leftColumnGoods: [], rightColumnGoods: [] } return { leftColumnGoods: [], rightColumnGoods: [] }
} }
@ -1437,7 +1437,7 @@ Page({
}, },
// 分组商品用于交错布局(左长右短,左短右长交替) // 分组商品用于交错布局(左长右短,左短右长交替)
groupGoodsForStaggeredLayout: function(goods) { groupGoodsForStaggeredLayout: function (goods) {
if (!goods || goods.length === 0) { if (!goods || goods.length === 0) {
return [] return []
} }
@ -1474,7 +1474,7 @@ Page({
// 规则:左长右短 -> 左短右长 交替排列 // 规则:左长右短 -> 左短右长 交替排列
// 偶数行(0,2,4...):左长右短 // 偶数行(0,2,4...):左长右短
// 奇数行(1,3,5...):左短右长 // 奇数行(1,3,5...):左短右长
distributeToColumns: function(goods) { distributeToColumns: function (goods) {
if (!goods || goods.length === 0) { if (!goods || goods.length === 0) {
return { leftColumnGoods: [], rightColumnGoods: [] } return { leftColumnGoods: [], rightColumnGoods: [] }
} }
@ -1506,7 +1506,7 @@ Page({
}, },
// 搜索输入(带防抖) // 搜索输入(带防抖)
onSearchInput: function(e) { onSearchInput: function (e) {
const keyword = e.detail.value const keyword = e.detail.value
@ -1533,7 +1533,7 @@ Page({
}, },
// 搜索商品 // 搜索商品
searchGoods: function() { searchGoods: function () {
// 重新显示tabBar // 重新显示tabBar
const app = getApp(); const app = getApp();
if (app && app.globalData) { if (app && app.globalData) {
@ -1579,14 +1579,14 @@ Page({
}, },
// 切换地区选择器 // 切换地区选择器
toggleRegionPicker: function() { toggleRegionPicker: function () {
this.setData({ this.setData({
showRegionPicker: !this.data.showRegionPicker showRegionPicker: !this.data.showRegionPicker
}) })
}, },
// 选择地区(强制刷新机制) // 选择地区(强制刷新机制)
selectRegion: function(e) { selectRegion: function (e) {
const region = e.currentTarget.dataset.region const region = e.currentTarget.dataset.region
// 立即关闭弹窗 // 立即关闭弹窗
@ -1620,12 +1620,12 @@ Page({
}, },
// 阻止事件冒泡 // 阻止事件冒泡
stopPropagation: function() { stopPropagation: function () {
// 空函数,用于阻止事件冒泡 // 空函数,用于阻止事件冒泡
}, },
// 选择品种 - 使用下拉刷新机制 // 选择品种 - 使用下拉刷新机制
selectCategory: function(e) { selectCategory: function (e) {
// 重新显示tabBar // 重新显示tabBar
const app = getApp(); const app = getApp();
if (app && app.globalData) { if (app && app.globalData) {
@ -1660,7 +1660,7 @@ Page({
}, },
// 查看商品详情 // 查看商品详情
viewGoodsDetail: function(e) { viewGoodsDetail: function (e) {
const item = e.currentTarget.dataset.item const item = e.currentTarget.dataset.item
// 确保productId存在,优先使用id,其次使用productId // 确保productId存在,优先使用id,其次使用productId
@ -1685,14 +1685,14 @@ Page({
}, },
// 跳转到我要卖蛋页面 // 跳转到我要卖蛋页面
navigateToSettlement: function() { navigateToSettlement: function () {
wx.switchTab({ wx.switchTab({
url: '/pages/settlement/index' url: '/pages/settlement/index'
}) })
}, },
// 跳转到招商合作页面 // 跳转到招商合作页面
navigateToCooperation: function() { navigateToCooperation: function () {
this.setData({ this.setData({
sidebarBtnHidden: true sidebarBtnHidden: true
}); });
@ -1702,7 +1702,7 @@ Page({
}, },
// 跳转到货源管理页面 // 跳转到货源管理页面
navigateToGoods: function() { navigateToGoods: function () {
this.setData({ this.setData({
sidebarBtnHidden: true sidebarBtnHidden: true
}); });
@ -1712,7 +1712,7 @@ Page({
}, },
// 预览图片 // 预览图片
previewImage: function(e) { previewImage: function (e) {
// 阻止事件冒泡,避免触发商品点击事件 // 阻止事件冒泡,避免触发商品点击事件
e.stopPropagation(); e.stopPropagation();
@ -1746,21 +1746,21 @@ Page({
}, },
// 关闭图片预览 // 关闭图片预览
closeImagePreview: function() { closeImagePreview: function () {
this.setData({ this.setData({
showImagePreview: false showImagePreview: false
}); });
}, },
// 预览图片切换事件 // 预览图片切换事件
onPreviewImageChange: function(e) { onPreviewImageChange: function (e) {
this.setData({ this.setData({
previewImageIndex: e.detail.current previewImageIndex: e.detail.current
}); });
}, },
// 滚动事件处理 - 优化性能 // 滚动事件处理 - 优化性能
onScroll: function(e) { onScroll: function (e) {
const { scrollTop } = e.detail; const { scrollTop } = e.detail;
// 清除之前的防抖定时器 // 清除之前的防抖定时器
@ -1779,7 +1779,7 @@ Page({
}, },
// 实际的滚动处理逻辑 // 实际的滚动处理逻辑
handleScroll: function(scrollTop) { handleScroll: function (scrollTop) {
const threshold = 50; const threshold = 50;
const backToTopThreshold = 300; const backToTopThreshold = 300;
@ -1827,7 +1827,7 @@ Page({
}, },
// 更新商品的收藏状态 // 更新商品的收藏状态
updateGoodsFavoriteStatus: function(goods, isLoadMore) { updateGoodsFavoriteStatus: function (goods, isLoadMore) {
// 获取用户手机号 // 获取用户手机号
let userPhone = ''; let userPhone = '';
try { try {
@ -1909,7 +1909,7 @@ Page({
}, },
// 回到顶部 // 回到顶部
scrollToTop: function() { scrollToTop: function () {
this.setData({ this.setData({
scrollTop: 0, scrollTop: 0,
searchSectionVisible: true, searchSectionVisible: true,
@ -1918,7 +1918,7 @@ Page({
}, },
// 上拉加载更多 // 上拉加载更多
onReachBottom: function() { onReachBottom: function () {
if (this.data.hasMoreData && !this.data.loadingMore) { if (this.data.hasMoreData && !this.data.loadingMore) {
this.loadGoods(true) this.loadGoods(true)
} }

Loading…
Cancel
Save