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