完善订单成本编辑与多商品置换,修正锁价跨天作废回池

This commit is contained in:
summer committed 2026-11-24 21:11:32 +08:00
1 parent a3262a455d
commit 2e4e7dad55
25 files changed
+430 -109

No files matched your search

+2 -2
View File
@@ -44,7 +44,7 @@ async function openPriceLockCancel(id){
const result=await api('/api/price-locks/'+encodeURIComponent(id)+'/edit-context');if(request!==priceLockPendingRequest||session.user.id!==user||!dialog.open)return;
if(result?.eligible!==true||result.lock?.id!==id||result.lock.status!=='pending'||!Number.isSafeInteger(result.revision)||typeof result.requiresApproval!=='boolean')throw new Error(result.reason||'这张锁价单暂不能作废,请重新读取。');
priceLockPendingAction={id,user,revision:result.revision,requiresApproval:result.requiresApproval,inputs:result.inputs,lock:result.lock};const approval=priceLockPendingNeedsApproval(priceLockPendingAction);
dialog.innerHTML=`<button class="dialog-close" data-action="close-price-lock" aria-label="关闭">×</button><div class="order-header"><div class="eyebrow">VOID PRICE LOCK</div><h2>${approval?'申请作废':'作废'} · ${e(result.lock.customer)}</h2></div>${priceLockFacts(result.lock)}<div class="note"><strong>录错作废</strong><p>生效后撤销本单有效收款、手填购料与信用卡手续费记账,释放料池预留,保留原单和作废记录。适用于录错单据。</p><p>本操作不登记真实客户退款,也不登记实物退料。</p></div><form id="price-lock-cancel-form"><label>作废原因<textarea name="reason" required maxlength="200" rows="2"></textarea></label><label class="check"><input name="verified" type="checkbox" required>已核实这是一张录错的待交付锁价单,确认整单作废。</label>${approval?'<p class="note">提交申请后,麦麦复核同意才撤销记账;待批期间原锁价单保持有效。</p>':''}<div class="actions">${button('返回锁价详情','open-price-lock','quiet',`data-id="${e(id)}"`)}<button class="danger" type="submit">${approval?'提交作废申请':'确认整单作废'}</button></div><div id="price-lock-action-error" aria-live="polite"></div></form>`;
dialog.innerHTML=`<button class="dialog-close" data-action="close-price-lock" aria-label="关闭">×</button><div class="order-header"><div class="eyebrow">VOID PRICE LOCK</div><h2>${approval?'申请作废':'作废'} · ${e(result.lock.customer)}</h2></div>${priceLockFacts(result.lock)}<div class="note"><strong>录错作废</strong><p>生效后撤销本单有效收款、手填购料与信用卡手续费记账,同日释放料池预留;跨天按原锁定克重和原成本回到实际作废日料池,参与当天加权,历史订单成本不变。保留原单和作废记录。适用于录错单据。</p><p>本操作不登记真实客户退款,也不登记实物退料。</p></div><form id="price-lock-cancel-form"><label>作废原因<textarea name="reason" required maxlength="200" rows="2"></textarea></label><label class="check"><input name="verified" type="checkbox" required>已核实这是一张录错的待交付锁价单,确认整单作废。</label>${approval?'<p class="note">提交申请后,麦麦复核同意才撤销记账;待批期间原锁价单保持有效。</p>':''}<div class="actions">${button('返回锁价详情','open-price-lock','quiet',`data-id="${e(id)}"`)}<button class="danger" type="submit">${approval?'提交作废申请':'确认整单作废'}</button></div><div id="price-lock-action-error" aria-live="polite"></div></form>`;
}
async function submitPriceLockCancel(form){
const entry=priceLockPendingAction;if(!entry||entry.user!==session.user.id)throw new Error('请重新读取锁价单后再作废。');const reason=lockFormValue(form,'reason').trim();if(!reason)throw new Error('请填写作废原因。');if(!form.querySelector('[name="verified"]')?.checked)throw new Error('请核实录错单据并勾选整单作废。');
@@ -82,7 +82,7 @@ async function openPriceLockChange(id){
const request=++priceLockChangesRequest,user=session.user.id,dialog=priceLockChangesDialog();dialog.innerHTML=`<button class="dialog-close" data-action="price-lock-changes-close" aria-label="关闭">×</button><div id="price-lock-change-loading">正在读取锁价申请…</div>`;if(!dialog.open)dialog.showModal();
try{const result=await api('/api/price-lock-changes/'+encodeURIComponent(id));if(request!==priceLockChangesRequest||user!==session.user.id||!dialog.open)return;if((result.requestId||result.id)!==id||!['edit','cancel'].includes(result.action)||!Array.isArray(result.changes)||!result.before)throw new Error('锁价申请详情未完整返回,请重新读取。');priceLockChangeEntry=result;
const canReview=session.user.role==='owner'&&result.status==='pending'&&!result.stale;
dialog.innerHTML=`<button class="dialog-close" data-action="price-lock-changes-close" aria-label="关闭">×</button><div class="eyebrow">PRICE LOCK REVIEW</div><h2>${result.action==='cancel'?'录错作废':'整单修改'}申请</h2><p>${e(result.requester_name||'')} · ${e(result.created||'')} · ${e(({pending:'待复核',approved:'已批准',rejected:'已驳回'})[result.status]||result.status)}</p><p>申请原因:${e(result.reason||'未提供')}</p>${result.stale?'<div class="error">原单或关联料池已有变动,本次申请不能直接批准。请驳回后重新核实提交。</div>':''}${priceLockChangeSnapshotHTML(result.before,'当前原单')}${result.action==='edit'?priceLockChangeSnapshotHTML(result.after,'申请修改后'):'<div class="note">批准后整单作废,撤销有效收款、手填购料及信用卡手续费记账,释放料池预留;保留原单与作废记录,不登记真实退款或实物退料。</div>'}${result.relatedPriceLocks?.length&&typeof relatedPriceLocksHTML==='function'?relatedPriceLocksHTML(result.relatedPriceLocks):''}${result.relatedOrders?.length?priceLockRelatedOrdersHTML(result.relatedOrders):''}${result.note?`<p>复核备注:${e(result.note)}</p>`:''}<div class="actions">${button('返回申请列表','price-lock-changes-open','quiet')}${button('查看原锁价单','price-lock-change-lock','',`data-id="${e(result.price_lock_id)}"`)}</div>${session.user.role==='owner'&&result.status==='pending'?`<form id="price-lock-review-form"><label>复核备注<textarea name="review_note" maxlength="240" rows="2" placeholder="驳回时必填"></textarea></label>${canReview?'<label class="check"><input type="checkbox" name="verified">已逐件核对商品、收款、购料与关联影响,确认批准本次申请。</label>':''}<div class="actions">${canReview?'<button class="primary" name="decision" value="approve" type="submit">批准申请</button>':''}<button class="danger" name="decision" value="reject" type="submit">驳回申请</button></div><div id="price-lock-action-error" aria-live="polite"></div></form>`:''}`;
dialog.innerHTML=`<button class="dialog-close" data-action="price-lock-changes-close" aria-label="关闭">×</button><div class="eyebrow">PRICE LOCK REVIEW</div><h2>${result.action==='cancel'?'录错作废':'整单修改'}申请</h2><p>${e(result.requester_name||'')} · ${e(result.created||'')} · ${e(({pending:'待复核',approved:'已批准',rejected:'已驳回'})[result.status]||result.status)}</p><p>申请原因:${e(result.reason||'未提供')}</p>${result.stale?'<div class="error">原单或关联料池已有变动,本次申请不能直接批准。请驳回后重新核实提交。</div>':''}${priceLockChangeSnapshotHTML(result.before,'当前原单')}${result.action==='edit'?priceLockChangeSnapshotHTML(result.after,'申请修改后'):'<div class="note">批准后整单作废,撤销有效收款、手填购料及信用卡手续费记账,同日释放预留;跨天按原克重原成本回到批准当天料池,历史订单成本不变。保留原单与作废记录,不登记真实退款或实物退料。</div>'}${result.relatedPriceLocks?.length&&typeof relatedPriceLocksHTML==='function'?relatedPriceLocksHTML(result.relatedPriceLocks):''}${result.relatedOrders?.length?priceLockRelatedOrdersHTML(result.relatedOrders):''}${result.note?`<p>复核备注:${e(result.note)}</p>`:''}<div class="actions">${button('返回申请列表','price-lock-changes-open','quiet')}${button('查看原锁价单','price-lock-change-lock','',`data-id="${e(result.price_lock_id)}"`)}</div>${session.user.role==='owner'&&result.status==='pending'?`<form id="price-lock-review-form"><label>复核备注<textarea name="review_note" maxlength="240" rows="2" placeholder="驳回时必填"></textarea></label>${canReview?'<label class="check"><input type="checkbox" name="verified">已逐件核对商品、收款、购料与关联影响,确认批准本次申请。</label>':''}<div class="actions">${canReview?'<button class="primary" name="decision" value="approve" type="submit">批准申请</button>':''}<button class="danger" name="decision" value="reject" type="submit">驳回申请</button></div><div id="price-lock-action-error" aria-live="polite"></div></form>`:''}`;
}catch(error){if(request===priceLockChangesRequest&&dialog.open)dialog.innerHTML=`<button class="dialog-close" data-action="price-lock-changes-close" aria-label="关闭">×</button><div class="error">${e(error.message)}</div>${button('重新读取申请','price-lock-change-open','',`data-id="${e(id)}"`)}`;}
}
async function submitPriceLockReview(form,submitter){