feat: 生产订单每个 BOM 生产数量限制为 1–9 的个位正整数

- 前端: 数量输入框改为 text/inputmode=numeric/maxlength=1,新增 capQty 实时拦截非个位(去非数字、限1位、超范围清空)
- 后端: 新增 _bom_qty_invalid 校验,order_new/order_edit 拒绝非个位数量并回显已填内容,提示「每个 BOM 的生产数量需为 1–9 的个位正整数」

Co-Authored-By: WorkBuddy <workbuddy@tencent.com>
This commit is contained in:
2026-10-26 10:51:55 +08:00
co-authored by WorkBuddy
parent 93f3ef458b
commit 38ee24f6ee
2 changed files with 29 additions and 2 deletions
+9 -2
View File
@@ -9,7 +9,7 @@
<input name="order_no" value="{{ o.order_no if o else '' }}" placeholder="如 WO20260911xxx">
<label>BOM 与生产数量 *</label>
<p class="small muted" style="margin:0 0 6px">可在同一订单中加入多个 BOM,每个 BOM 独立填写生产数量;点击「+ 添加 BOM」增加一行,不需要的行可删除。</p>
<p class="small muted" style="margin:0 0 6px">可在同一订单中加入多个 BOM,每个 BOM 独立填写生产数量(限 <b>1–9 的个位正整数</b>);点击「+ 添加 BOM」增加一行,不需要的行可删除。</p>
<div id="bomRows" class="bom-rows"></div>
<button type="button" class="btn" style="margin:2px 0 12px" onclick="addBomRow()">+ 添加 BOM</button>
@@ -36,12 +36,19 @@
<option value="">-- 选择 BOM --</option>
{% for b in boms %}<option value="{{ b.id }}">{{ b.code }}{% if b.name %} · {{ b.name }}{% endif %}</option>{% endfor %}
</select>
<input name="qty[]" type="number" step="0.01" min="0.01" required placeholder="生产数量" style="width:130px">
<input name="qty[]" type="text" inputmode="numeric" maxlength="1" required placeholder="数量 1-9" style="width:110px" oninput="capQty(this)">
<button type="button" class="link-danger" onclick="this.closest('.bom-row').remove();checkRows()">删除</button>
</div>
</template>
<script>
function capQty(el){
// 仅允许 1–9 的个位正整数: 去非数字、限制 1 位、超出范围清空
var v = (el.value || '').replace(/[^0-9]/g, '');
if (v.length > 1) v = v.slice(0, 1);
if (v !== '' && (parseInt(v, 10) < 1 || parseInt(v, 10) > 9)) v = '';
el.value = v;
}
function addBomRow(sel, qty){
var tpl = document.getElementById('bomTpl');
var row = tpl.content.firstElementChild.cloneNode(true);