diff --git a/Reject.js b/Reject.js index 3c255af..c2295d5 100644 --- a/Reject.js +++ b/Reject.js @@ -1380,10 +1380,21 @@ app.put('/api/supplies/:id/edit', async (req, res) => { return sendResponse(res, false, null, '货源已被锁定,无法编辑'); } - // 处理联系人信息 - let productContact = ''; - let contactPhone = ''; - if (contactId) { + // 处理联系人信息:只在有新联系人ID且能查询到时才更新,否则保持原有值 + let productContact = null; + let contactPhone = null; + + // 先查询原有联系人信息 + const [existingProduct] = await connection.query( + 'SELECT product_contact, contact_phone FROM products WHERE id = ?', + [productId] + ); + + // 如果没有提供contactId或contactId为空,使用原有联系人信息 + if (!contactId || contactId === '') { + productContact = existingProduct[0].product_contact; + contactPhone = existingProduct[0].contact_phone; + } else { // 从userlogin数据库获取联系人信息 const userLoginConnection = await userLoginPool.getConnection(); const [personnelData] = await userLoginConnection.query( @@ -1393,8 +1404,13 @@ app.put('/api/supplies/:id/edit', async (req, res) => { userLoginConnection.release(); if (personnelData && personnelData.length > 0) { + // 成功查询到联系人,使用新联系人信息 productContact = personnelData[0].alias || ''; contactPhone = personnelData[0].phoneNumber || ''; + } else { + // 未查询到联系人,使用原有联系人信息 + productContact = existingProduct[0].product_contact; + contactPhone = existingProduct[0].contact_phone; } } diff --git a/supply.html b/supply.html index 88022cf..0e4f72b 100644 --- a/supply.html +++ b/supply.html @@ -4611,7 +4611,7 @@ // 处理操作按钮 let actionsHTML = ''; if (supply.status === 'published') { - actionsHTML = ``; + actionsHTML = ` `; } else if (supply.status === 'pending_review') { actionsHTML = ` @@ -6100,14 +6100,14 @@ const autoOfflineTime = new Date(); autoOfflineTime.setMinutes(autoOfflineTime.getMinutes() + minutes); // 格式化为数据库存储的北京时间格式 (YYYY-MM-DD HH:mm:ss) - const autoOfflineTimeStr = autoOfflineTime.getFullYear() + '-' + - String(autoOfflineTime.getMonth() + 1).padStart(2, '0') + '-' + - String(autoOfflineTime.getDate()).padStart(2, '0') + ' ' + - String(autoOfflineTime.getHours()).padStart(2, '0') + ':' + - String(autoOfflineTime.getMinutes()).padStart(2, '0') + ':' + - String(autoOfflineTime.getSeconds()).padStart(2, '0'); - - const formData = { + const autoOfflineTimeStr = autoOfflineTime.getFullYear() + '-' + + String(autoOfflineTime.getMonth() + 1).padStart(2, '0') + '-' + + String(autoOfflineTime.getDate()).padStart(2, '0') + ' ' + + String(autoOfflineTime.getHours()).padStart(2, '0') + ':' + + String(autoOfflineTime.getMinutes()).padStart(2, '0') + ':' + + String(autoOfflineTime.getSeconds()).padStart(2, '0'); + + const formData = { productName: document.getElementById('productName').value, category: document.getElementById('category').value, price: document.getElementById('price').value, @@ -7966,6 +7966,9 @@ String(autoOfflineTime.getMinutes()).padStart(2, '0') + ':' + String(autoOfflineTime.getSeconds()).padStart(2, '0'); + // 获取当前编辑的货源信息,用于保留原联系人数据 + const currentSupply = supplyData.supplies.find(s => String(s.id) === String(currentEditSupplyId)); + const formData = { productName: document.getElementById('editProductName').value, sourceType: document.getElementById('editSourceType').value,