|
|
@ -233,6 +233,12 @@ Page({ |
|
|
showYolkSelectModal: false, // 控制蛋黄选择弹窗显示
|
|
|
showYolkSelectModal: false, // 控制蛋黄选择弹窗显示
|
|
|
selectedNameIndex: -1, // 商品名称弹窗中选中的索引
|
|
|
selectedNameIndex: -1, // 商品名称弹窗中选中的索引
|
|
|
selectedYolkIndex: -1,//蛋黄弹窗中选中的索引,
|
|
|
selectedYolkIndex: -1,//蛋黄弹窗中选中的索引,
|
|
|
|
|
|
// 销售员列表
|
|
|
|
|
|
salesPersonnelOptions: [], |
|
|
|
|
|
filteredSalesPersonnelOptions: [], |
|
|
|
|
|
selectedSalesPersonIndex: -1, |
|
|
|
|
|
showSalesPersonSelectModal: false, |
|
|
|
|
|
modalSalesPersonSearchKeyword: '', |
|
|
// 商品名称选项列表
|
|
|
// 商品名称选项列表
|
|
|
productNameOptions: ['罗曼粉', '伊莎粉', '罗曼灰', '海蓝灰', '海蓝褐', '绿壳', '粉一', '粉二', '粉八', '京粉1号', '京红', '京粉6号', '京粉3号', '农大系列', '黑鸡土蛋', '双黄蛋', '大午金凤', '黑凤'], |
|
|
productNameOptions: ['罗曼粉', '伊莎粉', '罗曼灰', '海蓝灰', '海蓝褐', '绿壳', '粉一', '粉二', '粉八', '京粉1号', '京红', '京粉6号', '京粉3号', '农大系列', '黑鸡土蛋', '双黄蛋', '大午金凤', '黑凤'], |
|
|
// 蛋黄选项
|
|
|
// 蛋黄选项
|
|
|
@ -307,10 +313,35 @@ Page({ |
|
|
|
|
|
|
|
|
console.log('最终使用的商品ID:', productId); |
|
|
console.log('最终使用的商品ID:', productId); |
|
|
|
|
|
|
|
|
|
|
|
// 加载销售员列表
|
|
|
|
|
|
this.loadSalesPersonnel(); |
|
|
|
|
|
|
|
|
// 加载商品详情(即使已有goodsData,也调用API获取最新数据)
|
|
|
// 加载商品详情(即使已有goodsData,也调用API获取最新数据)
|
|
|
this.loadGoodsDetail(productId, goodsData); |
|
|
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) { |
|
|
loadGoodsDetail: function (productId, preloadedData = null) { |
|
|
// 首先显示预加载的数据,确保UI快速响应
|
|
|
// 首先显示预加载的数据,确保UI快速响应
|
|
|
if (preloadedData) { |
|
|
if (preloadedData) { |
|
|
@ -569,7 +600,9 @@ Page({ |
|
|
yolk: goodsDetail.yolk || '', |
|
|
yolk: goodsDetail.yolk || '', |
|
|
spec: goodsDetail.spec || '', |
|
|
spec: goodsDetail.spec || '', |
|
|
region: goodsDetail.region || '', |
|
|
region: goodsDetail.region || '', |
|
|
grossWeight: goodsDetail.grossWeight || '' |
|
|
grossWeight: goodsDetail.grossWeight || '', |
|
|
|
|
|
product_contact: goodsDetail.product_contact || '', |
|
|
|
|
|
contact_phone: goodsDetail.contact_phone || '' |
|
|
}, |
|
|
}, |
|
|
showEditModal: true |
|
|
showEditModal: true |
|
|
}); |
|
|
}); |
|
|
@ -588,18 +621,20 @@ Page({ |
|
|
const editSupply = this.data.editSupply; |
|
|
const editSupply = this.data.editSupply; |
|
|
|
|
|
|
|
|
// 验证必填字段
|
|
|
// 验证必填字段
|
|
|
if (!editSupply.name) { |
|
|
if (!editSupply.price) { |
|
|
wx.showToast({ |
|
|
wx.showToast({ |
|
|
title: '请填写商品名称', |
|
|
title: '请填写销售价格', |
|
|
icon: 'none', |
|
|
icon: 'none', |
|
|
duration: 2000 |
|
|
duration: 2000 |
|
|
}); |
|
|
}); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (!editSupply.price) { |
|
|
// 验证价格是否为有效数字
|
|
|
|
|
|
const priceNum = parseFloat(editSupply.price); |
|
|
|
|
|
if (isNaN(priceNum) || priceNum < 0) { |
|
|
wx.showToast({ |
|
|
wx.showToast({ |
|
|
title: '请填写价格', |
|
|
title: '请填写有效的价格', |
|
|
icon: 'none', |
|
|
icon: 'none', |
|
|
duration: 2000 |
|
|
duration: 2000 |
|
|
}); |
|
|
}); |
|
|
@ -611,18 +646,25 @@ Page({ |
|
|
mask: true |
|
|
mask: true |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
// 调用API更新商品
|
|
|
// 调试日志:查看editSupply的完整数据
|
|
|
|
|
|
console.log('【saveEdit】editSupply完整数据:', JSON.stringify(editSupply, null, 2)); |
|
|
|
|
|
|
|
|
|
|
|
// 调试日志:查看productId的值
|
|
|
const productId = editSupply.productId || editSupply.id; |
|
|
const productId = editSupply.productId || editSupply.id; |
|
|
API.editProduct(productId, { |
|
|
console.log('【saveEdit】editSupply.productId:', editSupply.productId); |
|
|
productName: editSupply.name, |
|
|
console.log('【saveEdit】editSupply.id:', editSupply.id); |
|
|
|
|
|
console.log('【saveEdit】最终使用的productId:', productId); |
|
|
|
|
|
|
|
|
|
|
|
// 使用新的快速更新接口,只更新价格、联系人和电话
|
|
|
|
|
|
const updateData = { |
|
|
|
|
|
productId: productId, |
|
|
price: editSupply.price, |
|
|
price: editSupply.price, |
|
|
quantity: Number(editSupply.minOrder), |
|
|
product_contact: editSupply.product_contact || '', |
|
|
grossWeight: editSupply.grossWeight !== undefined && editSupply.grossWeight !== null && editSupply.grossWeight !== '' ? editSupply.grossWeight : "", |
|
|
contact_phone: editSupply.contact_phone || '', |
|
|
yolk: editSupply.yolk, |
|
|
}; |
|
|
specification: editSupply.spec || '', |
|
|
console.log('【saveEdit】快速更新数据:', updateData); |
|
|
region: editSupply.region || '', |
|
|
|
|
|
imageUrls: editSupply.imageUrls || [], |
|
|
API.request('/api/products/quick-update', 'POST', updateData) |
|
|
}) |
|
|
|
|
|
.then(res => { |
|
|
.then(res => { |
|
|
wx.hideLoading(); |
|
|
wx.hideLoading(); |
|
|
console.log('更新商品成功:', res); |
|
|
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) { |
|
|
chooseImage: function(e) { |
|
|
const type = e.currentTarget.dataset.type; |
|
|
const type = e.currentTarget.dataset.type; |
|
|
|