feat(client): 新建出入库单默认填充默认仓库(两端,原型同步)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@@ -75,9 +75,26 @@ class _StockInFormScreenState extends ConsumerState<StockInFormScreen> {
|
||||
} else {
|
||||
_items.add(_ItemRow());
|
||||
_initDefaults();
|
||||
_initWarehouseDefault();
|
||||
}
|
||||
}
|
||||
|
||||
/// 新建单默认填充默认仓库(2026-07-14):仓库列表加载完成后,
|
||||
/// `isDefault` 的仓 优先;无默认时仅剩 1 个仓才取它;否则保持 null。
|
||||
/// 编辑模式不受影响(`_loadEditOrder` 已从单据自身仓库回填)。
|
||||
Future<void> _initWarehouseDefault() async {
|
||||
try {
|
||||
final warehouses = await ref.read(warehouseListProvider.future);
|
||||
if (!mounted || _warehouseId != null) return;
|
||||
final defaultWh = warehouses.where((w) => w.isDefault).firstOrNull;
|
||||
final picked = defaultWh?.id ??
|
||||
(warehouses.length == 1 ? warehouses.first.id : null);
|
||||
if (picked != null) {
|
||||
setState(() => _warehouseId = picked);
|
||||
}
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
Future<void> _initDefaults() async {
|
||||
try {
|
||||
final shop = await ref.read(shopInfoProvider.future);
|
||||
|
||||
@@ -173,8 +173,29 @@ class _StockOutFormScreenState extends ConsumerState<StockOutFormScreen> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (_isEdit) _loadEditOrder();
|
||||
// 新单起始为空,用户通过「从库存选择」添加明细
|
||||
if (_isEdit) {
|
||||
_loadEditOrder();
|
||||
} else {
|
||||
// 新单起始为空,用户通过「从库存选择」添加明细
|
||||
_initWarehouseDefault();
|
||||
}
|
||||
}
|
||||
|
||||
/// 新建单默认填充默认仓库(2026-07-14):仓库列表加载完成后,
|
||||
/// `isDefault` 的仓 优先;无默认时仅剩 1 个仓才取它;否则保持 null。
|
||||
/// 编辑模式不受影响(`_loadEditOrder` 已从单据自身仓库回填)。
|
||||
Future<void> _initWarehouseDefault() async {
|
||||
try {
|
||||
final warehouses = await ref.read(warehouseListProvider.future);
|
||||
if (!mounted || _warehouseId != null) return;
|
||||
final defaultWh = warehouses.where((w) => w.isDefault).firstOrNull;
|
||||
final picked = defaultWh?.id ??
|
||||
(warehouses.length == 1 ? warehouses.first.id : null);
|
||||
if (picked != null) {
|
||||
setState(() => _warehouseId = picked);
|
||||
await _loadInventory(picked);
|
||||
}
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
Future<void> _loadEditOrder() async {
|
||||
|
||||
|
Before Width: | Height: | Size: 159 KiB After Width: | Height: | Size: 160 KiB |
|
Before Width: | Height: | Size: 156 KiB After Width: | Height: | Size: 156 KiB |
|
Before Width: | Height: | Size: 160 KiB After Width: | Height: | Size: 160 KiB |
|
Before Width: | Height: | Size: 133 KiB After Width: | Height: | Size: 132 KiB |
|
Before Width: | Height: | Size: 132 KiB After Width: | Height: | Size: 130 KiB |
|
Before Width: | Height: | Size: 134 KiB After Width: | Height: | Size: 132 KiB |
|
Before Width: | Height: | Size: 126 KiB After Width: | Height: | Size: 126 KiB |
|
Before Width: | Height: | Size: 123 KiB After Width: | Height: | Size: 123 KiB |
|
Before Width: | Height: | Size: 127 KiB After Width: | Height: | Size: 127 KiB |
|
Before Width: | Height: | Size: 84 KiB After Width: | Height: | Size: 82 KiB |
|
Before Width: | Height: | Size: 82 KiB After Width: | Height: | Size: 80 KiB |
|
Before Width: | Height: | Size: 85 KiB After Width: | Height: | Size: 83 KiB |
@@ -41,7 +41,8 @@ const CUSTOMERS = [
|
||||
['c3','喜来登酒店','xilaidengjiudian','xldjd','KH003'],['c4','婚庆批发王','hunqingpifawang','hqpfw','KH004'],
|
||||
['c5','社区团购站','shequtuangouzhan','sqtgz','KH005'],
|
||||
].map(a=>({id:a[0],name:a[1],py:a[2],init:a[3],code:a[4]}));
|
||||
const WAREHOUSES = [{id:'w1',name:'主仓'},{id:'w2',name:'二号仓'},{id:'w3',name:'冷藏库'}];
|
||||
// 2026-07-14:w1(主仓) 标记为默认仓(isDefault),新建单据仓库字段据此预填(真实端 Warehouse.isDefault)。
|
||||
const WAREHOUSES = [{id:'w1',name:'主仓',isDefault:true},{id:'w2',name:'二号仓'},{id:'w3',name:'冷藏库'}];
|
||||
const ORIGINS=[['o1','贵州茅台镇'],['o2','四川宜宾'],['o3','四川泸州'],['o4','江苏宿迁'],['o5','山西汾阳'],['o6','安徽亳州']].map(a=>({id:a[0],name:a[1],py:'',init:''}));
|
||||
const SHELF=[['h1','长期'],['h2','36个月'],['h3','24个月'],['h4','18个月']].map(a=>({id:a[0],name:a[1],py:'',init:''}));
|
||||
const STORAGE=[['t1','常温避光'],['t2','阴凉干燥'],['t3','防潮防晒']].map(a=>({id:a[0],name:a[1],py:'',init:''}));
|
||||
@@ -77,7 +78,10 @@ function reqFields(mode){ return editFields(mode).filter(k=>COLDEF[k].req); }
|
||||
|
||||
/* ---------------- 状态 ---------------- */
|
||||
let mode='in', status='new';
|
||||
const state = { doc:{partner:null,warehouse:null,date:today(),remark:''}, rows:[], docErr:new Set() };
|
||||
// 新建单默认填充默认仓库(2026-07-14):isDefault 的仓 优先;无默认时仅剩 1 个仓才取它;否则留空。
|
||||
// 编辑模式不受影响(由单据自身仓库回填,此函数只用于「新建」场景的初值)。
|
||||
function defaultWarehouseId(){ const def=WAREHOUSES.find(w=>w.isDefault); if(def) return def.id; return WAREHOUSES.length===1?WAREHOUSES[0].id:null; }
|
||||
const state = { doc:{partner:null,warehouse:defaultWarehouseId(),date:today(),remark:''}, rows:[], docErr:new Set() };
|
||||
function today(){ const d=new Date(); return d.toISOString().slice(0,10); }
|
||||
function newRow(){ return {id:'r'+(++SEQ), name:null,series:null,spec:null,prodDate:'',batch:'',qty:'1',price:'',sale:'',avail:null,expanded:false,origin:null,shelfLife:null,storage:null,doc:null,_err:new Set()}; }
|
||||
|
||||
@@ -438,7 +442,7 @@ function discardDraft(){ draftClear(); document.getElementById('noticeSlot').inn
|
||||
/* ---------------- 退出守卫 ---------------- */
|
||||
function exitGuard(){ if(!isDirty()){ resetForm(); toast('已取消'); return; } openOv('未保存的内容', `<div style="font-size:var(--fs-body);color:var(--text);line-height:1.6">当前${MODES[mode].title}尚未提交。是否保存为草稿,以免内容丢失?</div>`, [['继续编辑','ghost','closeOv()'],['放弃','danger','discardAndReset()'],['保存草稿','primary','closeOv();doSubmit(true)']]); }
|
||||
function discardAndReset(){ closeOv(); draftClear(); resetForm(); toast('已放弃录入'); }
|
||||
function resetForm(){ status='new'; state.doc={partner:null,warehouse:null,date:today(),remark:''}; state.docErr.clear(); state.rows=[newRow()]; setDateField(document.getElementById('orderDate'),state.doc.date); document.getElementById('remark').value=''; document.getElementById('noticeSlot').innerHTML=''; renderActions(); syncDocCombos(); syncDocLock(); refreshSummary(); renderDetail(); updateTotals(); }
|
||||
function resetForm(){ status='new'; state.doc={partner:null,warehouse:defaultWarehouseId(),date:today(),remark:''}; state.docErr.clear(); state.rows=[newRow()]; setDateField(document.getElementById('orderDate'),state.doc.date); document.getElementById('remark').value=''; document.getElementById('noticeSlot').innerHTML=''; renderActions(); syncDocCombos(); syncDocLock(); refreshSummary(); renderDetail(); updateTotals(); }
|
||||
|
||||
/* ---------------- 模式切换(入库 / 出库镜像)---------------- */
|
||||
function switchMode(m){ if(m===mode) return; mode=m; status='new';
|
||||
@@ -448,7 +452,7 @@ function switchMode(m){ if(m===mode) return; mode=m; status='new';
|
||||
document.getElementById('handlerLabel').textContent=MODES[m].handler;
|
||||
document.querySelector('.dochead-grid .field:nth-child(2) label').innerHTML=(m==='in'?'入库仓库':'出库仓库')+' <span class="req">*</span>';
|
||||
document.getElementById('kbdHint').style.display = m==='in'?'':'';
|
||||
state.doc={partner:null,warehouse:null,date:today(),remark:''}; state.docErr.clear(); state.rows=[newRow()];
|
||||
state.doc={partner:null,warehouse:defaultWarehouseId(),date:today(),remark:''}; state.docErr.clear(); state.rows=[newRow()];
|
||||
setDateField(document.getElementById('orderDate'),state.doc.date); document.getElementById('remark').value='';
|
||||
renderActions(); syncDocCombos(); syncDocLock(); refreshSummary(); renderDetail(); updateTotals(); maybeRestore();
|
||||
}
|
||||
|
||||