|
|
@ -122,15 +122,14 @@ Page({ |
|
|
showAuthModal: false, // 控制未授权提示弹窗显示
|
|
|
showAuthModal: false, // 控制未授权提示弹窗显示
|
|
|
showOneKeyLoginModal: false, // 控制一键登录弹窗显示
|
|
|
showOneKeyLoginModal: false, // 控制一键登录弹窗显示
|
|
|
pendingUserType: 'seller', // 记录用户即将选择的身份类型
|
|
|
pendingUserType: 'seller', // 记录用户即将选择的身份类型
|
|
|
avatarUrl: '/images/default-avatar.png' // 默认头像
|
|
|
avatarUrl: '/images/default-avatar.png', // 默认头像
|
|
|
|
|
|
partnerstatus: '' // 用户入驻状态,用于显示入驻/未入驻
|
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
onLoad() { |
|
|
onLoad() { |
|
|
console.log('卖家页面onLoad开始执行'); |
|
|
console.log('卖家页面onLoad开始执行'); |
|
|
// 移除强制登录检查,允许用户浏览货源页面
|
|
|
// 移除强制登录检查,允许用户浏览货源页面
|
|
|
// 只有在创建新货源时才检查登录状态
|
|
|
|
|
|
this.loadSupplies(); |
|
|
this.loadSupplies(); |
|
|
|
|
|
|
|
|
// 初始化规格搜索相关数据
|
|
|
// 初始化规格搜索相关数据
|
|
|
this.setData({ |
|
|
this.setData({ |
|
|
specSearchKeyword: '', |
|
|
specSearchKeyword: '', |
|
|
@ -138,7 +137,6 @@ Page({ |
|
|
filteredSpecOptions: this.data.specOptions, |
|
|
filteredSpecOptions: this.data.specOptions, |
|
|
filteredEditSpecOptions: this.data.specOptions |
|
|
filteredEditSpecOptions: this.data.specOptions |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
console.log('卖家页面onLoad执行完毕'); |
|
|
console.log('卖家页面onLoad执行完毕'); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
@ -315,6 +313,8 @@ Page({ |
|
|
|
|
|
|
|
|
onShow() { |
|
|
onShow() { |
|
|
console.log('seller页面onShow开始加载') |
|
|
console.log('seller页面onShow开始加载') |
|
|
|
|
|
// 获取用户入驻状态
|
|
|
|
|
|
this.getUserStatus(); |
|
|
// 检查页面是否是初次加载(onLoad已调用loadSupplies)
|
|
|
// 检查页面是否是初次加载(onLoad已调用loadSupplies)
|
|
|
// 避免在页面初次加载时重复加载数据
|
|
|
// 避免在页面初次加载时重复加载数据
|
|
|
if (!this.data._hasLoadedOnShow) { |
|
|
if (!this.data._hasLoadedOnShow) { |
|
|
@ -342,6 +342,26 @@ Page({ |
|
|
app.updateCurrentTab('seller'); |
|
|
app.updateCurrentTab('seller'); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
// 获取用户入驻状态
|
|
|
|
|
|
getUserStatus() { |
|
|
|
|
|
const openid = wx.getStorageSync('openid'); |
|
|
|
|
|
if (openid) { |
|
|
|
|
|
API.getUserInfo(openid) |
|
|
|
|
|
.then(response => { |
|
|
|
|
|
console.log('获取到的用户信息响应:', response); |
|
|
|
|
|
// 修复:访问data字段获取用户信息
|
|
|
|
|
|
const userInfo = response.data || {}; |
|
|
|
|
|
console.log('处理后的用户信息:', userInfo); |
|
|
|
|
|
this.setData({ |
|
|
|
|
|
partnerstatus: userInfo.partnerstatus || '' |
|
|
|
|
|
}); |
|
|
|
|
|
}) |
|
|
|
|
|
.catch(err => { |
|
|
|
|
|
console.error('获取用户信息失败:', err); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
// 加载货源列表并分类 - 修改为分页加载
|
|
|
// 加载货源列表并分类 - 修改为分页加载
|
|
|
loadSupplies() { |
|
|
loadSupplies() { |
|
|
console.log('开始加载货源数据 - 分页模式'); |
|
|
console.log('开始加载货源数据 - 分页模式'); |
|
|
@ -1189,26 +1209,12 @@ Page({ |
|
|
showAddSupply(e) { |
|
|
showAddSupply(e) { |
|
|
console.log('点击创建新货源按钮'); |
|
|
console.log('点击创建新货源按钮'); |
|
|
|
|
|
|
|
|
// 检查登录状态
|
|
|
|
|
|
const openid = wx.getStorageSync('openid'); |
|
|
|
|
|
const userId = wx.getStorageSync('userId'); |
|
|
|
|
|
|
|
|
|
|
|
if (!openid || !userId) { |
|
|
|
|
|
console.log('用户未登录,触发授权登录流程'); |
|
|
|
|
|
// 显示授权弹窗
|
|
|
|
|
|
this.setData({ |
|
|
|
|
|
showAuthModal: true, |
|
|
|
|
|
pendingUserType: 'seller' |
|
|
|
|
|
}); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 阻止事件冒泡,防止触发父元素的点击事件
|
|
|
// 阻止事件冒泡,防止触发父元素的点击事件
|
|
|
if (e && e.stopPropagation) { |
|
|
if (e && e.stopPropagation) { |
|
|
e.stopPropagation(); |
|
|
e.stopPropagation(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 已登录,继续原有逻辑
|
|
|
// 直接显示创建货源弹窗,无需登录验证
|
|
|
this.setData({ |
|
|
this.setData({ |
|
|
showImagePreview: false, |
|
|
showImagePreview: false, |
|
|
showModal: true, |
|
|
showModal: true, |
|
|
@ -1336,6 +1342,32 @@ Page({ |
|
|
}, |
|
|
}, |
|
|
// 添加新货源 - 先创建商品再上传图片(修复版)
|
|
|
// 添加新货源 - 先创建商品再上传图片(修复版)
|
|
|
addSupply() { |
|
|
addSupply() { |
|
|
|
|
|
// 检查登录状态
|
|
|
|
|
|
const userId = wx.getStorageSync('userId'); |
|
|
|
|
|
const openid = wx.getStorageSync('openid'); |
|
|
|
|
|
const userInfo = wx.getStorageSync('userInfo'); |
|
|
|
|
|
|
|
|
|
|
|
if (!userId || !openid || !userInfo) { |
|
|
|
|
|
console.log('用户未登录,显示登录提示'); |
|
|
|
|
|
// 用户未登录,显示未授权提示弹窗
|
|
|
|
|
|
wx.showModal({ |
|
|
|
|
|
title: '登录提示', |
|
|
|
|
|
content: '请先登录再发布商品', |
|
|
|
|
|
showCancel: true, |
|
|
|
|
|
confirmText: '去登录', |
|
|
|
|
|
success: (res) => { |
|
|
|
|
|
if (res.confirm) { |
|
|
|
|
|
// 用户点击确定,跳转到登录页面或显示登录弹窗
|
|
|
|
|
|
this.setData({ |
|
|
|
|
|
showAuthModal: true, |
|
|
|
|
|
pendingUserType: 'seller' |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
const { name, price, minOrder, yolk, spec, region, imageUrls } = this.data.newSupply |
|
|
const { name, price, minOrder, yolk, spec, region, imageUrls } = this.data.newSupply |
|
|
if (!name || !price || !minOrder || !yolk) { |
|
|
if (!name || !price || !minOrder || !yolk) { |
|
|
wx.showToast({ title: '请填写完整信息', icon: 'none', duration: 2000 }) |
|
|
wx.showToast({ title: '请填写完整信息', icon: 'none', duration: 2000 }) |
|
|
@ -1343,53 +1375,44 @@ Page({ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 显示加载中提示
|
|
|
// 显示加载中提示
|
|
|
wx.showLoading({ title: '正在创建商品...', mask: true }) |
|
|
wx.showLoading({ title: '正在验证权限...', mask: true }) |
|
|
|
|
|
|
|
|
const openid = wx.getStorageSync('openid') |
|
|
// 检查用户的partnerstatus是否为approved
|
|
|
console.log('当前用户openid:', openid) |
|
|
API.getUserInfo(openid) |
|
|
// 检查openid是否存在
|
|
|
.then(response => { |
|
|
if (!openid) { |
|
|
const userInfoRes = response.data; |
|
|
console.error('openid不存在,无法上传商品到服务器') |
|
|
console.log('获取用户信息成功:', userInfoRes) |
|
|
wx.hideLoading() |
|
|
|
|
|
wx.showModal({ |
|
|
// 检查partnerstatus字段
|
|
|
title: '登录状态异常', |
|
|
const partnerStatus = userInfoRes.partnerstatus || 'pending' |
|
|
content: '您的登录状态已失效,请重新登录后再尝试发布商品', |
|
|
console.log('用户合作状态:', partnerStatus) |
|
|
showCancel: false, |
|
|
|
|
|
success: () => { |
|
|
if (partnerStatus !== 'approved') { |
|
|
wx.showToast({ |
|
|
throw new Error('partnerstatus_not_approved') |
|
|
title: '创建失败,请先登录', |
|
|
} |
|
|
icon: 'none', |
|
|
|
|
|
duration: 3000 |
|
|
// 第一步:先创建商品(不带图片)
|
|
|
}) |
|
|
const productData = { |
|
|
|
|
|
productName: name, |
|
|
|
|
|
price: price, // 保留原始字符串,不进行数字转换
|
|
|
|
|
|
quantity: Number(minOrder), |
|
|
|
|
|
grossWeight: this.data.newSupply.grossWeight && this.data.newSupply.grossWeight !== '' ? this.data.newSupply.grossWeight : "", |
|
|
|
|
|
|
|
|
|
|
|
yolk: yolk, |
|
|
|
|
|
specification: spec || '', |
|
|
|
|
|
region: region || '', // 【新增】添加地区字段
|
|
|
|
|
|
rejectReason: '', |
|
|
|
|
|
imageUrls: [] // 明确设置为空数组
|
|
|
} |
|
|
} |
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
this.setData({ |
|
|
|
|
|
showModal: false, |
|
|
|
|
|
newSupply: { name: '', price: '', minOrder: '', yolk: '', spec: '', region: '', grossWeight: '', imageUrls: [] } |
|
|
|
|
|
}) |
|
|
|
|
|
this.enablePageScroll() |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 第一步:先创建商品(不带图片)
|
|
|
|
|
|
const productData = { |
|
|
|
|
|
productName: name, |
|
|
|
|
|
price: price, // 保留原始字符串,不进行数字转换
|
|
|
|
|
|
quantity: Number(minOrder), |
|
|
|
|
|
grossWeight: this.data.newSupply.grossWeight && this.data.newSupply.grossWeight !== '' ? this.data.newSupply.grossWeight : "", |
|
|
|
|
|
|
|
|
|
|
|
yolk: yolk, |
|
|
|
|
|
specification: spec || '', |
|
|
|
|
|
region: region || '', // 【新增】添加地区字段
|
|
|
|
|
|
rejectReason: '', |
|
|
|
|
|
imageUrls: [] // 明确设置为空数组
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
console.log('第一步:准备创建商品,数据:', productData) |
|
|
console.log('第一步:准备创建商品,数据:', productData) |
|
|
|
|
|
|
|
|
|
|
|
// 更新加载提示
|
|
|
|
|
|
wx.showLoading({ title: '正在创建商品...', mask: true }) |
|
|
|
|
|
|
|
|
// 调用API创建商品(不带图片)
|
|
|
// 调用API创建商品(不带图片)
|
|
|
API.publishProduct(productData) |
|
|
return API.publishProduct(productData) |
|
|
|
|
|
}) |
|
|
.then(res => { |
|
|
.then(res => { |
|
|
console.log('商品创建成功:', res) |
|
|
console.log('商品创建成功:', res) |
|
|
|
|
|
|
|
|
@ -1439,39 +1462,30 @@ Page({ |
|
|
console.error('商品创建或图片上传失败:', err) |
|
|
console.error('商品创建或图片上传失败:', err) |
|
|
wx.hideLoading() |
|
|
wx.hideLoading() |
|
|
|
|
|
|
|
|
// 错误处理
|
|
|
// 处理权限不足的情况
|
|
|
if (err.needRelogin) { |
|
|
if (err.message === 'partnerstatus_not_approved') { |
|
|
console.warn('检测到需要重新登录') |
|
|
|
|
|
wx.showModal({ |
|
|
wx.showModal({ |
|
|
title: '登录状态失效', |
|
|
title: '权限不足', |
|
|
content: '您的登录已过期,请重新授权登录', |
|
|
content: '您的合作伙伴身份尚未通过审核,请等待审核通过后再发布商品', |
|
|
showCancel: false, |
|
|
showCancel: false, |
|
|
success: (res) => { |
|
|
confirmText: '确定' |
|
|
if (res.confirm) { |
|
|
|
|
|
wx.removeStorageSync('openid') |
|
|
|
|
|
wx.removeStorageSync('userId') |
|
|
|
|
|
wx.navigateTo({ url: '/pages/login/index' }) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
} else { |
|
|
|
|
|
let errorMsg = '上传服务器失败' |
|
|
|
|
|
if (err.message && err.message.includes('用户不存在')) { |
|
|
|
|
|
errorMsg = '用户未登录,请先登录' |
|
|
|
|
|
} else if (err.message && err.message.includes('卖家才能发布商品')) { |
|
|
|
|
|
errorMsg = '请先在个人资料中修改用户类型为卖家' |
|
|
|
|
|
} else if (err.message && err.message.includes('商品不存在')) { |
|
|
|
|
|
errorMsg = '商品创建失败,无法上传图片' |
|
|
|
|
|
} |
|
|
|
|
|
wx.showModal({ |
|
|
|
|
|
title: '发布失败', |
|
|
|
|
|
content: errorMsg + '\n\n错误详情: ' + (err.message || JSON.stringify(err)), |
|
|
|
|
|
showCancel: false, |
|
|
|
|
|
success: () => { |
|
|
|
|
|
this.loadSupplies() |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
}) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 其他错误处理:所有错误都显示通用提示,不再跳转登录
|
|
|
|
|
|
let errorMsg = '上传服务器失败' |
|
|
|
|
|
if (err.message && err.message.includes('商品不存在')) { |
|
|
|
|
|
errorMsg = '商品创建失败,无法上传图片' |
|
|
} |
|
|
} |
|
|
|
|
|
wx.showModal({ |
|
|
|
|
|
title: '发布失败', |
|
|
|
|
|
content: errorMsg + '\n\n错误详情: ' + (err.message || JSON.stringify(err)), |
|
|
|
|
|
showCancel: false, |
|
|
|
|
|
success: () => { |
|
|
|
|
|
this.loadSupplies() |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
}) |
|
|
}) |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
@ -1651,6 +1665,37 @@ Page({ |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 检查用户合作状态
|
|
|
|
|
|
API.getUserInfo(openid) |
|
|
|
|
|
.then(response => { |
|
|
|
|
|
const userInfo = response.data; |
|
|
|
|
|
if (userInfo.partnerstatus !== 'approved') { |
|
|
|
|
|
wx.hideLoading(); |
|
|
|
|
|
wx.showToast({ |
|
|
|
|
|
title: '权限不足,无法保存商品', |
|
|
|
|
|
icon: 'none', |
|
|
|
|
|
duration: 3000 |
|
|
|
|
|
}); |
|
|
|
|
|
this.setData({ showEditModal: false }); |
|
|
|
|
|
this.enablePageScroll(); |
|
|
|
|
|
return Promise.reject('partnerstatus not approved'); |
|
|
|
|
|
} |
|
|
|
|
|
return Promise.resolve(); |
|
|
|
|
|
}) |
|
|
|
|
|
.catch(err => { |
|
|
|
|
|
if (err !== 'partnerstatus not approved') { |
|
|
|
|
|
wx.hideLoading(); |
|
|
|
|
|
wx.showToast({ |
|
|
|
|
|
title: '获取用户信息失败', |
|
|
|
|
|
icon: 'none', |
|
|
|
|
|
duration: 3000 |
|
|
|
|
|
}); |
|
|
|
|
|
this.setData({ showEditModal: false }); |
|
|
|
|
|
this.enablePageScroll(); |
|
|
|
|
|
} |
|
|
|
|
|
return Promise.reject(err); |
|
|
|
|
|
}) |
|
|
|
|
|
.then(() => { |
|
|
// 【关键修复】准备商品数据 - 确保包含地区字段
|
|
|
// 【关键修复】准备商品数据 - 确保包含地区字段
|
|
|
const productData = { |
|
|
const productData = { |
|
|
productName: editSupply.name, |
|
|
productName: editSupply.name, |
|
|
@ -1750,6 +1795,7 @@ Page({ |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
}); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
// 预览图片
|
|
|
// 预览图片
|
|
|
@ -2144,165 +2190,209 @@ Page({ |
|
|
showImagePreview: false |
|
|
showImagePreview: false |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
const id = e.currentTarget.dataset.id |
|
|
// 登录验证
|
|
|
// 优先使用编辑中的商品数据
|
|
|
const userId = wx.getStorageSync('userId'); |
|
|
let supply = null |
|
|
const openid = wx.getStorageSync('openid'); |
|
|
|
|
|
const userInfo = wx.getStorageSync('userInfo'); |
|
|
// 检查是否存在编辑中的数据
|
|
|
|
|
|
if (this.data.editSupply && this.data.editSupply.id === id) { |
|
|
if (!userId || !openid || !userInfo) { |
|
|
supply = { ...this.data.editSupply }; |
|
|
wx.showModal({ |
|
|
} else { |
|
|
title: '提示', |
|
|
// 否则从supplies中查找
|
|
|
content: '请先登录再进行商品上架操作', |
|
|
supply = this.data.supplies.find(s => s.id === id) |
|
|
showCancel: false, |
|
|
} |
|
|
success: (res) => { |
|
|
|
|
|
if (res.confirm) { |
|
|
if (!supply) { |
|
|
this.setData({ showAuthModal: true }); |
|
|
wx.hideLoading(); |
|
|
} |
|
|
// 恢复页面滚动
|
|
|
} |
|
|
this.enablePageScroll(); |
|
|
|
|
|
wx.showToast({ |
|
|
|
|
|
title: '操作失败,货源不存在', |
|
|
|
|
|
icon: 'none', |
|
|
|
|
|
duration: 2000 |
|
|
|
|
|
}); |
|
|
}); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 检查用户合作状态
|
|
|
|
|
|
API.getUserInfo(openid) |
|
|
|
|
|
.then(response => { |
|
|
|
|
|
const userInfo = response.data; |
|
|
|
|
|
if (userInfo.partnerstatus !== 'approved') { |
|
|
|
|
|
wx.hideLoading(); |
|
|
|
|
|
this.enablePageScroll(); |
|
|
|
|
|
wx.showModal({ |
|
|
|
|
|
title: '权限不足', |
|
|
|
|
|
content: '您的合作状态尚未通过审核,暂时无法进行商品上架操作', |
|
|
|
|
|
showCancel: false |
|
|
|
|
|
}); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const id = e.currentTarget.dataset.id |
|
|
|
|
|
// 优先使用编辑中的商品数据
|
|
|
|
|
|
let supply = null |
|
|
|
|
|
|
|
|
|
|
|
// 检查是否存在编辑中的数据
|
|
|
|
|
|
if (this.data.editSupply && this.data.editSupply.id === id) { |
|
|
|
|
|
supply = { ...this.data.editSupply }; |
|
|
|
|
|
} else { |
|
|
|
|
|
// 否则从supplies中查找
|
|
|
|
|
|
supply = this.data.supplies.find(s => s.id === id) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
wx.showLoading({ title: '处理中...', mask: true }); |
|
|
if (!supply) { |
|
|
|
|
|
wx.hideLoading(); |
|
|
// 判断当前货源状态,决定设置什么状态
|
|
|
this.enablePageScroll(); |
|
|
// 重新提交的商品应该先进入审核中
|
|
|
wx.showToast({ |
|
|
let newStatus = 'pending_review'; // 默认审核中
|
|
|
title: '货源信息不存在', |
|
|
if (supply.status === 'reviewed') { |
|
|
icon: 'none', |
|
|
newStatus = 'published'; // 已审核通过的货源可以直接上架
|
|
|
duration: 2000 |
|
|
} |
|
|
}); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
wx.showLoading({ title: '处理中...', mask: true }); |
|
|
|
|
|
|
|
|
|
|
|
// 判断当前货源状态,决定设置什么状态
|
|
|
|
|
|
// 重新提交的商品应该先进入审核中
|
|
|
|
|
|
let newStatus = 'pending_review'; // 默认审核中
|
|
|
|
|
|
if (supply.status === 'reviewed') { |
|
|
|
|
|
newStatus = 'published'; // 已审核通过的货源可以直接上架
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 同步数据到服务器数据库
|
|
|
// 同步数据到服务器数据库
|
|
|
// 仅当有serverProductId时才同步到服务器
|
|
|
// 仅当有serverProductId时才同步到服务器
|
|
|
if (supply.serverProductId) { |
|
|
if (supply.serverProductId) { |
|
|
const openid = wx.getStorageSync('openid'); |
|
|
const openid = wx.getStorageSync('openid'); |
|
|
if (openid) { |
|
|
if (openid) { |
|
|
// 审核失败、隐藏、审核中或下架的货源重新提交时,调用编辑接口同步商品内容和状态
|
|
|
// 审核失败、隐藏、审核中或下架的货源重新提交时,调用编辑接口同步商品内容和状态
|
|
|
if (supply.status === 'rejected' || supply.status === 'hidden' || supply.status === 'pending_review' || supply.status === 'sold_out') { |
|
|
if (supply.status === 'rejected' || supply.status === 'hidden' || supply.status === 'pending_review' || supply.status === 'sold_out') { |
|
|
console.log('审核失败、隐藏、审核中或下架货源重新提交,同步商品内容和状态到服务器'); |
|
|
console.log('审核失败、隐藏、审核中或下架货源重新提交,同步商品内容和状态到服务器'); |
|
|
// 准备商品数据,转换为服务器需要的格式
|
|
|
// 准备商品数据,转换为服务器需要的格式
|
|
|
const productData = { |
|
|
const productData = { |
|
|
openid: openid, |
|
|
openid: openid, |
|
|
productId: supply.serverProductId, |
|
|
productId: supply.serverProductId, |
|
|
product: { |
|
|
product: { |
|
|
productName: supply.name, |
|
|
productName: supply.name, |
|
|
price: supply.price, |
|
|
price: supply.price, |
|
|
quantity: supply.minOrder, |
|
|
quantity: supply.minOrder, |
|
|
grossWeight: supply.grossWeight || "", |
|
|
grossWeight: supply.grossWeight || "", |
|
|
yolk: supply.yolk, |
|
|
yolk: supply.yolk, |
|
|
specification: supply.spec, |
|
|
specification: supply.spec, |
|
|
resubmit: true // 关键参数:告诉服务器这是重新提交审核
|
|
|
resubmit: true // 关键参数:告诉服务器这是重新提交审核
|
|
|
}, |
|
|
}, |
|
|
status: newStatus // 明确传递状态参数,确保变为审核中状态
|
|
|
status: newStatus // 明确传递状态参数,确保变为审核中状态
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
console.log('准备发送商品编辑请求 - URL:', API.BASE_URL + '/api/product/edit'); |
|
|
console.log('准备发送商品编辑请求 - URL:', API.BASE_URL + '/api/product/edit'); |
|
|
console.log('准备发送的商品数据:', productData); |
|
|
console.log('准备发送的商品数据:', productData); |
|
|
// 调用编辑商品接口,该接口会自动设置状态为pending_review
|
|
|
// 调用编辑商品接口,该接口会自动设置状态为pending_review
|
|
|
wx.request({ |
|
|
wx.request({ |
|
|
url: API.BASE_URL + '/api/product/edit', |
|
|
url: API.BASE_URL + '/api/product/edit', |
|
|
method: 'POST', |
|
|
method: 'POST', |
|
|
data: productData, |
|
|
data: productData, |
|
|
success: (res) => { |
|
|
success: (res) => { |
|
|
console.log('商品内容和状态同步成功:', res); |
|
|
console.log('商品内容和状态同步成功:', res); |
|
|
// 重新加载数据以更新UI
|
|
|
// 重新加载数据以更新UI
|
|
|
this.loadSupplies(); |
|
|
this.loadSupplies(); |
|
|
}, |
|
|
}, |
|
|
fail: (err) => { |
|
|
fail: (err) => { |
|
|
console.error('商品内容和状态同步失败:', err); |
|
|
console.error('商品内容和状态同步失败:', err); |
|
|
// 重新加载数据以更新UI
|
|
|
// 重新加载数据以更新UI
|
|
|
this.loadSupplies(); |
|
|
this.loadSupplies(); |
|
|
}, |
|
|
}, |
|
|
complete: () => { |
|
|
complete: () => { |
|
|
// 确保在请求完成后隐藏loading并显示提示
|
|
|
// 确保在请求完成后隐藏loading并显示提示
|
|
|
try { |
|
|
try { |
|
|
wx.hideLoading(); |
|
|
wx.hideLoading(); |
|
|
// 恢复页面滚动
|
|
|
// 恢复页面滚动
|
|
|
this.enablePageScroll(); |
|
|
this.enablePageScroll(); |
|
|
wx.showToast({ |
|
|
wx.showToast({ |
|
|
title: newStatus === 'published' ? '上架成功' : '重新提交成功,等待审核', |
|
|
title: newStatus === 'published' ? '上架成功' : '重新提交成功,等待审核', |
|
|
duration: 2000 |
|
|
duration: 2000 |
|
|
}); |
|
|
}); |
|
|
} catch (e) { |
|
|
} catch (e) { |
|
|
console.error('显示提示时出错:', e); |
|
|
console.error('显示提示时出错:', e); |
|
|
// 确保即使在错误情况下也隐藏loading并恢复滚动
|
|
|
// 确保即使在错误情况下也隐藏loading并恢复滚动
|
|
|
try { |
|
|
try { |
|
|
wx.hideLoading(); |
|
|
wx.hideLoading(); |
|
|
this.enablePageScroll(); |
|
|
this.enablePageScroll(); |
|
|
} catch (innerErr) { |
|
|
} catch (innerErr) { |
|
|
console.error('隐藏loading时出错:', innerErr); |
|
|
console.error('隐藏loading时出错:', innerErr); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
}); |
|
|
} |
|
|
return; // 异步操作,稍后再继续执行
|
|
|
}); |
|
|
} else { |
|
|
return; // 异步操作,稍后再继续执行
|
|
|
// 其他情况只更新状态
|
|
|
} else { |
|
|
wx.request({ |
|
|
// 其他情况只更新状态
|
|
|
url: API.BASE_URL + '/api/product/review', |
|
|
wx.request({ |
|
|
method: 'POST', |
|
|
url: API.BASE_URL + '/api/product/review', |
|
|
data: { |
|
|
method: 'POST', |
|
|
openid: openid, |
|
|
data: { |
|
|
productId: supply.serverProductId, |
|
|
openid: openid, |
|
|
status: newStatus |
|
|
productId: supply.serverProductId, |
|
|
}, |
|
|
status: newStatus |
|
|
success: () => { |
|
|
}, |
|
|
this.loadSupplies(); |
|
|
success: () => { |
|
|
}, |
|
|
this.loadSupplies(); |
|
|
fail: (err) => { |
|
|
}, |
|
|
console.error('更新状态失败:', err); |
|
|
fail: (err) => { |
|
|
this.loadSupplies(); |
|
|
console.error('更新状态失败:', err); |
|
|
}, |
|
|
this.loadSupplies(); |
|
|
complete: () => { |
|
|
}, |
|
|
try { |
|
|
complete: () => { |
|
|
wx.hideLoading(); |
|
|
try { |
|
|
// 恢复页面滚动
|
|
|
wx.hideLoading(); |
|
|
this.enablePageScroll(); |
|
|
// 恢复页面滚动
|
|
|
wx.showToast({ |
|
|
this.enablePageScroll(); |
|
|
title: newStatus === 'published' ? '上架成功' : '重新提交成功,等待审核', |
|
|
wx.showToast({ |
|
|
duration: 2000 |
|
|
title: newStatus === 'published' ? '上架成功' : '重新提交成功,等待审核', |
|
|
}); |
|
|
duration: 2000 |
|
|
} catch (e) { |
|
|
}); |
|
|
console.error('显示提示时出错:', e); |
|
|
} catch (e) { |
|
|
// 确保即使在错误情况下也隐藏loading并恢复滚动
|
|
|
console.error('显示提示时出错:', e); |
|
|
try { |
|
|
// 确保即使在错误情况下也隐藏loading并恢复滚动
|
|
|
wx.hideLoading(); |
|
|
try { |
|
|
this.enablePageScroll(); |
|
|
wx.hideLoading(); |
|
|
} catch (innerErr) { |
|
|
this.enablePageScroll(); |
|
|
console.error('隐藏loading时出错:', innerErr); |
|
|
} catch (innerErr) { |
|
|
} |
|
|
console.error('隐藏loading时出错:', innerErr); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
}); |
|
|
|
|
|
return; // 异步操作,稍后再继续执行
|
|
|
} |
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
// 没有openid时的处理
|
|
|
|
|
|
wx.hideLoading(); |
|
|
|
|
|
// 恢复页面滚动
|
|
|
|
|
|
this.enablePageScroll(); |
|
|
|
|
|
wx.showToast({ |
|
|
|
|
|
title: '登录状态异常,请重新登录', |
|
|
|
|
|
icon: 'none', |
|
|
|
|
|
duration: 2000 |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
// 如果没有serverProductId,提示用户
|
|
|
|
|
|
wx.hideLoading(); |
|
|
|
|
|
// 恢复页面滚动
|
|
|
|
|
|
this.enablePageScroll(); |
|
|
|
|
|
wx.showToast({ |
|
|
|
|
|
title: '无法上架,商品未上传到服务器', |
|
|
|
|
|
icon: 'none', |
|
|
|
|
|
duration: 2000 |
|
|
}); |
|
|
}); |
|
|
return; // 异步操作,稍后再继续执行
|
|
|
|
|
|
} |
|
|
} |
|
|
} else { |
|
|
}) |
|
|
// 没有openid时的处理
|
|
|
.catch(err => { |
|
|
|
|
|
console.error('获取用户信息失败:', err); |
|
|
wx.hideLoading(); |
|
|
wx.hideLoading(); |
|
|
// 恢复页面滚动
|
|
|
|
|
|
this.enablePageScroll(); |
|
|
this.enablePageScroll(); |
|
|
wx.showToast({ |
|
|
wx.showToast({ |
|
|
title: '登录状态异常,请重新登录', |
|
|
title: '获取用户信息失败', |
|
|
icon: 'none', |
|
|
icon: 'none', |
|
|
duration: 2000 |
|
|
duration: 2000 |
|
|
}); |
|
|
}); |
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
// 如果没有serverProductId,提示用户
|
|
|
|
|
|
wx.hideLoading(); |
|
|
|
|
|
// 恢复页面滚动
|
|
|
|
|
|
this.enablePageScroll(); |
|
|
|
|
|
wx.showToast({ |
|
|
|
|
|
title: '无法上架,商品未上传到服务器', |
|
|
|
|
|
icon: 'none', |
|
|
|
|
|
duration: 2000 |
|
|
|
|
|
}); |
|
|
}); |
|
|
} |
|
|
|
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
// 下架货源 - 移除本地存储操作
|
|
|
// 下架货源 - 移除本地存储操作
|
|
|
@ -3329,5 +3419,43 @@ Page({ |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
// 入驻申请
|
|
|
|
|
|
applyForSettlement() { |
|
|
|
|
|
const openid = wx.getStorageSync('openid'); |
|
|
|
|
|
if (openid) { |
|
|
|
|
|
API.getUserInfo(openid) |
|
|
|
|
|
.then(response => { |
|
|
|
|
|
console.log('获取到的用户信息:', response); |
|
|
|
|
|
const userInfo = response.data; |
|
|
|
|
|
const partnerstatus = userInfo.partnerstatus || ''; |
|
|
|
|
|
if (partnerstatus === 'approved') { |
|
|
|
|
|
// 如果已经审核通过,显示提示
|
|
|
|
|
|
wx.showToast({ |
|
|
|
|
|
title: '您已成功入驻', |
|
|
|
|
|
icon: 'success', |
|
|
|
|
|
duration: 2000 |
|
|
|
|
|
}); |
|
|
|
|
|
} else { |
|
|
|
|
|
// 否则进入入驻页面
|
|
|
|
|
|
wx.navigateTo({ |
|
|
|
|
|
url: '/pages/settlement/index' |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
.catch(err => { |
|
|
|
|
|
console.error('获取用户信息失败:', err); |
|
|
|
|
|
// 获取失败时,默认进入入驻页面
|
|
|
|
|
|
wx.navigateTo({ |
|
|
|
|
|
url: '/pages/settlement/index' |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
|
|
|
} else { |
|
|
|
|
|
// 未登录时,直接进入入驻页面
|
|
|
|
|
|
wx.navigateTo({ |
|
|
|
|
|
url: '/pages/settlement/index' |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
|