Files
starandWorkBuddy 27fb218c40 fix: 生产订单数量放宽为正整數(≥1、不限位数、禁止小数)
- 用户澄清"保持个位"实为"不要小数点":移除 1–9 单 digit 上限,允许任意位正整数(如 12、100)
- 前端 capQty 改为仅保留数字、去小数点/负号、允许多位;输入框去掉 maxlength=1
- 后端 _bom_qty_invalid 改为校验正整数(≥1 且非小数),拒绝 1.5 等带小数点数量并提示

Co-Authored-By: WorkBuddy <workbuddy@tencent.com>
2026-10-26 11:10:05 +08:00

70 lines
3.5 KiB
HTML

{% extends "base.html" %}
{% block title %}{{ '编辑生产订单' if o else '新建生产订单' }}{% endblock %}
{% block content %}
<form method="post" class="card form-card" style="max-width:720px"
action="{{ url_for('order_edit', oid=o.id) if o else url_for('order_new') }}"
{% if o %}onsubmit="return confirm('确认保存修改?已录入的调入数量与已入账流水将保持不变(被移除 BOM 中已入账的物料仍保留其流水)。');"{% endif %}>
<h3>{{ '编辑生产订单' if o else '新建生产订单' }}</h3>
<label>订单号 {% if o %}(单号不可重复){% else %}(留空自动生成){% endif %}</label>
<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 独立填写生产数量(限<b>正整数,不含小数点</b>,如 1、12、100);点击「+ 添加 BOM」增加一行,不需要的行可删除。</p>
<div id="bomRows" class="bom-rows"></div>
<button type="button" class="btn" style="margin:2px 0 12px" onclick="addBomRow()">+ 添加 BOM</button>
<label>生产工厂</label>
<select name="factory_id">
<option value="">-- 不指定(汇总库存校验)--</option>
{% for f in factories %}
<option value="{{ f.id }}" {% if o and o.factory_id == f.id %}selected{% endif %}>{{ f.code }} · {{ f.name }}</option>
{% endfor %}
</select>
<label>备注</label>
<input name="remark" value="{{ o.remark if o else '' }}" placeholder="选填">
<div class="row-actions">
<button class="primary">{{ '保存修改' if o else '生成订单' }}</button>
<a class="btn" href="{{ url_for('orders') }}">取消</a>
</div>
<p class="small muted">生成后可在订单详情页按各 BOM 展开领料需求, 并手动录入每个物料的「调入数量」。</p>
</form>
{# 隐藏模板: 供 JS 克隆(含全部 BOM 选项) #}
<template id="bomTpl">
<div class="bom-row" style="display:flex; gap:10px; align-items:center; margin-bottom:6px">
<select name="bom_id[]" required>
<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="text" inputmode="numeric" required placeholder="数量(整数)" style="width:130px" oninput="capQty(this)">
<button type="button" class="link-danger" onclick="this.closest('.bom-row').remove();checkRows()">删除</button>
</div>
</template>
<script>
function capQty(el){
// 仅保留数字, 禁止小数点/负号, 允许多位正整数(不限位数)
var v = (el.value || '').replace(/[^\d]/g, '');
el.value = v === '' ? '' : String(parseInt(v, 10));
}
function addBomRow(sel, qty){
var tpl = document.getElementById('bomTpl');
var row = tpl.content.firstElementChild.cloneNode(true);
if (sel) row.querySelector('select').value = String(sel);
if (qty != null && qty !== undefined) row.querySelector('input').value = qty;
document.getElementById('bomRows').appendChild(row);
checkRows();
}
function checkRows(){
var rows = document.querySelectorAll('#bomRows .bom-row');
rows.forEach(function(r){
var btn = r.querySelector('button');
if (btn) btn.style.display = rows.length > 1 ? '' : 'none';
});
}
var init = {{ initial_lines|tojson }};
if (init && init.length){ init.forEach(function(x){ addBomRow(x[0], x[1]); }); }
else { addBomRow(); }
</script>
{% endblock %}