Browse Source

fix: 限制规格数量对最多只能创建三个

Boss2
Default User 2 months ago
parent
commit
5c81a133ea
  1. 28
      supply.html

28
supply.html

@ -2939,6 +2939,14 @@
// 添加规格和件数对
function addSpecQuantityPair() {
const container = document.getElementById('specQuantityPairs');
const pairs = container.querySelectorAll('.spec-quantity-pair');
// 限制最多只能创建三个规格对
if (pairs.length >= 3) {
alert('最多只能创建三个规格对');
return;
}
const existingSpecs = [];
container.querySelectorAll('.spec-value').forEach(input => {
if (input.value) existingSpecs.push(input.value);
@ -2953,6 +2961,16 @@
<button type="button" class="remove-quantity-btn" onclick="removeSpecQuantityPair(this)">×</button>
`;
container.appendChild(pair);
// 检查是否已达到最大数量,如果是则禁用添加按钮
const newPairCount = container.querySelectorAll('.spec-quantity-pair').length;
if (newPairCount >= 3) {
const addButton = document.querySelector('.add-spec-quantity-btn');
if (addButton) {
addButton.disabled = true;
addButton.className = 'add-spec-quantity-btn btn-disabled';
}
}
}
// 删除规格和件数对
@ -2973,6 +2991,16 @@
if (quantityInput) quantityInput.value = '';
if (costpriceInput) costpriceInput.value = '';
}
// 检查当前数量,如果少于三个则启用添加按钮
const newPairCount = container.querySelectorAll('.spec-quantity-pair').length;
if (newPairCount < 3) {
const addButton = document.querySelector('.add-spec-quantity-btn');
if (addButton) {
addButton.disabled = false;
addButton.className = 'add-spec-quantity-btn';
}
}
}
// 为规格和件数对显示规格选择弹窗

Loading…
Cancel
Save