diff --git a/pages/goods-update/goods-update.js b/pages/goods-update/goods-update.js
index 49e58e0..6ae1e8d 100644
--- a/pages/goods-update/goods-update.js
+++ b/pages/goods-update/goods-update.js
@@ -569,6 +569,47 @@ Page({
const finalRegion = preloadedData?.region || product.region || product.area || product.location || '暂无';
console.log('finalRegion:', finalRegion);
+ // 详细调试商品状态
+ console.log('=== 商品状态详细调试 ===');
+ console.log('API返回的完整product对象:', JSON.stringify(product, null, 2));
+ console.log('API返回的product.status:', product.status);
+ console.log('商品label字段:', product.label);
+ console.log('商品label类型:', typeof product.label);
+ console.log('商品是否包含status字段:', 'status' in product);
+ console.log('商品是否包含label字段:', 'label' in product);
+
+ // 检查预加载数据中的状态信息
+ console.log('=== 预加载数据状态检查 ===');
+ console.log('预加载数据中的status:', preloadedData?.status);
+ console.log('预加载数据中的label:', preloadedData?.label);
+
+ // 定义已下架状态列表
+ const soldOutStatuses = ['sold_out', 'unpublished', 'hidden'];
+
+ // 检查商品是否已下架
+ // 1. 首先检查预加载数据中的状态
+ const preloadedIsSoldOut =
+ (preloadedData?.label === 1 || preloadedData?.label === '1' || preloadedData?.label === true) ||
+ (preloadedData?.status && soldOutStatuses.includes(preloadedData?.status.toLowerCase()));
+
+ // 2. 然后检查API返回的数据中的状态
+ const apiIsSoldOut =
+ (product.label === 1 || product.label === '1' || product.label === true) ||
+ (product.status && soldOutStatuses.includes(product.status.toLowerCase()));
+
+ // 3. 综合判断,只要有一个为true就表示已下架
+ const isSoldOut = preloadedIsSoldOut || apiIsSoldOut;
+
+ // 根据是否已下架设置最终状态
+ let finalStatus = isSoldOut ? 'sold_out' : 'published';
+
+ // 详细记录状态判断信息
+ console.log('=== 状态判断结果 ===');
+ console.log('预加载数据判断是否已下架:', preloadedIsSoldOut);
+ console.log('API数据判断是否已下架:', apiIsSoldOut);
+ console.log('最终是否已下架:', isSoldOut);
+ console.log('最终状态:', finalStatus);
+
// 转换商品数据格式
const formattedGoods = {
id: productIdStr,
@@ -587,7 +628,8 @@ Page({
displayGrossWeight: formatGrossWeight(grossWeightValue, product.weight),
created_at: product.created_at || product.createdAt,
updated_at: product.updated_at || product.updatedAt,
- status: product.status,
+ status: finalStatus, // 使用处理后的状态
+ label: product.label, // 保留原始label字段
supplyStatus: supplyStatusValue,
sourceType: product.sourceType || '',
sourceTypeColor: getSourceTypeColor(product.sourceType),
@@ -601,7 +643,9 @@ Page({
region: finalRegion,
// 复制原始产品对象中的所有字段,确保不丢失任何数据
...product,
- // 重新设置创建者信息和创建时间,防止被product数据覆盖
+ // 重新设置关键字段,防止被product数据覆盖
+ status: finalStatus, // 确保状态字段使用我们处理后的值
+ label: product.label,
creatorName: creatorName,
formattedCreatedAt: formattedCreatedAt,
created_at: createdAt,
@@ -620,14 +664,35 @@ Page({
freshness: product.freshness || ''
};
+ console.log('最终formattedGoods.status:', formattedGoods.status);
+ console.log('最终formattedGoods.label:', formattedGoods.label);
+
console.log('最终formattedGoods.region:', formattedGoods.region);
// 调试输出完整的formattedGoods对象
console.log('最终格式化的商品数据:', JSON.stringify(formattedGoods, null, 2));
+ // 强制将测试商品设置为已下架状态,用于调试
+ // formattedGoods.status = 'sold_out';
+ // formattedGoods.label = 1;
+
+ console.log('=== 最终商品状态 ===');
+ console.log('goodsDetail.status:', formattedGoods.status);
+ console.log('goodsDetail.label:', formattedGoods.label);
+ console.log('按钮是否应该被禁用:', formattedGoods.status === 'sold_out');
+ console.log('是否应该显示disabled-button类:', formattedGoods.status === 'sold_out');
+
this.setData({
goodsDetail: formattedGoods
});
+
+ // 延迟检查数据绑定情况
+ setTimeout(() => {
+ const currentStatus = this.data.goodsDetail.status;
+ console.log('=== 数据绑定后检查 ===');
+ console.log('当前goodsDetail.status:', currentStatus);
+ console.log('按钮是否被正确绑定:', currentStatus === 'sold_out');
+ }, 100);
} else {
wx.showToast({
title: '获取商品详情失败',
@@ -976,7 +1041,8 @@ Page({
.then(res => {
wx.hideLoading();
console.log('下架商品成功:', res);
- if (res && res.code === 200) {
+ // 更灵活的成功判断条件,支持多种返回格式
+ if (res && (res.code === 200 || res.success === true || res.status === 'success')) {
wx.showToast({
title: '下架成功',
icon: 'success',
@@ -984,7 +1050,8 @@ Page({
});
this.setData({
- 'goodsDetail.label': 1
+ 'goodsDetail.status': 'sold_out',
+ 'goodsDetail.label': 1 // 保留label字段的更新,确保兼容性
});
} else {
wx.showToast({
diff --git a/pages/goods-update/goods-update.wxml b/pages/goods-update/goods-update.wxml
index 69625c9..72f38e1 100644
--- a/pages/goods-update/goods-update.wxml
+++ b/pages/goods-update/goods-update.wxml
@@ -189,11 +189,18 @@
编辑货源
diff --git a/pages/goods-update/goods-update.wxss b/pages/goods-update/goods-update.wxss
index 4e77db9..37a161d 100644
--- a/pages/goods-update/goods-update.wxss
+++ b/pages/goods-update/goods-update.wxss
@@ -654,13 +654,25 @@ video.slider-media .wx-video-volume-icon {
box-shadow: 0 4px 12px rgba(82, 196, 26, 0.3);
}
-/* 已下架按钮样式 */
+/* 已下架按钮样式 - 确保最高优先级 */
.publish-button.bottom-button.disabled-button,
.publish-button.bottom-button[disabled] {
- background-color: #d9d9d9;
- color: #999999;
- border: 2rpx solid #d9d9d9;
- box-shadow: none;
+ background-color: #d9d9d9 !important;
+ color: #999999 !important;
+ border: 2px solid #d9d9d9 !important;
+ box-shadow: none !important;
+ opacity: 0.8 !important;
+ transform: none !important;
+}
+
+/* 确保编辑按钮不受影响 */
+.edit-button.bottom-button.disabled-button,
+.edit-button.bottom-button[disabled] {
+ background-color: #d9d9d9 !important;
+ color: #999999 !important;
+ border: 2px solid #d9d9d9 !important;
+ box-shadow: none !important;
+ opacity: 0.8 !important;
}
/* 返回按钮样式 */
diff --git a/pages/goods/index.js b/pages/goods/index.js
index bff0bed..af10ee3 100644
--- a/pages/goods/index.js
+++ b/pages/goods/index.js
@@ -176,6 +176,38 @@ Page({
this.loadGoodsList()
},
+ /**
+ * 根据搜索关键词过滤数据
+ */
+ searchGoodsList(goodsList, keyword) {
+ if (!keyword || keyword.trim() === '') {
+ return goodsList
+ }
+
+ const searchTerm = keyword.toLowerCase().trim()
+
+ return goodsList.filter(item => {
+ // 检查多个字段是否包含搜索关键词
+ const fieldsToCheck = [
+ item.productName || item.name || '', // 产品名称
+ item.creatorName || '', // 创建人
+ item.specification || item.spec || '', // 规格
+ item.description || '', // 描述
+ item.region || '', // 地区
+ item.yolk || '', // 蛋黄
+ item.price || '', // 价格
+ item.grossWeight || item.weight || '', // 重量
+ item.category || '', // 种类
+ item.formattedCreatedAt || item.created_at || '' // 创建时间
+ ]
+
+ // 检查是否有任何字段包含搜索关键词
+ return fieldsToCheck.some(field => {
+ return field.toLowerCase().includes(searchTerm)
+ })
+ })
+ },
+
/**
* 根据筛选条件过滤数据
*/
@@ -309,8 +341,16 @@ Page({
type: isVideoUrl(url) ? 'video' : 'image'
}))
+ // 处理商品状态,将已下架的商品标记为售空
+ let status = item.status
+ // 如果商品状态不是已上架(published),则标记为售空(sold_out)
+ if (status !== 'published') {
+ status = 'sold_out'
+ }
+
return {
...item,
+ status: status, // 更新商品状态
formattedCreatedAt: this.formatDateTime(item.created_at || item.createTime),
creatorName: creatorName,
imageUrls: formattedImageUrls,
@@ -318,15 +358,46 @@ Page({
}
})
- // 应用筛选条件
+ // 应用筛选条件和搜索过滤
const originalList = [...newGoodsList]
- const filteredList = this.filterGoodsList(newGoodsList)
+ // 先应用搜索过滤
+ let searchFilteredList = this.searchGoodsList(newGoodsList, this.data.searchKeyword)
+ // 再应用筛选条件
+ let filteredList = this.filterGoodsList(searchFilteredList)
+
+ // 排序:已上架商品排在前面,售空商品排在后面
+ filteredList.sort((a, b) => {
+ if (a.status === 'published' && b.status === 'sold_out') {
+ return -1 // 已上架排在前面
+ } else if (a.status === 'sold_out' && b.status === 'published') {
+ return 1 // 售空排在后面
+ } else {
+ // 相同状态下,按创建时间倒序排序
+ const timeA = new Date(a.created_at || a.createTime).getTime()
+ const timeB = new Date(b.created_at || b.createTime).getTime()
+ return timeB - timeA
+ }
+ })
console.log('处理并筛选后的产品列表:', filteredList)
console.log('筛选前后数量对比:', originalList.length, '->', filteredList.length)
// 处理分页逻辑
- const updatedGoodsList = this.data.currentPage === 1 ? filteredList : [...this.data.goodsList, ...filteredList]
+ let updatedGoodsList = this.data.currentPage === 1 ? filteredList : [...this.data.goodsList, ...filteredList]
+
+ // 对整个列表进行排序,确保已上架商品始终在前面,售空商品在后面
+ updatedGoodsList.sort((a, b) => {
+ if (a.status === 'published' && b.status === 'sold_out') {
+ return -1 // 已上架排在前面
+ } else if (a.status === 'sold_out' && b.status === 'published') {
+ return 1 // 售空排在后面
+ } else {
+ // 相同状态下,按创建时间倒序排序
+ const timeA = new Date(a.created_at || a.createTime).getTime()
+ const timeB = new Date(b.created_at || b.createTime).getTime()
+ return timeB - timeA
+ }
+ })
// 判断是否还有更多数据
// 正确逻辑:如果API返回的原始数据数量小于pageSize,说明没有更多数据
diff --git a/pages/goods/index.wxml b/pages/goods/index.wxml
index c8e498c..6fd4009 100644
--- a/pages/goods/index.wxml
+++ b/pages/goods/index.wxml
@@ -24,7 +24,7 @@
-
+