Files
weiguang-jewelry-ledger/新账系统/web/dist/assets/PriceLocksPage-BnrsfcSz.js
T

1 line
87 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import{n as e}from"./rolldown-runtime-Dl_DZoUm.js";import{t}from"./receipt-BUADJAzs.js";import{i as n,n as r,r as i,t as a}from"./receipts-CjPRrg8S.js";import{c as o,l as s,p as c,s as l,tr as u,u as d,v as f}from"./index-D422TGjj.js";import{t as p}from"./settingsModel-DuLjBEgM.js";import{n as m,r as h}from"./materialQuote-B1yI_Tto.js";import{c as g,n as _,o as v,t as y}from"./shared-Da74NgmJ.js";import{a as b,i as x,n as S,o as C,r as w,s as T,t as E}from"./BusinessControls-B3wlV0Qu.js";import{a as D,d as O}from"./model-CDW0MnQe.js";var k=e(u(),1),A=f();function j(e){let t=e.lines?.[0];return!!t&&!(`line`in t)}function ee(e,t){let n=(t,n)=>h(t,n,v.memberKeys(e));function r(e,t){let n=t,r=[],i=[];if(!Array.isArray(e.materialSources)||e.materialSources.reduce((e,t)=>e+t.quantity,0)!==e.quantity||e.materialSources.reduce((e,t)=>e+t.amount,0)!==e.amount)throw Error(`原锁分来源克重或成本未完整读到,请重新读取。`);for(let t of e.materialSources){if(![`quantity`,`amount`,`basisAmount`,`basisMg`,`prefixMg`,`prefixAmount`].every(e=>Number.isSafeInteger(t[e])&&t[e]>=0)||!t.basisMg||!Array.isArray(t.allocations)||t.allocations.reduce((e,t)=>e+t.amount,0)!==t.amount)throw Error(`原锁分来源成本未完整读到,请重新读取。`);let e=Math.min(n,t.quantity);if(n-=e,!e){i.push({...t});continue}if(e===t.quantity){r.push({...t});continue}let a=y.poolMaterialAmount(t.basisAmount,t.basisMg,t.prefixMg+e)-t.prefixAmount,o=[],s=[],c=a;for(let e of t.allocations){let t=Math.min(c,e.amount);t&&o.push({...e,amount:t}),e.amount>t&&s.push({...e,amount:e.amount-t}),c-=t}if(c||a<0||a>t.amount)throw Error(`原锁分来源分币未完整读到,请重新读取。`);!a&&!o.length&&o.push({payer:t.allocations[0]?.payer||`owner`,amount:0});let l=[],u=[],d=e;for(let e of t.batches||[]){let t=Math.min(d,e.mg);t&&l.push({...e,mg:t}),e.mg>t&&u.push({...e,mg:e.mg-t}),d-=t}r.push({...t,quantity:e,amount:a,allocations:o,batches:l}),i.push({...t,quantity:t.quantity-e,amount:t.amount-a,allocations:s,batches:u,prefixMg:t.prefixMg+e,prefixAmount:t.prefixAmount+a})}if(n)throw Error(`实际耗料超过原锁来源克重。`);return{taken:r,rest:i}}function i(e){let t=String(e??``).trim();if(!/^\d+(?:\.\d{1,3})?$/.test(t))throw Error(`克重请填写正数,最多3位小数。`);let[n,r=``]=t.split(`.`),i=Number(n)*1e3+Number(r.padEnd(3,`0`));if(!Number.isSafeInteger(i)||i<=0)throw Error(`克重请填写大于0的有效数字。`);return i}function a(e,t,n){if(!U(e))return y.priceLockCost({lockedQuantity:K(e.locked_mg),quantity:t,buyRate:(Number(e.buy_rate)/100).toFixed(2),extraBuyRate:n});let a=e.materialPool,o=i(t),s=Math.min(o,e.locked_mg),c=Math.max(0,o-e.locked_mg),l=e.locked_mg-s;if(!a||typeof a.amount!=`number`||![`basisAmount`,`basisMg`,`prefixMg`,`prefixAmount`,`amount`].every(e=>typeof a[e]==`number`&&Number.isSafeInteger(a[e])&&a[e]>=0)||!a.basisMg)throw Error(`原锁料池成本来源未完整读到,请重新读取锁价单。`);let u=a.materialSources?r(a,s):null,d=u?u.taken.reduce((e,t)=>e+t.amount,0):y.poolMaterialAmount(a.basisAmount,a.basisMg,a.prefixMg+s)-a.prefixAmount,f=c?y.cents(n,`补重进货料价`):0;if(c&&!f)throw Error(`补重进货料价必须大于0。`);let p=c?Number((BigInt(c)*BigInt(f)+500n)/1000n):0,m=d,h=[];for(let t of u?u.taken.flatMap(e=>e.allocations):L(e)){let e=Math.min(m,t.amount);(e||!d&&!h.length)&&h.push({payer:t.payer,amount:e}),m-=e}if(m||d<0||d>a.amount)throw Error(`原锁料池成本分摊不完整,请重新读取锁价单。`);return{lockedMg:e.locked_mg,finalMg:o,originalUsedMg:s,extraMg:c,leftoverMg:l,originalPurchase:a.amount,originalUsedCost:d,extraCost:p,materialCost:d+p,leftoverCost:a.amount-d,allocations:h,...u?{materialSources:u.taken,leftoverMaterialSources:u.rest}:{}}}function o(e){let t=e.line,n=L(e)[0]?.payer||e.buy_payer||`owner`;return{...t,quantity:K(e.locked_mg),goldPrice:(e.sell_rate/100).toFixed(2),laborRate:(t.laborRate/100).toFixed(2),sale:(t.sale/100).toFixed(2),baseSale:((t.baseSale??t.sale)/100).toFixed(2),charges:(t.charges||[]).map(e=>({...e,amount:(e.amount/100).toFixed(2)})),payer:n,costParts:{material:(Number(e.material_amount)/100).toFixed(2),labor:``,accessories:`0`,other:`0`},costMaterial:{mode:`total`},costLabor:{mode:`total`},costPayers:{material:n,labor:`owner`}}}function s(e){return(0,A.jsxs)(A.Fragment,{children:[(0,A.jsxs)(`div`,{className:`order-header`,children:[(0,A.jsx)(`div`,{className:`eyebrow`,children:`GOLD PRICE LOCK`}),(0,A.jsxs)(`h2`,{children:[e.customer,` · `,q(e).length,`件黄金锁价`]})]}),u(e),q(e).length===1?ee(e):``,(0,A.jsxs)(`p`,{className:`small muted`,children:[`预计报价 ¥`,G(e.estimated_total),`;交付时按最终克重、工费和附加项目重新结算,销售金价保持原锁价格。`]}),e.note?(0,A.jsx)(A.Fragment,{children:(0,A.jsx)(`p`,{children:e.note})}):``,e.status===`cancelled`?(0,A.jsx)(A.Fragment,{children:(0,A.jsxs)(`p`,{className:`note`,children:[`已作废 · `,e.cancelled_reason||`原单记录保留`,(0,A.jsx)(`br`,{}),e.cancelled_at||``]})}):``,(0,A.jsx)(`div`,{className:`actions`,children:e.status===`pending`?(0,A.jsxs)(A.Fragment,{children:[I(`办理交付`,`deliver-price-lock`,`primary`,{"data-id":e.id}),F(e)]}):e.final_order_id?I(`查看销售单`,`open-lock-order`,`primary`,{"data-id":e.final_order_id}):``})]})}function c(e){return e.credit_card_fee_total!==void 0&&Number.isSafeInteger(e.credit_card_fee_total)?e.credit_card_fee_total:(e.credit_card_fees||[]).reduce((e,t)=>e+t.amount,0)}function l(e){let t=e.credit_card_fees||[];return!t.length&&!c(e)?``:(0,A.jsx)(A.Fragment,{children:(0,A.jsxs)(`div`,{className:`price-lock-card-fees internal`,children:[(0,A.jsxs)(`strong`,{children:[`已记录的信用卡手续费 · ¥`,G(c(e))]}),(0,A.jsx)(`ul`,{children:k.Children.toArray(t.map(e=>(0,A.jsx)(A.Fragment,{children:(0,A.jsxs)(`li`,{children:[(0,A.jsxs)(`span`,{children:[e.date,` · `,z(e.payer),`支付`,e.note?` · `+e.note:``]}),(0,A.jsxs)(`b`,{children:[`¥`,G(e.amount)]})]})})))}),(0,A.jsx)(`p`,{className:`small muted`,children:`已按各笔付款时保存的金额与费率计入内部成本;交付时沿用,不重复收取。退款不冲回已发生的手续费。`})]})})}function u(e){let t=e.status===`cancelled`?(0,A.jsx)(A.Fragment,{children:(0,A.jsxs)(`div`,{className:`note price-lock-voided-note`,children:[(0,A.jsx)(`strong`,{children:`这张锁价单已作废`}),(0,A.jsx)(`p`,{children:`客户收款、手填购料和信用卡手续费有效记账已撤销,料池预留已释放。下方原录入克重、售价和成本保留用于追溯,不计当前有效收付。`}),k.Children.toArray((e.cancellationReturns||[]).map(e=>(0,A.jsx)(A.Fragment,{children:(0,A.jsxs)(`p`,{children:[`商品 `,e.line_index+1,` · `,e.date,` 按原成本回池:`,(0,A.jsxs)(`strong`,{children:[K(e.mg),`g / ¥`,G(e.amount)]}),`,参与回池当天加权;原料池日期 `,e.origin_pool_id,`。`]})})))]})}):``,n=q(e);if(n.length>1){let r=n.reduce((e,t)=>e+t.locked_mg,0),i=n.some(H),a=n.reduce((e,t)=>e+(t.material_amount??0),0);return(0,A.jsxs)(A.Fragment,{children:[t,(0,A.jsxs)(`div`,{className:`grid three price-lock-facts`,children:[(0,A.jsxs)(`div`,{children:[`锁价日期`,(0,A.jsx)(`strong`,{children:e.date})]}),(0,A.jsxs)(`div`,{children:[`原锁总克重 · `,n.length,`件`,(0,A.jsxs)(`strong`,{children:[K(r),`g`]})]}),(0,A.jsxs)(`div`,{children:[e.status===`delivered`?`锁价及交付阶段净收款`:`客户实际已付净额`,(0,A.jsxs)(`strong`,{children:[`¥`,G(e.netReceived)]})]}),(0,A.jsxs)(`div`,{children:[`原锁料费合计`,(0,A.jsx)(`strong`,{children:i?`料费待补`:`¥`+G(a)})]}),(0,A.jsxs)(`div`,{children:[`状态`,(0,A.jsx)(`strong`,{children:e.status===`pending`?`待交付,不计利润`:e.status===`cancelled`?`已作废`:`已交付`})]})]}),ee(e),l(e)]})}e=n[0]||e;let r=U(e),i=e.materialPool,a=H(e)?(0,A.jsx)(A.Fragment,{children:(0,A.jsx)(`small`,{children:`关联用料不足,补足购料后自动核算料费与付款来源。`})}):(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`small`,{children:r?i?.materialSources?.length?te(i.materialSources):`${i?.date||e.material_pool_id||e.date}料池,加权均价约 ¥${G(i?.averageRate??e.buy_rate)}/克`:`${z(e.buy_payer)}支付,进货料价 ¥${G(e.buy_rate)}/克`}),r?(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`small`,{children:B(L(e))}),(0,A.jsxs)(`small`,{children:[i?.frozen?`已冻结锁价日成本`:`当天补料继续加权`,`,不重复记购料付款。`]})]}):``]});return(0,A.jsxs)(A.Fragment,{children:[t,(0,A.jsxs)(`div`,{className:`grid three price-lock-facts`,children:[(0,A.jsxs)(`div`,{children:[`锁价日期`,(0,A.jsx)(`strong`,{children:e.date})]}),(0,A.jsxs)(`div`,{children:[`原锁克重`,(0,A.jsxs)(`strong`,{children:[K(e.locked_mg),`g`]})]}),(0,A.jsxs)(`div`,{children:[`锁定销售金价`,(0,A.jsxs)(`strong`,{children:[`¥`,G(e.sell_rate),`/克`]})]}),(0,A.jsxs)(`div`,{children:[e.status===`delivered`?`锁价及交付阶段净收款`:`客户实际已付净额`,(0,A.jsxs)(`strong`,{children:[`¥`,G(e.netReceived)]}),e.status===`delivered`?(0,A.jsx)(A.Fragment,{children:(0,A.jsx)(`small`,{children:`后续收退款请查看销售单。`})}):``]}),(0,A.jsxs)(`div`,{children:[`原锁料费 · `,r?`当日加权料池`:`手动独立购料`,(0,A.jsx)(`strong`,{children:V(e)}),a]}),(0,A.jsxs)(`div`,{children:[`状态`,(0,A.jsx)(`strong`,{children:e.status===`pending`?`待交付,不计利润`:e.status===`cancelled`?`已作废`:`已交付`})]})]}),l(e)]})}function d(e,t){let n=e.lock.id;return(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(E,{className:`dialog-close`,"data-action":`close-price-lock`,"aria-label":`关闭`,children:`×`}),(0,A.jsxs)(`div`,{className:`order-header`,children:[(0,A.jsx)(`div`,{className:`eyebrow`,children:`VOID PRICE LOCK`}),(0,A.jsxs)(`h2`,{children:[t?`申请作废`:`作废`,` · `,e.lock.customer]})]}),u(e.lock),(0,A.jsxs)(`div`,{className:`note`,children:[(0,A.jsx)(`strong`,{children:`录错作废`}),(0,A.jsx)(`p`,{children:`生效后撤销本单有效收款、手填购料与信用卡手续费记账,同日释放料池预留;跨天按原锁定克重和原成本回到实际作废日料池,参与当天加权,历史订单成本不变。保留原单和作废记录。适用于录错单据。`}),(0,A.jsx)(`p`,{children:`本操作不登记真实客户退款,也不登记实物退料。`})]}),(0,A.jsxs)(`form`,{id:`price-lock-cancel-form`,children:[(0,A.jsxs)(`label`,{children:[`作废原因`,(0,A.jsx)(T,{name:`reason`,required:!0,maxLength:200,rows:2})]}),(0,A.jsxs)(`label`,{className:`check`,children:[(0,A.jsx)(x,{name:`verified`,type:`checkbox`,required:!0}),`已核实这是一张录错的待交付锁价单,确认整单作废。`]}),t?(0,A.jsx)(A.Fragment,{children:(0,A.jsx)(`p`,{className:`note`,children:`提交申请后,店主复核同意才撤销记账;待批期间原锁价单保持有效。`})}):``,(0,A.jsxs)(`div`,{className:`actions`,children:[I(`返回锁价详情`,`open-price-lock`,`quiet`,{"data-id":n}),(0,A.jsx)(E,{className:`danger`,type:`submit`,children:t?`提交作废申请`:`确认整单作废`})]}),(0,A.jsx)(`div`,{id:`price-lock-action-error`,"aria-live":`polite`})]})]})}function f(e){let t=e=>e===null?`待核算`:Number.isSafeInteger(e)?`¥`+G(e):`未提供`;return(0,A.jsx)(A.Fragment,{children:(0,A.jsxs)(`section`,{className:`lock-related-orders`,children:[(0,A.jsxs)(`h3`,{children:[`受影响的销售单(`,e.length,`张)`]}),(0,A.jsx)(`div`,{className:`table-wrap`,children:(0,A.jsx)(S,{columns:[{title:`订单`},{title:`货品成本:当前 → 生效后`},{title:`利润:当前 → 生效后`}],rows:e.map((e,n)=>({key:n,cells:[(0,A.jsxs)(A.Fragment,{children:[e.date,` · `,e.number||e.id]}),(0,A.jsxs)(A.Fragment,{children:[t(e.before?.goodsCost),` → `,t(e.after?.goodsCost)]}),(0,A.jsxs)(A.Fragment,{children:[t(e.before?.profit),` → `,t(e.after?.profit)]})]}))})})]})})}let p=g.validDate,_=()=>v.memberKeys(e);function b(e){if(e===void 0)return[];let t=e=>e===null||typeof e==`number`&&Number.isSafeInteger(e)&&e>=0,n=e=>e&&t(e.materialAmount)&&[`usedMaterialAmount`,`leftoverCost`].every(n=>!Object.hasOwn(e,n)||t(e[n]))&&Array.isArray(e.allocations)&&e.allocations.every(e=>_().includes(e.payer)&&Number.isSafeInteger(e.amount)&&e.amount>=0)&&(e.materialAmount===null||e.allocations.reduce((e,t)=>e+t.amount,0)===e.materialAmount);if(!Array.isArray(e)||!e.every(e=>e&&typeof e.id==`string`&&e.id&&p(e.date)&&n(e.before)&&n(e.after)))throw Error(`关联锁价单的成本影响未完整返回,请重新读取后复核。`);return e}function w(e){let t=b(e);if(!t.length)return``;let n=e=>e===null?`待补齐`:`¥`+G(e),r=e=>e.allocations.length?e.allocations.map(e=>R(e.payer)+` `+n(e.amount)).join(`;`):e.materialAmount===null?`待补齐后分摊`:`无分摊金额`,i=(e,t,n)=>(0,A.jsx)(A.Fragment,{children:(0,A.jsxs)(`tr`,{children:[(0,A.jsx)(`th`,{scope:`row`,children:e}),(0,A.jsx)(`td`,{children:t}),(0,A.jsx)(`td`,{children:n})]})});return(0,A.jsx)(A.Fragment,{children:(0,A.jsxs)(`section`,{className:`price-lock-related-impact`,children:[(0,A.jsxs)(`h3`,{children:[`同时受影响的锁价单(`,t.length,` 张)`]}),(0,A.jsx)(`p`,{className:`small muted`,children:`以下只调整料池成本和付款归属,客户锁定售价与实际收付款保持原记录。`}),k.Children.toArray(t.map(e=>(0,A.jsxs)(A.Fragment,{children:[(0,A.jsxs)(`h3`,{children:[e.date,` · `,e.number||e.id,e.customer?` · `+e.customer:``]}),(0,A.jsx)(`div`,{className:`table-wrap`,children:(0,A.jsxs)(C,{className:`material-detail-table material-change-comparison`,"aria-label":`关联锁价单成本影响`,children:[(0,A.jsx)(`thead`,{children:(0,A.jsxs)(`tr`,{children:[(0,A.jsx)(`th`,{children:`核对项目`}),(0,A.jsx)(`th`,{children:`变更前`}),(0,A.jsx)(`th`,{children:`批准后`})]})}),(0,A.jsxs)(`tbody`,{children:[i(`原锁预留料费`,n(e.before.materialAmount),n(e.after.materialAmount)),[`before`,`after`].some(t=>Object.hasOwn(e[t],`usedMaterialAmount`))?i(`交付耗用原锁料费`,Object.hasOwn(e.before,`usedMaterialAmount`)?n(e.before.usedMaterialAmount):`未交付`,Object.hasOwn(e.after,`usedMaterialAmount`)?n(e.after.usedMaterialAmount):`未交付`):``,[`before`,`after`].some(t=>Object.hasOwn(e[t],`leftoverCost`))?i(`少重回池成本`,Object.hasOwn(e.before,`leftoverCost`)?n(e.before.leftoverCost):`未交付`,Object.hasOwn(e.after,`leftoverCost`)?n(e.after.leftoverCost):`未交付`):``,i(`自动付款归属`,r(e.before),r(e.after))]})]})})]})))]})})}let D=t=>{let n=v.accountIdentity(e,t);return n?v.memberName(e,n.member)+n.channel:t};function O(t){return e?.pocketCatalog?.find(e=>e.key===t)?.name||String(t??``)}function ee(e){let t=q(e);return(0,A.jsx)(A.Fragment,{children:(0,A.jsx)(`div`,{className:`table-wrap price-lock-items`,children:(0,A.jsxs)(C,{"aria-label":`锁价商品明细`,children:[(0,A.jsx)(`thead`,{children:(0,A.jsxs)(`tr`,{children:[(0,A.jsx)(`th`,{children:`商品`}),(0,A.jsx)(`th`,{className:`number`,children:`原锁克重`}),(0,A.jsx)(`th`,{className:`number`,children:`原锁销售金价`}),(0,A.jsx)(`th`,{children:`工费与附加项目`}),(0,A.jsx)(`th`,{children:`原锁料费/付款来源`}),e.status===`delivered`?(0,A.jsx)(A.Fragment,{children:(0,A.jsx)(`th`,{children:`实际交付`})}):``]})}),(0,A.jsx)(`tbody`,{children:k.Children.toArray(t.map((t,n)=>{let r=t.line||{},i=t.delivery;return(0,A.jsx)(A.Fragment,{children:(0,A.jsxs)(`tr`,{children:[(0,A.jsxs)(`td`,{children:[(0,A.jsx)(`strong`,{children:r.name||`黄金`}),(0,A.jsxs)(`div`,{className:`small muted`,children:[`商品 `,n+1,r.code?` · `+r.code:``]})]}),(0,A.jsxs)(`td`,{className:`number`,children:[K(t.locked_mg),`g`]}),(0,A.jsxs)(`td`,{className:`number`,children:[`¥`,G(t.sell_rate),`/克`]}),(0,A.jsxs)(`td`,{children:[r.laborMode===`piece`?`件工费 ¥${G(r.laborRate??0)} × ${r.pieces||1}件`:`克工费 ¥${G(r.laborRate??0)}/克`,k.Children.toArray((r.charges||[]).map(e=>(0,A.jsx)(A.Fragment,{children:(0,A.jsxs)(`div`,{className:`small muted`,children:[e.name,` ¥`,G(e.amount)]})})))]}),(0,A.jsx)(`td`,{children:W(t)}),e.status===`delivered`?(0,A.jsx)(A.Fragment,{children:(0,A.jsx)(`td`,{children:i?`${K(i.finalMg??i.quantity??t.locked_mg)}g${i.extraMg??i.extra_mg?(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`br`,{}),`补重 `,K(i.extraMg??i.extra_mg??0),`g`]}):``}${i.leftoverMg??i.leftover_mg?(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`br`,{}),U(t)?`解除预留回池 `:`剩料留盘 `,K(i.leftoverMg??i.leftover_mg??0),`g`]}):``}${i.inventory?.pocket?(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`br`,{}),`货盘 `,O(i.inventory.pocket)]}):i.pocket?(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`br`,{}),`货盘 `,O(i.pocket)]}):``}`:`详见销售单`})}):``]})})}))})]})})})}function M(e,t){if(!e)return(0,A.jsx)(A.Fragment,{children:(0,A.jsxs)(`div`,{children:[(0,A.jsx)(`h3`,{children:t}),(0,A.jsx)(`p`,{children:`未提供`})]})});let n=`lock`in e?e.lock:e;if(!j(n))return(0,A.jsx)(A.Fragment,{children:(0,A.jsxs)(`div`,{className:`lock-change-snapshot`,children:[(0,A.jsx)(`h3`,{children:t}),(0,A.jsxs)(`p`,{children:[n.date||``,` · `,n.customer||``,` · 开单人 `,n.salesperson||`未提供`]}),ee(n),(0,A.jsxs)(`p`,{children:[`预计成交 `,Number.isSafeInteger(n.estimated_total)?`¥`+G(n.estimated_total):`未提供`,` · 已收净额 `,Number.isSafeInteger(n.netReceived)?`¥`+G(n.netReceived):`未提供`,` · 整单优惠`,` `,Number.isSafeInteger(n.discount)?`¥`+G(n.discount):`未提供`]}),n.note?(0,A.jsx)(A.Fragment,{children:(0,A.jsxs)(`p`,{children:[`客户备注:`,n.note]})}):``]})});let r=n.lines||[];return(0,A.jsx)(A.Fragment,{children:(0,A.jsxs)(`div`,{className:`lock-change-snapshot`,children:[(0,A.jsx)(`h3`,{children:t}),(0,A.jsxs)(`p`,{children:[n.date||``,` · `,n.customer||``,` · 开单人 `,n.salesperson||`未提供`]}),(0,A.jsx)(`div`,{className:`table-wrap`,children:(0,A.jsx)(S,{columns:[{title:`商品`},{title:`锁重/售价`},{title:`销售工费/附加项目`},{title:`原锁料费/付款人`}],rows:r.map((e,t)=>({key:t,cells:[e.name||`未提供`,(0,A.jsxs)(A.Fragment,{children:[e.quantity||`未提供`,`g`,(0,A.jsx)(`br`,{}),`¥`,e.goldPrice??`未提供`,`/克`]}),(0,A.jsxs)(A.Fragment,{children:[e.laborMode===`piece`?`件工费`:`克工费`,` ¥`,e.laborRate??`未提供`,e.laborMode===`piece`?` × `+(e.pieces||1)+`件`:`/克`,k.Children.toArray((e.charges||[]).map(e=>(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`br`,{}),e.name,` ¥`,e.amount]})))]}),e.material?.source===`pool`?`当日加权料池`:(0,A.jsxs)(A.Fragment,{children:[`手填 ¥`,e.material?.rate??`未提供`,`/克`,(0,A.jsx)(`br`,{}),z(e.material?.payer)]})]}))})}),(0,A.jsxs)(`p`,{children:[`客户实际付款 ¥`,n.payment?.amount??`未提供`,` · `,D(n.payment?.account||``),` · 整单优惠 ¥`,n.discount??`未提供`]}),n.note?(0,A.jsx)(A.Fragment,{children:(0,A.jsxs)(`p`,{children:[`客户备注:`,n.note]})}):``]})})}function N(t,n){return(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(E,{className:`dialog-close`,"data-action":`price-lock-changes-close`,"aria-label":`关闭`,children:`×`}),(0,A.jsx)(`div`,{className:`eyebrow`,children:`PRICE LOCK REVIEW`}),(0,A.jsxs)(`h2`,{children:[t.action===`cancel`?`录错作废`:`整单修改`,`申请`]}),(0,A.jsxs)(`p`,{children:[t.requester_name||``,` · `,t.created||``,` ·`,` `,{pending:`待复核`,approved:`已批准`,rejected:`已驳回`}[t.status]||t.status]}),(0,A.jsxs)(`p`,{children:[`申请原因:`,t.reason||`未提供`]}),t.stale?(0,A.jsx)(A.Fragment,{children:(0,A.jsx)(`div`,{className:`error`,children:`原单或关联料池已有变动,本次申请不能直接批准。请驳回后重新核实提交。`})}):``,M(t.before,`当前原单`),t.action===`edit`?M(t.after,`申请修改后`):(0,A.jsx)(A.Fragment,{children:(0,A.jsx)(`div`,{className:`note`,children:`批准后整单作废,撤销有效收款、手填购料及信用卡手续费记账,同日释放预留;跨天按原克重原成本回到批准当天料池,历史订单成本不变。保留原单与作废记录,不登记真实退款或实物退料。`})}),t.relatedPriceLocks?.length?w(t.relatedPriceLocks):``,t.relatedOrders?.length?f(t.relatedOrders):``,t.note?(0,A.jsx)(A.Fragment,{children:(0,A.jsxs)(`p`,{children:[`复核备注:`,t.note]})}):``,(0,A.jsxs)(`div`,{className:`actions`,children:[I(`返回申请列表`,`price-lock-changes-open`,`quiet`),I(`查看原锁价单`,`price-lock-change-lock`,``,{"data-id":t.price_lock_id})]}),e.user.role===`owner`&&t.status===`pending`?(0,A.jsx)(A.Fragment,{children:(0,A.jsxs)(`form`,{id:`price-lock-review-form`,children:[(0,A.jsxs)(`label`,{children:[`复核备注`,(0,A.jsx)(T,{name:`review_note`,maxLength:240,rows:2,placeholder:`驳回时必填`})]}),n?(0,A.jsx)(A.Fragment,{children:(0,A.jsxs)(`label`,{className:`check`,children:[(0,A.jsx)(x,{type:`checkbox`,name:`verified`}),`已逐件核对商品、收款、购料与关联影响,确认批准本次申请。`]})}):``,(0,A.jsxs)(`div`,{className:`actions`,children:[n?(0,A.jsx)(A.Fragment,{children:(0,A.jsx)(E,{className:`primary`,name:`decision`,value:`approve`,type:`submit`,children:`批准申请`})}):``,(0,A.jsx)(E,{className:`danger`,name:`decision`,value:`reject`,type:`submit`,children:`驳回申请`})]}),(0,A.jsx)(`div`,{id:`price-lock-action-error`,"aria-live":`polite`})]})}):``]})}function P(e){return e.rows.length?(0,A.jsx)(A.Fragment,{children:(0,A.jsx)(`div`,{className:`table-wrap`,children:(0,A.jsx)(S,{className:`price-lock-change-list`,columns:[{title:`原锁价单/客户`},{title:`申请`},{title:`申请人/日期`},{title:`状态`},{title:`操作`}],rows:e.rows.map((e,t)=>({key:t,cells:[(0,A.jsxs)(A.Fragment,{children:[e.number||e.before?.number||`锁价单`,(0,A.jsx)(`div`,{className:`small muted`,children:e.customer||e.before?.customer||``})]}),(0,A.jsxs)(A.Fragment,{children:[e.action===`cancel`?`录错作废`:`修改整单`,(0,A.jsx)(`div`,{className:`small muted`,children:e.reason||``})]}),(0,A.jsxs)(A.Fragment,{children:[e.requester_name||e.requester||``,(0,A.jsx)(`div`,{className:`small muted`,children:e.created||``})]}),{pending:`待店主复核`,approved:`已批准`,rejected:`已驳回`}[e.status]||e.status,I(`查看申请`,`price-lock-change-open`,``,{"data-id":e.requestId||e.id})]}))})})}):(0,A.jsx)(A.Fragment,{children:(0,A.jsx)(`p`,{className:`empty`,children:`暂无符合条件的申请。`})})}function F(t){return[`owner`,`assistant`].includes(e.user.role)?(0,A.jsxs)(A.Fragment,{children:[I(`修改`,`edit-price-lock`,`quiet`,{"data-id":t.id}),I(`作废`,`cancel-price-lock`,`quiet`,{"data-id":t.id})]}):``}let I=(e,t,n=``,r={})=>(0,A.jsx)(E,{type:`button`,"data-action":t,className:n,...r,children:e}),te=e=>m(e,R);function L(e){return H(e)?[]:U(e)?e.materialPool?.allocations||[]:[{payer:e.buy_payer,amount:Number(e.material_amount)}]}let R=n=>v.memberName(e,n,t),z=e=>e?R(e):`待补`;function B(e){return e.map(e=>z(e.payer)+` ¥`+G(e.amount)).join(`;`)}function V(e){let t=U(e)&&Number.isSafeInteger(e.materialPool?.amount)?e.materialPool?.amount:e.material_amount;return H(e)||!Number.isSafeInteger(t)?`料费待补`:`¥`+G(t)}let H=e=>e?.material_amount===null||U(e)&&(e.materialPool?.status===`pending`||e.materialPool?.amount===null),U=e=>e?.material_source===`pool`;function W(e){let t=U(e),n=e.materialPool,r=H(e);return(0,A.jsxs)(A.Fragment,{children:[e.status===`cancelled`?(0,A.jsx)(A.Fragment,{children:(0,A.jsx)(`div`,{className:`small danger-text`,children:`原录入成本(已撤销记账)`})}):``,(0,A.jsx)(`strong`,{children:V(e)}),(0,A.jsxs)(`div`,{className:`small muted`,children:[t?`当日加权料池`:`手动独立购料`,r?`;补足购料后自动核算付款来源`:t?(0,A.jsxs)(A.Fragment,{children:[` `,`· `,n?.date||e.material_pool_id||e.date,(0,A.jsx)(`br`,{}),B(L(e)),(0,A.jsx)(`br`,{}),n?.materialSources?.length?(0,A.jsxs)(A.Fragment,{children:[te(n.materialSources),(0,A.jsx)(`br`,{})]}):``,n?.frozen?`已冻结锁价日成本`:`当天补料继续加权`,`,不重复记购料付款。`]}):(0,A.jsxs)(A.Fragment,{children:[` `,`· `,z(e.buy_payer),(0,A.jsx)(`br`,{}),`进货料价 ¥`,G(e.buy_rate),`/克`]})]})]})}let G=v.yuan,K=v.grams;function q(e){return!Array.isArray(e?.lines)||!e.lines.length?e?[e]:[]:e.lines.map((t,n)=>{let r={...e,...t,id:t.id||t.lineId||t.price_lock_line_id||t.id,line:t.line||t,line_index:n,parent_id:e.id};return delete r.lines,r})}function ne(e,t){return e.rows.length?(0,A.jsx)(A.Fragment,{children:(0,A.jsx)(`div`,{className:`table-wrap`,children:(0,A.jsx)(S,{className:`price-lock-list`,columns:[{title:`锁价日期/客户`},{title:`黄金商品`},{title:`锁定克重`,headerClassName:`number`},{title:`销售金价`,headerClassName:`number`},{title:`已收净额`,headerClassName:`number`},{title:t===`cancelled`?`原录入成本(已撤销记账)`:`原料来源/成本`},{title:`操作`}],rows:e.rows.map((e,t)=>({key:t,cellClasses:[void 0,void 0,`number`,`number`,`number`,void 0,void 0],cells:[(0,A.jsxs)(A.Fragment,{children:[e.date,(0,A.jsx)(`br`,{}),e.customer]}),q(e).map(e=>e.line?.name||`黄金`).map((e,t)=>(0,A.jsxs)(k.Fragment,{children:[t>0&&(0,A.jsx)(`br`,{}),e]},t)),(0,A.jsxs)(A.Fragment,{children:[K(q(e).reduce((e,t)=>e+t.locked_mg,0)),`g`]}),q(e).map(e=>`¥`+G(e.sell_rate)+`/克`).map((e,t)=>(0,A.jsxs)(k.Fragment,{children:[t>0&&(0,A.jsx)(`br`,{}),e]},t)),(0,A.jsxs)(A.Fragment,{children:[`¥`,G(e.netReceived)]}),q(e).map(e=>W(e)).map((e,t)=>(0,A.jsxs)(k.Fragment,{children:[t>0&&(0,A.jsx)(`hr`,{className:`lock-row-divider`}),e]},t)),(0,A.jsx)(A.Fragment,{children:(0,A.jsxs)(`div`,{className:`actions`,children:[I(`查看`,`open-price-lock`,``,{"data-id":e.id}),e.status===`pending`?(0,A.jsxs)(A.Fragment,{children:[I(`交付`,`deliver-price-lock`,`primary`,{"data-id":e.id}),F(e)]}):``]})})]}))})})}):t===`cancelled`?(0,A.jsx)(A.Fragment,{children:(0,A.jsxs)(`div`,{className:`empty`,children:[(0,A.jsx)(`strong`,{children:`目前没有已作废锁价单`}),`作废后保留的原单会显示在这里。`]})}):(0,A.jsx)(A.Fragment,{children:(0,A.jsxs)(`div`,{className:`empty`,children:[(0,A.jsx)(`strong`,{children:`目前没有锁价待交付记录`}),`已交付记录会进入订单列表。`]})})}return{listRecords:ne,changeRows:P,changeDetail:N,cancelView:d,detailView:s,priceLockFacts:u,priceLockLines:q,priceLockLineInputs:o,priceLockDeliveryCost:a,materialSourceSegmentsText:te,validateMaterialQuote:n,lockQuantityMg:i}}function M({label:e,name:t,value:n=``,type:r=`text`,update:i,hidden:a=!1,children:o,...s}){return(0,A.jsxs)(`label`,{hidden:a,children:[e,(0,A.jsx)(x,{type:r,name:t,value:n??``,...s,onChange:i?e=>i(e.target.value):void 0}),o]})}function N(e){return(0,A.jsx)(M,{type:`number`,min:`0`,step:`0.01`,required:!0,...e})}function P({label:e,name:t,value:n,options:r,update:i,children:a,hidden:o,...s}){return(0,A.jsxs)(`label`,{hidden:o,children:[e,(0,A.jsx)(b,{name:t,value:n??``,...s,onChange:i?e=>i(e.target.value):void 0,children:r.map(e=>{let[t,n,r]=typeof e==`string`?[e,e]:e;return(0,A.jsx)(`option`,{value:t,disabled:!!r,children:n},t)})}),a]})}function F({name:e,value:t,update:n,children:r,hidden:i,...a}){return(0,A.jsxs)(`label`,{className:`check`,hidden:i,children:[(0,A.jsx)(x,{type:`checkbox`,name:e,checked:!!t,onChange:e=>n(e.target.checked),...a}),r]})}function I({name:e,onClick:t,children:n,className:r=``,...i}){return(0,A.jsx)(E,{type:`button`,className:r,"data-action":e,onClick:t,...i,children:n})}function te({title:e,kicker:t,desc:n,children:r}){return(0,A.jsxs)(`div`,{className:`page-heading`,children:[(0,A.jsxs)(`div`,{children:[(0,A.jsx)(`div`,{className:`eyebrow`,children:t}),(0,A.jsx)(`h1`,{children:e}),(0,A.jsx)(`p`,{className:`muted`,children:n})]}),(0,A.jsx)(`div`,{className:`actions`,children:r})]})}function L({rows:e,change:t,title:n=`客户附加项目(选填)`,restore:r}){let i=(n,r)=>t(e.map((e,t)=>t===n?r:e));return(0,A.jsxs)(`div`,{className:`sale-charges`,children:[(0,A.jsxs)(`div`,{className:`panel-title`,children:[(0,A.jsx)(`strong`,{children:n}),(0,A.jsx)(I,{name:`add-charge`,onClick:()=>t([...e,v.newCharge({},()=>crypto.randomUUID())]),children:`+ 添加附加项目`})]}),(0,A.jsx)(`div`,{className:`charge-list`,children:e.map((n,a)=>(0,A.jsxs)(`div`,{className:`charge-row`,"data-charge-id":n.id,children:[(0,A.jsx)(P,{label:`附加项目`,name:`chargeType`,options:[...v.chargeNames,`其他`],value:n.type,update:e=>i(a,v.changeChargeType(n,e))}),(0,A.jsx)(M,{label:`附加项目名称`,name:`chargeName`,maxLength:40,hidden:n.type!==`其他`,disabled:n.type!==`其他`,value:n.customName,update:e=>i(a,{...n,customName:e})}),(0,A.jsx)(N,{label:`附加金额(元)`,name:`chargeAmount`,value:n.amount,placeholder:`没有收费填0,可修改金额`,update:e=>i(a,v.setChargeAmount(n,e))}),(0,A.jsxs)(`div`,{children:[(0,A.jsx)(I,{className:`quiet`,name:`remove-charge`,onClick:()=>t(e.filter((e,t)=>a!==t)),children:`移除附加项`}),(0,A.jsxs)(`small`,{className:`charge-cost-status muted`,hidden:!n.costRemoved,children:[`内部成本已移除`,` `,(0,A.jsx)(I,{name:`restore-charge-cost`,className:`quiet`,onClick:()=>r?r(a):i(a,{...n,costRemoved:!1}),children:`恢复内部成本`})]})]})]},n.id))})]})}function R({state:e,payment:t,change:n,methodLabel:r=`收款方式`,recipientLabel:i=`收款人`,disabled:a=!1,required:o=!1}){let s=t.method===`信用卡`;return(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(P,{label:r,name:`payment_method`,value:t.method,update:e=>n({...t,method:e}),options:v.paymentMethods(e),disabled:a,required:o}),(0,A.jsx)(P,{label:i,name:`payment_recipient`,value:s?`麦麦`:t.recipient,options:v.recipientOptions(e,t),update:e=>n({...t,recipient:e}),disabled:s||a,required:o,children:v.creditCardAvailable(e)&&(0,A.jsxs)(`small`,{className:`small muted payment-account-note`,hidden:!s,children:[`信用卡统一由`,v.memberName(e,`owner`),`收款。`]})})]})}function z({id:e,state:t,payment:n,cents:r,change:i,enabled:a=!0}){let o=a&&n.method===`信用卡`,s=v.creditCardRate(t),c=null;return o&&r!==null&&Number.isSafeInteger(r)&&r>=0&&(c=_.amount(r,s)),(0,A.jsxs)(`div`,{className:`credit-card-preview`,id:e,hidden:!o,children:[(0,A.jsxs)(`div`,{className:`credit-card-heading`,children:[(0,A.jsx)(`strong`,{children:`信用卡手续费(内部)`}),(0,A.jsx)(`span`,{className:`small muted`,children:`自动计算 · 客户单据不显示`})]}),(0,A.jsxs)(`div`,{className:`credit-card-fields`,children:[(0,A.jsxs)(`label`,{children:[`手续费(元,自动)`,(0,A.jsx)(x,{type:`number`,min:`0`,step:`0.01`,readOnly:!0,"data-credit-card-amount":``,"aria-label":`信用卡手续费自动金额`,value:c==null?``:(c/100).toFixed(2)})]}),(0,A.jsx)(P,{label:`手续费付款人`,name:`credit_card_fee_payer`,value:n.payer,options:v.memberOptions(t,!1,{selected:n.payer}),update:e=>i({...n,payer:e}),disabled:!o,required:o})]}),(0,A.jsx)(`p`,{"data-credit-card-formula":``,className:`small muted`,children:c==null?`填写客户付款金额后自动计算`+s+`‰手续费;付款人默认`+v.memberName(t,`owner`)+`,可按实际修改。`:`客户付款金额 ¥`+v.yuan(r)+` × `+s+`‰ = ¥`+v.yuan(c)+`。计入内部成本,客户付款金额不变;退款不退回已发生的手续费。`})]})}var B=e=>typeof e==`object`&&!!e&&!Array.isArray(e),V=(e,t)=>e==null||t(e),H=e=>typeof e==`string`,U=e=>H(e)||typeof e==`number`;function W(e){return B(e)&&V(e.account,H)&&V(e.credit_card_fee_payer,H)&&V(e.amount,U)&&V(e.verified,e=>typeof e==`boolean`)}function G(e){return Array.isArray(e)&&e.every(e=>B(e)&&V(e.name,H)&&V(e.amount,U))}function K(e){return B(e)&&[`name`,`code`,`lineId`,`laborMode`].every(t=>V(e[t],H))&&[`quantity`,`goldPrice`,`laborRate`,`pieces`].every(t=>V(e[t],U))&&V(e.charges,G)&&V(e.material,B)}function q(e){return B(e)&&[`member`,`date`,`customer`,`salesperson`,`note`].every(t=>V(e[t],H))&&V(e.discount,U)&&V(e.payment,W)&&V(e.line,K)&&V(e.material,B)&&V(e.lines,e=>Array.isArray(e)&&e.every(K))}function ne(e){return B(e)&&V(e.inputs,q)&&V(e.revision,Number.isSafeInteger)&&V(e.reason,H)&&q(e)}function re(e){return B(e)&&V(e.lineId,H)&&V(e.quantity,U)&&V(e.pocket,H)&&V(e.line,B)&&V(e.charges,G)&&V(e.inventory,B)&&V(e.extraMaterial,B)}function ie(e){return B(e)&&V(e.revision,Number.isSafeInteger)&&V(e.lines,e=>Array.isArray(e)&&e.every(re))&&V(e.fee_items,e=>Array.isArray(e)&&e.every(B))&&V(e.settlement,W)&&re(e)}function ae(e){try{return y.cents(e)}catch{return null}}function J(e){try{return{result:e()}}catch(e){return{error:e instanceof Error?e.message:String(e)}}}function Y(e,t){try{let n=JSON.parse(localStorage.getItem(e)||`null`);return t(n)?n:null}catch{return null}}function oe(e){return e.map(e=>({id:e.id,nameType:e.type,customName:e.customName,name:e.type===`其他`?e.customName:e.type,amount:e.amount,chargePrices:e.prices,...e.costRemoved?{costRemoved:!0}:{}}))}function se(e,t,n){let r=v.accountIdentity(e,t?.account||``);return{method:r?.channel||`微信`,recipient:v.memberAccountPrefix(r?.member||(v.teamMode(e)?n:`assistant`)),payer:t?.credit_card_fee_payer||`owner`,verified:!!t?.verified,amount:t?.amount??``}}function X(e){return{account:_.normalizeAccount((e.method===`信用卡`?`麦麦`:e.recipient)+e.method),credit_card_fee_payer:e.payer,verified:e.verified}}function ce(e,t,n,r){if(!e||!e.totalMg)throw Error(`当日尚无可用材料。请先登记购料,再保存锁价。`);if(e.totalAmount==null)throw Error(`料池成本尚未补齐,请先核对材料记录,再保存锁价。`);let i=e.totalAmount,a=y.poolMaterialPreview(e,t,{allUsages:n.flatMap(e=>e.usages||[])}),o=a.usedMg,s=Math.max(0,e.totalMg-o),c=Math.max(0,t.reduce((e,t)=>e+t.mg,0)-s),l=e.purchases.flatMap(e=>e.allocations||[{payer:e.payer,amount:e.amount}]);return t.map(n=>{let u=a.amounts[n.lineIndex],d=[],f=a.covered&&!c&&u!=null,p=y.poolMaterialAmount(i,e.totalMg,o),m=u??0,h=``;if(o+=n.mg,f){for(let e of l){if(!e.payer||!v.memberKeys(r).includes(e.payer)||!Number.isSafeInteger(e.amount)||e.amount<=0)throw Error(`料池付款来源未完整读到,请刷新料池。`);if(p>=e.amount){p-=e.amount;continue}h||=e.payer;let t=Math.min(m,e.amount-p),n=d.find(t=>t.payer===e.payer);if(t&&(n?n.amount+=t:d.push({payer:e.payer,amount:t})),m-=t,p=0,!m)break}if(p||m)throw Error(`料池付款来源不足,请刷新并核对购料。`);u||d.push({payer:h||l.at(-1)?.payer||`owner`,amount:0})}return{...n,amount:f?u:null,allocations:d,revision:e.revision,covered:!!f,shortageMg:c,averageRate:e.averageRate,remainingMg:s,totalMg:e.totalMg,usedMg:a.usedMg,wantedMg:t.reduce((e,t)=>e+t.mg,0)}})}function le({client:e,state:t,views:n,date:r,member:i,entries:a,editId:o=``,delivery:s=!1}){let[c,l]=(0,k.useState)(0),[u,d]=(0,k.useState)(null),[f,p]=(0,k.useState)(null);(0,k.useEffect)(()=>{if(s)return;let t=!0;return e.api(`/api/material-pools`).then(O).then(e=>{t&&d({seq:c,data:e})}).catch(e=>{t&&d({seq:c,error:e.message})}),()=>{t=!1}},[e,t.user.id,c,s]);let m=u?.seq===c?u.data:null,h=m?D(m):[],g=h.find(e=>e.id===r),_={date:r,member:i,...o?{priceLockId:o}:{},entries:a},v=!!a.length&&(s||!!m&&(o||g?.personalPools)),y=JSON.stringify(_);(0,k.useEffect)(()=>{if(!v)return;let t=!0,r=JSON.parse(y);return e.api(`/api/material-pools/quote`,r).then(e=>n.validateMaterialQuote(e,r)).then(e=>{t&&p({key:y,seq:c,value:e})}).catch(e=>{t&&p({key:y,seq:c,error:e.message})}),()=>{t=!1}},[e,y,c,v,n]);let b=[],x=!s&&u?.seq===c&&u.error||``;if(a.length&&!x){if(!s&&!m)x=`正在读取每日料池,请稍候。`;else if(!s&&!m?.rolling?.enabled)x=`请先启用统一料池,再选择当日加权料价。`;else if(v){if(f?.key!==y||f?.seq!==c)x=`正在按订单归属核对个人回收料与公共补足,请稍候。`;else if(f.value===void 0)x=f.error;else{let e=f.value.pools.find(e=>e.poolId===r),t=e?.before?.eligibleRemainingMg??0,n=Math.max(0,a.reduce((e,t)=>e+t.mg,0)-t);b=f.value.entries.map(r=>({...r,revision:e?.revision,balance:e,averageRate:g?.averageRate,remainingMg:t,shortageMg:n,covered:f.value.entries.every(e=>e.amount!==null)&&!n}))}}else{let e=J(()=>ce(g,a,h,t));b=e.result||[],x=e.error||``}}return{rows:b,error:x,reload:()=>l(e=>e+1)}}function Z({q:e,error:t,date:n,member:r,state:i}){let a=v.grams,o=v.memberName(i,r),s=e?.balance,c=t||`请填写锁定克重。`;return!t&&e&&(c=s?n+` · `+o+`先用本人回收料,公共补足;`+(s.before?`本次前可用:个人 `+a(s.before.personalRemainingMg)+`g,公共 `+a(s.before.publicRemainingMg)+`g;`:``)+`本次后余:个人回收料 `+a(s.personalRemainingMg)+`g,公共料 `+a(s.publicRemainingMg)+`g。本行预留 `+a(e.mg)+`g。`:n+` 料池 `+a(Number(e.totalMg))+`g,已用/预留 `+a(Number(e.usedMg))+`g,可用 `+a(e.remainingMg)+`g;本行预留 `+a(e.mg)+`g,本单共预留 `+a(e.wantedMg??e.mg)+`g。`,e.shortageMg?c+=`还缺 `+a(e.shortageMg)+`g,请先补足购料后再保存锁价。`:e.amount!=null&&e.covered||(c+=`材料成本待补齐,请先核对后保存锁价。`)),(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`p`,{className:`material-pool-note small muted`+(t||e&&!e.covered?` danger-text`:``),"data-lock-part":`pool-material-note`,"aria-live":`polite`,children:c}),(0,A.jsx)(`div`,{className:`price-lock-material-payers small`,"data-lock-part":`pool-material-payers`,"aria-live":`polite`,children:!t&&e?.covered&&(0,A.jsxs)(A.Fragment,{children:[!!e.materialSources?.length&&(0,A.jsx)(`div`,{className:`material-source-segments`,children:e.materialSources.map((e,t)=>(0,A.jsxs)(`div`,{children:[(0,A.jsx)(`strong`,{children:e.kind===`personal_recovery`?v.memberName(i,e.member??``)+`个人回收料`:`公共料`}),(0,A.jsxs)(`span`,{children:[a(e.quantity),`g`]}),(0,A.jsx)(`b`,{children:e.amount==null?`料费待补`:`¥`+v.yuan(e.amount)}),e.averageRate!=null&&(0,A.jsxs)(`small`,{children:[`加权约 ¥`,v.yuan(e.averageRate),`/克`]})]},t))}),(0,A.jsx)(`strong`,{children:`自动付款来源:`}),e.allocations.map(e=>v.memberName(i,e.payer)+` ¥`+v.yuan(e.amount)).join(` · `)]})})]})}function Q(e={}){let t=e.material||{},n=t.manual||t;return{key:crypto.randomUUID(),lineId:e.lineId,name:e.name??`足金999`,code:e.code||``,quantity:String(e.quantity??``),goldPrice:String(e.goldPrice??``),laborRate:String(e.laborRate??``),laborMode:e.laborMode||`gram`,pieces:String(e.pieces??`1`),charges:(e.charges||[]).map(e=>v.newCharge(e,()=>crypto.randomUUID())),source:t.source||`manual`,rate:String(n.rate??``),payer:n.payer||`owner`,verified:!!n.verified}}function ue(e,t,n,r){let i={rate:e.rate,payer:e.payer,verified:e.verified};return{...e.lineId?{lineId:e.lineId}:{},name:e.name.trim(),code:e.code.trim(),unit:`g`,pricingMode:`auto`,quantity:e.quantity,goldPrice:e.goldPrice,laborRate:e.laborRate,laborMode:e.laborMode,pieces:e.pieces,charges:oe(e.charges),material:e.source===`pool`?{source:`pool`,poolId:t,revision:n?.revision||``,...r?{manual:i}:{}}:i}}function de(e,t,n,r){let i=Y(r,ne),a=n?i?.inputs||n.inputs:i||{},o=a.member||v.currentMember(e);return{date:a.date||e.today,member:o,customer:a.customer||``,salesperson:a.salesperson||(n?e.user.name:v.defaultSalesperson(e,t)),note:a.note||``,discount:a.discount??`0`,payment:se(e,a.payment,o),lines:(a.lines?.length?a.lines:[{...a.line,material:a.material}]).map(Q),reason:n&&i?.reason||``,revision:n?i?.revision??n.revision:void 0,conflicted:!!(n&&i&&i.revision!==n.revision)}}function fe({client:e,state:t,session:n,views:a,edit:s,save:c,blocked:l,reset:u}){let d=s?i(t.user.id,s.lock.id):r(t.user.id),[f,p]=(0,k.useState)(()=>de(t,n,s,d)),[m,h]=(0,k.useState)(!1),[g,_]=(0,k.useState)(``),b=f.lines.flatMap((e,t)=>{let n=J(()=>a.lockQuantityMg(e.quantity)).result;return e.source===`pool`&&n?[{lineIndex:t,poolId:f.date,mg:n,...e.lineId?{lineId:e.lineId}:{}}]:[]}),S=le({client:e,state:t,views:a,date:f.date,member:f.member,entries:b,editId:s?.lock.id});function C(e){return{...v.teamMode(t)?{member:f.member}:{},date:f.date,customer:f.customer.trim(),salesperson:f.salesperson,note:f.note,discount:f.discount,payment:{amount:f.payment.amount,...X(f.payment)},lines:f.lines.map((t,n)=>ue(t,f.date,S.rows.find(e=>e.lineIndex===n),e))}}let w=JSON.stringify(s?{id:s.lock.id,revision:f.revision,inputs:C(!0),reason:f.reason}:C(!0));(0,k.useEffect)(()=>{localStorage.setItem(d,w)},[d,w]);let D=e=>{p(t=>({...t,...e})),h(!1)},O=(e,t)=>D({lines:f.lines.map((n,r)=>e===r?{...n,...t}:n)}),j=s&&t.user.role===`assistant`&&(s.requiresApproval!==!1||f.date!==t.today);function ee(){f.lines.length>=60?_(`每张锁价单最多填写60件商品。`):D({lines:[...f.lines,Q()]})}function B(e){f.lines.length<=1?_(`请至少保留一件锁价商品。`):D({lines:f.lines.filter((t,n)=>n!==e)})}let V=J(()=>y.orderTotal(C(!1).lines.map(e=>y.sale(e).sale),y.cents(f.discount),`yuan`)).result;async function H(e){e.preventDefault(),_(``);try{let e=v.validateOrderIdentity(C(!1),{requireInternalNote:!1});for(let[n,r]of e.lines.entries()){if(!r.name)throw Error(`请填写商品 `+(n+1)+` 的黄金商品名称。`);if(y.isSilver(r.name))throw Error(`锁价仅支持按克黄金,银饰请直接开单。`);if(a.lockQuantityMg(r.quantity),y.cents(r.goldPrice)<=0)throw Error(`销售金价须大于0。`);if(`source`in r.material){if(f.date!==t.today&&(!s||f.date!==s.lock.date))throw Error(`当日加权料池只支持今天锁价;补录其他日期请使用手动填写料价。`);let e=S.rows.find(e=>e.lineIndex===n);if(S.error||!e?.covered)throw Error(S.error||(e?.shortageMg?`当日料池还缺 `+v.grams(e.shortageMg)+`g,请先补足购料后再保存锁价。`:`材料成本待补齐,请先核对后保存锁价。`));if(!r.material.revision)throw Error(`请刷新料池,核对当前成本与自动付款来源后再保存。`)}else{if(y.cents(r.material.rate)<=0)throw Error(`原进货料价须大于0。`);if(!r.material.verified)throw Error(`请核实客户实际付款与各件原锁料费实际付款。`)}}if(y.cents(e.payment.amount,`客户实际付款`),y.orderTotal(e.lines.map(e=>y.sale(e).sale),y.cents(f.discount),`yuan`),!e.payment.verified)throw Error(`请核实客户实际付款与原锁料费实际付款。`);let n=`/api/price-locks`;if(s){if(f.conflicted)throw Error(`锁价单已有新记录,请重新读取当前资料后再修改。`);if(!f.reason.trim()||!m)throw Error(`请填写修改原因,并核实整单更正资料后勾选确认。`);n+=`/`+encodeURIComponent(s.lock.id)+(j?`/change-requests`:`/edit`),Object.assign(e,{revision:f.revision,reason:f.reason.trim(),verified:!0,...j?{action:`edit`}:{}})}await c(n,e,{key:d,value:w})}catch(e){s&&e instanceof Error&&`status`in e&&e.status===409&&(p(e=>({...e,conflicted:!0})),h(!1)),_(e instanceof Error?e.message:String(e))}}let U=e=>D({payment:e}),W=()=>o(`price-locks`);return(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(te,{kicker:`GOLD PRICE LOCK`,title:s?`修改待交付锁价单`:`黄金锁价`,desc:s?`原单号 `+s.lock.number+`;按核实后的整单资料更正,尚未交付。`:`同一客户可添加多件按克黄金,每件分别锁定售价与原料来源;整单收款、整单交付。保存后暂不出入库、不计利润。`,children:s?(0,A.jsx)(I,{name:`leave-lock-edit`,className:`quiet`,onClick:W,children:`退出修改`}):(0,A.jsxs)(`div`,{className:`create-mode-controls`,role:`group`,"aria-label":`开单方式`,children:[(0,A.jsx)(I,{name:`create-mode`,"data-mode":`direct`,onClick:()=>o(`create`),children:`直接开单`}),(0,A.jsx)(I,{name:`create-mode`,className:`primary`,"data-mode":`lock`,children:`锁价`})]})}),(0,A.jsxs)(`form`,{id:`price-lock-create-form`,"data-price-lock-edit-id":s?.lock.id,onSubmit:H,children:[(0,A.jsxs)(`section`,{className:`panel`,children:[(0,A.jsx)(`h2`,{children:`客户与锁价日期`}),(0,A.jsxs)(`div`,{className:`grid four`,children:[(0,A.jsx)(M,{label:`锁价日期`,name:`date`,type:`date`,value:f.date,required:!0,max:t.today,update:e=>D({date:e})}),(0,A.jsx)(M,{label:`客户称呼/代号(必填)`,name:`customer`,value:f.customer,maxLength:60,required:!0,update:e=>D({customer:e})}),(0,A.jsx)(M,{label:`开单人(必填)`,name:`salesperson`,value:f.salesperson,maxLength:30,required:!0,update:e=>D({salesperson:e})}),v.teamMode(t)&&(t.user.role===`owner`&&!s?(0,A.jsx)(P,{label:`订单归属(经营款与业绩)`,name:`member`,options:v.memberOptions(t),value:f.member,update:e=>D({member:e})}):(0,A.jsxs)(`label`,{children:[`订单归属(经营款与业绩)`,(0,A.jsx)(x,{value:v.memberName(t,f.member),readOnly:!0}),(0,A.jsx)(x,{type:`hidden`,name:`member`,value:f.member})]}))]})]}),(0,A.jsx)(`div`,{id:`lock-create-lines`,children:f.lines.map((e,n)=>{let r=(e,t)=>O(n,{[e]:t}),i=e.source===`pool`,a=S.rows.find(e=>e.lineIndex===n),o=J(()=>y.sale(ue(e,f.date,a,!1)).sale).result,c=J(()=>y.purchaseCosts({unit:`g`,quantity:e.quantity,costParts:{material:`0`,labor:`0`,accessories:`0`,other:`0`},costMaterial:{mode:`gram`,rate:e.rate}}).total).result;return(0,A.jsxs)(`section`,{className:`panel line-item price-lock-create-line`,"data-price-lock-sale":``,"data-line-id":e.lineId||``,children:[(0,A.jsxs)(`div`,{className:`line-top`,children:[(0,A.jsxs)(`strong`,{children:[`商品 `,String(n+1).padStart(2,`0`)]}),(0,A.jsx)(I,{name:`remove-lock-line`,className:`quiet`,onClick:()=>B(n),children:`移除商品`})]}),(0,A.jsxs)(`div`,{className:`grid four`,children:[(0,A.jsx)(M,{label:`黄金商品名称(可自定义)`,name:`name`,required:!0,maxLength:60,value:e.name,update:e=>r(`name`,e)}),(0,A.jsx)(M,{label:`款号(选填)`,name:`code`,maxLength:40,value:e.code,update:e=>r(`code`,e)}),(0,A.jsx)(M,{label:`锁定克重(g)`,name:`quantity`,type:`number`,min:`0.001`,step:`0.001`,required:!0,value:e.quantity,update:e=>r(`quantity`,e)}),(0,A.jsx)(N,{label:`锁定销售金价(元/克)`,name:`goldPrice`,value:e.goldPrice,update:e=>r(`goldPrice`,e)}),(0,A.jsx)(P,{label:`销售工费方式`,name:`laborMode`,options:[[`gram`,`克工费`],[`piece`,`件工费`]],value:e.laborMode,update:e=>r(`laborMode`,e)}),(0,A.jsx)(N,{label:`销售工费`,name:`laborRate`,value:e.laborRate,update:e=>r(`laborRate`,e)}),(0,A.jsx)(M,{label:`计工费件数`,name:`pieces`,type:`number`,min:`1`,step:`1`,required:e.laborMode===`piece`,hidden:e.laborMode!==`piece`,value:e.pieces,update:e=>r(`pieces`,e)})]}),(0,A.jsx)(L,{rows:e.charges,change:e=>r(`charges`,e)}),(0,A.jsx)(`p`,{className:`calculation small`,"data-lock-part":`sale-estimate`,"aria-live":`polite`,children:o==null?`填写克重、销售金价与工费后显示本行报价。`:`本行商品及附加项目合计 ¥`+v.yuan(o)}),(0,A.jsxs)(`div`,{className:`internal price-lock-original-material`,children:[(0,A.jsx)(`h3`,{children:`原锁金料成本`}),(0,A.jsx)(P,{label:`原锁材料来源`,name:`material_source`,options:[[`manual`,`手动填写料价`],[`pool`,`当日加权料价`]],value:e.source,update:e=>r(`source`,e)}),(0,A.jsxs)(`div`,{"data-lock-part":`manual-material`,hidden:i,children:[(0,A.jsxs)(`div`,{className:`grid three`,children:[(0,A.jsx)(N,{label:`原锁进货料价(元/克)`,name:`material_rate`,required:!i,disabled:i,value:e.rate,update:e=>r(`rate`,e)}),(0,A.jsx)(P,{label:`原锁料费付款人`,name:`material_payer`,required:!i,disabled:i,options:v.memberOptions(t,!1,{selected:e.payer}),value:e.payer,update:e=>r(`payer`,e)}),(0,A.jsxs)(`div`,{children:[(0,A.jsx)(`span`,{className:`small muted`,children:`这批金料已付金额`}),(0,A.jsx)(`div`,{className:`summary-amount`,children:c==null?`待填写`:`¥`+v.yuan(c)})]})]}),(0,A.jsx)(F,{name:`material_verified`,value:e.verified,update:e=>r(`verified`,e),required:!i,disabled:i,children:`已核实原锁金料的实际付款。`}),(0,A.jsx)(`p`,{className:`small muted`,children:`独立记录本行原锁金料的实际付款;工费、快递等在交付时填写实际成本。库存归属也在交付时确认。`})]}),(0,A.jsxs)(`div`,{"data-lock-part":`pool-material`,hidden:!i,children:[(0,A.jsxs)(`div`,{className:`grid three`,children:[(0,A.jsx)(M,{label:`料池日期(随锁价日期)`,name:`material_pool_date`,value:i?f.date:``,readOnly:!0}),(0,A.jsx)(M,{label:`加权进货料价(元/克,自动)`,name:`material_pool_rate`,value:i&&a?a.materialSources?.length?a.materialSources.map(e=>(e.kind===`personal_recovery`?v.memberName(t,e.member??``)+`个人回收料`:`公共料`)+` `+(e.averageRate==null?`待补`:(e.averageRate/100).toFixed(2))).join(`;`):a.averageRate==null?``:(a.averageRate/100).toFixed(2):``,readOnly:!0}),(0,A.jsxs)(`div`,{children:[(0,A.jsx)(`span`,{children:`本行预留料费(元,自动)`}),(0,A.jsx)(`div`,{className:`summary-amount`,children:a?.amount==null?`待确定`:`¥`+v.yuan(a.amount)})]})]}),(0,A.jsx)(Z,{q:a,date:f.date,member:f.member,state:t,error:f.date!==t.today&&(!s||f.date!==s.lock.date)?`当日加权料池只支持今天锁价;补录其他日期请使用手动填写料价。`:S.error}),(0,A.jsx)(I,{name:`reload-price-lock-pool`,className:`quiet`,onClick:S.reload,children:`刷新料池`}),(0,A.jsx)(`p`,{className:`small muted`,children:`使用已登记购料,按购料付款顺序自动归属,可涉及多人;保存锁价不再登记料费付款。锁价当天补料仍参与加权,跨天后保留锁价日成本。`})]})]})]},e.key)})}),(0,A.jsxs)(`div`,{className:`lock-add-product`,children:[(0,A.jsx)(I,{name:`add-lock-line`,onClick:ee,children:`+ 添加商品`}),(0,A.jsx)(`span`,{className:`small muted`,children:`每件商品可自定义名称、克重、售价、工费和原锁成本。`})]}),(0,A.jsxs)(`section`,{className:`panel`,children:[(0,A.jsx)(`h2`,{children:`客户实际已付款`}),(0,A.jsx)(`p`,{className:`small muted`,children:`填写整单已经收到的金额,可与预计报价不同;尚未收款填0。`}),(0,A.jsxs)(`div`,{className:`grid three`,children:[(0,A.jsx)(N,{label:`实际收款(元)`,name:`received_amount`,value:f.payment.amount,update:e=>U({...f.payment,amount:e})}),(0,A.jsx)(R,{state:t,payment:f.payment,change:U})]}),(0,A.jsx)(F,{name:`payment_verified`,value:f.payment.verified,update:e=>U({...f.payment,verified:e}),required:!0,children:`已核实实际收款金额与账户。`}),(0,A.jsx)(z,{id:`lock-create-card-fee`,state:t,payment:f.payment,change:U,cents:ae(f.payment.amount)})]}),s&&(0,A.jsxs)(`section`,{className:`panel lock-pending-review`,children:[(0,A.jsx)(`p`,{className:`note`,children:j?`提交修改申请,店主复核同意后生效;待批期间沿用原锁价记账。`:`保存后按核实后的整单资料更正锁价记录、收款与原锁料费。`}),f.conflicted&&(0,A.jsxs)(`div`,{className:`error`,children:[`原锁价单已有新记录,已填写内容已保留。请重新读取当前资料后核对。`,(0,A.jsx)(I,{name:`reset-lock-edit`,onClick:()=>{window.confirm(`使用当前锁价资料会替换这份未保存的修改内容,确认重新读取?`)&&(localStorage.removeItem(d),u())},children:`使用当前锁价资料`})]}),(0,A.jsxs)(`label`,{children:[`修改原因`,(0,A.jsx)(T,{name:`pending_edit_reason`,required:!0,maxLength:200,rows:2,value:f.reason,onChange:e=>p({...f,reason:e.target.value})})]}),(0,A.jsx)(F,{name:`pending_edit_verified`,value:m,update:h,required:!0,children:`已核实整单商品、原锁金料、客户实际已付款与账户,确认本次更正。`}),(0,A.jsx)(I,{name:`leave-lock-edit`,onClick:W,children:`退出修改`})]}),(0,A.jsxs)(`section`,{className:`panel`,children:[(0,A.jsxs)(`div`,{className:`grid two`,children:[(0,A.jsx)(N,{label:`整单优惠(元)`,name:`discount`,value:f.discount,update:e=>D({discount:e})}),(0,A.jsxs)(`label`,{children:[`客户可见备注`,(0,A.jsx)(T,{name:`note`,maxLength:170,rows:2,value:f.note,onChange:e=>D({note:e.target.value})})]})]}),(0,A.jsx)(`p`,{id:`lock-sale-estimate`,className:`calculation small`,children:V?f.lines.length+`件商品及附加项目合计 ¥`+v.yuan(V.subtotal)+`;`+v.orderRoundingHint(V):`填写各件商品的克重、销售金价与工费后显示整单预计报价。`}),(0,A.jsxs)(`div`,{className:`form-actions`,children:[(0,A.jsxs)(`div`,{children:[(0,A.jsx)(`span`,{className:`small muted`,children:`整单预计成交额 · 四舍五入到元`}),(0,A.jsx)(`div`,{id:`lock-create-total`,className:`summary-amount`,children:V?v.orderAmount(V.total,`yuan`):`待填写`}),(0,A.jsx)(`div`,{className:`small muted`,children:`待交付,不计利润`})]}),(0,A.jsx)(E,{className:`primary`,type:`submit`,"data-lock-create-submit":``,disabled:l||f.conflicted,children:s?j?`提交修改申请`:`保存锁价修改`:`保存锁价待交付`})]}),(0,A.jsx)(`div`,{id:`price-lock-error`,"aria-live":`polite`,children:g&&(0,A.jsx)(`div`,{className:`error`,children:g})})]})]})]})}function pe({views:e,state:t,item:n,line:r,index:i,stock:a,cost:o,quote:s,update:c,changeStock:l}){let u=(e,t)=>c(v.setLineField(r,e,t)),d=(e,t)=>c(v.setPurchaseField(r,e,t)),f=r.purchase,p=r.laborMode===`piece`,m=f.laborMode===`gram`,h=r.nameType===`其他`,g=v.pocketCountsEnabled(t,r.pocket),_=n.material_source===`pool`,y=Number(r.quantity)*1e3>n.locked_mg,b=y&&a.extra_source===`pool`,S=e=>v.memberOptions(t,!1,{selected:e}),C=o?.extraPool?`原锁耗用 `+v.grams(o.originalUsedMg)+`g,料费 ¥`+v.yuan(o.originalUsedCost)+`;补重 `+e.materialSourceSegmentsText(o.extraPool.materialSources??[])+`;合计 ¥`+v.yuan(o.materialCost):o?_?`${o.materialSources?.length?e.materialSourceSegmentsText(o.materialSources):`原锁按 `+(n.material_pool_id||n.date)+` 料池耗用 `+v.grams(o.originalUsedMg)+`g,料费 ¥`+v.yuan(o.originalUsedCost)}${o.extraMg?`;补重 `+v.grams(o.extraMg)+`g × `+a.extra_rate+`元/克,料费 ¥`+v.yuan(o.extraCost):``};合计 ¥${v.yuan(o.materialCost)}`:`原锁使用 ${v.grams(o.originalUsedMg)}g × ${v.yuan(n.buy_rate)}元/克${o.extraMg?`;补重 `+v.grams(o.extraMg)+`g × `+a.extra_rate+`元/克`:``} = ${v.yuan(o.materialCost)}元`:_?`原锁料费沿用料池实际分币金额;有补重时,请填写补重进货料价。`:`料费按原锁进货价计算;有补重时,请先填写补重进货料价。`,w=o?`原锁${_?`预留`:`料费已付`} ¥${v.yuan(n.material_amount)};本件耗用料费 ¥${v.yuan(o.materialCost)}${o.leftoverMg?`;`+(_?`解除预留回池 `:`余料 `)+v.grams(o.leftoverMg)+`g,成本 ¥`+v.yuan(o.leftoverCost)+(o.leftoverMaterialSources?.length?`(`+e.materialSourceSegmentsText(o.leftoverMaterialSources)+`)`:``):``}${_?`;已有购料付款不重复登记。`:``}`:y?`请填写本件补重料价,计算实际耗用成本。`:`填写本件最终交付克重,自动计算实际耗料。`,T=o&&a.original_stock&&r.pocket?`${_?`原锁金料已在料池预留,不重复入库;`:a.original_stock===`receive`?`原锁 `+v.grams(n.locked_mg)+`g 先入库;`:`原锁金料此前已入库;`}${o.extraMg?b?`补重从交付当日料池耗用,不重复入库;`:a.extra_stock===`receive`?`补重 `+v.grams(o.extraMg)+`g 先入库;`:a.extra_stock===`stocked`?`补重金料此前已入库;`:`请选择补重金料是否已入库;`:``}从「${v.pocketLabel(t,r.pocket)}」出库 ${v.grams(o.finalMg)}g${g?` / `+(Number(r.stockCount)?r.stockCount+`对`:`未记录对数`):``}。${o.leftoverMg?_?`少重 `+v.grams(o.leftoverMg)+`g 解除预留回到料池,实物留在货盘,不重复入库或扣料。`:`余料 `+v.grams(o.leftoverMg)+`g 留在该货盘,按原进货价计成本,不重复入库。`:``}`:`选择本件实际货盘和金料入库情况后,显示库存动作。`,E=[[``,`请选择`],[`receive`,`尚未记入,交付时先入库`],[`stocked`,`此前已记入,只出库`]];return(0,A.jsxs)(`section`,{className:`panel price-lock-delivery-line`,"data-price-lock-delivery-item":``,"data-line-id":n.id||``,"data-line-index":i,children:[(0,A.jsxs)(`div`,{className:`panel-title`,children:[(0,A.jsxs)(`h2`,{children:[n.line.name,` · 最终商品与实际成本`]}),(0,A.jsxs)(`span`,{className:`small muted`,children:[`原锁 `,v.grams(n.locked_mg),`g · ¥`,v.yuan(n.sell_rate),`/克`]})]}),(0,A.jsxs)(`div`,{className:`line-item`,children:[(0,A.jsx)(`div`,{className:`line-top`,children:(0,A.jsxs)(`strong`,{children:[`商品 `,String(i+1).padStart(2,`0`)]})}),(0,A.jsxs)(`div`,{className:`grid four`,children:[(0,A.jsx)(P,{label:`商品名称`,name:`nameType`,value:r.nameType,options:[...v.productNames,`其他`],disabled:!0}),(0,A.jsx)(M,{label:`其他商品名称`,name:`customName`,value:r.customName,maxLength:60,hidden:!h,disabled:!0,required:h}),(0,A.jsx)(P,{label:`计价方式`,name:`pricingMode`,value:`auto`,options:[[`auto`,`按金价与工费计算`],[`manual`,`直接填写金额`]],disabled:!0}),(0,A.jsx)(P,{label:`单位`,name:`unit`,value:`g`,options:[`g`,`件`],disabled:!0}),(0,A.jsx)(M,{label:`克重/数量`,name:`quantity`,type:`number`,required:!0,min:`0.001`,step:`0.001`,value:r.quantity,update:e=>u(`quantity`,e)}),(0,A.jsx)(N,{label:`原锁销售金价(元/克,固定)`,name:`goldPrice`,value:r.goldPrice,disabled:!0}),(0,A.jsx)(P,{label:`销售工费方式`,name:`laborMode`,value:r.laborMode,required:!0,options:[[`gram`,`克工费`],[`piece`,`件工费`]],update:e=>u(`laborMode`,e)}),(0,A.jsx)(N,{label:`销售工费`,name:`laborRate`,value:r.laborRate,update:e=>u(`laborRate`,e)}),(0,A.jsx)(M,{label:`计工费件数`,name:`pieces`,type:`number`,min:`1`,step:`1`,value:r.pieces,required:p,hidden:!p,disabled:!p,update:e=>u(`pieces`,e)}),(0,A.jsx)(M,{label:`销售单价说明(客户可见)`,name:`priceNote`,maxLength:100,value:r.priceNote,hidden:!0,disabled:!0}),(0,A.jsx)(N,{label:`商品基础金额(不含附加项目)`,name:`baseSale`,value:r.baseSale,hidden:!0,disabled:!0,required:!1})]}),(0,A.jsx)(L,{title:`工费附加项目(选填)`,rows:r.charges,change:e=>c({...r,charges:e})}),(0,A.jsxs)(`div`,{className:`grid two sale-result`,children:[(0,A.jsx)(M,{label:`本行销售额(元,含附加项目)`,type:`number`,name:`sale`,value:r.sale,readOnly:!0}),(0,A.jsx)(`p`,{className:`calculation small`,children:r.view?.calculation})]}),(0,A.jsxs)(`div`,{className:`internal`,children:[(0,A.jsx)(`div`,{className:`internal-title`,children:`内部成本 · 客户单据不显示`}),(0,A.jsxs)(`div`,{className:`grid two cost-source-fields`,children:[(0,A.jsx)(P,{label:`出库货盘(仅黄金)`,name:`pocket`,value:r.pocket,required:!0,options:v.pocketOptions(t,r.pocket).map(([e,t,n])=>[e,e?t:`请选择本件实际黄金货盘`,n]),update:e=>u(`pocket`,e)}),(0,A.jsx)(M,{label:`出库数量(对)`,name:`stockCount`,type:`number`,min:`1`,max:`1000000000`,step:`1`,inputMode:`numeric`,value:r.stockCount,placeholder:`一对填1`,hidden:!g,disabled:!g,required:g,update:e=>u(`stockCount`,e),children:(0,A.jsx)(`small`,{className:`muted`,children:`与计工费件数分别填写。`})})]}),(0,A.jsxs)(`div`,{className:`cost-fields grid`,children:[(0,A.jsxs)(`div`,{className:`purchase-material`,children:[(0,A.jsx)(P,{label:`进货料费方式`,name:`cost-materialMode`,value:`total`,options:[[`gram`,`按克料价`],[`total`,`原锁+补重自动核算`]],disabled:!0}),(0,A.jsx)(N,{label:`进货料价(元/克)`,name:`cost-materialRate`,value:``,placeholder:`填写每克进货料价`,hidden:!0,disabled:!0,required:!1}),(0,A.jsx)(N,{label:`实际耗用料费合计(元,自动)`,name:`cost-material`,value:o?(o.materialCost/100).toFixed(2):``,placeholder:`开单前必填,没有填0`,readOnly:!0}),(0,A.jsx)(P,{label:`原锁料费付款人`,name:`cost-materialPayer`,value:f.materialPayer,options:S(f.materialPayer),required:!0,disabled:!0,hidden:_}),(0,A.jsx)(`p`,{className:`purchase-formula`,children:C}),_&&(0,A.jsxs)(`p`,{children:[`原锁耗用来源:`,(o?.allocations||n.materialPool?.allocations||[]).map(e=>v.memberName(t,e.payer)+` ¥`+v.yuan(e.amount)).join(` · `)]})]}),(0,A.jsxs)(`div`,{className:`purchase-labor`,children:[(0,A.jsx)(P,{label:`进货工费方式`,name:`cost-laborMode`,value:f.laborMode,options:[[`gram`,`克工费`],[`total`,`总工费`]],update:e=>d(`laborMode`,e)}),(0,A.jsx)(N,{label:`进货克工费(元/克)`,name:`cost-laborRate`,value:f.laborRate,placeholder:`填写每克工费`,required:m,hidden:!m,disabled:!m,update:e=>d(`laborRate`,e)}),(0,A.jsx)(N,{label:`进货总工费(元)`,name:`cost-labor`,value:f.labor,placeholder:`开单前必填,没有填0`,readOnly:m,update:e=>d(`labor`,e)}),(0,A.jsx)(P,{label:`进货工费付款人`,name:`cost-laborPayer`,value:f.laborPayer,options:S(f.laborPayer),required:!0,update:e=>d(`laborPayer`,e)}),(0,A.jsx)(`p`,{className:`purchase-formula`,children:r.view?.laborFormula}),v.teamMode(t)&&f.costFundings?.labor&&(0,A.jsx)(x,{type:`hidden`,className:`cost-funding`,"data-component":`labor`,"data-reference":JSON.stringify(f.costFundings.labor)})]}),(0,A.jsx)(x,{type:`hidden`,name:`cost-accessories`,value:f.accessories}),(0,A.jsx)(x,{type:`hidden`,name:`cost-other`,value:f.other}),(0,A.jsx)(x,{type:`hidden`,name:`payer`,value:r.payer})]})]})]}),(0,A.jsxs)(`div`,{className:`internal lock-line-inventory`,children:[(0,A.jsx)(`h3`,{children:`本件金料与库存确认`}),(0,A.jsxs)(`div`,{"data-lock-count-source":``,hidden:!g,children:[(0,A.jsx)(P,{label:`成品来源`,name:`count_source`,value:a.count_source,options:[[`stocked`,`已在货盘`],[`receive`,`本次新入库`]],required:g,disabled:!g,update:e=>l(`count_source`,e)}),(0,A.jsx)(`p`,{className:`small muted`,children:`只确认本次交付成品的实际对数。选本次新入库时,对数先入库一次再销售出库;原锁及补重金料的克重另行核对。`})]}),(0,A.jsxs)(`div`,{className:`grid two`,children:[(0,A.jsx)(P,{label:`原锁金料是否已记入本件货盘`,name:`original_stock`,value:_?`stocked`:a.original_stock,options:_?[...E.slice(0,2),[`stocked`,`料池已预留,仅出库,不重复入库`]]:E,required:!_,disabled:_,update:e=>l(`original_stock`,e)}),(0,A.jsx)(`div`,{className:`lock-material-breakdown`,children:w})]}),(0,A.jsxs)(`div`,{"data-lock-part":`extra-material`,className:`lock-extra-material`,hidden:!y,children:[(0,A.jsx)(`h3`,{children:`本件超出原锁克重的补重金料`}),(0,A.jsx)(P,{label:`补重料费来源`,name:`extra_source`,value:a.extra_source,options:[[`manual`,`手动填写料价`],[`pool`,`交付当日加权料池`]],required:y,disabled:!y,update:e=>l(`extra_source`,e)}),(0,A.jsx)(`div`,{className:`note`,hidden:!b,children:s.error||s.rows.find(e=>e.lineIndex===i)?.allocations.map(e=>v.memberName(t,e.payer)+` ¥`+v.yuan(e.amount)).join(` · `)}),(0,A.jsx)(I,{name:`reload-price-lock-pool`,className:`quiet`,onClick:s.reload,children:`刷新补重料池`}),(0,A.jsxs)(`div`,{className:`grid three`,hidden:b,children:[(0,A.jsx)(N,{label:`补重进货料价(元/克)`,name:`extra_rate`,value:a.extra_rate,required:y&&!b,disabled:!y||b,update:e=>l(`extra_rate`,e)}),(0,A.jsx)(P,{label:`补重料费付款人`,name:`extra_payer`,value:a.extra_payer,options:[[``,`请选择`],...S(a.extra_payer)],required:y&&!b,disabled:!y||b,update:e=>l(`extra_payer`,e)}),(0,A.jsx)(P,{label:`补重金料是否已记入本件货盘`,name:`extra_stock`,value:a.extra_stock,options:E,required:y&&!b,disabled:!y||b,update:e=>l(`extra_stock`,e)})]}),(0,A.jsx)(F,{name:`extra_verified`,value:a.extra_verified,update:e=>l(`extra_verified`,e),hidden:b,required:y&&!b,disabled:!y||b,children:`已核实本件补重料费实际付款。`})]}),(0,A.jsx)(`p`,{className:`note`,children:T})]})]})}function me({state:e,form:t,update:n,cardFee:r}){let i=(e,r,i)=>n(v.editFeeRow(t,e,r,i));return(0,A.jsxs)(`section`,{className:`panel internal`,children:[(0,A.jsxs)(`div`,{className:`panel-title`,children:[(0,A.jsx)(`h2`,{children:`实际费用(内部)`}),(0,A.jsx)(I,{name:`add-fee`,onClick:()=>n(v.addManualFee(t,e,()=>crypto.randomUUID())),children:`+ 添加其他成本`})]}),(0,A.jsx)(`p`,{className:`small muted`,children:`上方附加项目自动带入成本。请填写实际已付金额,没有成本填0;不需要的整单费用可移除。客户单据不显示。`}),(0,A.jsx)(M,{label:`费用实际支付日期`,name:`fees_date`,type:`date`,value:t.date,max:e.today,required:!0,readOnly:!0}),(0,A.jsx)(`div`,{id:`fee-rows`,children:t.feeRows.map((r,a)=>(0,A.jsxs)(`div`,{className:`fee-row`,"data-fee":r.key,children:[(0,A.jsxs)(`div`,{className:`fee-title`,children:[r.key.startsWith(`manual:`)?(0,A.jsx)(M,{label:`费用项目名称`,name:`feeNote`,value:r.note,maxLength:150,required:!0,update:e=>i(a,`note`,e)}):(0,A.jsx)(`strong`,{children:r.note}),(0,A.jsx)(`span`,{children:v.feeSourceText(r)})]}),(0,A.jsx)(N,{label:`实际成本(元)`,name:`feeAmount`,value:r.amount,placeholder:`没有成本填0`,update:e=>i(a,`amount`,e)}),(0,A.jsx)(P,{label:`费用付款人`,name:`feePayer`,value:r.payer,options:v.memberOptions(e,!0,{selected:r.payer}),update:e=>i(a,`payer`,e)}),(0,A.jsx)(I,{name:`remove-fee`,className:`quiet`,onClick:()=>n(v.removeFeeRow(t,a)),children:`移除费用`}),v.teamMode(e)&&r.funding&&(0,A.jsx)(x,{type:`hidden`,className:`cost-funding`,"data-component":`fee`,"data-reference":JSON.stringify(r.funding)})]},r.key))}),(0,A.jsxs)(`p`,{className:`small muted`,children:[`实际费用合计`,` `,t.feeRows.some(e=>e.amount===``)?`待补齐`:`¥`+v.yuan(t.feeRows.reduce((e,t)=>e+Math.round(Number(t.amount)*100),r||0))]})]})}var he=()=>crypto.randomUUID();function ge(e,t,n,r){let i=Y(r,ie),a=i?.revision===e.revision?i:{},o=t.priceLockLines(e),s=o.map(e=>a.lines?.find(t=>t.lineId===e.id)||(o.length===1&&a.line?a:{})),c=v.teamMode(n.st)?v.currentMember(n.st):`assistant`,l=e.member||c,u=s.map((e,n)=>e.line||(e.quantity?e:{...t.priceLockLineInputs(o[n]),pocket:o[n].line.pocket??``})),d=a.fee_items||[{key:`shipping`,note:`快递费`,amount:v.shopFeeDefaults(n.st).shipping,payer:c,status:`estimated`,edited:!1}],f=v.newForm(n,{id:e.id,member:c,date:a.date||n.st.today,fees_date:a.date||n.st.today,lines:u,fee_items:d,fee_cost_mode:`legacy`,rounding_mode:`yuan`,discount:a.discount??(e.discount/100).toFixed(2)});return{form:{...f,lines:f.lines.map(e=>({...e,historicalPocket:!1,pool:null}))},stock:s.map((e,t)=>({original_stock:o[t].material_source===`pool`?`stocked`:e.inventory?.original||``,count_source:e.inventory?.countSource||`stocked`,extra_source:e.extraMaterial?.source||`manual`,extra_rate:e.extraMaterial?.rate??``,extra_payer:e.extraMaterial?.payer||``,extra_stock:e.inventory?.extra||``,extra_verified:!!e.extraMaterial?.verified})),customer_type:a.customer_type||``,note:a.note??e.note??``,payment:se(n.st,{...a.settlement,account:a.settlement?.account||e.cash_events?.find(e=>e.kind===`receipt`)?.account},l),verified:!1}}function _e({client:e,state:t,session:n,views:r,lock:i,save:s,blocked:c}){let l=a(t.user.id,i.id),u={st:t,session:n,uuid:he},[d,f]=(0,k.useState)(()=>ge(i,r,u,l)),[p,m]=(0,k.useState)(``),h=r.priceLockLines(i),g=d.form.lines.flatMap((e,t)=>{let n=(J(()=>r.lockQuantityMg(e.quantity)).result||0)-h[t].locked_mg;return n>0&&d.stock[t].extra_source===`pool`?[{lineIndex:t,poolId:d.form.date,mg:n}]:[]}),b=le({client:e,state:t,views:r,date:d.form.date,member:i.member||v.currentMember(t),entries:g,delivery:!0}),S=d.form.lines.map((e,t)=>J(()=>{let n=d.stock[t],i=n.extra_source===`pool`&&r.lockQuantityMg(e.quantity)>h[t].locked_mg,a=r.priceLockDeliveryCost(h[t],e.quantity,i?`1`:n.extra_rate);if(i){let e=b.rows.find(e=>e.lineIndex===t);if(!e||e.amount===null)throw Error(b.error||`当日料池不足或成本待补,请核实购料。`);return{...a,extraCost:e.amount,materialCost:a.originalUsedCost+e.amount,extraPool:e}}return a})),C=v.syncForm({...d.form,fees_date:d.form.date,lines:d.form.lines.map((e,t)=>{let n=S[t].result?(S[t].result.materialCost/100).toFixed(2):``;return{...e,purchase:{...e.purchase,materialMode:`total`,material:n,total:n,originalTotal:n}}})},u),w=C.form,T=C.draft.lines,D=J(()=>y.orderTotal(T.map(e=>y.sale(e).sale),y.cents(w.discount),`yuan`)).result,O=D?D.total-i.netReceived:null,j={amount:O==null?``:(Math.abs(O)/100).toFixed(2),...X(d.payment)},ee=d.payment.method===`信用卡`&&O!==null&&O>0?_.amount(O,v.creditCardRate(t)):0,P=T.map((e,n)=>{let r=d.stock[n],i=h[n].material_source===`pool`,a=b.rows.find(e=>e.lineIndex===n);return{...e,lineId:h[n].id,inventory:{pocket:e.pocket,original:i?`stocked`:r.original_stock,extra:r.extra_source===`pool`?`stocked`:r.extra_stock,...v.pocketCountsEnabled(t,e.pocket)?{countSource:r.count_source}:{}},extraMaterial:{source:r.extra_source,...r.extra_source===`pool`?{poolId:w.date,revision:a?.revision}:{},rate:r.extra_rate,payer:r.extra_payer,verified:r.extra_verified}}}),L={revision:i.revision,date:w.date,customer_type:d.customer_type,note:d.note,discount:w.discount,settlement:j,fee_items:C.draft.fee_items,fee_auto_initialized:!0,verified:d.verified,lines:P},B=JSON.stringify(L);(0,k.useEffect)(()=>{localStorage.setItem(l,B)},[l,B]);let V=e=>f({...d,form:e}),H=e=>f({...d,payment:e});async function U(e){e.preventDefault(),m(``);try{for(let e of S)if(!e.result)throw Error(e.error);v.validateIssueDraft({lines:T,fee_items:L.fee_items,discount:w.discount,rounding_mode:`yuan`},t,{requireIdentity:!1});let e=P.map((e,n)=>{let r=v.pocketCountsEnabled(t,e.inventory.pocket),i=S[n].result.extraMg;if(!v.activePocketKeys(t).includes(e.pocket)||![`receive`,`stocked`].includes(e.inventory.original))throw Error(`请选择商品 `+(n+1)+` 的实际出库货盘,并确认原锁金料是否已入库。`);if(r&&![`receive`,`stocked`].includes(e.inventory.countSource??``))throw Error(`请选择商品 `+(n+1)+` 的成品来源。`);if(i&&e.extraMaterial.source!==`pool`&&(!e.extraMaterial.verified||!v.memberKeys(t).includes(e.extraMaterial.payer)||![`receive`,`stocked`].includes(e.inventory.extra)))throw Error(`请填写商品 `+(n+1)+` 的补重料价、付款人、是否已入库,并确认实际付款。`);return{quantity:e.quantity,...r?{stockCount:v.stockCountValue(String(e.stockCount??``))}:{},laborRate:e.laborRate,laborMode:e.laborMode,pieces:e.pieces,charges:e.charges,payer:e.payer,costParts:{labor:e.costParts.labor,accessories:e.costParts.accessories,other:e.costParts.other},costLabor:e.costLabor,costPayers:e.costPayers,lineId:e.lineId,inventory:{pocket:e.pocket,original:e.inventory.original,...r?{countSource:e.inventory.countSource}:{},...i?{extra:e.inventory.extra}:{}},...i?{extraMaterial:e.extraMaterial}:{}}});if(!D)throw Error(`请填写各件最终克重、销售工费及整单优惠,再核对客户补退款。`);if(O&&!j.verified)throw Error(`请先核实客户补款或退款已实际完成。`);if(!d.verified)throw Error(`请核对各件实物、实际成本、库存来源与整单客户收付款后确认交付。`);let n={revision:i.revision,date:w.date,customer_type:d.customer_type,note:d.note,discount:w.discount,...O?{settlement:j}:{},fee_items:L.fee_items,verified:!0,lines:e};await s(`/api/price-locks/`+encodeURIComponent(i.id)+`/deliver`,n,{key:l,value:B})}catch(e){m(e.message)}}let W=e=>S.reduce((t,n)=>t+(n.result?.[e]||0),0);return(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(te,{kicker:`LOCK DELIVERY`,title:`办理锁价交付`,desc:`逐件核对最终克重、实际成本与货盘;全部商品一次交付,按整单核对补款或退款。`,children:(0,A.jsx)(I,{name:`refresh-price-locks`,onClick:()=>o(`price-locks`),children:`返回待交付`})}),(0,A.jsx)(`section`,{className:`panel`,children:r.priceLockFacts(i)}),(0,A.jsxs)(`form`,{id:`price-lock-delivery-form`,"data-id":i.id,"data-revision":i.revision,onSubmit:U,children:[(0,A.jsx)(`section`,{className:`panel`,children:(0,A.jsxs)(`div`,{className:`grid two`,children:[(0,A.jsx)(M,{label:`交付日期`,name:`date`,type:`date`,required:!0,min:i.date,max:t.today,value:w.date,update:e=>V({...w,date:e,fees_date:e})}),(0,A.jsxs)(`fieldset`,{className:`customer-type-field`,children:[(0,A.jsx)(`legend`,{children:`客户类型(必选)`}),(0,A.jsx)(`div`,{className:`customer-type-options`,children:[[`new`,`新客户`],[`returning`,`老客户`]].map(([e,t])=>(0,A.jsxs)(`label`,{title:e===`new`?`首次成交`:`再次成交`,children:[(0,A.jsx)(x,{type:`radio`,name:`customer_type`,value:e,required:!0,checked:d.customer_type===e,onChange:()=>f({...d,customer_type:e})}),(0,A.jsx)(`span`,{children:t})]},e))})]}),(0,A.jsx)(M,{label:`交付备注(客户可见,选填)`,name:`delivery_note`,value:d.note,maxLength:170,update:e=>f({...d,note:e})})]})}),(0,A.jsx)(`div`,{id:`lines`,children:w.lines.map((e,n)=>(0,A.jsx)(pe,{views:r,state:t,item:h[n],line:e,index:n,stock:d.stock[n],cost:S[n].result,quote:b,update:e=>V(v.updateLine(w,n,e)),changeStock:(e,t)=>f({...d,form:w,stock:d.stock.map((r,i)=>n===i?{...r,[e]:t}:r)})},h[n].id))}),(0,A.jsxs)(`section`,{className:`panel internal`,children:[(0,A.jsx)(`h2`,{children:`整单交付汇总`}),(0,A.jsx)(`p`,{id:`lock-delivery-summary`,className:`note`,"aria-live":`polite`,children:S.every(e=>e.result)?`原锁耗用 `+v.grams(W(`originalUsedMg`))+`g,成本 ¥`+v.yuan(W(`originalUsedCost`))+`;补重 `+v.grams(W(`extraMg`))+`g,补重成本 ¥`+v.yuan(W(`extraCost`))+`;剩料/回池 `+v.grams(W(`leftoverMg`))+`g,成本 ¥`+v.yuan(W(`leftoverCost`))+`。库存动作按各件所选货盘登记。`:`请逐件补齐最终克重和补重料价,再核对整单交付汇总。`})]}),(0,A.jsx)(me,{state:t,form:w,update:V,cardFee:(i.credit_card_fee_total||0)+ee}),(0,A.jsxs)(`section`,{className:`panel`,children:[(0,A.jsxs)(`div`,{className:`grid two`,children:[(0,A.jsx)(N,{label:`整单优惠(元)`,name:`discount`,value:w.discount,update:e=>V({...w,discount:e})}),(0,A.jsxs)(`div`,{children:[(0,A.jsx)(`span`,{className:`small muted`,children:`整单最终成交额 · 四舍五入到元`}),(0,A.jsx)(`div`,{id:`lock-final-total`,className:`summary-amount`,children:D?v.orderAmount(D.total,`yuan`):`待填写`}),(0,A.jsx)(`p`,{id:`lock-rounding-note`,className:`small muted`,children:D&&v.orderRoundingHint(D)})]})]}),(0,A.jsxs)(`div`,{className:`lock-settlement`,children:[(0,A.jsx)(`h2`,{id:`lock-settlement-title`,children:O==null?`客户补款/退款`:O>0?`客户需补款`:O<0?`应退还客户`:`无需补款或退款`}),(0,A.jsx)(`p`,{id:`lock-settlement-hint`,className:`small muted`,"aria-live":`polite`,children:D?`整单已收净额 ¥`+v.yuan(i.netReceived)+`;最终成交 ¥`+v.yuan(D.total)+(O?`;本次`+(O>0?`补收`:`退款`)+` ¥`+v.yuan(Math.abs(O)):`,金额已结清`)+`。`:`先填写各件最终克重、销售工费及整单优惠,再核对客户补退款。`}),(0,A.jsxs)(`div`,{id:`lock-settlement-fields`,hidden:O===0,children:[(0,A.jsxs)(`div`,{className:`grid three`,children:[(0,A.jsx)(M,{label:`本次实际补退款(元)`,name:`settlement_amount`,type:`number`,value:j.amount,readOnly:!0,required:!!O,disabled:O===0}),(0,A.jsx)(R,{state:t,payment:d.payment,change:H,required:!!O,disabled:O===0,methodLabel:O!==null&&O<0?`退款方式`:`补收款方式`,recipientLabel:O!==null&&O<0?`退款账户归属`:`收款人`})]}),(0,A.jsx)(F,{name:`settlement_verified`,value:d.payment.verified,update:e=>H({...d.payment,verified:e}),required:!!O,disabled:O===0,children:`已核实本次补款到账/退款已实际完成。`})]})]}),(0,A.jsx)(z,{id:`lock-delivery-card-fee`,state:t,payment:d.payment,change:H,cents:O,enabled:O==null||O>0}),(0,A.jsx)(F,{name:`delivery_verified`,required:!0,value:d.verified,update:e=>f({...d,verified:e}),children:`已逐件核对实物、实际成本、出入库来源与整单客户收付款,确认全部交付。`}),(0,A.jsxs)(`div`,{className:`form-actions`,children:[(0,A.jsx)(`span`,{className:`small muted`,children:`保存后才记销售、完整成本和利润,可打印正式客户单据。`}),(0,A.jsx)(E,{type:`submit`,className:`primary`,disabled:c,children:`确认整单交付并生成销售单`})]}),(0,A.jsx)(`div`,{id:`price-lock-error`,"aria-live":`polite`,children:p&&(0,A.jsx)(`div`,{className:`error`,children:p})})]})]})]})}function $(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function ve(e){try{let t=JSON.parse(sessionStorage.getItem(e)||`{}`);return $(t)?t:{}}catch{return{}}}function ye(e,t,n,r){let i=[e.user,t,n].join(`|`),[a,o]=(0,k.useState)(null);return(0,k.useEffect)(()=>{if(!t)return;let n=!0;return e.api(t).then(e=>r(e)).then(e=>{n&&o({key:i,result:e})}).catch(e=>{n&&o({key:i,error:p(e)})}),()=>{n=!1}},[e,t,i,r]),a?.key===i?a:{}}function be(e){if(!$(e)||!$(e.line))return!1;let t=e.line;return typeof t.name==`string`&&Number.isSafeInteger(t.sale)&&Number.isSafeInteger(t.laborRate)&&(t.charges==null||Array.isArray(t.charges)&&t.charges.every(e=>$(e)&&Number.isSafeInteger(e.amount)))&&Number.isSafeInteger(e.locked_mg)&&Number.isSafeInteger(e.sell_rate)&&(e.buy_rate===null||Number.isSafeInteger(e.buy_rate))&&(e.material_amount===null||Number.isSafeInteger(e.material_amount))}function xe(e){return $(e)&&typeof e.id==`string`&&typeof e.date==`string`&&typeof e.customer==`string`&&typeof e.number==`string`&&typeof e.salesperson==`string`&&(e.status===`pending`||e.status===`cancelled`||e.status===`delivered`)&&Number.isSafeInteger(e.revision)&&Number.isSafeInteger(e.netReceived)&&Number.isSafeInteger(e.discount)&&be(e)&&(e.lines==null||Array.isArray(e.lines)&&e.lines.every(be))}function Se(e){return $(e)&&typeof(e.requestId||e.id)==`string`&&(e.action===`edit`||e.action===`cancel`)&&(e.status===`pending`||e.status===`approved`||e.status===`rejected`)&&typeof e.created==`string`}function Ce(e,t,n){return $(e)&&e.eligible===!0&&$(e.lock)&&typeof e.lock.id==`string`&&typeof e.lock.date==`string`&&typeof e.lock.number==`string`&&(e.lock.customer===void 0||typeof e.lock.customer==`string`)&&e.lock.id===t&&e.lock.status===`pending`&&Number.isSafeInteger(e.revision)&&typeof e.requiresApproval==`boolean`&&$(e.inputs)&&(!n||Array.isArray(e.inputs.lines)&&e.inputs.lines.length>0)}function we(e,t){return $(e)&&(e.requestId||e.id)===t&&(e.action===`edit`||e.action===`cancel`)&&Array.isArray(e.changes)&&xe(e.before)&&Se(e)&&Number.isSafeInteger(e.revision)}function Te(e){if(!$(e)||!Array.isArray(e.rows)||!e.rows.every(xe))throw Error(`记录未完整返回,请重试。`);return{rows:e.rows}}function Ee(e){if(!$(e)||!Array.isArray(e.rows)||!e.rows.every(Se))throw Error(`记录未完整返回,请重试。`);return{rows:e.rows}}var De=e=>[`changes`,`review`].includes(e)?`price-lock-changes-dialog`:`price-lock-dialog`;function Oe({children:e,kind:t,close:n}){return(0,A.jsx)(w,{id:De(t),onCancel:e=>{e.preventDefault(),n()},children:e})}var ke=new WeakMap;function Ae({client:e,state:r,session:i,route:a,onState:u,onRecoverOther:f}){l(e);let m=d(),h=a===`price-lock-create`,g=h?s(`edit`):``,_=h?``:s(`deliver`),v=h?``:s(`lock`),y=ke.get(e),[b,x]=(0,k.useState)(m),[S,C]=(0,k.useState)(0),[w,T]=(0,k.useState)(()=>y?.user===r.user.id?y.list:`pending`),[D,O]=(0,k.useState)(null),[j,M]=(0,k.useState)(()=>y?.user===r.user.id?y.changes:`pending`),[N,P]=(0,k.useState)(``),[F,L]=(0,k.useState)(``),[R,z]=(0,k.useState)(``),[B,V]=(0,k.useState)(!1);m!==b&&(x(m),O(null),z(``),V(!1));let H=!!e.pending(),U=e.busy||H,W=(0,k.useMemo)(()=>ee(r,i),[r,i]),G=D||(!_&&v?{kind:`detail`,id:v}:null),K=G?.kind,q=G?.id,ne=g||_||q,re=(0,k.useMemo)(()=>e=>{if(g||K===`cancel`){if(!Ce(e,ne,!!g))throw Error($(e)&&typeof e.reason==`string`&&e.reason||`锁价修改资料未完整返回,请重新读取。`);if(K===`cancel`&&!g){if(!xe(e.lock))throw Error(`锁价单资料未完整返回,请重新读取。`);return{kind:`cancel`,value:{...e,lock:e.lock}}}return{kind:`edit`,value:e}}if(K===`review`){if(!we(e,q))throw Error(`锁价申请详情未完整返回,请重新读取。`);return{kind:`review`,value:e}}if(K===`changes`)return{kind:`changes`,value:Ee(e)};if(!xe(e)||e.id!==ne)throw Error(`锁价单资料未完整返回,请重新读取。`);return{kind:`lock`,value:e}},[q,ne,K,g]),ie=`/api/price-locks/`+encodeURIComponent(ne||``),ae=ye(e,g||K===`cancel`?ie+`/edit-context`:K===`changes`?`/api/price-lock-changes?status=`+j:K===`review`?`/api/price-lock-changes/`+encodeURIComponent(q||``):_||v||K===`detail`?ie:``,S,re),J=ye(e,!h&&!_?`/api/price-locks?status=`+w:``,S,Te),Y=ae.result,oe=Y?.kind===`edit`?Y.value:null,se=Y?.kind===`cancel`?Y.value:null,X=Y?.kind===`lock`?Y.value:null,ce=Y?.kind===`review`?Y.value:null,le=Y?.kind===`changes`?Y.value:null,Z=()=>{z(``),V(!1),C(e=>e+1)},Q=()=>{O(null),z(``),V(!1)},ue=()=>{Q(),P(``),L(``),o(`price-locks`),Z()},de=()=>{Q(),v&&o(`price-locks`)};function pe(t){if(!(t.target instanceof Element))return;let n=t.target.closest(`button[data-action]`);if(!n||!t.currentTarget.contains(n))return;let i=n.dataset.action||``,a=n.dataset.id||``;if([`edit-price-lock`,`cancel-price-lock`].includes(i)&&U)z(`请先恢复上次未确认的操作,再修改或作废锁价单。`);else switch(i){case`open-price-lock`:case`price-lock-change-lock`:Q(),o(`price-locks`,{search:`?lock=`+encodeURIComponent(a)});break;case`deliver-price-lock`:Q(),o(`price-locks`,{search:`?deliver=`+encodeURIComponent(a)});break;case`edit-price-lock`:Q(),o(`price-lock-create`,{search:`?edit=`+encodeURIComponent(a)});break;case`new-price-lock`:Q(),o(`price-lock-create`);break;case`cancel-price-lock`:V(!1),z(``),O({kind:`cancel`,id:a});break;case`price-lock-changes-open`:V(!1),z(``),O({kind:`changes`});break;case`price-lock-change-open`:V(!1),z(``),O({kind:`review`,id:a});break;case`price-lock-changes-close`:case`close-price-lock`:de();break;case`price-lock-changes-filter`:ke.set(e,{user:r.user.id,list:w,changes:n.dataset.status||j}),M(n.dataset.status||j),Z();break;case`price-lock-changes-reload`:Z();break;case`price-lock-list-status`:ke.set(e,{user:r.user.id,list:n.dataset.status||w,changes:j}),T(n.dataset.status||w),Z();break;case`refresh-price-locks`:ue();break;case`open-lock-order`:Q(),o(`orders`,{search:`?order=`+encodeURIComponent(a)})}}async function me(n,i,a,s){if(!$(a)||!$(i))throw Error(`锁价操作回执未完整返回,请重新读取后核对。`);let l=$(a.request)?a.request:{},d=$(a.lock)?a.lock:{},f=n.split(`/`).at(-1),p=a.price_lock_id||l.price_lock_id||d.id||(n===`/api/price-locks`?a.id:n.split(`/`)[3]);if(typeof p!=`string`||!p)throw Error(`锁价操作回执未完整返回,请重新读取后核对。`);if(n===`/api/price-locks`)s&&t(localStorage,s.key,s.value),Q(),o(`price-locks`,{search:`?lock=`+encodeURIComponent(p)}),P(`锁价已保存到待交付,尚未出入库、不计利润`);else if(f===`deliver`){let e=a.order_id||a.id;if(typeof e!=`string`||!e||typeof i.date!=`string`)throw Error(`交付回执未完整返回,请重新读取后核对。`);s&&t(localStorage,s.key,s.value);let n=`mm-order-book-`+r.user.id,c=ve(n);sessionStorage.setItem(n,JSON.stringify({...c,mode:`date`,date:i.date,q:``,status:``})),o(`orders`,{search:`?order=`+encodeURIComponent(e)})}else s&&t(localStorage,s.key,s.value),L(p),Q(),o(`price-locks`),P(f===`change-requests`?`锁价申请已提交`:f===`approve`?`锁价申请已批准`:f===`reject`?`锁价申请已驳回`:f===`cancel`?`锁价单已作废`:`锁价修改已保存`);Z();try{let t=await c(e);e.user===t.user.id&&u?.(t)}catch{P(`操作已保存,最新记录暂未读到。请重新读取,不要重复提交。`)}}async function he(t,n,r){await me(t,n,await e.mutate(t,n,void 0,r?.value),r)}async function ge(){try{let t=e.pending();if(t&&!n.accepts(t.url)&&f)return await f();let i=await e.retryPending();i&&$(i.result)&&(n.finish({client:e,state:r,job:i.job,result:i.result,storage:localStorage}),await me(i.job.url,i.job.data,i.result))}catch(e){z(p(e)),e instanceof Error&&`status`in e&&e.status===409&&V(!0)}}async function be(e){let t=e.target;if(t instanceof HTMLFormElement&&[`price-lock-cancel-form`,`price-lock-review-form`].includes(t.id)&&(e.preventDefault(),!(U||B))){z(``);try{let n=new FormData(t),i=n.get(`verified`)===`on`;if(K===`cancel`){let e=se;if(!e)throw Error(`锁价修改资料未完整返回,请重新读取。`);let t=String(n.get(`reason`)||``).trim();if(!t)throw Error(`请填写作废原因。`);if(!i)throw Error(`请核实录错单据并勾选整单作废。`);let a=r.user.role===`assistant`&&(e.requiresApproval!==!1||e.inputs.date!==r.today);await he(ie+(a?`/change-requests`:`/cancel`),{revision:e.revision,reason:t,verified:!0,...a?{action:`cancel`}:{}})}else{let t=ce,a=e.nativeEvent instanceof SubmitEvent?e.nativeEvent.submitter:null,o=a instanceof HTMLButtonElement?a.value:``,s=String(n.get(`review_note`)||``).trim();if(!t||r.user.role!==`owner`||t.status!==`pending`||![`approve`,`reject`].includes(o))throw Error(`请重新读取待复核申请。`);if(o===`approve`&&(t.stale||!i))throw Error(t.stale?`原单或关联料池已有变化,请驳回后重新提交。`:`请核实全部变更与关联影响并勾选确认。`);if(o===`reject`&&!s)throw Error(`请填写驳回原因。`);await he(`/api/price-lock-changes/`+encodeURIComponent(t.requestId||t.id)+`/`+o,o===`approve`?{revision:t.price_lock_revision??t.revision,verified:!0,...s?{note:s}:{}}:{note:s})}}catch(e){z(p(e)),e instanceof Error&&`status`in e&&e.status===409&&V(!0)}}}let Se=ae.error?(0,A.jsxs)(`div`,{className:`error`,children:[ae.error,` `,(0,A.jsx)(E,{type:`button`,onClick:Z,children:`重新读取`})]}):(0,A.jsx)(`p`,{children:`正在读取锁价记录…`});return(0,A.jsx)(`div`,{className:`business-pages`,onClick:pe,onSubmit:be,children:(0,A.jsxs)(`div`,{id:`main`,children:[H&&!e.busy&&(0,A.jsxs)(`div`,{className:`note`,role:`alert`,children:[`上次提交结果尚未确认。`,(0,A.jsx)(E,{type:`button`,"data-action":`retry`,disabled:e.busy,onClick:ge,children:`恢复原操作`})]}),N&&(0,A.jsx)(`p`,{role:`status`,className:`note`,children:N}),F&&!h&&!_&&N&&(0,A.jsxs)(`div`,{className:`actions`,children:[(0,A.jsx)(I,{name:`open-price-lock`,"data-id":F,className:`primary`,children:`查看锁价单`}),(0,A.jsx)(I,{name:`refresh-price-locks`,children:`返回待交付`}),(0,A.jsx)(I,{name:`price-lock-changes-open`,children:`查看修改与作废申请`})]}),R&&!G&&(0,A.jsx)(`p`,{role:`alert`,className:`error`,children:R}),h?g&&!oe?Se:(0,A.jsx)(fe,{client:e,state:r,session:i,views:W,edit:g?oe:null,save:he,blocked:U,reset:Z},g+`-`+(g?S:0)):_?X?X.status===`pending`?(0,A.jsx)(_e,{client:e,state:r,session:i,views:W,lock:X,save:he,blocked:U},_):(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(te,{kicker:`LOCK DELIVERED`,title:`这张锁价单已交付`,desc:`请查看已生成的销售单,不要重复交付。`,children:(0,A.jsx)(I,{name:`refresh-price-locks`,children:`返回待交付`})}),W.priceLockFacts(X),X.final_order_id&&(0,A.jsx)(I,{name:`open-lock-order`,"data-id":X.final_order_id,children:`查看销售单`})]}):Se:(0,A.jsxs)(A.Fragment,{children:[(0,A.jsxs)(te,{title:w===`cancelled`?`已作废锁价单`:`待交付`,kicker:w===`cancelled`?`VOIDED PRICE LOCKS`:`PENDING DELIVERY`,desc:w===`cancelled`?`以下为录错作废后保留的原单。收款、手填购料与信用卡手续费记账已撤销,料池预留已释放;原录入成本仅供追溯,不计有效支出。`:`显示所有日期的锁价待交付记录。锁价时只记实际收付,交付后才计销售、成本和利润。`,children:[(0,A.jsx)(I,{name:`new-price-lock`,className:`primary`,children:`新增锁价`}),(0,A.jsx)(I,{name:`price-lock-changes-open`,children:`修改与作废申请`}),(0,A.jsx)(I,{name:`refresh-price-locks`,children:`刷新`})]}),(0,A.jsx)(`div`,{className:`actions lock-list-filter`,children:[`pending`,`cancelled`].map(e=>(0,A.jsx)(I,{name:`price-lock-list-status`,"data-status":e,className:e===w?`primary`:``,children:e===`pending`?`待交付`:`已作废`},e))}),(0,A.jsx)(`section`,{className:`panel`,children:(0,A.jsx)(`div`,{id:`price-lock-list`,"aria-live":`polite`,children:J.error?(0,A.jsxs)(`div`,{className:`error`,children:[J.error,` `,(0,A.jsx)(I,{name:`refresh-price-locks`,children:`重新读取`})]}):J.result?W.listRecords(J.result,w):`正在读取待交付记录…`})})]}),G&&!_&&!h&&(0,A.jsxs)(Oe,{kind:G.kind,close:de,children:[K===`changes`?(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(E,{type:`button`,className:`dialog-close`,"data-action":`price-lock-changes-close`,"aria-label":`关闭`,children:`×`}),(0,A.jsx)(`h2`,{children:`锁价修改与作废申请`}),(0,A.jsx)(`div`,{className:`actions`,children:[`pending`,`all`].map(e=>(0,A.jsx)(I,{name:`price-lock-changes-filter`,"data-status":e,className:e===j?`primary`:``,children:e===`all`?`全部记录`:`待复核`},e))}),(0,A.jsx)(`div`,{id:`price-lock-changes-content`,children:le?W.changeRows(le):Se})]}):K===`detail`?(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(E,{type:`button`,className:`dialog-close`,"data-action":`close-price-lock`,"aria-label":`关闭锁价记录`,children:`×`}),(0,A.jsx)(`div`,{id:`price-lock-detail`,children:X?W.detailView(X):Se})]}):(K===`cancel`?se:ce)?(0,A.jsx)(`fieldset`,{style:{display:`contents`},disabled:U||B,children:K===`cancel`&&se?W.cancelView(se,r.user.role===`assistant`&&(se.requiresApproval!==!1||se.inputs.date!==r.today)):ce&&W.changeDetail(ce,r.user.role===`owner`&&ce.status===`pending`&&!ce.stale)}):(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(I,{name:`close-price-lock`,children:`关闭`}),Se]}),R&&(0,A.jsxs)(`div`,{role:`alert`,className:`error`,children:[R,` `,(0,A.jsx)(E,{type:`button`,onClick:Z,children:`重新读取`})]}),B&&(0,A.jsx)(E,{type:`button`,onClick:de,children:`关闭`})]},K+`-`+q)]})})}export{Ae as PriceLocksPage};