From 53de5d0120aab8c02624ec5457e080c66b273146 Mon Sep 17 00:00:00 2001 From: Default User Date: Fri, 2 Jan 2026 14:02:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=9B=E5=BB=BA=E8=B4=A7?= =?UTF-8?q?=E6=BA=90=E6=97=B6=E4=BB=B6=E6=95=B0=E6=B2=A1=E6=9C=89=E5=A4=9A?= =?UTF-8?q?=E6=AC=A1=E4=B8=8A=E4=BC=A0=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Reject.js | 6 +- supply.html | 803 ++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 686 insertions(+), 123 deletions(-) diff --git a/Reject.js b/Reject.js index 54f4691..eaf43b7 100644 --- a/Reject.js +++ b/Reject.js @@ -798,7 +798,7 @@ app.post('/api/supplies/create', async (req, res) => { productName, category: category || '', // 添加种类 price: price.toString(), // 确保是varchar类型 - quantity: parseInt(quantity), + quantity: quantity, // 保持为逗号分隔的字符串,不转换为整数 grossWeight, yolk, specification, @@ -828,7 +828,7 @@ app.post('/api/supplies/create', async (req, res) => { // 没有quality字段,不包含quality字段的插入 insertQuery = 'INSERT INTO products (productId, sellerId, productName, category, price, quantity, grossWeight, yolk, specification, producting, region, status, supplyStatus, sourceType, description, rejectReason, imageUrls, created_at, audit_time, product_contact, contact_phone) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; insertParams = [ - productId, productData.sellerId, productName, category || '', price.toString(), parseInt(quantity), grossWeight, + productId, productData.sellerId, productName, category || '', price.toString(), quantity, grossWeight, yolk, specification, producting, region, productData.status, productData.supplyStatus, productData.sourceType, productData.description, productData.rejectReason, productData.imageUrls, new Date(), new Date(), productContact, contactPhone // 添加联系人信息 @@ -837,7 +837,7 @@ app.post('/api/supplies/create', async (req, res) => { // 有quality字段,包含quality字段的插入 insertQuery = 'INSERT INTO products (productId, sellerId, productName, category, price, quantity, grossWeight, yolk, specification, producting, quality, region, status, supplyStatus, sourceType, description, rejectReason, imageUrls, created_at, audit_time, product_contact, contact_phone) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; insertParams = [ - productId, productData.sellerId, productName, category || '', price.toString(), parseInt(quantity), grossWeight, + productId, productData.sellerId, productName, category || '', price.toString(), quantity, grossWeight, yolk, specification, producting, quality, region, productData.status, productData.supplyStatus, productData.sourceType, productData.description, productData.rejectReason, productData.imageUrls, new Date(), new Date(), productContact, contactPhone // 添加联系人信息 diff --git a/supply.html b/supply.html index 9ee5434..59d1cb8 100644 --- a/supply.html +++ b/supply.html @@ -992,6 +992,102 @@ height: 150px; } } + + /* 件数输入样式 */ + #quantityContainer { + display: flex; + flex-direction: column; + gap: 10px; + } + + .quantity-item { + display: flex; + align-items: center; + gap: 10px; + } + + .quantity-input { + flex: 1; + } + + .remove-quantity-btn { + width: 32px; + height: 32px; + border: none; + background-color: #ff4d4f; + color: white; + border-radius: 50%; + font-size: 16px; + cursor: pointer; + display: flex; + align-items: center; + justify-content: center; + } + + .add-quantity-btn { + align-self: flex-start; + padding: 8px 16px; + border: 1px dashed #1677ff; + background-color: white; + color: #1677ff; + border-radius: 4px; + cursor: pointer; + font-size: 14px; + } + + .add-quantity-btn:hover { + background-color: #e6f7ff; + } + + /* 规格和件数对样式 */ + #specQuantityContainer, + #editSpecQuantityContainer { + display: flex; + flex-direction: column; + gap: 10px; + } + + .spec-quantity-pair { + display: flex; + align-items: center; + gap: 10px; + background-color: #fafafa; + padding: 10px; + border-radius: 8px; + border: 1px solid #f0f0f0; + } + + .spec-value { + flex: 1; + padding: 10px; + border: 1px solid #d9d9d9; + border-radius: 8px; + font-size: 14px; + box-sizing: border-box; + background-color: white; + cursor: pointer; + } + + .quantity-input { + width: 120px; + background-color: white; + } + + .add-spec-quantity-btn { + align-self: flex-start; + padding: 8px 16px; + border: 1px dashed #1677ff; + background-color: white; + color: #1677ff; + border-radius: 4px; + cursor: pointer; + font-size: 14px; + margin-top: 5px; + } + + .add-spec-quantity-btn:hover { + background-color: #e6f7ff; + } @@ -1150,16 +1246,6 @@ - -
- -
- 请选择规格 - - -
-
-
@@ -1180,6 +1266,19 @@
+ +
+ +
+ +
+ + +
+ + +
+
@@ -1190,24 +1289,18 @@
- -
- - -
- - -
- - -
- + +
+ + +
+
@@ -1251,7 +1344,7 @@
第三方货源: 贸易商货源
@@ -1273,7 +1366,7 @@
@@ -1299,7 +1392,7 @@
(如果有色卡可以在货源描述里面填写色度)
@@ -1321,7 +1414,7 @@
@@ -1348,7 +1441,7 @@
@@ -1370,7 +1463,7 @@
@@ -1395,7 +1488,7 @@
@@ -1417,7 +1510,7 @@
@@ -1522,16 +1615,6 @@
- -
- -
- 请选择规格 - - -
-
-
@@ -1552,6 +1635,19 @@
+ +
+ +
+ +
+ + +
+ + +
+
@@ -1562,24 +1658,18 @@
- -
- - -
- - -
- - -
- + +
+ + +
+
@@ -1607,7 +1697,7 @@
@@ -1634,7 +1724,7 @@
第三方货源: 贸易商货源
@@ -1656,7 +1746,7 @@
@@ -1678,7 +1768,7 @@
@@ -1704,7 +1794,7 @@
(如果有色卡可以在货源描述里面填写色度)
@@ -1726,7 +1816,7 @@
@@ -1748,7 +1838,7 @@
@@ -1770,7 +1860,7 @@
@@ -1817,7 +1907,7 @@ // 编辑相关全局变量 let currentEditSupplyId = null; - let editSelectedSpec = ''; + let editSelectedSpec = []; let editSelectedProvince = ''; let editSelectedCity = ''; let editSelectedDistrict = ''; @@ -1890,6 +1980,9 @@ loadContacts(); loadFormData(); // 加载保存的表单数据,包括联系人信息 bindEvents(); + + // 初始化至少一个规格和件数对 + addSpecQuantityPair(); }; // 绑定事件 @@ -1990,7 +2083,7 @@ // 规格选择功能 let allSpecOptions = ['净重47+', '净重46-47', '净重45-46', '净重44-45', '净重43-44', '净重42-43', '净重41-42', '净重40-41', '净重39-40', '净重38-39', '净重37-39', '净重37-38', '净重36-38', '净重36-37', '净重35-36', '净重34-35', '净重33-34', '净重32-33', '净重32-34', '净重31-32', '净重30-35', '净重30-34', '净重30-32', '净重30-31', '净重29-31', '净重29-30', '净重28-29', '净重28以下', '毛重52以上', '毛重50-51', '毛重48-49', '毛重47-48', '毛重46-47', '毛重45-47', '毛重45-46', '毛重44-45', '毛重43-44', '毛重42-43', '毛重41-42', '毛重40-41', '毛重38-39', '毛重36-37', '毛重34-35', '毛重32-33', '毛重30-31', '毛重30以下']; let filteredSpecOptions = [...allSpecOptions]; - let selectedSpec = ''; + let selectedSpec = []; // 产品包装选择功能 let allProductingOptions = ['1*360枚新包装', '1*360枚旧包新拖', '1*360枚旧包旧拖', '1*420枚新包装', '1*480枚新包装', '30枚蛋托散装', '360枚散托']; @@ -2046,21 +2139,46 @@ const option = document.createElement('div'); option.className = 'select-item'; option.textContent = spec; + + // 检查当前规格是否已被选中 + if (selectedSpec.includes(spec)) { + option.classList.add('selected'); + } + + // 单击选择逻辑 option.onclick = () => { - // 移除所有选项的选中状态 + // 单选逻辑:移除所有选中状态 document.querySelectorAll('.select-item').forEach(item => { item.classList.remove('selected'); }); - // 添加当前选项的选中状态 + + // 添加当前选中状态 option.classList.add('selected'); - selectedSpec = spec; + + // 更新selectedSpec数组为单选 + selectedSpec = [spec]; }; + + // 双击确认逻辑 option.ondblclick = () => { - // 双击直接确认选择 - document.getElementById('specDisplayText').textContent = spec; - document.getElementById('specValue').value = spec; - hideSpecSelectModal(); + // 确保当前选项被选中 + if (!option.classList.contains('selected')) { + // 单选逻辑:移除所有选中状态 + document.querySelectorAll('.select-item').forEach(item => { + item.classList.remove('selected'); + }); + + // 添加当前选中状态 + option.classList.add('selected'); + + // 更新selectedSpec数组为单选 + selectedSpec = [spec]; + } + + // 自动确认选择 + confirmSpecSelection(); }; + specOptionsList.appendChild(option); }); } @@ -2079,13 +2197,98 @@ // 确认规格选择 function confirmSpecSelection() { - if (selectedSpec) { - document.getElementById('specDisplayText').textContent = selectedSpec; - document.getElementById('specValue').value = selectedSpec; + if (currentSpecInput) { + // 如果是为规格和件数对选择规格 + if (selectedSpec.length > 0) { + currentSpecInput.value = selectedSpec.join(', '); + } else { + currentSpecInput.value = ''; + } + } else { + // 否则,为旧的规格选择逻辑 + if (selectedSpec.length > 0) { + document.getElementById('specDisplayText').textContent = selectedSpec.join(', '); + document.getElementById('specValue').value = JSON.stringify(selectedSpec); + // 根据选中的规格数量动态调整件数输入框数量 + adjustQuantityInputs(); + } else { + document.getElementById('specDisplayText').textContent = '请选择规格'; + document.getElementById('specValue').value = '[]'; + } } hideSpecSelectModal(); } + // 添加件数输入项 + function addQuantityItem() { + const container = document.getElementById('quantityContainer'); + const quantityItem = document.createElement('div'); + quantityItem.className = 'quantity-item'; + quantityItem.innerHTML = ` + + + `; + container.insertBefore(quantityItem, container.lastElementChild); + } + + // 删除件数输入项 + function removeQuantityItem(btn) { + const container = document.getElementById('quantityContainer'); + const quantityItems = container.querySelectorAll('.quantity-item'); + + // 至少保留一个件数输入项 + if (quantityItems.length > 1) { + const quantityItem = btn.parentElement; + quantityItem.remove(); + } + } + + // 根据选中的规格数量调整件数输入框数量 + function adjustQuantityInputs() { + const container = document.getElementById('quantityContainer'); + const quantityItems = container.querySelectorAll('.quantity-item'); + const specCount = selectedSpec.length; + + // 如果规格数量大于件数输入框数量,添加缺少的输入框 + while (quantityItems.length < specCount) { + addQuantityItem(); + } + } + + // 添加规格和件数对 + function addSpecQuantityPair() { + const container = document.getElementById('specQuantityPairs'); + const pair = document.createElement('div'); + pair.className = 'spec-quantity-pair'; + pair.innerHTML = ` + + + + `; + container.appendChild(pair); + } + + // 删除规格和件数对 + function removeSpecQuantityPair(btn) { + const pair = btn.parentElement; + const specInput = pair.querySelector('.spec-value'); + const quantityInput = pair.querySelector('.quantity-input'); + + // 清除当前对的输入值 + if (specInput) specInput.value = ''; + if (quantityInput) quantityInput.value = ''; + } + + // 为规格和件数对显示规格选择弹窗 + function showSpecSelectModalForPair(input) { + // 保存当前点击的输入框 + currentSpecInput = input; + showSpecSelectModal(); + } + + // 保存当前点击的规格输入框 + let currentSpecInput = null; + // 显示产品包装选择弹窗 function showProductingSelectModal() { const productingSelectModal = document.getElementById('productingSelectModal'); @@ -3482,6 +3685,51 @@ `; } + // 解析规格和件数为数组 + let specifications = []; + let quantities = []; + + try { + if (supply.specification) { + if (typeof supply.specification === 'string') { + // 规格存储为中文逗号分隔的字符串 + specifications = supply.specification.split(',').filter(spec => spec.trim()); + } else if (Array.isArray(supply.specification)) { + specifications = supply.specification; + } else { + specifications = [supply.specification]; + } + } else if (supply.spec) { + specifications = [supply.spec]; + } + } catch (e) { + specifications = [supply.specification || supply.spec || '无']; + } + + try { + if (supply.quantity) { + if (typeof supply.quantity === 'string') { + // 件数存储为英文逗号分隔的字符串 + quantities = supply.quantity.split(',').filter(qty => qty.trim()); + } else if (Array.isArray(supply.quantity)) { + quantities = supply.quantity; + } else { + quantities = [supply.quantity]; + } + } + } catch (e) { + quantities = [supply.quantity || '0']; + } + + // 生成规格-件数对应关系的HTML + let specQuantityBoxes = ''; + const maxLength = Math.max(specifications.length, quantities.length); + for (let i = 0; i < maxLength; i++) { + const spec = specifications[i] || '无'; + const quantity = quantities[i] || '0'; + specQuantityBoxes += `
• 规格${i + 1}: ${spec} - 件数: ${quantity}件
`; + } + return `
@@ -3490,21 +3738,30 @@
-
- ${supply.productName} - ${status.text} - -
-
-
蛋黄: ${supply.yolk || '无'}
-
规格: ${supply.specification || supply.spec || '无'}
-
货源状态: ${supply.supplyStatus || '未设置'}
-
货源描述: ${supply.description || '无'}
-
件数: ${supply.quantity || '0'}件
-
斤重: ${supply.grossWeight || ''}斤
-
地区: ${supply.region || '未设置'}
-
价格: ¥${supply.price || '0'}
-
创建时间: ${formatDate(supply.created_at)}
+ +
+ +
+
+ ${supply.productName} + ${status.text} + +
+ +
+
蛋黄: ${supply.yolk || '无'}
+
货源状态: ${supply.supplyStatus || '未设置'}
+
货源描述: ${supply.description || '无'}
+
斤重: ${supply.grossWeight || ''}斤
+
地区: ${supply.region || '未设置'}
+
价格: ¥${supply.price || '0'}
+
创建时间: ${formatDate(supply.created_at)}
+
+
+ +
+ ${specQuantityBoxes} +
${actionsHTML} @@ -3779,16 +4036,53 @@ // 重置表单函数(全局函数,以便多个地方可以调用) function resetForm() { - document.getElementById('createSupplyForm').reset(); - document.getElementById('uploadImages').innerHTML = ''; + // 重置表单 + const createSupplyForm = document.getElementById('createSupplyForm'); + if (createSupplyForm) { + createSupplyForm.reset(); + } + + // 重置图片 + const uploadImages = document.getElementById('uploadImages'); + if (uploadImages) { + uploadImages.innerHTML = ''; + } supplyData.uploadedImages = []; + + // 重置规格-件数对 + const specQuantityPairs = document.getElementById('specQuantityPairs'); + if (specQuantityPairs) { + specQuantityPairs.innerHTML = ''; + // 重新添加一个空的规格-件数对 + addSpecQuantityPair(); + } + // 重置自定义选择状态 - document.getElementById('specDisplayText').textContent = '请选择规格'; - document.getElementById('regionDisplayText').textContent = '请选择地区'; - document.getElementById('sourceTypeDisplayText').textContent = '请选择货源类型'; - document.getElementById('productNameDisplayText').textContent = '请选择商品名称'; - document.getElementById('yolkDisplayText').textContent = '请选择蛋黄类型'; - document.getElementById('contactIdDisplayText').textContent = '请选择联系人'; + const regionDisplayText = document.getElementById('regionDisplayText'); + if (regionDisplayText) { + regionDisplayText.textContent = '请选择地区'; + } + + const sourceTypeDisplayText = document.getElementById('sourceTypeDisplayText'); + if (sourceTypeDisplayText) { + sourceTypeDisplayText.textContent = '请选择货源类型'; + } + + const productNameDisplayText = document.getElementById('productNameDisplayText'); + if (productNameDisplayText) { + productNameDisplayText.textContent = '请选择商品名称'; + } + + const yolkDisplayText = document.getElementById('yolkDisplayText'); + if (yolkDisplayText) { + yolkDisplayText.textContent = '请选择蛋黄类型'; + } + + const contactIdDisplayText = document.getElementById('contactIdDisplayText'); + if (contactIdDisplayText) { + contactIdDisplayText.textContent = '请选择联系人'; + } + // 重置选择变量 selectedSpec = ''; selectedProvince = ''; @@ -3797,25 +4091,50 @@ selectedProductName = ''; selectedYolk = ''; selectedContactId = ''; + // 确保隐藏字段也被重置 - document.getElementById('specValue').value = ''; - document.getElementById('regionValue').value = ''; - document.getElementById('supplyStatus').value = ''; - document.getElementById('sourceType').value = ''; - document.getElementById('productName').value = ''; - document.getElementById('yolk').value = ''; - document.getElementById('contactId').value = ''; + const specValue = document.getElementById('specValue'); + if (specValue) specValue.value = ''; + + const regionValue = document.getElementById('regionValue'); + if (regionValue) regionValue.value = ''; + + const supplyStatus = document.getElementById('supplyStatus'); + if (supplyStatus) supplyStatus.value = ''; + + const sourceType = document.getElementById('sourceType'); + if (sourceType) sourceType.value = ''; + + const productName = document.getElementById('productName'); + if (productName) productName.value = ''; + + const yolk = document.getElementById('yolk'); + if (yolk) yolk.value = ''; + + const contactId = document.getElementById('contactId'); + if (contactId) contactId.value = ''; + // 重置货源状态按钮样式 - document.getElementById('preSaleBtn').style.borderColor = '#d9d9d9'; - document.getElementById('preSaleBtn').style.color = '#666'; - document.getElementById('inStockBtn').style.borderColor = '#d9d9d9'; - document.getElementById('inStockBtn').style.color = '#666'; + const preSaleBtn = document.getElementById('preSaleBtn'); + if (preSaleBtn) { + preSaleBtn.style.borderColor = '#d9d9d9'; + preSaleBtn.style.color = '#666'; + } + + const inStockBtn = document.getElementById('inStockBtn'); + if (inStockBtn) { + inStockBtn.style.borderColor = '#d9d9d9'; + inStockBtn.style.color = '#666'; + } } // 显示创建货源模态框 function showAddSupplyModal() { document.getElementById('createSupplyModal').style.display = 'flex'; + // 重新加载联系人数据,确保最新 + loadContacts(); + // 尝试从localStorage加载保存的表单数据 const savedFormData = localStorage.getItem('supplyFormDraft'); if (savedFormData) { @@ -3839,6 +4158,7 @@ const contactId = document.getElementById('contactId'); const specDisplayText = document.getElementById('specDisplayText'); const regionDisplayText = document.getElementById('regionDisplayText'); + const contactIdDisplayText = document.getElementById('contactIdDisplayText'); // 安全地设置表单值 if (productName) productName.value = formData.productName || ''; @@ -3860,6 +4180,10 @@ if (regionDisplayText && formData.regionDisplay) { regionDisplayText.textContent = formData.regionDisplay; } + // 恢复联系人显示文本 + if (contactIdDisplayText && formData.contactIdDisplay) { + contactIdDisplayText.textContent = formData.contactIdDisplay; + } // 恢复其他自定义下拉框显示文本 if (sourceTypeDisplayText && formData.sourceTypeDisplay) { sourceTypeDisplayText.textContent = formData.sourceTypeDisplay; @@ -4411,14 +4735,30 @@ const userInfo = checkLogin(); if (!userInfo) return; + // 获取规格和件数数据 + const pairs = document.querySelectorAll('.spec-quantity-pair'); + const specifications = []; + const quantities = []; + + pairs.forEach(pair => { + const specValue = pair.querySelector('.spec-value').value.trim(); + const quantityValue = pair.querySelector('.quantity-input').value.trim(); + + if (specValue) { + specifications.push(specValue); + // 件数可以为0,所以只检查是否有值(包括"0") + quantities.push(quantityValue); + } + }); + const formData = { productName: document.getElementById('productName').value, category: document.getElementById('category').value, price: document.getElementById('price').value, - quantity: document.getElementById('quantity').value, + quantity: quantities.join(','), // 将件数以英文逗号分隔的字符串形式提交 grossWeight: document.getElementById('grossWeight').value, yolk: document.getElementById('yolk').value, - specification: document.getElementById('specValue').value, + specification: specifications.join(','), // 将规格以中文逗号分隔的字符串形式提交 producting: document.getElementById('productingValue').value, supplyStatus: document.getElementById('supplyStatus').value, sourceType: document.getElementById('sourceType').value, @@ -4442,7 +4782,11 @@ alert('请输入价格'); return; } - if (!formData.quantity) { + if (specifications.length === 0) { + alert('请选择规格'); + return; + } + if (quantities.length === 0) { alert('请输入件数'); return; } @@ -4466,6 +4810,11 @@ alert('请上传至少一张商品图片'); return; } + // 增强联系人信息验证 + if (!formData.contactId || formData.contactId.trim() === '') { + alert('联系人信息缺失,请分配联系人'); + return; + } // 检查是否为重复货源 const isDuplicate = await checkDuplicateSupply(formData); @@ -4975,9 +5324,66 @@ document.getElementById('editRegionDisplayText').textContent = supply.region || '请选择地区'; document.getElementById('editRegionValue').value = supply.region || ''; document.getElementById('editPrice').value = supply.price || ''; - document.getElementById('editQuantity').value = supply.quantity || ''; document.getElementById('editGrossWeight').value = supply.grossWeight || ''; + // 规格和件数 - 支持中文逗号分隔和英文逗号分隔字符串 + let specifications = []; + let quantities = []; + + // 解析规格(中文逗号分隔字符串) + try { + if (supply.specification) { + if (typeof supply.specification === 'string') { + specifications = supply.specification.split(',').filter(spec => spec.trim()); + } else if (Array.isArray(supply.specification)) { + specifications = supply.specification; + } else { + specifications = [supply.specification]; + } + } else if (supply.spec) { + specifications = [supply.spec]; + } + } catch (e) { + specifications = [supply.specification || supply.spec || '无']; + } + + // 解析件数(英文逗号分隔字符串) + try { + if (supply.quantity) { + if (typeof supply.quantity === 'string') { + quantities = supply.quantity.split(',').filter(qty => qty.trim()); + } else if (Array.isArray(supply.quantity)) { + quantities = supply.quantity; + } else { + quantities = [supply.quantity]; + } + } + } catch (e) { + quantities = [supply.quantity || '0']; + } + + // 动态生成规格-件数对输入框 + const specQuantityPairs = document.getElementById('editSpecQuantityPairs'); + // 清空现有对 + specQuantityPairs.innerHTML = ''; + + // 如果没有规格-件数对,添加一个空的 + if (specifications.length === 0) { + addEditSpecQuantityPair(); + } else { + // 根据规格数量生成相应的规格-件数对 + for (let i = 0; i < specifications.length; i++) { + const pair = document.createElement('div'); + pair.className = 'spec-quantity-pair'; + pair.innerHTML = ` + + + + `; + specQuantityPairs.appendChild(pair); + } + } + // 显示商品图片 const editUploadImages = document.getElementById('editUploadImages'); editUploadImages.innerHTML = ''; @@ -5096,18 +5502,46 @@ const option = document.createElement('div'); option.className = 'select-item'; option.textContent = spec; - if (spec === editSelectedSpec) { + + // 检查当前规格是否已被选中 + if (editSelectedSpec.includes(spec)) { option.classList.add('selected'); } + + // 单击选择逻辑 option.onclick = () => { - // 移除所有选项的选中状态 + // 单选逻辑:移除所有选中状态 document.querySelectorAll('#editSpecOptionsList .select-item').forEach(item => { item.classList.remove('selected'); }); - // 添加当前选项的选中状态 + + // 添加当前选中状态 option.classList.add('selected'); - editSelectedSpec = spec; + + // 更新editSelectedSpec数组为单选 + editSelectedSpec = [spec]; + }; + + // 双击确认逻辑 + option.ondblclick = () => { + // 确保当前选项被选中 + if (!option.classList.contains('selected')) { + // 单选逻辑:移除所有选中状态 + document.querySelectorAll('#editSpecOptionsList .select-item').forEach(item => { + item.classList.remove('selected'); + }); + + // 添加当前选中状态 + option.classList.add('selected'); + + // 更新editSelectedSpec数组为单选 + editSelectedSpec = [spec]; + } + + // 自动确认选择 + confirmEditSpecSelection(); }; + specOptionsList.appendChild(option); }); } @@ -5126,13 +5560,98 @@ // 确认编辑规格选择 function confirmEditSpecSelection() { - if (editSelectedSpec) { - document.getElementById('editSpecDisplayText').textContent = editSelectedSpec; - document.getElementById('editSpecValue').value = editSelectedSpec; + if (currentEditSpecInput) { + // 如果是为规格和件数对选择规格 + if (editSelectedSpec.length > 0) { + currentEditSpecInput.value = editSelectedSpec.join(', '); + } else { + currentEditSpecInput.value = ''; + } + } else { + // 否则,为旧的规格选择逻辑 + if (editSelectedSpec.length > 0) { + document.getElementById('editSpecDisplayText').textContent = editSelectedSpec.join(', '); + document.getElementById('editSpecValue').value = JSON.stringify(editSelectedSpec); + // 根据选中的规格数量动态调整件数输入框数量 + adjustEditQuantityInputs(); + } else { + document.getElementById('editSpecDisplayText').textContent = '请选择规格'; + document.getElementById('editSpecValue').value = '[]'; + } } hideEditSpecSelectModal(); } + // 添加编辑件数输入项 + function addEditQuantityItem() { + const container = document.getElementById('editQuantityContainer'); + const quantityItem = document.createElement('div'); + quantityItem.className = 'quantity-item'; + quantityItem.innerHTML = ` + + + `; + container.insertBefore(quantityItem, container.lastElementChild); + } + + // 删除编辑件数输入项 + function removeEditQuantityItem(btn) { + const container = document.getElementById('editQuantityContainer'); + const quantityItems = container.querySelectorAll('.quantity-item'); + + // 至少保留一个件数输入项 + if (quantityItems.length > 1) { + const quantityItem = btn.parentElement; + quantityItem.remove(); + } + } + + // 根据选中的规格数量调整编辑件数输入框数量 + function adjustEditQuantityInputs() { + const container = document.getElementById('editQuantityContainer'); + const quantityItems = container.querySelectorAll('.quantity-item'); + const specCount = editSelectedSpec.length; + + // 如果规格数量大于件数输入框数量,添加缺少的输入框 + while (quantityItems.length < specCount) { + addEditQuantityItem(); + } + } + + // 添加编辑规格和件数对 + function addEditSpecQuantityPair() { + const container = document.getElementById('editSpecQuantityPairs'); + const pair = document.createElement('div'); + pair.className = 'spec-quantity-pair'; + pair.innerHTML = ` + + + + `; + container.appendChild(pair); + } + + // 删除编辑规格和件数对 + function removeEditSpecQuantityPair(btn) { + const pair = btn.parentElement; + const specInput = pair.querySelector('.spec-value'); + const quantityInput = pair.querySelector('.quantity-input'); + + // 清除当前对的输入值 + if (specInput) specInput.value = ''; + if (quantityInput) quantityInput.value = ''; + } + + // 为编辑规格和件数对显示规格选择弹窗 + function showEditSpecSelectModalForPair(input) { + // 保存当前点击的输入框 + currentEditSpecInput = input; + showEditSpecSelectModal(); + } + + // 保存当前点击的编辑规格输入框 + let currentEditSpecInput = null; + // 编辑产品包装选择功能 // 显示编辑产品包装选择弹窗 function showEditProductingSelectModal() { @@ -5763,15 +6282,30 @@ } try { + // 获取规格和件数数据 + const pairs = document.querySelectorAll('#editSpecQuantityPairs .spec-quantity-pair'); + const specifications = []; + const quantities = []; + + pairs.forEach(pair => { + const specValue = pair.querySelector('.spec-value').value.trim(); + const quantityValue = pair.querySelector('.quantity-input').value.trim(); + + if (specValue && quantityValue) { + specifications.push(specValue); + quantities.push(quantityValue); + } + }); + const formData = { productName: document.getElementById('editProductName').value, sourceType: document.getElementById('editSourceType').value, category: document.getElementById('editCategory').value, price: document.getElementById('editPrice').value, - quantity: document.getElementById('editQuantity').value, + quantity: quantities.join(','), // 将件数以英文逗号分隔的字符串形式提交 grossWeight: document.getElementById('editGrossWeight').value, yolk: document.getElementById('editYolk').value, - specification: document.getElementById('editSpecValue').value, + specification: specifications.join(','), // 将规格以中文逗号分隔的字符串形式提交 producting: document.getElementById('editProductingValue').value, supplyStatus: document.getElementById('editSupplyStatus').value, description: document.getElementById('editDescription').value, @@ -5785,14 +6319,43 @@ alert('请选择商品名称'); return false; } + if (!formData.category) { + alert('请选择种类'); + return false; + } if (!formData.price) { alert('请输入价格'); return false; } - if (!formData.quantity) { + if (specifications.length === 0) { + alert('请选择规格'); + return false; + } + if (quantities.length === 0) { alert('请输入件数'); return false; } + if (!formData.supplyStatus) { + alert('请选择货源状态(预售/现货)'); + return false; + } + if (!formData.sourceType) { + alert('请选择货源类型'); + return false; + } + if (!formData.region) { + alert('请选择地区'); + return false; + } + if (!formData.contactId) { + alert('请选择联系人'); + return false; + } + // 增强联系人信息验证 + if (!formData.contactId || formData.contactId.trim() === '') { + alert('联系人信息缺失,请分配联系人'); + return false; + } const response = await fetch(`/api/supplies/${currentEditSupplyId}/edit`, { method: 'PUT',