|
|
|
@ -3854,90 +3854,104 @@ Page({ |
|
|
|
} |
|
|
|
|
|
|
|
const supplyId = e.currentTarget.dataset.id; |
|
|
|
console.log('下架商品 - ID:', supplyId); |
|
|
|
console.log('当前商品列表长度:', this.data.supplies.length); |
|
|
|
console.log('当前已上架商品列表长度:', this.data.publishedSupplies.length); |
|
|
|
|
|
|
|
// 查找对应商品
|
|
|
|
let supply = this.data.supplies.find(s => s.id === supplyId); |
|
|
|
|
|
|
|
// 如果在主列表中找不到,尝试在已上架商品列表中查找
|
|
|
|
if (!supply) { |
|
|
|
supply = this.data.publishedSupplies.find(s => s.id === supplyId); |
|
|
|
console.log('在已上架列表中查找结果:', supply ? '找到' : '未找到'); |
|
|
|
} |
|
|
|
|
|
|
|
// 添加确认对话框,防止误触
|
|
|
|
wx.showModal({ |
|
|
|
title: '确认下架', |
|
|
|
content: '确定要下架该商品吗?', |
|
|
|
confirmText: '确定', |
|
|
|
cancelText: '取消', |
|
|
|
success: (res) => { |
|
|
|
if (res.confirm) { |
|
|
|
console.log('下架商品 - ID:', supplyId); |
|
|
|
console.log('当前商品列表长度:', this.data.supplies.length); |
|
|
|
console.log('当前已上架商品列表长度:', this.data.publishedSupplies.length); |
|
|
|
|
|
|
|
// 如果仍然找不到商品,尝试直接使用传入的ID下架(容错处理)
|
|
|
|
if (!supply) { |
|
|
|
console.warn('未在本地列表中找到商品,但尝试直接下架:', supplyId); |
|
|
|
// 查找对应商品
|
|
|
|
let supply = this.data.supplies.find(s => s.id === supplyId); |
|
|
|
|
|
|
|
// 禁用页面滚动
|
|
|
|
this.disablePageScroll(); |
|
|
|
wx.showLoading({ title: '下架中...', mask: true }); |
|
|
|
// 如果在主列表中找不到,尝试在已上架商品列表中查找
|
|
|
|
if (!supply) { |
|
|
|
supply = this.data.publishedSupplies.find(s => s.id === supplyId); |
|
|
|
console.log('在已上架列表中查找结果:', supply ? '找到' : '未找到'); |
|
|
|
} |
|
|
|
|
|
|
|
// 直接使用传入的ID尝试下架
|
|
|
|
API.hideProduct(supplyId) |
|
|
|
.then(res => { |
|
|
|
console.log('直接下架成功:', res); |
|
|
|
wx.hideLoading(); |
|
|
|
this.enablePageScroll(); |
|
|
|
wx.showToast({ title: '已下架', icon: 'success', duration: 2000 }); |
|
|
|
// 如果仍然找不到商品,尝试直接使用传入的ID下架(容错处理)
|
|
|
|
if (!supply) { |
|
|
|
console.warn('未在本地列表中找到商品,但尝试直接下架:', supplyId); |
|
|
|
|
|
|
|
// 清理购物车并重新加载列表
|
|
|
|
this.cleanUnpublishedFromAllCarts(supplyId); |
|
|
|
setTimeout(() => { |
|
|
|
this.loadSupplies(); |
|
|
|
}, 100); |
|
|
|
}) |
|
|
|
.catch(err => { |
|
|
|
console.error('直接下架失败:', err); |
|
|
|
wx.hideLoading(); |
|
|
|
this.enablePageScroll(); |
|
|
|
wx.showToast({ title: '下架失败,请重试', icon: 'none', duration: 2000 }); |
|
|
|
}); |
|
|
|
return; |
|
|
|
} |
|
|
|
// 禁用页面滚动
|
|
|
|
this.disablePageScroll(); |
|
|
|
wx.showLoading({ title: '下架中...', mask: true }); |
|
|
|
|
|
|
|
// 直接使用传入的ID尝试下架
|
|
|
|
API.hideProduct(supplyId) |
|
|
|
.then(res => { |
|
|
|
console.log('直接下架成功:', res); |
|
|
|
wx.hideLoading(); |
|
|
|
this.enablePageScroll(); |
|
|
|
wx.showToast({ title: '已下架', icon: 'success', duration: 2000 }); |
|
|
|
|
|
|
|
// 清理购物车并重新加载列表
|
|
|
|
this.cleanUnpublishedFromAllCarts(supplyId); |
|
|
|
setTimeout(() => { |
|
|
|
this.loadSupplies(); |
|
|
|
}, 100); |
|
|
|
}) |
|
|
|
.catch(err => { |
|
|
|
console.error('直接下架失败:', err); |
|
|
|
wx.hideLoading(); |
|
|
|
this.enablePageScroll(); |
|
|
|
wx.showToast({ title: '下架失败,请重试', icon: 'none', duration: 2000 }); |
|
|
|
}); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// 检查是否有serverProductId,只有上传到服务器的商品才能下架
|
|
|
|
if (!supply.serverProductId) { |
|
|
|
// 没有serverProductId,提示用户
|
|
|
|
wx.showToast({ title: '无法下架,商品未上传到服务器', icon: 'none', duration: 2000 }); |
|
|
|
return; |
|
|
|
} |
|
|
|
// 检查是否有serverProductId,只有上传到服务器的商品才能下架
|
|
|
|
if (!supply.serverProductId) { |
|
|
|
// 没有serverProductId,提示用户
|
|
|
|
wx.showToast({ title: '无法下架,商品未上传到服务器', icon: 'none', duration: 2000 }); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// 禁用页面滚动
|
|
|
|
this.disablePageScroll(); |
|
|
|
wx.showLoading({ title: '下架中...', mask: true }); |
|
|
|
// 禁用页面滚动
|
|
|
|
this.disablePageScroll(); |
|
|
|
wx.showLoading({ title: '下架中...', mask: true }); |
|
|
|
|
|
|
|
// 调用API下架商品
|
|
|
|
API.hideProduct(supply.serverProductId) |
|
|
|
.then(res => { |
|
|
|
console.log('服务器下架成功:', res); |
|
|
|
wx.hideLoading(); |
|
|
|
// 恢复页面滚动
|
|
|
|
this.enablePageScroll(); |
|
|
|
wx.showToast({ title: '已下架', icon: 'success', duration: 2000 }); |
|
|
|
// 调用API下架商品
|
|
|
|
API.hideProduct(supply.serverProductId) |
|
|
|
.then(res => { |
|
|
|
console.log('服务器下架成功:', res); |
|
|
|
wx.hideLoading(); |
|
|
|
// 恢复页面滚动
|
|
|
|
this.enablePageScroll(); |
|
|
|
wx.showToast({ title: '已下架', icon: 'success', duration: 2000 }); |
|
|
|
|
|
|
|
// 清理所有用户购物车中已下架的商品
|
|
|
|
this.cleanUnpublishedFromAllCarts(supply.serverProductId); |
|
|
|
// 清理所有用户购物车中已下架的商品
|
|
|
|
this.cleanUnpublishedFromAllCarts(supply.serverProductId); |
|
|
|
|
|
|
|
// 只需要调用一次loadSupplies
|
|
|
|
setTimeout(() => { |
|
|
|
this.loadSupplies(); |
|
|
|
}, 100); |
|
|
|
}) |
|
|
|
.catch(err => { |
|
|
|
console.error('服务器下架失败:', err); |
|
|
|
wx.hideLoading(); |
|
|
|
// 恢复页面滚动
|
|
|
|
this.enablePageScroll(); |
|
|
|
wx.showToast({ title: '服务器同步失败,请重试', icon: 'none', duration: 3000 }); |
|
|
|
// 只需要调用一次loadSupplies
|
|
|
|
setTimeout(() => { |
|
|
|
this.loadSupplies(); |
|
|
|
}, 100); |
|
|
|
}) |
|
|
|
.catch(err => { |
|
|
|
console.error('服务器下架失败:', err); |
|
|
|
wx.hideLoading(); |
|
|
|
// 恢复页面滚动
|
|
|
|
this.enablePageScroll(); |
|
|
|
wx.showToast({ title: '服务器同步失败,请重试', icon: 'none', duration: 3000 }); |
|
|
|
|
|
|
|
// 只需要调用一次loadSupplies
|
|
|
|
setTimeout(() => { |
|
|
|
this.loadSupplies(); |
|
|
|
}, 100); |
|
|
|
}); |
|
|
|
// 只需要调用一次loadSupplies
|
|
|
|
setTimeout(() => { |
|
|
|
this.loadSupplies(); |
|
|
|
}, 100); |
|
|
|
}); |
|
|
|
} else if (res.cancel) { |
|
|
|
console.log('用户取消下架操作'); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
// 清理所有用户购物车中已下架的商品 - 移除本地存储操作
|
|
|
|
|