diff --git a/supply.html b/supply.html index 81ba995..0a6d988 100644 --- a/supply.html +++ b/supply.html @@ -5095,7 +5095,7 @@ addSpecQuantityPair(); } else { // 根据规格数量生成相应的规格-件数对 - for (let i = 0; i < specifications.length; i++) { + for (let i = 0; i < Math.min(specifications.length, 3); i++) { const pair = document.createElement('div'); pair.className = 'spec-quantity-pair'; pair.innerHTML = ` @@ -6815,6 +6815,10 @@ costprices = [supply.costprice || '0']; } + // 保存原有规格数量,用于后续判断是否允许删除 + window.originalSpecCount = Math.max(specifications.length, quantities.length, costprices.length); + if (window.originalSpecCount === 0) window.originalSpecCount = 1; + // 动态生成规格-件数对输入框 const specQuantityPairs = document.getElementById('editSpecQuantityPairs'); // 清空现有对 @@ -7155,6 +7159,13 @@ // 添加编辑规格和件数对 function addEditSpecQuantityPair() { const container = document.getElementById('editSpecQuantityPairs'); + const existingPairs = container.querySelectorAll('.spec-quantity-pair'); + + // 限制最多添加3条规格 + if (existingPairs.length >= 3) { + alert('最多只能添加3条规格信息'); + return; + } const existingSpecs = []; container.querySelectorAll('.spec-value').forEach(input => { if (input.value) existingSpecs.push(input.value); @@ -7177,6 +7188,17 @@ const container = pair.parentElement; const pairs = container.querySelectorAll('.spec-quantity-pair'); + // 检查要删除的是否是原有规格 + // 这里通过判断该规格是否在初始加载的规格数量范围内来确定是否为原有规格 + // 获取所有规格对,并检查要删除的是第几个 + const allPairs = Array.from(pairs); + const pairIndex = allPairs.indexOf(pair); + + if (pairIndex < (window.originalSpecCount || 1)) { + alert('不允许删除原有规格信息'); + return; + } + // 如果超过一个对,移除整个对元素 if (pairs.length > 1) { pair.remove();