Browse Source

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

pull/11/head
SwTt29 2 months ago
parent
commit
95460ad05e
  1. 2
      pages/goods-update/goods-update.wxml
  2. 98
      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>

98
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: '跳转失败,请稍后重试',
@ -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',
@ -546,12 +546,12 @@ Page({
}) })
}, },
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
} }
@ -986,8 +986,8 @@ 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)
@ -1075,7 +1075,7 @@ Page({
}, },
// 加载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;
@ -1146,7 +1146,7 @@ Page({
}, },
// 处理缓存的商品数据 // 处理缓存的商品数据
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