diff --git a/pages/goods-update/goods-update.js b/pages/goods-update/goods-update.js
index 9ba26fc..ce47d9c 100644
--- a/pages/goods-update/goods-update.js
+++ b/pages/goods-update/goods-update.js
@@ -233,6 +233,12 @@ Page({
showYolkSelectModal: false, // 控制蛋黄选择弹窗显示
selectedNameIndex: -1, // 商品名称弹窗中选中的索引
selectedYolkIndex: -1,//蛋黄弹窗中选中的索引,
+ // 销售员列表
+ salesPersonnelOptions: [],
+ filteredSalesPersonnelOptions: [],
+ selectedSalesPersonIndex: -1,
+ showSalesPersonSelectModal: false,
+ modalSalesPersonSearchKeyword: '',
// 商品名称选项列表
productNameOptions: ['罗曼粉', '伊莎粉', '罗曼灰', '海蓝灰', '海蓝褐', '绿壳', '粉一', '粉二', '粉八', '京粉1号', '京红', '京粉6号', '京粉3号', '农大系列', '黑鸡土蛋', '双黄蛋', '大午金凤', '黑凤'],
// 蛋黄选项
@@ -307,10 +313,35 @@ Page({
console.log('最终使用的商品ID:', productId);
+ // 加载销售员列表
+ this.loadSalesPersonnel();
+
// 加载商品详情(即使已有goodsData,也调用API获取最新数据)
this.loadGoodsDetail(productId, goodsData);
},
+ // 加载销售员列表
+ loadSalesPersonnel: function () {
+ console.log('加载销售员列表');
+ API.getSalesPersonnel()
+ .then(res => {
+ console.log('获取销售员列表成功:', res);
+ const salesOptions = res.map(item => ({
+ id: item.id,
+ name: item.name || '未知',
+ phoneNumber: item.phoneNumber || ''
+ }));
+ this.setData({
+ salesPersonnelOptions: salesOptions,
+ filteredSalesPersonnelOptions: salesOptions
+ });
+ console.log('销售员列表数据:', this.data.salesPersonnelOptions);
+ })
+ .catch(err => {
+ console.error('获取销售员列表失败:', err);
+ });
+ },
+
loadGoodsDetail: function (productId, preloadedData = null) {
// 首先显示预加载的数据,确保UI快速响应
if (preloadedData) {
@@ -569,7 +600,9 @@ Page({
yolk: goodsDetail.yolk || '',
spec: goodsDetail.spec || '',
region: goodsDetail.region || '',
- grossWeight: goodsDetail.grossWeight || ''
+ grossWeight: goodsDetail.grossWeight || '',
+ product_contact: goodsDetail.product_contact || '',
+ contact_phone: goodsDetail.contact_phone || ''
},
showEditModal: true
});
@@ -588,18 +621,20 @@ Page({
const editSupply = this.data.editSupply;
// 验证必填字段
- if (!editSupply.name) {
+ if (!editSupply.price) {
wx.showToast({
- title: '请填写商品名称',
+ title: '请填写销售价格',
icon: 'none',
duration: 2000
});
return;
}
- if (!editSupply.price) {
+ // 验证价格是否为有效数字
+ const priceNum = parseFloat(editSupply.price);
+ if (isNaN(priceNum) || priceNum < 0) {
wx.showToast({
- title: '请填写价格',
+ title: '请填写有效的价格',
icon: 'none',
duration: 2000
});
@@ -611,18 +646,25 @@ Page({
mask: true
});
- // 调用API更新商品
+ // 调试日志:查看editSupply的完整数据
+ console.log('【saveEdit】editSupply完整数据:', JSON.stringify(editSupply, null, 2));
+
+ // 调试日志:查看productId的值
const productId = editSupply.productId || editSupply.id;
- API.editProduct(productId, {
- productName: editSupply.name,
+ console.log('【saveEdit】editSupply.productId:', editSupply.productId);
+ console.log('【saveEdit】editSupply.id:', editSupply.id);
+ console.log('【saveEdit】最终使用的productId:', productId);
+
+ // 使用新的快速更新接口,只更新价格、联系人和电话
+ const updateData = {
+ productId: productId,
price: editSupply.price,
- quantity: Number(editSupply.minOrder),
- grossWeight: editSupply.grossWeight !== undefined && editSupply.grossWeight !== null && editSupply.grossWeight !== '' ? editSupply.grossWeight : "",
- yolk: editSupply.yolk,
- specification: editSupply.spec || '',
- region: editSupply.region || '',
- imageUrls: editSupply.imageUrls || [],
- })
+ product_contact: editSupply.product_contact || '',
+ contact_phone: editSupply.contact_phone || '',
+ };
+ console.log('【saveEdit】快速更新数据:', updateData);
+
+ API.request('/api/products/quick-update', 'POST', updateData)
.then(res => {
wx.hideLoading();
console.log('更新商品成功:', res);
@@ -955,6 +997,89 @@ Page({
}
},
+ // 打开销售员选择弹窗
+ openSalesPersonModal: function() {
+ console.log('打开销售员选择弹窗');
+ const editSupply = this.data.editSupply;
+ const salesPersonnelOptions = this.data.salesPersonnelOptions;
+
+ // 查找当前联系人在选项中的索引
+ let currentSalesPersonIndex = -1;
+ if (editSupply.product_contact) {
+ currentSalesPersonIndex = salesPersonnelOptions.findIndex(
+ item => item.name === editSupply.product_contact
+ );
+ }
+
+ this.setData({
+ showSalesPersonSelectModal: true,
+ selectedSalesPersonIndex: currentSalesPersonIndex >= 0 ? currentSalesPersonIndex : -1,
+ modalSalesPersonSearchKeyword: '',
+ filteredSalesPersonnelOptions: salesPersonnelOptions
+ });
+ },
+
+ // 关闭销售员选择弹窗
+ closeSalesPersonSelectModal: function() {
+ this.setData({
+ showSalesPersonSelectModal: false
+ });
+ },
+
+ // 销售员弹窗搜索输入
+ onModalSalesPersonSearchInput: function(e) {
+ const keyword = e.detail.value;
+ const salesPersonnelOptions = this.data.salesPersonnelOptions;
+
+ // 过滤销售员选项
+ const filteredOptions = salesPersonnelOptions.filter(option => {
+ return option.name.includes(keyword) ||
+ (option.phoneNumber && option.phoneNumber.includes(keyword));
+ });
+
+ this.setData({
+ modalSalesPersonSearchKeyword: keyword,
+ filteredSalesPersonnelOptions: filteredOptions,
+ selectedSalesPersonIndex: -1
+ });
+ },
+
+ // 清除销售员弹窗搜索关键词
+ clearModalSalesPersonSearch: function() {
+ this.setData({
+ modalSalesPersonSearchKeyword: '',
+ filteredSalesPersonnelOptions: this.data.salesPersonnelOptions,
+ selectedSalesPersonIndex: -1
+ });
+ },
+
+ // 选择销售员
+ onSalesPersonSelect: function(e) {
+ const index = e.currentTarget.dataset.index;
+ this.setData({
+ selectedSalesPersonIndex: index
+ });
+ },
+
+ // 确认销售员选择
+ confirmSalesPersonSelection: function() {
+ const selectedIndex = this.data.selectedSalesPersonIndex;
+ const filteredOptions = this.data.filteredSalesPersonnelOptions;
+
+ if (selectedIndex >= 0 && selectedIndex < filteredOptions.length) {
+ const selectedSalesPerson = filteredOptions[selectedIndex];
+
+ // 更新联系人和联系电话
+ this.setData({
+ ['editSupply.product_contact']: selectedSalesPerson.name,
+ ['editSupply.contact_phone']: selectedSalesPerson.phoneNumber || this.data.editSupply.contact_phone,
+ showSalesPersonSelectModal: false
+ });
+
+ console.log('选择销售员后更新editSupply:', this.data.editSupply);
+ }
+ },
+
// 选择图片
chooseImage: function(e) {
const type = e.currentTarget.dataset.type;
diff --git a/pages/goods-update/goods-update.wxml b/pages/goods-update/goods-update.wxml
index fc05831..e777584 100644
--- a/pages/goods-update/goods-update.wxml
+++ b/pages/goods-update/goods-update.wxml
@@ -209,66 +209,17 @@
-
- 商品图片
-
-
-
-
-
- ×
-
-
-
- +
-
-
- 最多上传5张图片
-
+ 销售价格
+
- 商品名称
-
-
- {{editSupply.productName || editSupply.name || '请选择商品名称'}}
- ▼
-
+ 联系人
+
+ {{editSupply.product_contact || '请选择联系人'}}
+ ▼
- 蛋黄
-
-
- {{editSupply.yolk || '请选择蛋黄类型'}}
- ▼
-
-
-
- 规格
-
-
-
- {{editSupply.spec || '请选择规格'}}
- ▼
-
-
- 地区
-
- {{editSupply.region || '请选择省市区'}}
-
-
- 价格
-
-
- 件数
-
-
- 斤重
-
+ 联系电话
+
@@ -414,4 +365,55 @@
+
+
+
+
+
+
+ 取消
+ 确定
+
+
+
+
+
+
+
+ ✕
+
+
+
+
+
+
+
+ {{item.name}}
+ {{item.phoneNumber || '暂无电话'}}
+
+
+
+
\ No newline at end of file
diff --git a/server-example/server-mysql.js b/server-example/server-mysql.js
index c266668..94688ac 100644
--- a/server-example/server-mysql.js
+++ b/server-example/server-mysql.js
@@ -5613,6 +5613,11 @@ app.post('/api/product/edit', async (req, res) => {
productKeys: product ? Object.keys(product) : '无product'
});
+ // ========== 【新增】调试:打印productId的类型和值 ==========
+ console.log('【调试】productId类型:', typeof productId, '值:', productId);
+ console.log('【调试】openid类型:', typeof openid, '值:', openid);
+ // ========== 调试结束 ==========
+
// ========== 【新增】编辑商品时的地区字段调试 ==========
console.log('【地区字段调试】编辑商品 - 开始处理');
console.log('【地区字段调试】请求体中的region字段:', req.body.region);
@@ -6796,6 +6801,84 @@ app.post('/api/products/update-contacts', async (req, res) => {
}
});
+// 添加API接口:快速更新商品价格和联系人信息(不验证sellerId)
+app.post('/api/products/quick-update', async (req, res) => {
+ console.log('【快速更新】收到请求:', req.body);
+ try {
+ const { productId, price, product_contact, contact_phone } = req.body;
+
+ if (!productId) {
+ return res.status(400).json({
+ success: false,
+ code: 400,
+ message: '缺少productId参数'
+ });
+ }
+
+ // 查找商品
+ const product = await Product.findOne({
+ where: { productId }
+ });
+
+ if (!product) {
+ console.error('【快速更新】商品不存在:', productId);
+ return res.status(404).json({
+ success: false,
+ code: 404,
+ message: '商品不存在'
+ });
+ }
+
+ console.log('【快速更新】找到商品:', product.productName);
+
+ // 只更新指定的字段
+ const updateFields = {
+ updated_at: getBeijingTime()
+ };
+
+ if (price !== undefined) {
+ updateFields.price = price;
+ console.log('【快速更新】更新价格:', price);
+ }
+
+ if (product_contact !== undefined) {
+ updateFields.product_contact = product_contact;
+ console.log('【快速更新】更新联系人:', product_contact);
+ }
+
+ if (contact_phone !== undefined) {
+ updateFields.contact_phone = contact_phone;
+ console.log('【快速更新】更新联系电话:', contact_phone);
+ }
+
+ // 执行更新
+ await Product.update(updateFields, {
+ where: { productId }
+ });
+
+ console.log('【快速更新】商品更新成功:', productId);
+
+ res.json({
+ success: true,
+ code: 200,
+ message: '更新成功',
+ data: {
+ productId,
+ price: updateFields.price,
+ product_contact: updateFields.product_contact,
+ contact_phone: updateFields.contact_phone
+ }
+ });
+ } catch (error) {
+ console.error('【快速更新】更新商品失败:', error);
+ res.status(500).json({
+ success: false,
+ code: 500,
+ message: '更新商品失败: ' + error.message
+ });
+ }
+});
+
// REST API接口 - 获取用户会话列表
app.get('/api/conversations/user/:userId', async (req, res) => {
try {
diff --git a/utils/api.js b/utils/api.js
index cea9fc9..c2d1134 100644
--- a/utils/api.js
+++ b/utils/api.js
@@ -1641,6 +1641,25 @@ module.exports = {
});
},
+ // 获取销售员列表 - projectName='销售员'的人员
+ getSalesPersonnel: function () {
+ console.log('获取销售员列表...');
+ return new Promise((resolve) => {
+ request('/api/managers', 'GET', { type: 'seller' }) // type=seller查询销售员
+ .then(res => {
+ console.log('获取销售员列表成功:', res);
+ // 适配不同的数据返回格式
+ const data = res && res.data && Array.isArray(res.data) ? res.data :
+ res && Array.isArray(res) ? res : [];
+ resolve(data);
+ })
+ .catch(err => {
+ console.error('获取销售员列表失败:', err);
+ resolve([]);
+ });
+ });
+ },
+
// 根据手机号获取客服的managerId - 优化版
getManagerIdByPhone: function (phoneNumber) {
console.log('根据手机号获取managerId:', phoneNumber);
@@ -3322,7 +3341,10 @@ module.exports = {
specification: processedProductData.specification || '',
region: productData.region || '', // 【重要】确保地区字段在product对象中
imageUrls: processedProductData.imageUrls || [], // 【重要】包含处理后的图片URL
- status: processedProductData.status || ''
+ status: processedProductData.status || '',
+ // 新增:联系人和联系电话
+ product_contact: processedProductData.product_contact || '',
+ contact_phone: processedProductData.contact_phone || '',
},
// 同时在顶层也传递status参数,确保服务器端能正确接收
status: processedProductData.status || ''