13 lines
175 KiB
JavaScript
13 lines
175 KiB
JavaScript
import{n as e}from"./rolldown-runtime-Dl_DZoUm.js";import{a as t,i as n,n as r,o as i,r as a,s as o,t as s}from"./BusinessControls-DBHpCgMH.js";import{b as c,c as l,l as u,nr as d,w as f}from"./index-BvkDlq1y.js";import{c as p,i as m,n as h,o as g,r as _,s as v,t as y}from"./orderReads-CYNcthgw.js";import{t as b}from"./printStatus-BtZ3ZK8T.js";import{c as x,n as S,t as C}from"./shared-D0Ng0yPd.js";var w=c();function T({id:e,label:t,close:n,children:r,ownClose:i=!1}){return(0,w.jsxs)(a,{id:e,"aria-label":t,onCancel:e=>{e.preventDefault(),n()},children:[!i&&(0,w.jsx)(s,{type:`button`,className:`dialog-close`,"data-action":`close-dialog`,"aria-label":t,onClick:n,children:`×`}),r]})}var E=e(d(),1);function D({state:e,session:a,currentOrder:o,orderChangeDetail:c,orderOwnershipDetail:l,orderCancellationDetail:u,ui:d={}}){function f(e,{zero:t=!1,optional:n=!1,signed:r=!1,title:i=`库存数量(对)`}={}){let a=String(e??``).trim();if(!a&&n)return null;if(r){if(!/^-?\d+$/.test(a)||!Number.isSafeInteger(Number(a))||Math.abs(Number(a))>1e9||Number(a)===0)throw Error(i+`请填写非0整数,增加填正数,减少填负数。`);return Number(a)}if(!/^\d+$/.test(a)||!Number.isSafeInteger(Number(a))||Number(a)>1e9||Number(a)<+!t)throw Error(i+`请填写`+(t?`非负`:`大于0的`)+`整数,一对填1。`);return Number(a)}function p(t=``){let n=[...new Set((e?.accounts||[]).map(v))].filter(e=>{let n=de(e)?.member;return!n||Ve(n)||e===t});return t&&!n.includes(t)&&n.push(t),n}let m=[`现货`,`金料`,`找金`,`回收旧料`,`君宝汇`];function h(){return Array.isArray(e?.pockets)?e.pockets:m}function g(e,t=``,{name:r=`stockCount`,title:i=`出库数量(对)`,optional:a=!1,readOnly:o=!1,visible:s=$(e),help:c}={}){let l=c??(a?`历史未记录对数,可保留空白;与计工费件数分别填写。`:`与计工费件数分别填写。`);return(0,w.jsxs)(`label`,{className:`stock-count-field`,"data-stock-count-field":``,hidden:!s,children:[i,(0,w.jsx)(n,{name:r,readOnly:o,defaultValue:t??``,type:`number`,min:`1`,max:`1000000000`,step:`1`,inputMode:`numeric`,disabled:!s,required:s&&!a,placeholder:`一对填1`}),l?(0,w.jsx)(`small`,{className:`muted`,children:l}):``]})}function _(){return e?.user?.member||a?.user?.member||(e?.user?.role===`owner`?`owner`:`assistant`)}function v(e){return typeof S==`object`&&typeof S.normalizeAccount==`function`?S.normalizeAccount(e):[`助理信用卡`,`助理1信用卡`,`助理2信用卡`,`麦麦信用卡`].includes(e)?`麦麦信用卡`:e}function y(){return Be().filter(Ve)}function b(e=!1,{historical:t=!1,selected:n=``}={}){let r=(t?Be():y()).filter(e=>He()||e!==`assistant2`);e&&(r=[...r.filter(e=>e!==`owner`),...r.filter(e=>e===`owner`)]);let i=r.map(e=>[e,ze(e)+(t&&!Ve(e)?`(已停用)`:``)]);return n&&Be().includes(n)&&!r.includes(n)&&i.push([n,ze(n)+`(已停用 · 原记录)`]),i}let T=(e,n,r,i)=>(i&&Be().includes(i)&&!Ve(i)&&r.some(e=>Be().includes(Array.isArray(e)?e[0]:e))&&!r.some(e=>(Array.isArray(e)?e[0]:e)===i)&&(r=[...r,[i,ze(i)+`(已停用 · 原记录)`]]),(0,w.jsxs)(`label`,{children:[e,(0,w.jsx)(t,{name:n,defaultValue:i,children:k(r)})]})),D=(e,t,n=``)=>O(e,t,n,`number`,{min:`0`,step:`0.01`,required:!0}),O=(e,t,r=``,i=`text`,a={})=>(0,w.jsxs)(`label`,{children:[e,(0,w.jsx)(n,{type:i,name:t,defaultValue:r,...a})]}),k=e=>e.map(e=>{let[t,n,r]=Array.isArray(e)?e:[e,e];return(0,w.jsx)(`option`,{value:t,disabled:!!r,children:t===n?fe(t):n},t)}),A={confirm:`确认订单`,receipt:`登记收款`,refund:`登记退款`,expense:`直接费用`,fees:`补记旧单费用`,cost:`补齐货品成本`,deliver:`完成销售记账`,complete:`补齐旧单账务`,cancel:`取消订单`,return:`整单退货`,settlement:`实际交款`,review:`店主复核`,correct:`更正流水`,ownership:`修改订单归属`};function j(e){return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`p`,{className:`small muted`,children:`修改后,订单的经营款与业绩按新归属统计。原单号、实际收退款账户、成本付款人及库存记录保留。`}),e===`owner`?``:(0,w.jsx)(`p`,{className:`small order-ownership-access-note`,children:`生效后,本单将从原归属助理的列表移出,原助理不能再查看或修改本单。`})]})}function M(e){let t=new Date(e);return Number.isNaN(t.getTime())?`时间未提供`:t.toLocaleString(`zh-CN`)}function N(e){return e&&Be().includes(e.member)&&typeof e.label==`string`&&!!e.label}let P={pending:`待店主复核`,approved:`已修改归属`,rejected:`已驳回`};function F(e,t=void 0){if(!e||typeof e.id!=`string`||!e.id||typeof e.order_id!=`string`||!e.order_id||t&&e.order_id!==t||!Object.hasOwn(P,e.status)||!Number.isSafeInteger(e.order_revision)||typeof e.reason!=`string`||typeof e.requester_name!=`string`||typeof e.created!=`string`||typeof e.stale!=`boolean`||typeof e.canApprove!=`boolean`||!N(e.before)||!N(e.after)||e.before.member===e.after.member)throw Error(`归属修改资料未完整返回,请重新读取订单后复核。`);return e}function I(e){return F(e),(0,w.jsxs)(`div`,{className:`order-ownership-pair`,"aria-label":`订单归属原值与新值`,children:[(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`small`,{children:`原归属`}),(0,w.jsx)(`strong`,{children:e.before.label})]}),(0,w.jsx)(`span`,{"aria-hidden":`true`,children:`→`}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`small`,{children:e.status===`pending`?`申请归属`:`本次新归属`}),(0,w.jsx)(`strong`,{children:e.after.label})]})]})}function L(e){let t=K(e);if(!t.length)return``;let n=e=>e===null?`待补齐`:`¥`+Ue(e),r=e=>e.allocations.length?e.allocations.map(e=>ze(e.payer)+` `+n(e.amount)).join(`;`):e.materialAmount===null?`待补齐后分摊`:`无分摊金额`,a=(e,t,n)=>(0,w.jsxs)(`tr`,{children:[(0,w.jsx)(`th`,{scope:`row`,children:e}),(0,w.jsx)(`td`,{children:t}),(0,w.jsx)(`td`,{children:n})]});return(0,w.jsxs)(`section`,{className:`price-lock-related-impact`,children:[(0,w.jsxs)(`h3`,{children:[`同时受影响的锁价单(`,t.length,` 张)`]}),(0,w.jsx)(`p`,{className:`small muted`,children:`以下只调整料池成本和付款归属,客户锁定售价与实际收付款保持原记录。`}),E.Children.toArray(t.map(e=>(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`h3`,{children:[e.date,` · `,e.number||e.id,e.customer?` · `+e.customer:``]}),(0,w.jsx)(`div`,{className:`table-wrap`,children:(0,w.jsxs)(i,{className:`material-detail-table material-change-comparison`,"aria-label":`关联锁价单成本影响`,children:[(0,w.jsx)(`thead`,{children:(0,w.jsxs)(`tr`,{children:[(0,w.jsx)(`th`,{children:`核对项目`}),(0,w.jsx)(`th`,{children:`变更前`}),(0,w.jsx)(`th`,{children:`批准后`})]})}),(0,w.jsxs)(`tbody`,{children:[a(`原锁预留料费`,n(e.before.materialAmount),n(e.after.materialAmount)),[`before`,`after`].some(t=>Object.hasOwn(e[t],`usedMaterialAmount`))?a(`交付耗用原锁料费`,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`))?a(`少重回池成本`,Object.hasOwn(e.before,`leftoverCost`)?n(e.before.leftoverCost):`未交付`,Object.hasOwn(e.after,`leftoverCost`)?n(e.after.leftoverCost):`未交付`):``,a(`自动付款归属`,r(e.before),r(e.after))]})]})})]})))]})}function R(e,{signed:t=!1}={}){return Number.isSafeInteger(e?.stockCount)?(0,w.jsx)(`div`,{className:`small stock-count-number`,children:Q(e.stockCount,{signed:t})}):$(e?.pocket)?(0,w.jsx)(`div`,{className:`small muted`,children:`未记录对数`}):``}function z(e){if(!e)return``;let t=(e,t,n=!1)=>(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`h3`,{children:e}),t.length?(0,w.jsx)(`div`,{className:`table-wrap`,children:(0,w.jsxs)(i,{className:`order-change-inventory`,children:[(0,w.jsx)(`thead`,{children:(0,w.jsxs)(`tr`,{children:[(0,w.jsx)(`th`,{children:`日期`}),(0,w.jsx)(`th`,{children:`货盘`}),n?``:(0,w.jsx)(`th`,{children:`库存业务`}),(0,w.jsx)(`th`,{className:`number`,children:n?`本次增减`:`已记克重`})]})}),(0,w.jsx)(`tbody`,{children:E.Children.toArray(t.map(e=>(0,w.jsxs)(`tr`,{children:[(0,w.jsx)(`td`,{children:e.date}),(0,w.jsx)(`td`,{children:te(e.pocket)}),n?``:(0,w.jsx)(`td`,{children:e.kind||`未提供`}),(0,w.jsxs)(`td`,{className:`number`,children:[e.mg>0?`+`:``,ke(e.mg),`g`,R(e,{signed:!0})]})]})))})]})}):(0,w.jsx)(`p`,{className:`small muted`,children:n?`本次没有黄金货盘净变动。`:`没有本单库存流水。`})]});return(0,w.jsxs)(`section`,{className:`order-change-inventory-summary`,children:[(0,w.jsx)(`h3`,{children:`库存原值与批准后变化`}),(0,w.jsx)(`p`,{className:`small muted`,children:`以下为本单各日期、货盘的库存流水;正数为增加,负数为减少。按件商品或退回供应商不计黄金货盘。`}),e.legacyCountNotice?(0,w.jsx)(`p`,{className:`note`,children:e.legacyCountNotice}):``,t(`原库存记录`,e.before),t(`同意后的库存记录`,e.after),t(`本次库存净变化`,e.changes,!0)]})}function B(e){let t=new Set((e.corrections||[]).filter(e=>e.type===`expense`).map(e=>e.target));return e.expenses.filter(e=>e.amount>0&&!t.has(e.id))}function V(e){return B(e).map(e=>`${e.date} · ${e.note||`实际费用`}\n${X(e.amount)} · ${Y(e.payer)}支付`).join(`
|
||
|
||
`)||`无已记费用`}function H(e){let t=new Set((e.corrections||[]).filter(e=>e.type===`payment`).map(e=>e.target));return e.payments.filter(e=>e.amount>0&&!t.has(e.id)).map(e=>`${e.date} · ${e.kind===`receipt`?`客户收款`:`客户退款`}\n${X(e.amount)} · ${e.account?fe(e.account):`账户未提供`}`).join(`
|
||
|
||
`)||`无有效收退款`}function U(e,t,n=`锁价购料成本`){if(!e.priceLockCosts&&!t.priceLockCosts)return``;if(e.priceLockCosts?.lines||t.priceLockCosts?.lines){let n=e.priceLockCosts||{},r=t.priceLockCosts||{},i=n.lines||r.lines;return E.Children.toArray(i.map((e,t)=>{let i=n.lines?.find(t=>t.lineId===e.lineId)||{},a=r.lines?.find(t=>t.lineId===e.lineId)||{};return U({priceLockCosts:{...i,date:n.date}},{priceLockCosts:{...a,date:r.date}},`商品 `+(t+1)+` · 锁价购料成本`)}))}let r=e.priceLockCosts||{},i=t.priceLockCosts||{},a=e=>e===`pool`?`原锁料池`:e===`manual`?`手填原锁料价`:`未提供`;return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`tr`,{className:`change-section-row`,children:(0,w.jsx)(`th`,{colSpan:3,scope:`colgroup`,children:n})}),G(`原锁日期`,r.date,i.date),G(`原锁料费来源`,a(r.materialSource),a(i.materialSource)),G(`原锁进货料价(每克)`,X(r.buyRate),X(i.buyRate)),G(`原锁料费付款人`,r.materialSource===`pool`?`按原锁料池分摊`:Y(r.buyPayer),i.materialSource===`pool`?`按原锁料池分摊`:Y(i.buyPayer)),G(`原锁整批料费`,X(r.materialAmount),X(i.materialAmount)),G(`补重进货料价(每克)`,X(r.extraRate),X(i.extraRate)),G(`补重料费付款人`,r.extraPayer?Y(r.extraPayer):`无补重`,i.extraPayer?Y(i.extraPayer):`无补重`)]})}function W(e,t){if(!e)return`无此商品`;let n=X;if(t===`name`)return`${e.name||`未填写`}${e.priceNote?`
|
||
`+e.priceNote:``}`;if(t===`code`)return e.code||`未填写`;if(t===`quantity`)return e.unit===`g`?ke(e.quantity)+`g`:String(e.quantity)+`件`;if(t===`sale`)return n(e.sale);if(t===`pricing`)return e.goldPrice==null?`手填基础金额 ${n(e.baseSale??e.sale)}`:`销售金价 ${n(e.goldPrice)}/克\n${e.laborMode===`gram`?`销售克工费`:`销售件工费`} ${n(e.laborRate)}${e.laborMode===`gram`?`/克`:`/件`}\n件数 ${e.pieces??`未填写`}`;if(t===`stockCount`)return Number.isSafeInteger(e.stockCount)||$(e.pocket)?Q(e.stockCount):`不记录对数`;if(t===`pocket`)return te(e.pocket)||`外配/不扣黄金`;if(t===`charges`)return e.charges?.length?e.charges.map(e=>`${e.name}:${n(e.amount)}`).join(`
|
||
`):`无附加收费`;if(t===`cost`)return n(e.cost);if(t===`material`){let t=e.costMaterial;return t?.mode===`pool`?`每日购料:${t.poolId}\n本行料费:${n(e.costParts?.material)}${e.materialPool?.allocations?.length?`
|
||
`+e.materialPool.allocations.map(e=>Y(e.payer)+` `+n(e.amount)).join(`;`):e.costParts?.material==null?`
|
||
待补采购后分摊`:``}`:`${t?.mode===`gram`?`每克料价 `+n(t.rate)+`/克`:`料费总额`}\n${n(e.costParts?.material)}`}return t===`labor`?`${e.costLabor?.mode===`gram`?`进货克工费 `+n(e.costLabor.rate)+`/克`:`进货总工费`}\n${n(e.costParts?.labor)}`:t===`extra`?e.costParts?`配件 ${n(e.costParts.accessories)}\n其他 ${n(e.costParts.other)}`:`原货品成本未分项`:t===`payers`?`料费:${e.costMaterial?.mode===`pool`?e.materialPool?.allocations?.map(e=>Y(e.payer)+` `+n(e.amount)).join(`;`)||`按真实采购分摊`:Y(e.costPayers?.material??e.payer)}\n进货工费:${Y(e.costPayers?.labor??e.payer)}\n配件及其他:${Y(e.payer)}`:``}function G(e,t,n){let r=String(t??``)!==String(n??``);return(0,w.jsxs)(`tr`,{...r?{className:`order-change-modified`}:{},children:[(0,w.jsxs)(`th`,{scope:`row`,children:[e,r?(0,w.jsx)(`span`,{className:`change-mark`,children:`已修改`}):``]}),(0,w.jsx)(`td`,{children:J(t)}),(0,w.jsx)(`td`,{children:J(n)})]})}function K(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=>Be().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&&Me(e.date)&&n(e.before)&&n(e.after)))throw Error(`关联锁价单的成本影响未完整返回,请重新读取后复核。`);return e}function ee(e,t=void 0){let n=t=>t&&t.id===e.order_id&&Number.isSafeInteger(t.total)&&Array.isArray(t.lines)&&Array.isArray(t.expenses)&&Array.isArray(t.payments),r=e=>e===null||Number.isSafeInteger(e);if(!e||typeof e.id!=`string`||!e.id||typeof e.order_id!=`string`||t&&e.order_id!==t||!Object.hasOwn(oe,e.status)||!Number.isSafeInteger(e.order_revision)||typeof e.reason!=`string`||typeof e.requester_name!=`string`||typeof e.created!=`string`||typeof e.stale!=`boolean`||typeof e.canApprove!=`boolean`||!n(e.before)||!n(e.after)||![`before`,`after`].every(t=>e.summary?.[t]&&[`total`,`netReceived`,`directCost`].every(n=>Number.isSafeInteger(e.summary[t][n]))&&[`goodsCost`,`profit`,`settlementDue`].every(n=>r(e.summary[t][n]))))throw Error(`修改申请资料未完整返回,请重新读取订单后复核。`);if(e.relatedOrders!==void 0){if(!Array.isArray(e.relatedOrders))throw Error(`关联订单的修改影响未完整返回,请重新读取后复核。`);e.relatedOrders.forEach(t=>ee({...e,order_id:t.id,before:t.before,after:t.after,summary:t.summary,relatedOrders:[]}))}if(K(e.relatedPriceLocks),e.action!==void 0&&!Object.hasOwn(se,e.action))throw Error(`变更申请类型未完整返回,请重新读取后复核。`);let i=e.summary.inventory;if(i!==void 0&&(!i||![`before`,`after`,`changes`].every(e=>Array.isArray(i[e])&&i[e].every(e=>typeof e.date==`string`&&typeof e.pocket==`string`&&Number.isSafeInteger(e.mg)))))throw Error(`变更申请库存摘要未完整返回,请重新读取后复核。`);return e}function q(e){let t=ee(e),n=t.before,r=t.after,a=(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(w.Fragment,{children:[E.Children.toArray([[`业务日期`,`date`],[`客户称呼/代号`,`customer`],[`开单人`,`salesperson`],[`收款方式与收款人`,`payment_account`],[`客户单备注`,`note`],[`内部备注(客户不可见)`,`internal_note`]].map(([e,t])=>G(e,t===`payment_account`?fe(n[t]):n[t],t===`payment_account`?fe(r[t]):r[t]))),G(`成交取整方式`,n.rounding_mode===`yuan`?`四舍五入到整数元`:`保留到分`,r.rounding_mode===`yuan`?`四舍五入到整数元`:`保留到分`)]}),G(`新增费用默认支付日期`,n.fees_date||n.date,r.fees_date||r.date)]}),G(`交付日期`,n.delivered_date,r.delivered_date)]}),o=E.Children.toArray([[`成交金额`,`total`],[`收款净额`,`netReceived`],[`货品成本`,`goodsCost`],[`实际费用合计`,`directCost`],[`利润`,`profit`],[`双方待结净额`,`settlementDue`]].map(([e,n])=>G(e,X(t.summary.before[n]),X(t.summary.after[n])))),s=E.Children.toArray(Array.from({length:Math.max(n.lines.length,r.lines.length)},(e,t)=>(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`tr`,{className:`change-section-row`,children:(0,w.jsxs)(`th`,{colSpan:3,scope:`colgroup`,children:[`商品 `,t+1]})}),E.Children.toArray([[`商品与销售计价说明`,`name`],[`商品编号`,`code`],[`克重/数量`,`quantity`],[`销售金价、工费与件数`,`pricing`],[`成交金额(含附加收费)`,`sale`],[`客户附加收费`,`charges`],[`货盘`,`pocket`],[`出库数量(对)`,`stockCount`],[`货品成本合计`,`cost`],[`进货料价与料费`,`material`],[`进货工费`,`labor`],[`其他货品成本`,`extra`],[`成本付款人`,`payers`]].map(([e,i])=>G(e,W(n.lines[t],i),W(r.lines[t],i))))]}))),c=E.Children.toArray((t.relatedOrders||[]).map(e=>(0,w.jsxs)(`section`,{className:`order-change-related`,children:[(0,w.jsxs)(`h3`,{children:[`同时受影响的关联订单:`,e.number||e.id]}),(0,w.jsx)(`p`,{className:`small muted`,children:`本次修改会重新分配同批购料的成本及付款人。以下关联订单的利润与待结金额也会随批准一起更新。`}),q({...t,order_id:e.id,before:e.before,after:e.after,summary:e.summary,relatedOrders:[],relatedPriceLocks:[]})]})));return(0,w.jsxs)(`div`,{className:`order-change-comparison`,children:[(0,w.jsx)(`p`,{className:`small muted`,children:`原值为申请时快照,申请值由服务器按本次变更试算。批准前请核对客户实付、商品、成本、费用及付款人。`}),(0,w.jsx)(`div`,{className:`table-wrap`,children:(0,w.jsxs)(i,{className:`order-change-table`,"aria-label":`变更申请原值与申请值对照`,children:[(0,w.jsx)(`thead`,{children:(0,w.jsxs)(`tr`,{children:[(0,w.jsx)(`th`,{children:`核对项目`}),(0,w.jsx)(`th`,{children:`原值(申请时)`}),(0,w.jsx)(`th`,{children:`申请值(同意后)`})]})}),(0,w.jsxs)(`tbody`,{children:[a,U(n,r),G(`订单状态`,Ie[n.status]||n.status,Ie[r.status]||r.status),G(`退货日期`,n.returned_date,r.returned_date),G(`整单优惠`,X(n.discount),X(r.discount)),o,s,(0,w.jsx)(`tr`,{className:`change-section-row`,children:(0,w.jsx)(`th`,{colSpan:3,scope:`colgroup`,children:`逐笔收退款与实际费用`})}),G(`有效客户收退款/账户`,H(n),H(r)),G(`已记实际费用/日期/付款人`,V(n),V(r))]})]})}),z(t.summary.inventory),c,L(t.relatedPriceLocks),(0,w.jsx)(`p`,{className:`small muted`,children:`双方已发生的实际交款保留;试算不会发起真实收款、退款或转账。批准时仍会校验订单和关联资料版本。`})]})}function J(e){return String(e==null||e===``?`未填写`:e).split(`
|
||
`).map((e,t)=>(0,w.jsxs)(E.Fragment,{children:[t>0&&(0,w.jsx)(`br`,{}),e]},t))}function Y(e){return e?ze(e):`待补齐`}function X(e){return e==null?`待补齐`:`¥`+Ue(e)}function Z(e){try{return X(C.cents(e))}catch{return`金额未提供`}}function Q(e,{signed:t=!1,unknown:n=`未记录对数`}={}){return Number.isSafeInteger(e)?(t&&Number(e)>0?`+`:``)+e+`对`:n}function $(t){return!!t&&e?.pocketCatalog?.some(e=>e.key===t&&e.countUnit===`pair`)===!0}function te(t){return e?.pocketCatalog?.find(e=>e.key===t)?.name||String(t??``)}function ne(e){if(!e||!Array.isArray(e.lines)||!e.lines.length||!e.lines.every(e=>[`quantity`,`materialReturnedCost`,`laborRestockedCost`,`costLoss`].every(t=>Number.isSafeInteger(e[t])))||!e.summary||![`refundAmount`,`retainedAmount`,`materialReturnedCost`,`laborRestockedCost`,`costLoss`,`directCost`,`profit`,`profitAdjustment`].every(t=>Number.isSafeInteger(e.summary[t])))throw Error(`售后核算资料未完整返回,请重新读取订单。`);return e}function re(e,{preview:t=!1}={}){let n=ne(e),i=n.summary,a=e=>`¥`+Ue(e),o=[[`实际退款`,i.refundAmount],[`扣留客户款`,i.retainedAmount],[`回料池原料成本`,i.materialReturnedCost],[`现货保留工费`,i.laborRestockedCost],[`本单货品成本损失`,i.costLoss],[`售后最终利润`,i.profit],[`本次售后利润调整`,i.profitAdjustment]];return(0,w.jsxs)(`section`,{className:`order-after-sale-summary`+(t?` is-preview`:``),"aria-label":t?`售后核对预览`:`已保存售后详情`,children:[(0,w.jsxs)(`div`,{className:`panel-title`,children:[(0,w.jsx)(`h3`,{children:t?`售后核对预览`:`售后处理结果`}),(0,w.jsx)(`span`,{className:`badge`,children:t?`尚未保存`:`已记账`})]}),(0,w.jsx)(`dl`,{className:`order-after-sale-totals`,children:E.Children.toArray(o.map(([e,t])=>(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`dt`,{children:e}),(0,w.jsx)(`dd`,{...t<0?{className:`danger-text`}:{},children:a(t)})]})))}),(0,w.jsx)(`div`,{className:`table-wrap`,children:(0,w.jsx)(r,{"aria-label":`逐件售后回库与成本`,columns:[{title:`商品与实际去向`},{title:`实际退回`},{title:`回料成本`},{title:`保留工费`},{title:`成本损失`}],rows:n.lines.map((e,t)=>({key:t,cells:[(0,w.jsxs)(w.Fragment,{children:[e.name||`商品 `+(e.lineIndex+1),(0,w.jsxs)(`div`,{className:`small muted`,children:[te(e.pocket),` · `,e.disposition===`stock`?`完好现货`:`旧料/损坏`]})]}),(0,w.jsxs)(w.Fragment,{children:[ke(e.quantity),`g`,e.disposition===`stock`&&$(e.pocket)?(0,w.jsx)(`div`,{className:`small`,children:Q(e.stockCount)}):``]}),a(e.materialReturnedCost),a(e.laborRestockedCost),a(e.costLoss)]}))})}),(0,w.jsx)(`p`,{className:`small muted`,children:`实退材料按原成本回售后日料池,不新增采购付款。完好现货工费留在退回现货批次;旧料工费与未退回材料成本计损失。原单实际费用继续保留。`})]})}function ie(e){let t=e.action||`edit`,n=e.action_input||e.action_details||{};if(t===`edit`)return``;if(n.afterSale){let t=ve(e.after);return(0,w.jsxs)(`section`,{className:`order-change-action-summary`,children:[(0,w.jsx)(`h3`,{children:`本次售后申请`}),(0,w.jsxs)(`p`,{children:[`售后日期:`,n.date,` · 申请原因:`,e.reason]}),re(t,{preview:!0})]})}let r=[[`申请动作`,ce(e)],[`业务日期`,n.date||e.after.returned_date||e.after.date]];return n.amount!==void 0&&r.push([`本次金额`,Z(n.amount)]),n.account&&r.push([`退款账户`,fe(n.account)]),n.payer&&r.push([`实际付款人`,Y(n.payer)]),n.note&&r.push([`费用项目/说明`,n.note]),n.reference&&r.push([`退款凭据备注`,n.reference]),Array.isArray(n.returnCounts)&&r.push([`实际退回数量(对)`,n.returnCounts.map((e,t)=>`商品 `+(t+1)+`:`+Q(e==null?null:Number(e))).join(`
|
||
`)]),Array.isArray(n.returnPockets)&&r.push([`退货实物去向`,n.returnPockets.map((t,n)=>`${e.before.lines[n]?.name||`商品 `+(n+1)}:${te(t)||`退供应商/不留黄金货盘`}`).join(`
|
||
`)]),Array.isArray(n.fee_items)&&r.push([`本次旧费用`,n.fee_items.map(e=>`${e.note||`费用`}:${Z(e.amount)} · ${Y(e.payer)}支付`).join(`
|
||
`)]),(0,w.jsxs)(`section`,{className:`order-change-action-summary`,children:[(0,w.jsx)(`h3`,{children:`本次申请动作`}),(0,w.jsx)(`dl`,{className:`order-change-action-facts`,children:E.Children.toArray(r.map(([e,t])=>(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`dt`,{children:e}),(0,w.jsx)(`dd`,{children:J(t)})]})))}),(0,w.jsx)(`p`,{className:`small muted`,children:`下方对照为服务器试算;批准后才登记这笔变更,不会由系统发起真实收款、退款或转账。`})]})}function ae(e){let t=new Date(e);return Number.isNaN(t.getTime())?`时间未提供`:t.toLocaleString(`zh-CN`)}let oe={pending:`待店主复核`,approved:`已同意变更`,rejected:`已驳回`},se={edit:`修改订单`,expense:`费用补记`,fees:`旧费用核实`,refund:`退款`,return:`退货`,cost:`成本补录`};function ce(e){return(e.action_input||e.action_details)?.afterSale?`处理订单售后`:e.action_label||se[e.action||`edit`]||`订单变更`}let le={pending:`待店主复核`,approved:`已同意取消`,rejected:`已驳回`};function ue(e){let t=new Date(e);return Number.isNaN(t.getTime())?`时间未提供`:t.toLocaleString(`zh-CN`)}let de=e=>x.accountIdentity(Be(),e);function fe(e){let t=de(e);return t?ze(t.member)+t.channel:e}function pe(e){if(!e||![`total`,`netReceived`,`directCost`].every(t=>Number.isSafeInteger(e[t]))||![`goodsCost`,`profit`,`settlementDue`].every(t=>e[t]===null||Number.isSafeInteger(e[t]))||!Array.isArray(e.inventory)||!e.inventory.every(e=>typeof e.date==`string`&&typeof e.pocket==`string`&&Number.isSafeInteger(e.mg)))throw Error(`取消撤销摘要未完整返回,请重新读取订单。`);return e}function me(e=o){let t=Ee(e)?.data;if(!t?.eligible||t.pending||t.directToday!==!0||!/^\d{4}-\d{2}-\d{2}$/.test(t.directActionDate||``)||e?.date!==t.directActionDate||e?.price_lock_id||![`draft`,`confirmed`,`delivered`].includes(e?.status||``))return!1;try{return pe(t.summary),!0}catch{return!1}}function he(t,n=e.today,r=o){let i=Ce(r)?.data;return[`expense`,`fees`,`refund`,`return`].includes(t)&&!!i&&!i.pending&&/^\d{4}-\d{2}-\d{2}$/.test(i.directActionDate||``)&&i.actions?.[t]?.directToday===!0&&r?.date===i.directActionDate&&n===i.directActionDate&&!(d.action===t&&d.forceApproval)}function ge(t){return e.user.role===`assistant`&&[`expense`,`fees`,`refund`,`return`,`cost`].includes(t)}function _e(t,n=e.today){return ge(t)&&!he(t,n)}function ve(e){return e?.orderAfterSale||null}function ye(){return a?.user?.id||``}function be(e=o){return e&&l?.id===e.id&&l.user===ye()&&l.revision===e.revision?l:null}function xe(e=o){return be(e)?.data?.pending||e?.ownershipPending||null}function Se(){return a?.user?.id||``}function Ce(e=o){return e&&c?.id===e.id&&c.user===Se()&&c.revision===e.revision?c:null}function we(e){return Ce(e)?.data?.pending||e?.changePending||null}function Te(){return a?.user?.id||``}function Ee(e=o){return e&&u?.id===e.id&&u.user===Te()&&u.revision===e.revision?u:null}function De(e){return Ee(e)?.data?.pending||e.cancellationPending||null}function Oe(e){if([`afterSale`,`orderAfterSale`].includes(e.kind??``))return``;let t=e.printStatus?.printed;return(0,w.jsx)(`span`,{"data-print-kind":e.printStatus?.kind||(e.kind===`recovery`?`recovery`:`order`),"data-print-id":e.printStatus?.id||e.id,className:`document-print-badge `+(t?`is-printed`:`is-unprinted`),title:t?`已记录打印操作`:`尚未记录打印操作`,children:t?`✓ 已打印`:`未打印`})}let ke=x.grams,Ae=e=>String(e??``),je=new Intl.DateTimeFormat(`zh-CN`,{timeZone:`Asia/Shanghai`,year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,hourCycle:`h23`}),Me=x.validDate;function Ne(e){if(typeof e!=`string`||!/^\d{4}-\d{2}-\d{2}T(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d{1,3})?)?(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)$/.test(e)||!Me(e.slice(0,10)))return`未记录`;let t=new Date(e);if(Number.isNaN(t.getTime()))return`未记录`;let n=Object.fromEntries(je.formatToParts(t).map(e=>[e.type,e.value]));return`${n.year}-${n.month}-${n.day} ${n.hour}:${n.minute}`}function Pe(e){return(0,w.jsxs)(`div`,{className:`small muted order-entry-time`,children:[`录入时间(北京时间):`,Ne(e.created)]})}function Fe(e){return![`afterSale`,`orderAfterSale`,`recovery`].includes(e.kind??``)&&Number.isSafeInteger(e.revision)&&e.revision>0&&e.reviewed_revision===e.revision}let Ie={draft:`旧草稿`,confirmed:`旧单待补齐`,delivered:`已完成`,returned:`已退货`,cancelled:`已取消`,after_sale:`售后`,recovery:`回收`},Le=e=>(0,w.jsx)(`span`,{className:`order-status `+([`draft`,`confirmed`].includes(e.status)?`danger-text`:`muted`),children:Ie[e.status]||e.status}),Re=(e,t,n=``,r={})=>(0,w.jsx)(s,{type:`button`,"data-action":t,className:n,...r,children:e});function ze(t){return e?.shopSettings?.members?.find(e=>e.member===t)?.label||e?.members?.find(e=>e.member===t)?.label||a?.loginOptions?.find(e=>e.member===t)?.label||{owner:`麦麦`,assistant:`娜娜`,assistant2:`小昊`}[t??``]||`待确认`}let Be=()=>x.memberKeys(e),Ve=t=>x.memberEnabled(e,t);function He(){return!!(e?.user?.member||e?.members?.some(e=>e.member===`assistant2`))}let Ue=e=>e==null?`待补`:x.yuan(e);return{yuan:Ue,teamMode:He,teamMemberKeys:Be,teamMemberName:ze,badge:Le,orderEntryTimeHTML:Pe,showOrderCopyEntry:!1,button:Re,e:Ae,printStatusBadge:Oe,orderIsReviewed:Fe,grams:ke,validOrderDate:Me,activePocketKeys:h,pocketLabel:te,accountDisplayName:fe,orderCancellationPending:De,orderChangePending:we,orderOwnershipPending:xe,orderAfterSaleRecord:ve,orderActionRequiresApproval:_e,actionName:A,currentOrderCancellation:Ee,orderCancellationCanDirect:me,currentOrderOwnership:be,orderCancellationTime:ue,orderCancellationStatus:le,currentOrderChange:Ce,orderChangeActionLabel:ce,orderChangeStatus:oe,orderChangeTime:ae,orderChangeActionSummaryHTML:ie,orderChangeComparisonHTML:q,orderOwnershipPairHTML:I,orderOwnershipTime:M,orderOwnershipEffectHTML:j,orderOwnershipStatus:P,orderAfterSaleSummaryHTML:re,stockCountText:Q,pocketCountsEnabled:$,orderActionUsesChangeForm:ge,moneyField:D,choice:T,teamMemberOptions:b,field:O,stockCountField:g,activePaymentAccounts:p,orderChangeActionLabels:se,normalizePaymentAccount:v,accountIdentity:de,memberAccountPrefix:x.memberAccountPrefix,teamMemberEnabled:Ve,opts:k,currentMember:_,stockCountValue:f,validateOrderCancellationSummary:pe,inventoryCountHTML:R,orderChangeMoney:X,validateOrderChangeRequest:ee,validateOrderOwnershipRequest:F,orderActionCanDirect:he,orderChangeUser:Se}}function O({orderBookFilters:e,state:t},{yuan:n,teamMode:a,teamMemberKeys:o,teamMemberName:c,badge:l,orderEntryTimeHTML:u,showOrderCopyEntry:d,button:f,e:p,printStatusBadge:m,orderIsReviewed:h,grams:g,validOrderDate:_,activePocketKeys:v,pocketLabel:y,accountDisplayName:b}){let S=e=>e?c(e):`待补`;function C(e){return e?[...e.customerCash||[],...e.orderPayments||[]].map(e=>({...e,activityType:e.kind===`receipt`?`客户收款`:`客户退款`,who:b(e.account),activityName:e.product||`客户收退款`})).concat((e.materialOutlays||[]).map(e=>({...e,activityType:e.source===`extra`?`补重料费付款`:`原锁料费付款`,who:S(e.payer),activityName:(e.product||`黄金`)+` · `+g(e.quantity)+`g × `+n(e.rate)+`元/克`})),(e.deliveryGoodsOutlays||[]).map(e=>({...e,activityType:`交付货品支出`,who:S(e.payer),activityName:e.name})),(e.directOutlays||[]).map(e=>({...e,activityType:`实际费用`,who:S(e.payer),activityName:e.note}))).sort((e,t)=>e.date.localeCompare(t.date)):[]}function T(e){if(!e?.summary?.eventCount)return``;let t=e.summary,i=C(e);return(0,w.jsxs)(`section`,{className:`panel lock-activity`,children:[(0,w.jsx)(`h2`,{children:`锁价实际收付`}),(0,w.jsxs)(`p`,{className:`small muted`,children:[e.from===e.date?e.date:e.from+` 至 `+e.date,`实际发生的锁价收退款与支出。此区不随订单搜索或状态筛选变化;每日对账归集这些收付。待交付不计销售和利润;交付日计入完整订单利润,原锁料款不重复记支出。`]}),(0,w.jsxs)(`div`,{className:`lock-activity-summary`,children:[(0,w.jsxs)(`span`,{children:[`客户实收`,(0,w.jsxs)(`strong`,{children:[`¥`,n(t.receipt)]})]}),(0,w.jsxs)(`span`,{children:[`客户实退`,(0,w.jsxs)(`strong`,{children:[`¥`,n(t.refund)]})]}),(0,w.jsxs)(`span`,{children:[c(`owner`),`实际支出`,(0,w.jsxs)(`strong`,{children:[`¥`,n(t.ownerOutlay)]})]}),(0,w.jsxs)(`span`,{children:[c(`assistant`),`实际支出`,(0,w.jsxs)(`strong`,{children:[`¥`,n(t.assistantOutlay)]})]})]}),(0,w.jsxs)(`details`,{children:[(0,w.jsxs)(`summary`,{children:[`查看 `,i.length,` 项收付记录`]}),(0,w.jsx)(`div`,{className:`table-wrap`,children:(0,w.jsx)(r,{className:`lock-activity-table`,columns:[{title:`日期/锁价单`},{title:`项目/客户`},{title:`账户/付款人`},{title:`金额`,headerClassName:`number`}],rows:i.map((e,t)=>({key:t,cellClasses:[void 0,void 0,void 0,`number`],cells:[(0,w.jsxs)(w.Fragment,{children:[e.date,(0,w.jsx)(`br`,{}),(0,w.jsx)(s,{className:`link-button`,"data-action":`open-price-lock`,"data-id":e.price_lock_id,children:e.number||`锁价记录`})]}),(0,w.jsxs)(w.Fragment,{children:[e.activityType,` · `,e.activityName,(0,w.jsx)(`div`,{className:`small muted`,children:e.customer})]}),e.who,e.amount==null?`待补齐`:`¥`+n(e.amount)]}))})})]})]})}let D=[[``,`全部状态`],[`reviewed`,`已复核`],[`unreviewed`,`未复核`],[`after_sale`,`售后`],[`recovery`,`回收`],[`price_lock`,`锁价`]],O=[[`today`,`今天`],[`yesterday`,`昨天`],[`month`,`本月`],[`date`,`某天`],[`range`,`自定义区间`]];function k(){return`销售与利润按开单/交付日期,售后与回收按记录日期筛选。普通订单收款显示当前累计;锁价收退款按实际发生日期计入,待交付不计销售和利润。已取消订单不计本页销售汇总;直接回收付款计入每日购料,不计销售和利润。`}let A=x.previousDate,j=()=>e;function M(){let e=j(),n=t.today;if(e.mode===`range`){if(!e.from||!e.to)throw Error(`请选择开始日期和结束日期。`);if(!_(e.from)||!_(e.to)||e.from<`2000-01-01`||e.to<`2000-01-01`)throw Error(`日期区间无效,请选择2000-01-01起的有效日期。`);if(e.from>n||e.to>n)throw Error(`请选择今天或之前的日期。`);if(e.from>e.to)throw Error(`开始日期不能晚于结束日期。`);return{from:e.from,date:e.to,name:`自定义区间`}}if(e.mode===`date`){if(!e.date)throw Error(`请选择要查看的日期。`);if(!_(e.date))throw Error(`日期无效,请重新选择。`);if(e.date>n)throw Error(`请选择今天或之前的日期。`);return{from:e.date,date:e.date,name:e.date}}if(e.mode===`yesterday`){let e=A(n);return{from:e,date:e,name:`昨日`}}return{from:e.mode===`month`?n.slice(0,7)+`-01`:n,date:n,name:e.mode===`month`?`本月`:`今日`}}function N(){let e=v(),n=[...new Set([...(t?.pocketCatalog||[]).filter(e=>!e.active).map(e=>e.key),...(t?.orders||[]).flatMap(e=>(e.lines||[]).map(e=>e.pocket))].filter(t=>t&&!e.includes(t)))];return[[``,`全部货盘`],[`external`,`配货`],...e.map(e=>[e,y(e)]),...n.map(e=>[e,y(e)+`(已停用 · 历史)`])]}function P(e,t,r){return(0,w.jsx)(`div`,{className:`order-mobile-list`,children:E.Children.toArray(e.map(e=>(0,w.jsxs)(`article`,{className:`order-mobile-card `+(e.status===`cancelled`||e.status===`returned`?`order-reversed`:``),children:[(0,w.jsx)(`div`,{className:`order-mobile-heading`,children:H(e,t)}),(0,w.jsxs)(`div`,{className:`order-mobile-meta`,children:[e.date,` · `,e.kind===`recovery`?`已记录`:l(e),` `,B(e)]}),(0,w.jsxs)(`div`,{className:`order-mobile-amounts`,children:[(0,w.jsxs)(`div`,{children:[(0,w.jsxs)(`span`,{children:[`克重/件数`,e.kind===`recovery`?`(折后)`:``]}),(0,w.jsx)(`strong`,{children:z(e)})]}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`span`,{children:`售价`}),(0,w.jsx)(`strong`,{children:R(e,`sale`)})]})]}),e.status===`cancelled`?(0,w.jsx)(`p`,{className:`small muted`,children:`已取消,未计入汇总`}):``,(e.balance??0)<0?(0,w.jsx)(`p`,{className:`small danger-text`,children:`退款待处理`}):``,(0,w.jsxs)(`details`,{className:`order-mobile-breakdown`,children:[(0,w.jsx)(`summary`,{children:`成本、利润与备注`}),(0,w.jsxs)(`dl`,{children:[(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`dt`,{children:`货盘/类型`}),(0,w.jsx)(`dd`,{children:e.types.map(p).join(`、`)||`—`})]}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`dt`,{children:`料成本`}),(0,w.jsx)(`dd`,{children:R(e,`material`)})]}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`dt`,{children:`工费及附加成本`}),(0,w.jsxs)(`dd`,{children:[R(e,`laborAndFees`),L(e)]})]}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`dt`,{children:`成本合计`}),(0,w.jsxs)(`dd`,{children:[R(e,`totalCost`),e.unallocated?(0,w.jsxs)(`div`,{className:`small muted`,children:[`含未分项 ¥`,n(e.unallocated)]}):``,e.pendingCosts?(0,w.jsxs)(`div`,{className:`small danger-text`,children:[`另有 `,e.pendingCosts,` 项费用未入账`]}):``]})]}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`dt`,{children:`利润`}),(0,w.jsx)(`dd`,{children:R(e,`profit`)})]})]}),(0,w.jsx)(`div`,{className:`order-mobile-note`,children:e.kind===`afterSale`?I(e)+`支付`:e.note||`暂无备注`}),(0,w.jsx)(`div`,{className:`order-mobile-print-status`,children:m(e)}),e.costHint?(0,w.jsx)(`p`,{className:`small `+(e.incomplete?`danger-text`:`muted`),children:e.costHint}):``,[`afterSale`,`orderAfterSale`,`recovery`].includes(e.kind??``)?``:u(e),r&&![`afterSale`,`orderAfterSale`,`recovery`].includes(e.kind??``)?f(`复制新增`,`copy-order`,`order-copy-button`,{"data-id":e.id}):``]})]})))})}function F(e){return(0,w.jsxs)(w.Fragment,{children:[g(e.mg)+`g`+(e.pieces?` / `+e.pieces+`件`:``),(0,w.jsx)(`div`,{className:`small muted`,children:`克重不含银饰`})]})}function I(e){return e.costItems?.[0]?.payer?c(e.costItems[0].payer):`付款人待补`}function L(e){if(e.kind===`recovery`||e.status===`draft`)return``;if(e.kind===`afterSale`)return(0,w.jsx)(`div`,{className:`order-fee-parts`,children:(0,w.jsx)(`span`,{children:`售后费用`})});if(e.kind===`orderAfterSale`)return(0,w.jsx)(`div`,{className:`order-fee-parts`,children:(0,w.jsx)(`span`,{children:`原单售后成本调整`})});let t=new Map;for(let n of e.laborAndFeeItems||[]){let e=n.component+`:`+n.name,r=t.get(e);t.set(e,{name:n.name,amount:(r?.amount||0)+(n.amount||0),missing:r?.missing||n.amount==null})}let r=[...t.values()].filter(e=>e.amount||e.missing);return r.length?(0,w.jsx)(`div`,{className:`order-fee-parts`,children:E.Children.toArray(r.map(e=>(0,w.jsxs)(`span`,{children:[e.name,` `,e.missing?e.amount?`已知 ¥`+n(e.amount)+`,待补`:`待补`:`¥`+n(e.amount)]})))}):``}function R(e,t){if(e.kind===`recovery`)return(0,w.jsx)(`span`,{className:`muted`,children:`—`});if(e.status===`draft`)return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`span`,{className:`muted`,children:`未开单`}),t===`sale`&&e.originalSale!=null?(0,w.jsxs)(`div`,{className:`small muted`,children:[`报价 ¥`,n(e.originalSale)]}):``]});if(e[t]!=null)return`¥`+n(e[t]);let r=e.known?.[t],i=[`material`,`laborAndFees`].includes(t)&&e.legacyUnallocated,a=i?`未分项`:e.materialCostPending&&[`material`,`totalCost`,`profit`].includes(t)?`料费待补`:t===`profit`&&e.status===`confirmed`?`旧单待补齐`:`待补齐`;return(0,w.jsxs)(w.Fragment,{children:[r?`已知 ¥`+n(r):``,(0,w.jsx)(`div`,{className:`small `+(i?`muted`:`danger-text`),children:a})]})}function z(e){return[e.mg?g(e.mg)+`g`:``,e.pieces?e.pieces+`件`:``].filter(Boolean).join(` / `)||`—`}function B(e){return h(e)?(0,w.jsx)(`span`,{className:`order-review-status`,children:`已复核`}):``}function V(e){return f(`修改`,`after-sale-edit`,`after-sale-edit-button`,{"data-id":e.after_sale_id||e.id,"aria-label":`修改 `+e.customer+` 的售后记录`})}function H(e,t=void 0){if(e.kind===`orderAfterSale`)return(0,w.jsxs)(s,{className:`link-button order-book-link order-book-customer-first`,"data-action":`open-order`,"data-id":e.order_id||e.id,children:[(0,w.jsx)(`strong`,{className:`order-book-customer-name`,children:e.customer||`未填称呼`}),(0,w.jsxs)(`span`,{className:`order-book-secondary muted`,children:[`订单售后 · `,e.paper_number||e.number]}),(0,w.jsx)(`span`,{className:`small muted`,children:`查看原单售后结果`})]});if(e.kind===`recovery`)return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(s,{className:`link-button order-book-link order-book-customer-first`,"data-action":`recovery-open`,"data-id":e.recovery_id||e.id,children:[(0,w.jsxs)(`span`,{className:`order-book-identity-line`,children:[(0,w.jsx)(`strong`,{className:`order-book-customer-name`,children:e.customer||`未填称呼`}),(0,w.jsx)(`span`,{className:`order-book-recovery-badge`,children:`回收`})]}),(0,w.jsx)(`span`,{className:`order-book-secondary muted`,children:e.number}),(0,w.jsxs)(`span`,{className:`order-book-recovery-payment`,children:[`回收付款 ¥`,n(e.cashPayment)]})]}),f(`打印`,`recovery-print`,`quiet order-book-recovery-print`,{"data-id":e.recovery_id||e.id,"aria-label":`打印 `+(e.customer||`客户`)+` 的回收单`})]});if(t!==void 0){let n=(0,w.jsx)(`strong`,{className:`order-book-customer-name`,children:e.customer||`未填称呼`}),r=e.recovery_mode===`exchange`?(0,w.jsxs)(`span`,{className:`order-book-identity-line`,children:[n,(0,w.jsx)(`span`,{className:`order-book-recovery-badge is-exchange`,children:`置换`})]}):n;return e.kind===`afterSale`?(0,w.jsxs)(`div`,{className:`after-sale-identity order-book-customer-first`,children:[r,(0,w.jsxs)(`span`,{className:`order-book-secondary muted`,children:[`售后 · `,e.project||e.note]}),V(e)]}):(0,w.jsxs)(s,{className:`link-button order-book-link order-book-customer-first`,"data-action":`open-order`,"data-id":e.id,"data-order-book-version":t,children:[r,(0,w.jsx)(`span`,{className:`order-book-secondary muted`,children:e.paper_number||e.number})]})}return e.kind===`afterSale`?(0,w.jsxs)(`div`,{className:`after-sale-identity`,children:[(0,w.jsxs)(`strong`,{children:[`售后 · `,e.project||e.note]}),(0,w.jsx)(`span`,{children:e.customer}),V(e)]}):(0,w.jsxs)(s,{className:`link-button order-book-link`,"data-action":`open-order`,"data-id":e.id,"data-order-book-version":t,children:[(0,w.jsx)(`strong`,{children:e.paper_number||e.number}),(0,w.jsx)(`span`,{children:e.customer||`未填称呼`})]})}let U=(e,t,n=``,r=!1)=>(0,w.jsxs)(`div`,{className:`stat `+(r?`emphasis`:``),children:[(0,w.jsx)(`small`,{children:e}),(0,w.jsx)(`strong`,{children:t}),(0,w.jsx)(`div`,{className:`hint`,children:n})]});function W(e,t){let r=e.unknownCounts?.[t]||0,i=e.knownCounts?.[t];return r&&i===0&&!e[t]&&!e.afterSaleCount?(0,w.jsx)(`span`,{className:`muted`,children:[`material`,`laborAndFees`].includes(t)&&e.unallocated?`未分项`:`未补齐`}):(r?`已知 `:``)+`¥`+n(e[t])}function G(e){let t=e?.summaryWithoutCancelled,n=e?.receiptsWithoutCancelled;if(!Array.isArray(e?.rows)||e.displayRows!==void 0&&!Array.isArray(e.displayRows)||e.recoveryCount!==void 0&&(!Number.isSafeInteger(e.recoveryCount)||e.recoveryCount<0)||!t||!n||n.basis!==`orderDate`||n.filterScope!==`matchingOrdersWithoutCancelled`||n.from!==e.from||n.date!==e.date||![`sale`,`material`,`laborAndFees`,`unallocated`,`totalCost`,`profit`,`ownerCost`,`assistantCost`].every(e=>Number.isSafeInteger(t[e])&&Number.isSafeInteger(t.knownCounts?.[e])&&t.knownCounts[e]>=0&&Number.isSafeInteger(t.unknownCounts?.[e])&&t.unknownCounts[e]>=0)||![`orderCount`,`completedCount`,`draftCount`,`incompleteCount`,`afterSaleCount`,`recordCount`,`mg`,`pieces`,`unknownCosts`,`unknownCostCount`,`unknownProfitCount`].every(e=>Number.isSafeInteger(t[e])&&t[e]>=0)||![`receipt`,`refund`,`net`].every(e=>Number.isSafeInteger(n[e]))||!Array.isArray(n.channels)||!n.channels.every(e=>e&&typeof e.name==`string`&&[`receipt`,`refund`,`net`].every(t=>Number.isSafeInteger(e[t])))||![`wechat`,`alipay`,`cash`].every(e=>n.channels.some(t=>t.channel===e)))throw Error(`订单汇总数据尚未完整返回,请刷新后重新读取。`);return e}function K(t,r){G(t);let s=t.summaryWithoutCancelled,h=t.receiptsWithoutCancelled,g=t.recoveryCount||0,_={version:1},v=t.rows.filter(e=>e.status===`cancelled`).length,y=s.unknownProfitCount||0,b=s.unknownCosts||0,x=(s.unknownCostCount||0)>0||b>0,S=[`已完成 ${s.completedCount} 单`,g?`另有回收 ${g} 笔`:null,s.afterSaleCount?`另有售后 ${s.afterSaleCount} 笔`:null,s.draftCount?`旧草稿 ${s.draftCount} 单`:null,s.incompleteCount?`${s.incompleteCount} 单账务待补齐`:null,v?`${v} 单取消未计汇总`:null].filter(Boolean).join(` · `),C=[`wechat`,`alipay`,`cash`,`credit_card`].map(e=>h.channels.find(t=>t.channel===e)||{channel:e,name:{wechat:`微信`,alipay:`支付宝`,cash:`现金`,credit_card:`信用卡`}[e],receipt:0,refund:0}).filter(e=>![`cash`,`credit_card`].includes(e.channel)||e.receipt!==0||e.refund!==0),T=(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`div`,{className:`order-stat-lines`,children:E.Children.toArray(C.map(e=>(0,w.jsxs)(`span`,{children:[(0,w.jsx)(`b`,{children:e.name}),(0,w.jsxs)(`span`,{children:[`¥`,n(e.receipt)]})]})))}),(0,w.jsxs)(`div`,{className:`order-stat-refund`,children:[`退款 ¥`,n(h.refund)]})]}),D=(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`div`,{className:`order-stat-lines`,children:E.Children.toArray((a()?o():[`owner`,`assistant`]).map(e=>(0,w.jsxs)(`span`,{children:[(0,w.jsx)(`b`,{children:c(e)}),(0,w.jsx)(`span`,{children:W(s,`${e}Cost`)})]})))}),x?(0,w.jsxs)(`div`,{className:`order-stat-refund danger-text`,children:[s.unknownCostCount?`${s.unknownCostCount} 单成本未补齐`:``,s.unknownCostCount&&b?` · `:``,b?`${b} 项成本未补齐/未入账`:``]}):``]}),O=s.unknownCostCount&&s.knownCounts?.totalCost===0&&!s.totalCost&&!s.afterSaleCount?`未补齐`:`¥`+n(s.totalCost),k=(0,w.jsxs)(w.Fragment,{children:[U(r.name+`销售订单`,(0,w.jsxs)(w.Fragment,{children:[s.orderCount,(0,w.jsx)(`span`,{className:`stat-unit`,children:`单`})]}),S),U(r.name+`利润`+(y?`(已核算部分)`:``),y&&s.knownCounts?.profit===0&&!s.profit&&!s.afterSaleCount?`待补齐`:`¥`+n(s.profit),y?y+` 单利润待补齐`:`已扣货品成本、实际费用和售后费用`,!0),U(r.name+`收款`,`¥`+n(h.receipt),T),U(r.name+`成本`+(x?`(已知部分)`:``),O,D)]}),A=`${r.name} · 汇总 ${s.orderCount} 单${g?` · 回收 `+g+` 笔`:``}${s.afterSaleCount?` · 售后 `+s.afterSaleCount+` 笔`:``}${v?`,另有 `+v+` 单取消未计`:``}${e.q||e.status||e.pocket||e.member?`(已筛选)`:``}`,j=t.displayRows??t.rows;return j.length?{cards:k,count:A,list:[(0,w.jsx)(`div`,{className:`table-wrap order-book-table-wrap`,children:(0,w.jsxs)(i,{className:`order-book-table`,"aria-label":r.name+`订单账本`,children:[(0,w.jsx)(`thead`,{children:(0,w.jsxs)(`tr`,{children:[(0,w.jsx)(`th`,{className:`order-index`,children:`序号`}),(0,w.jsx)(`th`,{children:`客户/销售、回收或售后`}),(0,w.jsx)(`th`,{children:`类型`}),(0,w.jsx)(`th`,{className:`number`,children:`克重/件数`}),(0,w.jsx)(`th`,{className:`number`,children:`售价`}),(0,w.jsx)(`th`,{className:`number`,children:`料成本`}),(0,w.jsx)(`th`,{className:`number`,children:`工费及附加成本`}),(0,w.jsx)(`th`,{className:`number`,children:`成本合计`}),(0,w.jsx)(`th`,{className:`number`,children:`利润`}),(0,w.jsx)(`th`,{children:`备注`}),(0,w.jsx)(`th`,{className:`order-print-status`,children:`打印状态`})]})}),(0,w.jsx)(`tbody`,{children:E.Children.toArray(j.map((e,t)=>(0,w.jsxs)(`tr`,{className:[`afterSale`,`orderAfterSale`].includes(e.kind??``)?`order-after-sale`:e.kind===`recovery`?`order-recovery`:e.status===`draft`?`order-draft`:e.status===`returned`||e.status===`cancelled`?`order-reversed`:``,children:[(0,w.jsx)(`td`,{className:`order-index`,children:t+1}),(0,w.jsxs)(`td`,{className:`order-customer`,children:[H(e,_.version),(0,w.jsxs)(`div`,{className:`small muted`,children:[`业务日期 `,e.date,` ·`,` `,e.kind===`recovery`?(0,w.jsx)(`span`,{className:`order-status muted`,children:`已记录`}):l(e),B(e)]}),[`afterSale`,`orderAfterSale`,`recovery`].includes(e.kind??``)?``:u(e),d&&![`afterSale`,`orderAfterSale`,`recovery`].includes(e.kind??``)?f((0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`span`,{"aria-hidden":`true`,children:`+`}),`复制新增`]}),`copy-order`,`order-copy-button`,{"data-id":e.id,"aria-label":`复制 `+(e.paper_number||e.number)+` 为新订单`}):``,e.status===`cancelled`?(0,w.jsx)(`div`,{className:`small muted`,children:`未计入汇总`}):``,(e.balance??0)<0?(0,w.jsx)(`div`,{className:`small danger-text`,children:`退款待处理`}):``]}),(0,w.jsx)(`td`,{className:`order-type`,children:e.types.map(p).map((e,t)=>(0,w.jsxs)(E.Fragment,{children:[t>0&&(0,w.jsx)(`br`,{}),e]},t))||`—`}),(0,w.jsxs)(`td`,{className:`number`,children:[z(e),e.kind===`recovery`?(0,w.jsx)(`div`,{className:`small muted`,children:`折后克重`}):``]}),(0,w.jsx)(`td`,{className:`number`,children:R(e,`sale`)}),(0,w.jsx)(`td`,{className:`number`,children:R(e,`material`)}),(0,w.jsxs)(`td`,{className:`number order-fees`,children:[R(e,`laborAndFees`),L(e)]}),(0,w.jsxs)(`td`,{className:`number`,children:[R(e,`totalCost`),e.unallocated?(0,w.jsxs)(`div`,{className:`small muted`,children:[`含未分项 ¥`,n(e.unallocated)]}):``,e.pendingCosts?(0,w.jsxs)(`div`,{className:`small danger-text`,children:[`另有 `,e.pendingCosts,` 项费用未入账`]}):``]}),(0,w.jsx)(`td`,{className:`number order-profit`,children:R(e,`profit`)}),(0,w.jsxs)(`td`,{className:`order-notes`,children:[e.kind===`afterSale`?I(e)+`支付`:e.note||(0,w.jsx)(`span`,{className:`muted`,children:`—`}),e.costHint?(0,w.jsx)(`div`,{className:`small `+(e.incomplete?`danger-text`:`muted`),children:e.costHint}):``]}),(0,w.jsx)(`td`,{className:`order-print-status`,children:m(e)||`—`})]})))}),(0,w.jsx)(`tfoot`,{children:(0,w.jsxs)(`tr`,{children:[(0,w.jsxs)(`td`,{colSpan:2,children:[`汇总 `,s.orderCount,` 单`,g?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`br`,{}),`回收 `,g,` 笔`]}):``,s.afterSaleCount?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`br`,{}),`售后 `,s.afterSaleCount,` 笔`]}):``]}),(0,w.jsx)(`td`,{}),(0,w.jsx)(`td`,{className:`number`,children:F(s)}),(0,w.jsx)(`td`,{className:`number`,children:W(s,`sale`)}),(0,w.jsx)(`td`,{className:`number`,children:W(s,`material`)}),(0,w.jsx)(`td`,{className:`number`,children:W(s,`laborAndFees`)}),(0,w.jsxs)(`td`,{className:`number`,children:[x?`已知 `:``,`¥`,n(s.totalCost),s.unallocated?(0,w.jsxs)(`div`,{className:`small muted`,children:[`含未分项 ¥`,n(s.unallocated)]}):``]}),(0,w.jsx)(`td`,{className:`number`,children:W(s,`profit`)}),(0,w.jsx)(`td`,{className:`small order-notes`,children:[v?v+` 单取消未计汇总`:``,s.draftCount?s.draftCount+` 单草稿未计金额`:``,s.unknownCostCount?s.unknownCostCount+` 单成本未补齐`:``,y?y+` 单利润待补齐`:``].filter(Boolean).join(`;`)||`账本金额`}),(0,w.jsx)(`td`,{})]})})]})}),P(j,1,d)]}:{cards:k,count:A,list:(0,w.jsxs)(`div`,{className:`empty`,children:[(0,w.jsx)(`strong`,{children:`这个日期没有符合条件的订单、回收或售后`}),`可以切换日期,或调整搜索和状态筛选。`]})}}return{renderOrderBook:K,orderBookRange:M,orderBookPocketOptions:N,orderBookScope:k,orderBookPeriodOptions:O,orderBookStatusOptions:D,priceLockActivityHTML:T,teamMemberName:c}}function k({currentOrder:e,state:t,detailForm:n,error:a,navigation:o},{orderCancellationPending:s,orderChangePending:c,orderOwnershipPending:l,orderAfterSaleRecord:u,button:d,showOrderCopyEntry:f,orderActionRequiresApproval:p,teamMode:m,orderIsReviewed:h,accountDisplayName:g,badge:_,teamMemberName:v,orderEntryTimeHTML:y,yuan:b,actionName:x,currentOrderCancellation:S,orderCancellationCanDirect:T,currentOrderOwnership:D,e:O,printStatusBadge:k,orderCancellationTime:A,orderCancellationStatus:j,currentOrderChange:M,orderChangeActionLabel:N,orderChangeStatus:P,orderChangeTime:F,orderChangeActionSummaryHTML:I,orderChangeComparisonHTML:L,orderOwnershipPairHTML:R,orderOwnershipTime:z,orderOwnershipEffectHTML:B,orderOwnershipStatus:V,orderAfterSaleSummaryHTML:H,grams:U,pocketLabel:W,stockCountText:G,pocketCountsEnabled:K,teamMemberKeys:ee}){function q(e){let t=[...e.payments.map(e=>({date:e.date,type:String(e.reference||``).startsWith(`更正冲回:取消审批作废;`)?`作废冲回`+(e.kind===`receipt`?`收款`:`退款`):e.kind===`receipt`?`客户收款`:`客户退款`,amount:e.amount,who:g(e.account),note:e.reference})),...e.expenses.map(e=>({date:e.date,type:String(e.note||``).startsWith(`更正冲回:取消审批作废;`)?`作废冲回费用`:`直接费用`,amount:e.amount,who:v(e.payer)+`支付`,note:e.note})),...e.settlements.map(e=>({date:e.date,type:(e.amount<0?v(`owner`)+`返`+v(`assistant`):v(`assistant`)+`交`+v(`owner`))+` · `+(e.bucket===`cost`?`货款`:`利润`),amount:Math.abs(e.amount),who:e.actor,note:e.note}))].sort((e,t)=>e.date.localeCompare(t.date));return t.length?(0,w.jsx)(`div`,{className:`table-wrap`,children:(0,w.jsx)(r,{columns:[{title:`日期`},{title:`业务`},{title:`金额`},{title:`账户/经办人`},{title:`说明`}],rows:t.map((e,t)=>({key:t,cells:[e.date,e.type,(0,w.jsxs)(w.Fragment,{children:[`¥`,b(e.amount)]}),e.who,e.note]}))})}):(0,w.jsx)(`p`,{className:`muted`,children:`还没有收退款、费用或交款记录。`})}function J(e){return e.assistantInventoryCredit?(0,w.jsxs)(`div`,{className:`note`,children:[`留在自有货盘的金料/退回货品由`,v(`assistant`),`垫付`,` `,(0,w.jsxs)(`strong`,{children:[`¥`,b(e.assistantInventoryCredit)]}),`,已在货款结算中抵扣。`,e.assistantInventoryCreditExplanation?(0,w.jsx)(`div`,{className:`small`,children:e.assistantInventoryCreditExplanation}):``,(0,w.jsxs)(`div`,{className:`small`,children:[`抵扣后货款待结 ¥`,b(e.costDue),`;利润待结 ¥`,b(e.profitDue),`。库存垫资只抵扣结算,不重复扣减订单成本或利润。`]})]}):``}function Y(e){return(0,w.jsxs)(`section`,{className:`panel`,children:[(0,w.jsxs)(`h2`,{children:[v(e.member),`的经营订单`]}),(0,w.jsxs)(`p`,{className:`small muted`,children:[`利润计入`,v(e.member),`的业绩,代收与垫付在每日对账核对。`]}),t.user.role===`owner`?d(`查看助理月度利润`,`goto-team-funds`):``]})}function X(e){return(0,w.jsxs)(`details`,{className:`panel detail-product-trace`,children:[(0,w.jsx)(`summary`,{children:`商品来源与原始说明`}),(0,w.jsx)(`ul`,{className:`detail-product-sources`,children:E.Children.toArray(e.lines.map((e,t)=>(0,w.jsxs)(`li`,{children:[(0,w.jsxs)(`strong`,{children:[t+1,` · `,e.name]}),(0,w.jsxs)(`span`,{children:[e.unit===`g`?U(e.quantity)+`g`:e.quantity+`件`,` ·`,` `,W(String(e.pocket||``).trim())||`配货`,e.code?` · 编号 `+e.code:``]}),e.priceNote?(0,w.jsx)(`span`,{children:e.priceNote}):``]})))})]})}function Z(e){let t=u(e).summary,n=Number.isSafeInteger(t.directCost)?t.directCost:e.directCost;return(0,w.jsxs)(`section`,{className:`panel detail-profit detail-profit-known`,"aria-label":`售后最终利润`,children:[(0,w.jsxs)(`div`,{className:`detail-profit-heading`,children:[(0,w.jsx)(`h2`,{children:`售后最终利润`}),(0,w.jsxs)(`strong`,{children:[`¥`,b(t.profit)]})]}),(0,w.jsxs)(`p`,{className:`detail-profit-formula`,children:[`扣留客户款 ¥`,b(t.retainedAmount),` − 货品成本损失 ¥`,b(t.costLoss),` − 已发生费用 ¥`,b(n),` = ¥`,b(t.profit)]}),(0,w.jsxs)(`p`,{className:`small muted`,children:[`本次售后利润调整 ¥`,b(t.profitAdjustment),`,记在售后日期;原成交计算保留供追溯。`]})]})}function Q(e,t,{voided:n=!1}={}){if(u(e))return Z(e);let{total:r,missing:i}=t,a=[`delivered`,`returned`,`cancelled`].includes(e.status),o=n||[`returned`,`cancelled`].includes(e.status),s=n?`作废后净额`:e.status===`returned`?`退货后净额`:e.status===`cancelled`?`取消后净额`:`实际订单利润`,c=a&&!i&&e.profit!=null,l=a?c?`¥`+b(e.profit):`待核算`:`尚未完成销售记账`,d=o?0:e.total,f=a?c?`${o?`销售净额`:`成交金额`} ¥${b(d)} − ${o?`保留成本`:`成本合计`} ¥${b(r)} = ${s} ¥${b(e.profit)}`:`成交金额 ¥${b(e.total)} − 完整成本待补,利润暂不确认。`:`旧单账务补齐后,按实际销售与成本核算利润。`;return c&&d-r!==e.profit&&(f=`${o?`销售净额`:`成交金额`} ¥${b(d)};成本合计 ¥${b(r)}。利润沿用已记账金额,历史差异请核对下方流水。`),(0,w.jsxs)(`section`,{className:`panel detail-profit`+(c?` detail-profit-known`:``),"aria-label":s,children:[(0,w.jsxs)(`div`,{className:`detail-profit-heading`,children:[(0,w.jsx)(`h2`,{children:s}),(0,w.jsx)(`strong`,{children:l})]}),(0,w.jsx)(`p`,{className:`detail-profit-formula`,children:f}),o?(0,w.jsx)(`p`,{className:`small muted`,children:`原成交金额不计有效销售;未退清的客户款另在收退款记录中核对。`}):``]})}function $(e,t){let n=Object.fromEntries(ee().map(e=>[e,v(e)]));return(0,w.jsx)(`div`,{className:`table-wrap`,children:(0,w.jsxs)(i,{className:`detail-cost-table`,"aria-label":t,children:[(0,w.jsx)(`thead`,{children:(0,w.jsxs)(`tr`,{children:[(0,w.jsx)(`th`,{children:`成本项目`}),(0,w.jsx)(`th`,{children:`付款人`}),(0,w.jsx)(`th`,{className:`number`,children:`金额`})]})}),(0,w.jsx)(`tbody`,{children:E.Children.toArray(e.map(e=>{let t=e.calculation,r=t?.weighted,i=t?r?`耗用 ${U(t.quantity)}g${t.rate==null?``:` · 加权均价约 `+b(t.rate)+`元/克`};按实际购料分摊`:`${U(t.quantity)}g × ${t.rate==null?`单价待补`:b(t.rate)+`元/克`}`:``,a=e.poolPending?`待补采购后分摊`:e.allocations?e.allocations.filter(e=>e.amount!==0).map(e=>(n[e.payer]||`待补`)+` ¥`+b(e.amount)).map((e,t)=>(0,w.jsxs)(E.Fragment,{children:[t>0&&(0,w.jsx)(`br`,{}),e]},t)):n[e.payer]||`待补`;return(0,w.jsxs)(`tr`,{...e.amount==null?{className:`detail-cost-missing`}:{},children:[(0,w.jsxs)(`td`,{children:[e.priceLockSource===`original`?`原锁料费`:e.priceLockSource===`extra`?`补重料费`:e.name,(0,w.jsxs)(`div`,{className:`small muted`,children:[e.source,e.excluded?` · 已冲回`:``]}),i?(0,w.jsx)(`div`,{className:`small muted`,children:i}):``]}),(0,w.jsx)(`td`,{className:`detail-cost-payer`,children:a}),(0,w.jsx)(`td`,{className:`number`,children:e.amount==null?(0,w.jsx)(`span`,{className:`danger-text`,children:`待补齐`}):`¥`+b(e.amount)})]})}))})]})})}function te(e){let t=u(e).summary,n=Number.isSafeInteger(t.directCost)?t.directCost:e.directCost,r=t.costLoss+n;return(0,w.jsxs)(`section`,{className:`panel detail-costs`,"aria-label":`售后保留成本`,children:[(0,w.jsxs)(`div`,{className:`panel-title`,children:[(0,w.jsx)(`h2`,{children:`售后成本怎么算`}),(0,w.jsx)(`span`,{className:`small muted`,children:`原真实费用继续保留`})]}),(0,w.jsxs)(`div`,{className:`detail-total-row`,children:[(0,w.jsx)(`span`,{children:`货品成本损失`}),(0,w.jsxs)(`b`,{children:[`¥`,b(t.costLoss)]})]}),(0,w.jsxs)(`div`,{className:`detail-total-row`,children:[(0,w.jsx)(`span`,{children:`原单费用与新增售后成本`}),(0,w.jsxs)(`b`,{children:[`¥`,b(n)]})]}),(0,w.jsxs)(`div`,{className:`detail-total-row detail-total-final`,children:[(0,w.jsx)(`span`,{children:`售后保留成本`}),(0,w.jsxs)(`strong`,{children:[`¥`,b(r)]})]}),(0,w.jsxs)(`p`,{className:`small muted`,children:[`回料成本 ¥`,b(t.materialReturnedCost),` 与现货保留工费 ¥`,b(t.laborRestockedCost),` `,`回到库存,不计本单损失。`]}),(0,w.jsxs)(`details`,{children:[(0,w.jsx)(`summary`,{children:`查看原货品成本与费用记录`}),$(C.orderCosts(e).rows,`原货品成本与实际费用`)]})]})}function ne(e,t=ye(e),{voided:n=!1}={}){if(u(e))return te(e);let{costs:r,rows:i,knownTotal:a,missing:o,knownGoods:s,paidFees:c}=t,l=i.filter(e=>!e.excluded&&e.kind!==`pending`&&e.amount!==0),d=i.filter(e=>e.kind===`pending`&&e.amount!==0),f=i.filter(e=>e.excluded&&e.amount!==0),p=l.filter(e=>e.amount!=null).map(e=>e.amount),m=p.reduce((e,t)=>e+t,0),h=m===a?p:[s,c].filter(e=>e!==0),g=(h.length?h:[0]).map(e=>`¥`+b(e)).join(` + `),_=Object.fromEntries(ee().map(e=>[e,0]));for(let e of l)for(let t of e.allocations||[e])Object.hasOwn(_,t.payer)&&(_[t.payer]+=t.amount??0);let y=Object.entries(_).filter(([,e])=>e!==0).map(([e,t])=>(0,w.jsxs)(`span`,{children:[v(e),` `,(0,w.jsxs)(`b`,{children:[`¥`,b(t)]})]}));return(0,w.jsxs)(`section`,{className:`panel order-costs detail-costs`,"aria-label":`成本明细与付款人`,children:[(0,w.jsxs)(`div`,{className:`panel-title`,children:[(0,w.jsx)(`h2`,{children:`成本怎么算`}),(0,w.jsx)(`span`,{className:`small muted`,children:r.goodsExcluded?`冲回后保留成本`:`货品成本+实际费用`})]}),l.length?$(l,`有效成本明细与付款人`):(0,w.jsx)(`p`,{className:`small muted detail-zero-cost`,children:o?`成本尚未补齐。`:`已核实成本为 ¥0.00。`}),(0,w.jsxs)(`div`,{className:`detail-cost-sum`,children:[(0,w.jsx)(`span`,{children:o?`已知成本`:`成本合计`}),(0,w.jsxs)(`div`,{className:`detail-cost-equation`,children:[g,` = `,(0,w.jsxs)(`strong`,{children:[`¥`,b(a)]})]}),y.length?(0,w.jsxs)(`p`,{className:`detail-cost-payer-totals`,"aria-label":`有效成本按付款人合计`,children:[(0,w.jsxs)(`span`,{className:`muted`,children:[`付款人合计`,o||m!==a?`(已知)`:``]}),E.Children.toArray(y)]}):``]}),o?(0,w.jsx)(`p`,{className:`small danger-text detail-cost-warning`,children:e.materialCostPending?`料费待补,补足当日购料后自动更新成本和利润。`:`货品成本尚未补齐,以上只合计已知金额,不能当作完整成本。`}):``,d.length?(0,w.jsxs)(`div`,{className:`detail-pending-costs`,children:[(0,w.jsxs)(`p`,{className:`small danger-text`,children:[`以下 `,d.length,` 项费用尚未入账,不计入成本合计和实际利润。`]}),$(d,`尚未入账的费用`)]}):``,r.goodsExcluded?(0,w.jsx)(`p`,{className:`small muted detail-cost-status`,children:n?`本单已按录错作废,原货品成本和费用保留供查阅,已撤销的金额不计入本单成本。`:`原货品成本已冲回,不计当前成本;实际发生的费用仍保留。`}):``,f.length?(0,w.jsxs)(`details`,{className:`detail-cost-history`,children:[(0,w.jsx)(`summary`,{children:`原货品成本(已冲回,不计当前成本)`}),$(f,`已冲回的原货品成本`)]}):``]})}function re(e,t){return e==null?`待补`:`¥`+(t===`yuan`?(e/100).toLocaleString(`zh-CN`,{minimumFractionDigits:0,maximumFractionDigits:0}):b(e))}function ie(e,t){let n=W(String(t.pocket||``).trim())||`配货`,r=e.status===`delivered`?`出货货盘`:e.status===`returned`?`原出货货盘`:e.status===`cancelled`?`原登记货盘`:[`draft`,`confirmed`].includes(e.status)?`拟出库货盘`:`登记货盘`;return(0,w.jsxs)(`span`,{className:`detail-line-pocket`,children:[r,`:`,n,Number.isSafeInteger(t.stockCount)?` · `+G(t.stockCount):K(t.pocket)?` · 未记录对数`:``]})}function ae(e,{voided:t=!1}={}){let n=t||[`returned`,`cancelled`].includes(e.status),r=[`draft`,`confirmed`].includes(e.status),i=e.lines.reduce((e,t)=>e+t.sale,0),a=e.discount||0,o=i-a,s=Number.isSafeInteger(e.rounding_adjustment)?e.rounding_adjustment:e.total-o,c=t?`原成交金额(已作废)`:n?`原成交金额`:r?`报价合计`:`成交金额`,l=t?`本单已作废,以下原销售计算仅供追溯。`:n?`原销售已冲回,以下保留原成交计算。`:r?`尚未完成销售记账,以下为已保存报价。`:``;return(0,w.jsxs)(`section`,{className:`panel detail-sales`,"aria-label":`销售计算`,children:[(0,w.jsxs)(`div`,{className:`panel-title`,children:[(0,w.jsx)(`h2`,{children:`销售怎么算`}),n||r?(0,w.jsx)(`span`,{className:`small muted`,children:`原单记录`}):``]}),l?(0,w.jsx)(`p`,{className:`small muted`,children:l}):``,E.Children.toArray(e.lines.map((t,n)=>{let r=t.charges||[],i=r.reduce((e,t)=>e+(t.amount??0),0),a=Number.isSafeInteger(t.baseSale)?t.baseSale:t.sale-i,o=t.pricingMode===`auto`&&t.unit===`g`&&Number.isSafeInteger(t.goldPrice)&&Number.isSafeInteger(t.laborRate)&&[`gram`,`piece`].includes(t.laborMode??``)&&(t.laborMode!==`piece`||Number.isSafeInteger(t.pieces)&&t.pieces>0),s=t.unit===`g`?U(t.quantity)+`g`:t.quantity+`件`,c=o?t.laborMode===`gram`?`${U(t.quantity)}g ×(金价 ${b(t.goldPrice)}元/克 + 工费 ${b(t.laborRate)}元/克)`:`${U(t.quantity)}g × 金价 ${b(t.goldPrice)}元/克 + ${t.pieces}件 × 件工费 ${b(t.laborRate)}元/件`:`直接填基础金额`;return(0,w.jsxs)(`article`,{className:`detail-sale-line`,children:[(0,w.jsxs)(`div`,{className:`detail-line-heading`,children:[(0,w.jsxs)(`div`,{className:`detail-line-identity`,children:[(0,w.jsxs)(`strong`,{children:[e.lines.length>1?n+1+` · `:``,t.name]}),ie(e,t)]}),(0,w.jsx)(`span`,{className:`small muted`,children:s})]}),(0,w.jsxs)(`p`,{className:`detail-formula`,children:[c,o?` = `:` `,(0,w.jsxs)(`strong`,{children:[`¥`,b(a)]})]}),!o&&t.priceNote?(0,w.jsx)(`p`,{className:`small muted detail-price-note`,children:t.priceNote}):``,r.length?(0,w.jsx)(`div`,{className:`detail-sale-addons`,children:E.Children.toArray(r.map(e=>(0,w.jsxs)(`span`,{children:[`+ `,e.name,` `,(0,w.jsx)(`b`,{children:e.amount==null?`收费未填`:`¥`+b(e.amount)})]})))}):``,e.lines.length>1||r.length?(0,w.jsxs)(`div`,{className:`detail-line-total`,children:[(0,w.jsx)(`span`,{children:`本行合计`}),(0,w.jsxs)(`b`,{children:[`¥`,b(t.sale)]})]}):``]})})),(0,w.jsxs)(`div`,{className:`detail-sale-total`,children:[e.lines.length>1||a||e.rounding_mode===`yuan`?(0,w.jsxs)(`div`,{className:`detail-total-row`,children:[(0,w.jsx)(`span`,{children:`销售小计`}),(0,w.jsxs)(`span`,{children:[`¥`,b(i)]})]}):``,a?(0,w.jsxs)(`div`,{className:`detail-total-row`,children:[(0,w.jsx)(`span`,{children:`- 整单优惠`}),(0,w.jsxs)(`span`,{children:[`¥`,b(a)]})]}):``,e.rounding_mode===`yuan`?(0,w.jsxs)(`p`,{className:`small muted detail-rounding`,children:[`整单四舍五入到元:¥`,b(o),` → `,re(e.total,`yuan`),s?`(`+(s>0?`+`:`−`)+b(Math.abs(s))+`元)`:``]}):``,(0,w.jsxs)(`div`,{className:`detail-total-row detail-total-final`,children:[(0,w.jsx)(`span`,{children:c}),(0,w.jsx)(`strong`,{children:re(e.total,e.rounding_mode)})]})]}),e.note?(0,w.jsxs)(`p`,{className:`detail-customer-note small`,children:[(0,w.jsx)(`span`,{className:`muted`,children:`客户单备注:`}),e.note]}):``]})}function oe(e){let t=u(e);if(!t)return``;try{return(0,w.jsxs)(`section`,{className:`panel order-after-sale-detail`,children:[(0,w.jsxs)(`div`,{className:`panel-title`,children:[(0,w.jsx)(`h2`,{children:`已处理售后`}),(0,w.jsxs)(`span`,{className:`small muted`,children:[`售后日 `,t.date||e.returned_date]})]}),(0,w.jsxs)(`p`,{className:`change-reason`,children:[`售后原因:`,t.reason]}),H(t),(0,w.jsxs)(`dl`,{className:`order-after-sale-facts`,children:[(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`dt`,{children:`实际退款账户/付款人`}),(0,w.jsxs)(`dd`,{children:[g(t.refund?.account),` · `,v(t.refund?.payer)]})]}),t.deductionReason?(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`dt`,{children:`扣留原因`}),(0,w.jsx)(`dd`,{children:t.deductionReason})]}):``,t.refund?.reference?(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`dt`,{children:`退款凭据备注`}),(0,w.jsx)(`dd`,{children:t.refund.reference})]}):``]}),t.expenses?.length?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`h3`,{children:`本次新增售后成本`}),(0,w.jsx)(`ul`,{children:E.Children.toArray(t.expenses.map(e=>(0,w.jsxs)(`li`,{children:[e.note,` · ¥`,b(e.amount),` · `,v(e.payer),`支付`]})))})]}):(0,w.jsx)(`p`,{className:`small muted`,children:`本次没有新增售后成本。`})]})}catch(t){return(0,w.jsxs)(`section`,{className:`panel`,children:[(0,w.jsx)(`h2`,{children:`已处理售后`}),(0,w.jsx)(`p`,{className:`danger-text`,children:t instanceof Error?t.message:String(t)}),d(`重新读取订单`,`reload-order-change`,``,{"data-id":e.id})]})}}function se(e){return(0,w.jsxs)(`li`,{children:[(0,w.jsxs)(`div`,{className:`change-record-title`,children:[(0,w.jsx)(`strong`,{children:V[e.status]}),e.stale&&e.status===`pending`?(0,w.jsx)(`span`,{className:`badge danger`,children:`订单已有变动`}):``]}),R(e),(0,w.jsxs)(`div`,{children:[`申请人:`,e.requester_name,` · `,z(e.created)]}),(0,w.jsxs)(`p`,{className:`change-reason`,children:[`修改原因:`,e.reason]}),e.status===`pending`?``:(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`div`,{className:`small muted`,children:[`处理人:`,e.reviewer_name||e.requester_name,` ·`,` `,z(e.reviewed||e.created)]}),e.note?(0,w.jsxs)(`p`,{className:`change-reason`,children:[e.status===`rejected`?`驳回意见`:`复核备注`,`:`,e.note]}):``]})]})}function ce(e){let n=D(e),r=n?.data,i=l(e);if(!r)return(0,w.jsxs)(`section`,{className:`panel order-ownership-panel`,children:[(0,w.jsx)(`h2`,{children:`订单归属`}),(0,w.jsx)(`p`,{className:n?.error?`danger-text`:`muted`,role:`status`,children:n?.error||`订单归属资料尚未读取。`}),d(`重新读取归属资料`,`order-ownership-reload`,``,{"data-id":e.id})]});if(!i&&!r.requests.length)return!r.eligible&&r.reason?(0,w.jsxs)(`p`,{className:`small muted order-ownership-unavailable`,children:[`修改归属:`,r.reason]}):``;let a=t.user.role===`owner`&&r.canApprove&&i?.status===`pending`,o=r.requests.find(e=>e.status===`approved`&&e.after.member===r.member);return(0,w.jsxs)(`section`,{className:`panel order-ownership-panel`,id:`order-ownership-panel`,children:[(0,w.jsxs)(`div`,{className:`panel-title`,children:[(0,w.jsx)(`h2`,{children:`订单归属修改`}),i?(0,w.jsx)(`span`,{className:`badge warn`,children:`归属待复核`}):o?(0,w.jsx)(`span`,{className:`badge`,children:`归属已修改`}):``]}),!i&&o?(0,w.jsxs)(w.Fragment,{children:[R(o),(0,w.jsxs)(`p`,{className:`small muted`,children:[o.reviewer_name||o.requester_name,` ·`,` `,z(o.reviewed||o.created),` · 原因:`,o.reason]})]}):``,i?(0,w.jsxs)(w.Fragment,{children:[R(i),(0,w.jsx)(`p`,{children:`申请尚未生效,仍按原归属计账。助理修改归属均须店主复核,今天的订单也一样;复核完成前暂停本单其他修改、记账和取消申请。`}),B(i.before.member),i.stale?(0,w.jsx)(`div`,{className:`error`,role:`status`,children:`订单在申请后已有变动,不能同意旧申请。请店主驳回后按最新订单重新申请。`}):``,a?(0,w.jsxs)(`div`,{className:`actions`,children:[!i.stale&&i.canApprove?d(`核对并同意归属`,`order-ownership-approve`,`primary`,{"data-id":i.id}):``,d(`驳回归属申请`,`order-ownership-reject`,``,{"data-id":i.id})]}):(0,w.jsx)(`p`,{className:`small muted`,children:`等待店主账号核对原归属、新归属和修改原因。`})]}):``,(0,w.jsxs)(`details`,{open:!!i,children:[(0,w.jsxs)(`summary`,{children:[`归属修改与复核记录(`,r.requests.length,`)`]}),(0,w.jsx)(`ul`,{className:`timeline change-history`,children:E.Children.toArray(r.requests.map(se))})]})]})}function le(e){return(0,w.jsxs)(`li`,{children:[(0,w.jsxs)(`div`,{className:`change-record-title`,children:[(0,w.jsx)(`strong`,{children:P[e.status]}),(0,w.jsx)(`span`,{className:`badge`,children:N(e)}),e.stale&&e.status===`pending`?(0,w.jsx)(`span`,{className:`badge danger`,children:`订单已有变动`}):``]}),(0,w.jsxs)(`div`,{children:[`申请人:`,e.requester_name,` · `,F(e.created)]}),(0,w.jsxs)(`p`,{className:`change-reason`,children:[`申请原因:`,e.reason]}),e.status===`pending`?``:(0,w.jsxs)(`div`,{className:`small muted`,children:[`复核人:`,e.reviewer_name||`未提供`,` · `,F(e.reviewed),e.note?(0,w.jsxs)(`p`,{className:`change-reason`,children:[e.status===`rejected`?`驳回意见`:`复核备注`,`:`,e.note]}):``]}),(0,w.jsxs)(`details`,{children:[(0,w.jsx)(`summary`,{children:`查看本次原值与申请值`}),I(e),L(e)]})]})}function ue(e){let n=M(e),r=n?.data,i=c(e);if(!r)return(0,w.jsxs)(`section`,{className:`panel order-change-panel`,children:[(0,w.jsx)(`h2`,{children:`变更申请与复核`}),(0,w.jsx)(`p`,{className:n?.error?`danger-text`:`muted`,role:`status`,children:n?.error||`变更申请资料尚未读取,请先重新读取订单。`}),d(`重新读取订单`,`reload-order-change`,``,{"data-id":e.id})]});if(!i&&!r.requests.length)return``;let a=t.user.role===`owner`&&r.canApprove&&i?.status===`pending`;return(0,w.jsxs)(`section`,{className:`panel order-change-panel`,id:`order-change-panel`,children:[(0,w.jsxs)(`div`,{className:`panel-title`,children:[(0,w.jsx)(`h2`,{children:`变更申请与复核`}),i?(0,w.jsx)(`span`,{className:`badge warn`,children:`待店主复核`}):``]}),i?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`p`,{children:[(0,w.jsxs)(`strong`,{children:[`本次申请:`,N(i),`。`]}),`申请期间仍按原订单计账,本次申请尚未生效。店主同意后才更新原单;复核完成前暂停本单其他记账和取消申请。`]}),i.stale?(0,w.jsx)(`div`,{className:`error`,role:`status`,children:`订单在申请后已有变动,原申请不能同意。请店主驳回后按最新订单重新申请。`}):``,a?(0,w.jsxs)(`div`,{className:`actions`,children:[i.stale?``:d(`查看变更并复核`,`approve-order-change`,`primary`,{"data-id":i.id}),d(`驳回变更申请`,`reject-order-change`,``,{"data-id":i.id})]}):(0,w.jsx)(`p`,{className:`small muted`,children:`由店主账号核对原值与申请值后复核。`})]}):``,(0,w.jsxs)(`details`,{open:!!i,children:[(0,w.jsxs)(`summary`,{children:[`变更申请与复核记录(`,r.requests.length,`)`]}),(0,w.jsx)(`ul`,{className:`timeline change-history`,children:E.Children.toArray(r.requests.map(le))})]})]})}function de(e){return e.direct===!0?(0,w.jsxs)(`li`,{children:[(0,w.jsx)(`div`,{className:`cancellation-record-title`,children:(0,w.jsx)(`strong`,{children:`当天直接取消`})}),(0,w.jsxs)(`div`,{children:[`经办人:`,e.operator_name||e.requester_name,` ·`,` `,A(e.executedAt||e.created)]}),(0,w.jsx)(`p`,{className:`cancellation-reason`,children:e.reason}),e.note?(0,w.jsxs)(`p`,{className:`small cancellation-reason`,children:[`处理备注:`,e.note]}):``]}):(0,w.jsxs)(`li`,{children:[(0,w.jsxs)(`div`,{className:`cancellation-record-title`,children:[(0,w.jsx)(`strong`,{children:j[e.status]}),e.stale&&e.status===`pending`?(0,w.jsx)(`span`,{className:`badge danger`,children:`订单已有变动`}):``]}),(0,w.jsxs)(`div`,{children:[`申请人:`,e.requester_name,` · `,A(e.created)]}),(0,w.jsx)(`p`,{className:`cancellation-reason`,children:e.reason}),e.status===`pending`?``:(0,w.jsxs)(`div`,{className:`small muted`,children:[`复核人:`,e.reviewer_name||`未提供`,` · `,A(e.reviewed),e.note?(0,w.jsxs)(`p`,{className:`cancellation-reason`,children:[e.status===`rejected`?`驳回意见`:`复核备注`,`:`,e.note]}):``]})]})}function fe(e){if(e.price_lock_id)return``;let n=S(e),r=n?.data,i=s(e),a=we(e);if(!r)return(0,w.jsxs)(`section`,{className:`panel order-cancellation-panel`,children:[(0,w.jsx)(`h2`,{children:`取消申请与复核`}),(0,w.jsx)(`p`,{className:n?.error?`danger-text`:`muted`,role:`status`,children:n?.error||`取消申请资料尚未读取,请先重新读取订单。`}),d(`重新读取订单`,`reload-order-cancellation`,``,{"data-id":e.id})]});if(!i&&!r.requests.length)return``;let o=t.user.role===`owner`&&r.canApprove&&i?.status===`pending`;return(0,w.jsxs)(`section`,{className:`panel order-cancellation-panel`,id:`order-cancellation-panel`,children:[(0,w.jsxs)(`div`,{className:`panel-title`,children:[(0,w.jsx)(`h2`,{children:a?`已取消 · 录错作废`:`取消申请与复核`}),i?(0,w.jsx)(`span`,{className:`badge warn`,children:`待店主复核`}):``]}),i?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`p`,{children:`申请期间仍按原订单计账,尚未取消。复核完成前暂停本单财务修改和退货。`}),i.stale?(0,w.jsx)(`div`,{className:`error`,role:`status`,children:`订单在申请后已有变动,原申请不能同意。请店主驳回后重新申请,再按最新资料核对。`}):``,o?(0,w.jsxs)(`div`,{className:`actions`,children:[i.stale?``:d(`同意取消`,`approve-order-cancellation`,`danger`,{"data-id":i.id}),d(`驳回`,`reject-order-cancellation`,``,{"data-id":i.id})]}):(0,w.jsx)(`p`,{className:`small muted`,children:`由店主账号查看撤销摘要并复核。`})]}):``,a?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`p`,{children:`本单为录错作废:销售、成本、收款及费用已撤销,原有库存出入已冲回。原单、原流水与处理记录保留;本次没有登记真实退货或发起退款。`}),(0,w.jsx)(`p`,{className:`small muted`,children:`双方已登记的实际交款保留,请继续核对下方待结金额。`})]}):``,(0,w.jsxs)(`details`,{open:!!i,children:[(0,w.jsxs)(`summary`,{children:[`取消申请与处理记录(`,r.requests.length,`)`]}),(0,w.jsx)(`ul`,{className:`timeline cancellation-history`,children:E.Children.toArray(r.requests.map(de))})]})]})}function pe(e){return(0,w.jsxs)(`div`,{className:`document-print-controls`,children:[k(e),(0,w.jsx)(`small`,{className:`muted`,children:`点击客户预览里的“打印”后自动记录。`})]})}function me(e){return e.recovery_id?(0,w.jsx)(`div`,{className:`note`,children:`这张销售单由置换结算自动生成。重量、抵扣与收付款请在关联置换单核对;修改或取消请从关联置换单进入,整套收付款、购料与库存一起更正。`}):``}function he(e){if(!e.materialCostPending)return``;let t=[...new Set(e.lines.filter(e=>e.costMaterial?.mode===`pool`).map(e=>e.costMaterial.poolId))];return(0,w.jsxs)(`div`,{className:`note material-order-pending`,children:[(0,w.jsx)(`strong`,{children:`料费待补,销售单已生成。`}),` `,t.map(O).join(`、`),` `,`每日料价的购料尚未覆盖耗用克重,成本、利润和双方待结金额暂待补;补足购料后自动更新。`,d(`登记/查看每日购料`,`goto-material-pools`,`quiet`)]})}function ge(e){return c(e)||s(e)}function _e(e){let n=D(e)?.data;return!n?.eligible||n.pending||l(e)||ge(e)?``:d(t.user.role===`owner`&&n.canDirect?`修改归属`:`申请修改归属`,`order-ownership-request`,`order-ownership-trigger`,{"data-id":e.id})}function ve(e){return(0,w.jsxs)(`aside`,{className:`detail-internal-note`,"aria-label":`内部备注(客户不可见)`,children:[(0,w.jsx)(`span`,{className:`detail-internal-note-label`,children:`内部备注 · 客户不可见`}),(0,w.jsx)(`p`,{children:e.internal_note?e.internal_note.split(/\r\n?|\n/).map((e,t)=>(0,w.jsxs)(E.Fragment,{children:[t>0&&(0,w.jsx)(`br`,{}),e]},t)):(0,w.jsx)(`span`,{className:`muted`,children:`未填写`})})]})}function ye(e){let t=C.orderCosts(e),n=[],r=new Map;for(let e of t.rows)if((e.materialPoolId||e.priceLockSource)&&e.calculation?.weighted){let t=e.source,i=r.get(t);if(i)i.amount=Number(i.amount)+Number(e.amount),i.allocations.push({payer:e.payer,amount:e.amount});else{let i={...e,allocations:[{payer:e.payer,amount:e.amount}]};r.set(t,i),n.push(i)}}else n.push(e);let i=new Set((e.corrections||[]).filter(e=>e.type===`expense`).map(e=>e.target));for(let t of e.expenses||[])t.amount<0&&!i.has(t.id)&&!String(t.note||``).startsWith(`更正冲回:`)&&n.push({kind:`paid`,name:t.note,source:t.date,amount:t.amount,payer:t.payer});let a=t.goodsExcluded?0:e.goodsCost,o=t.goodsExcluded?0:Number.isSafeInteger(a)?a:Number.isSafeInteger(e.knownGoodsCost)?e.knownGoodsCost:t.total.goods,s=Number.isSafeInteger(e.directCost)?e.directCost:n.filter(e=>e.kind===`paid`).reduce((e,t)=>e+(t.amount??0),0),c=!t.goodsExcluded&&(!Number.isSafeInteger(a)||t.total.goodsMissing>0);return{costs:t,rows:n,goods:a,knownGoods:o,paidFees:s,missing:c,knownTotal:o+s,total:c?null:o+s}}function be(e,{reviewAllowed:t=!1}={}){return(0,w.jsxs)(w.Fragment,{children:[d(`查看置换结算单`,`recovery-open`,`primary`,{"data-id":e.recovery_id}),d(`客户预览/打印`,`recovery-print`,``,{"data-id":e.recovery_id}),t?d(`店主复核`,`show-review`):``]})}function xe(e,t){if(e.lines.some(e=>e.priceLockPool))return``;let n=d(t?`申请整单退货`:`整单退货`,`show-return`,`quiet`,{title:`旧入口:仅登记退货,实际退款另行登记`});return e.lines.some(e=>e.unit!==`g`||C.isSilver(e.name))?n:(0,w.jsxs)(`details`,{className:`order-legacy-actions`,children:[(0,w.jsx)(`summary`,{children:`旧版退货入口`}),(0,w.jsx)(`p`,{className:`small muted`,children:`原先分开办理退货、退款的入口。实际整单售后请优先使用“处理售后”核对退款、损失和回库。`}),n]})}function Se(e,{blocked:t=!1}={}){return e.status!==`delivered`||t||u(e)||e.recovery_id||e.lines.some(e=>e.unit!==`g`||C.isSilver(e.name))?``:d(`处理售后`,`order-after-sale-open`,`primary order-after-sale-trigger`,{"data-id":e.id})}function Ce(e){let t=S(e)?.data;return l(e)||e.price_lock_id||![`draft`,`confirmed`,`delivered`].includes(e.status)||s(e)||c(e)||!t?.eligible?``:d(T(e)?`取消订单`:`申请取消`,`request-order-cancellation`,`danger`,{"data-id":e.id})}function we(e){return e.cancellationApproved||S(e)?.data?.requests.find(e=>e.status===`approved`)||null}function Te(){let r=e,i=[`delivered`,`returned`,`cancelled`].includes(r.status),S=s(r),C=c(r),T=l(r),D=!!S||!!C||!!T,O=!!u(r),k=!!we(r),A=D||!!k||O,j=t.user.role===`owner`,M=(0,w.jsxs)(w.Fragment,{children:[d(`客户预览/打印`,`print`,`primary`,{"data-id":r.id}),f?d((0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`span`,{"aria-hidden":`true`,children:`+`}),`复制新增`]}),`copy-order`,`order-copy-button`,{"data-id":r.id}):``]});r.status===`draft`&&j||D||O||(M=(0,w.jsxs)(w.Fragment,{children:[d(j||r.date===t.today?`修改订单`:`申请修改`,`edit-order`,`primary`,{"data-id":r.id}),M]})),r.status===`draft`&&j&&!A&&(M=E.Children.toArray([M,d(`继续填写并开单`,`edit`)]));let N=e=>p(e);r.status===`confirmed`&&!A&&(r.pendingFees.length&&(M=E.Children.toArray([M,d(N(`fees`)?`申请补记旧单费用`:`补记旧单费用`,`show-fees`)])),r.balance>0&&(M=E.Children.toArray([M,d(`登记收款`,`show-receipt`)])),M=E.Children.toArray([M,d(j?`补齐/核对货品成本`:`申请补录货品成本`,`show-cost`)]),M=E.Children.toArray([M,d(`补齐旧单账务`,`show-complete`)])),r.status!==`draft`&&!A&&(M=E.Children.toArray([M,d(N(`expense`)?`申请补记费用`:`记额外费用`,`show-expense`)])),M=E.Children.toArray([M,Ce(r)]),M=E.Children.toArray([M,Se(r,{blocked:A})]),r.status===`delivered`&&!A&&(M=E.Children.toArray([M,xe(r,N(`return`))])),[`cancelled`,`returned`].includes(r.status)&&r.netReceived>0&&!A&&!u(r)&&(M=E.Children.toArray([M,d(N(`refund`)?`申请登记退款`:`登记实际退款`,`show-refund`)])),i&&!D&&r.settlementDue!=null&&r.settlementDue!==0&&!r.materialCostPending&&!m()&&(M=E.Children.toArray([M,d(`登记实际交款/返款`,`show-settlement`)])),j&&!D&&(!k&&!O&&(r.payments.some(e=>!e.price_lock_event_id)||r.expenses.length)||r.settlements.length)&&(M=E.Children.toArray([M,d(`更正记错的流水`,`show-correct`)])),j&&!D&&r.reviewed_revision!==r.revision&&(M=E.Children.toArray([M,d(`店主复核`,`show-review`)])),r.recovery_id&&(M=be(r,{reviewAllowed:j&&!D&&r.reviewed_revision!==r.revision}));let P=ye(r),F=!D&&h(r)?(0,w.jsxs)(`div`,{className:`order-review-seal`,role:`status`,"aria-label":`已审批,店主已复核`,children:[(0,w.jsxs)(`svg`,{viewBox:`0 0 24 24`,"aria-hidden":`true`,focusable:`false`,children:[(0,w.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,w.jsx)(`path`,{d:`m7 12 3.2 3.2L17 8.5`})]}),(0,w.jsx)(`strong`,{children:`已审批`}),(0,w.jsx)(`small`,{children:`店主已复核`})]}):``;return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`div`,{id:`order-detail-navigation`,className:`order-detail-navigation`,hidden:!o,"aria-busy":!1,children:o}),(0,w.jsxs)(`div`,{className:`order-header order-detail-header`,children:[(0,w.jsx)(`div`,{className:`eyebrow`,children:`ORDER DETAIL`}),(0,w.jsxs)(`div`,{className:`order-detail-heading`,children:[(0,w.jsxs)(`div`,{className:`order-detail-title`,children:[(0,w.jsx)(`h2`,{children:String(r.customer??``).trim()||`未填客户称呼`}),ve(r)]}),F]}),(0,w.jsxs)(`p`,{className:`small muted order-detail-identifiers`,children:[`纸单号 `,r.paper_number||`未分配`,` · 系统单号 `,r.number,` · 收款账户 `,g(r.payment_account)]}),_(r),r.member?(0,w.jsxs)(`span`,{className:`badge member-badge`,children:[v(r.member),`的订单`]}):``,_e(r),(0,w.jsxs)(`span`,{className:`muted small`,children:[`业务日期 `,r.date,` · 开单人 `,r.salesperson]}),y(r)]}),he(r),me(r),i?``:(0,w.jsx)(`div`,{className:`note`,children:r.status===`draft`?`这是尚未开单的旧草稿,继续填写后生成销售单据。`:`这张旧单尚未完成销售记账。请按实际情况补齐款项、货品成本和费用,再点“补齐旧单账务”;保存时一并记费用、扣库存和计算利润。`}),pe(r),(0,w.jsx)(`div`,{className:`actions detail-actions`,children:M}),fe(r),ue(r),ce(r),(0,w.jsx)(`div`,{id:`detail-form`,className:`detail-form`,children:n}),(0,w.jsx)(`div`,{id:`detail-error`,role:`alert`,children:a}),oe(r),(0,w.jsxs)(`div`,{className:`order-detail-breakdown`,children:[ae(r,{voided:k}),ne(r,P,{voided:k})]}),Q(r,P,{voided:k}),X(r),r.funds_mode===`team`?Y(r):(0,w.jsxs)(`details`,{className:`panel detail-settlement`,children:[(0,w.jsx)(`summary`,{children:m()?`历史两人结算(只供追溯,不计入团队往来)`:`与`+v(`assistant`)+`的结算`}),(0,w.jsxs)(`div`,{className:`grid three`,children:[(0,w.jsxs)(`div`,{children:[v(`owner`),`垫资应回收 `,(0,w.jsxs)(`strong`,{children:[`¥`,b(r.ownerCost)]}),(0,w.jsx)(`br`,{}),(0,w.jsxs)(`small`,{className:`muted`,children:[`实际已交净额 ¥`,b(r.costTransferred)]})]}),(0,w.jsxs)(`div`,{children:[`已记账订单利润`,` `,(0,w.jsx)(`strong`,{children:i?r.profit==null?r.materialCostPending?`料费待补`:`成本未补齐`:`¥`+b(r.profit):`旧单待补齐`}),(0,w.jsx)(`br`,{}),(0,w.jsxs)(`small`,{className:`muted`,children:[`实际已交净额 ¥`,b(r.profitTransferred)]})]}),(0,w.jsxs)(`div`,{children:[Number(r.settlementDue)<0?v(`owner`)+`待转回`+v(`assistant`):v(`assistant`)+`待交`+v(`owner`),` `,(0,w.jsx)(`strong`,{children:r.settlementDue==null?`料费待补`:`¥`+b(Math.abs(r.settlementDue))}),(0,w.jsx)(`br`,{}),(0,w.jsx)(`small`,{className:`muted`,children:r.materialCostPending?`补足购料后自动计算;当前不能登记交款`:i?`含本单货款与利润,该日购料结算另行核对`:`旧单完成销售记账后形成应交款`})]})]}),J(r),r.ownerDirect?O?(0,w.jsxs)(`div`,{className:`note`,children:[v(`owner`),`账户实际留存客户款 ¥`,b(r.ownerDirect),`,已纳入售后扣留款与最终利润,请按实际账户核对结算。`]}):(0,w.jsxs)(`div`,{className:`note`,children:[v(`owner`),`直接收客户净额 ¥`,b(r.ownerDirect),`,`,r.status===`delivered`?`已从总待结金额扣除,货款/利润拆分需单独复核。`:r.price_lock_id&&r.status===`returned`&&r.netReceived===0?`客户已退清;跨账户收退款形成的差额已计入双方结算。`:`这部分属于客户款,取消/退货后须从原账户退客户,不算应返助理。`]}):``,(0,w.jsx)(`p`,{className:`small muted`,style:{margin:`14px 0 0`},children:`开单后按单交货款,利润月底交。退货返款单独记录,不抵下一笔。这里记录实际转账,不会发起付款。`})]}),(0,w.jsxs)(`details`,{className:`panel`,children:[(0,w.jsx)(`summary`,{children:`收退款与费用记录`}),q(r),(0,w.jsxs)(`details`,{children:[(0,w.jsx)(`summary`,{children:`操作记录`}),(0,w.jsx)(`ul`,{className:`timeline`,children:E.Children.toArray(r.audit.map(e=>(0,w.jsxs)(`li`,{children:[x[e.action]||e.action,` · `,e.actor,(0,w.jsx)(`small`,{children:new Date(e.created).toLocaleString(`zh-CN`)}),e.detail.reason?e.detail.reason:``]})))})]})]})]})}return{renderDetail:Te}}var A=e=>e==null?``:(e/100).toFixed(2),j=Object.keys(C.costLabels);function M(e,t,n,r,i){let a={unit:e.unit,quantity:t,costParts:n};for(let[e,t]of[[`material`,`costMaterial`],[`labor`,`costLabor`]])a[t]=r[e]===`gram`?{mode:`gram`,rate:i[e]}:{mode:`total`};return C.purchaseCosts(a)}function N({line:e,index:r,members:i,fallback:a,choice:o,opts:s,grams:c,yuan:l}){let u=`cost-`+r+`-`,d=e.unit===`g`?(e.quantity/1e3).toFixed(3):e.quantity,f=Object.fromEntries(j.map(t=>[t,e.costParts?A(e.costParts[t]):[`accessories`,`other`].includes(t)?`0`:``])),p=[`gram`,`total`].includes(e.costMaterial?.mode??``)?e.costMaterial.mode:f.material===``?`gram`:`total`,[m,h]=(0,E.useState)(f),[g,_]=(0,E.useState)({material:e.unit===`g`?p:`total`,labor:e.unit===`g`&&e.costLabor?.mode||`total`}),[v,y]=(0,E.useState)({material:A(e.costMaterial?.rate),labor:A(e.costLabor?.rate)}),b=e.unit!==`g`||p===`total`?f.material:``,x=(e,t)=>h(n=>({...n,[e]:t})),S=(e,t,n)=>{t===`total`&&(e===`labor`||m.material===``)&&x(e,n),_(n=>({...n,[e]:t}))},C=(e,t,r,i=!1)=>(0,w.jsxs)(`label`,{children:[t,(0,w.jsx)(n,{type:`number`,name:u+e,min:`0`,step:`0.01`,placeholder:`开单前必填,没有填0`,required:!i,readOnly:i,value:r,onChange:t=>x(e,t.target.value)})]});function T(r){let o=r===`material`,c=g[r]===`gram`,f=e.costPayers?.[r]??e.payer??a,p=m[r],h;if(c)try{let t=M(e,d,{material:`0`,labor:`0`,accessories:`0`,other:`0`},{material:`total`,labor:`total`,[r]:`gram`},v).parts[r];p=A(t),h=t==null?o?`填写每克进货料价后,系统自动乘以本行克重。`:`填写每克工费后自动乘以克重。`:d+`g × `+v[r]+`元/克 = `+l(t)+`元`}catch(e){p=``,h=e instanceof Error?e.message:String(e)}else h=o?e.unit===`g`?`直接填写本行料费合计,不再乘以克重。`:`按件商品请填写本行料费合计`+(v.material?`;每克料价已保留,切回g可恢复`:``)+`。`:`直接填写本行总工费。`;let _=i(!1,{selected:f});return(0,w.jsxs)(`div`,{className:`purchase-`+r,"data-prefix":u,"data-mode":g[r],children:[(0,w.jsxs)(`div`,{className:`grid purchase-cost-grid`,children:[(0,w.jsxs)(`label`,{children:[o?`进货料费方式`:`进货工费方式`,(0,w.jsxs)(t,{name:u+r+`Mode`,value:g[r],onChange:e=>S(r,e.target.value,p),children:[(0,w.jsx)(`option`,{value:`gram`,disabled:e.unit!==`g`,children:o?`按克料价`:`克工费`}),(0,w.jsx)(`option`,{value:`total`,children:o?`直接填总料费`:`总工费`})]})]}),(0,w.jsxs)(`label`,{hidden:!c,children:[o?`进货料价(元/克)`:`进货克工费(元/克)`,(0,w.jsx)(n,{type:`number`,name:u+r+`Rate`,min:`0`,step:`0.01`,value:v[r],placeholder:o?`填写每克进货料价`:`填写每克工费`,disabled:!c,required:c,onChange:e=>y(t=>({...t,[r]:e.target.value}))})]}),C(r,o?`料费成本合计(元)`:`进货总工费(元)`,p,c),(0,w.jsxs)(`label`,{className:`purchase-payer`,children:[o?`料费付款人`:`进货工费付款人`,(0,w.jsxs)(t,{required:!0,name:u+r+`Payer`,defaultValue:_.some(([e])=>e===f)?f:``,children:[_.some(([e])=>e===f)?null:(0,w.jsx)(`option`,{value:``,disabled:!0,children:`请选择`}),s(_)]})]})]}),(0,w.jsx)(`p`,{className:`purchase-formula small muted`,"aria-live":`polite`,children:h}),o&&(0,w.jsx)(`p`,{className:`purchase-original small muted`,hidden:!b,children:b&&`已保留原料费合计 `+b+`元。原金额不会当成每克料价;切换按克后请填写实际进货料价。`})]})}let D;try{D=M(e,d,m,g,v).total}catch{D=null}return(0,w.jsxs)(`div`,{className:`internal cost-editor`,children:[(0,w.jsxs)(`h3`,{children:[e.name,` · `,e.unit===`g`?c(e.quantity)+`g`:e.quantity+`件`]}),(0,w.jsx)(`div`,{className:`cost-fallback-payer`,children:o(`配件及其他成本付款人`,`goodsPayer`,i(),e.payer||`owner`)}),!e.costParts&&e.cost!==null&&(0,w.jsxs)(`p`,{className:`small`,children:[`原记录未分项,总额 ¥`,l(e.cost),`;请按凭据拆分,不要把总额再填入每个项目。`]}),(0,w.jsxs)(`div`,{className:`cost-fields grid`,children:[T(`material`),T(`labor`),C(`accessories`,`配件成本(元,本行合计)`,m.accessories),C(`other`,`其他货品成本(元,本行合计)`,m.other)]}),(0,w.jsxs)(`div`,{className:`cost-summary small`,children:[`本行货品成本合计:`,D==null?`请补齐(没有的项目填0)`:`¥`+l(D)]})]})}function P({currentOrder:e,ui:r={},state:i},{orderActionUsesChangeForm:a,orderActionRequiresApproval:c,orderAfterSaleRecord:l,orderOwnershipPending:u,orderCancellationPending:d,orderChangePending:f,moneyField:p,choice:m,teamMemberOptions:h,field:g,grams:_,yuan:v,pocketCountsEnabled:y,stockCountField:b,teamMode:x,teamMemberName:T,accountDisplayName:D,activePaymentAccounts:O,orderChangeActionLabels:k,actionName:A,button:j,normalizePaymentAccount:M,accountIdentity:P,memberAccountPrefix:F,teamMemberEnabled:I,opts:L,currentMember:R,activePocketKeys:z,pocketLabel:B,stockCountValue:V}){function H(t,n){return n.map((n,r)=>{if(!y(n))return null;let i=V(t.querySelector(`[name="returnCount-`+r+`"]`)?.value,{title:`商品 `+(r+1)+`实际退回数量(对)`}),a=e?.lines?.[r]?.stockCount;if(Number.isSafeInteger(a)&&i!==a)throw Error(`商品 `+(r+1)+`整单退回数量须与原出库的`+a+`对一致。`);return i})}function U(e){return M((e?.querySelector?.(`[name="payment_recipient"]`)?.value||``)+(e?.querySelector?.(`[name="payment_method"]`)?.value||``))}function W(t){let n=Object.fromEntries(new FormData(t)),r=t.dataset.kind,a={...n,date:n.date||i.today,verified:n.verified===`on`,feesVerified:n.feesVerified===`on`};if(r===`fees`&&(a.revision=e.revision,a.fee_items=[...t.querySelectorAll(`.fee-verify-row`)].map(t=>({...e.pendingFees.find(e=>e.key===t.dataset.key),status:`estimated`,amount:t.querySelector(`[name="verifiedAmount"]`).value,payer:t.querySelector(`[name="verifiedPayer"]`).value}))),r===`correct`){let[e,t]=n.entry.split(`:`);a.type=e,a.target=t}return r===`cost`&&(a.costs=Array.from(t.querySelectorAll(`.cost-editor`),(e,t)=>{let n=n=>e.querySelector(`[name="cost-`+t+`-`+n+`"]`).value,r=e=>n(e+`Mode`)===`gram`?{mode:`gram`,rate:n(e+`Rate`)}:{mode:`total`};return{parts:Object.fromEntries(Object.keys(C.costLabels).map(e=>[e,n(e)])),costMaterial:r(`material`),costLabor:r(`labor`),costPayers:{material:n(`materialPayer`),labor:n(`laborPayer`)},payer:e.querySelector(`[name="goodsPayer"]`).value}})),(r===`receipt`||r===`refund`)&&(a.account=U(t)),r===`correct`&&a.account&&(a.account=M(a.account)),r===`return`&&(a.returnPockets=e.lines.map((e,r)=>t.querySelector(`[name="return-`+r+`"]`)?.value??n[`return-`+r]),a.returnCounts=H(t,a.returnPockets)),r===`complete`&&(a.stockCounts={},e.lines.forEach((e,n)=>{e.unit===`g`&&y(e.pocket)&&e.stockCount==null&&(a.stockCounts[n]=V(t.querySelector(`[name="completeCount-`+n+`"]`)?.value,{title:`商品 `+(n+1)+`实际出库数量(对)`}))})),[`review`,`complete`].includes(r)&&(a.revision=e.revision),a}function G(e,t){return t?`本次提交${k[e]}申请。店主同意后才记账;待批期间原订单、收退款、费用、库存和利润均不变。系统不会发起真实付款。`:`原单与本次业务日期均为今天,核实后直接记账,无需店主审批。改为其他业务日期须提交申请。系统不会发起真实付款。`}function K(e){let t=c(e,r.date);return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`div`,{className:`note`,id:`order-action-mode`,"aria-live":`polite`,children:G(e,t)}),e===`return`?``:(0,w.jsxs)(`label`,{children:[(0,w.jsx)(`span`,{id:`order-action-reason-label`,children:t?`申请原因`:`登记原因`}),(0,w.jsx)(o,{name:`change_reason`,maxLength:200,rows:2,required:!0,placeholder:`写清本次需要登记或更正的原因。`})]}),[`cost`,`expense`].includes(e)?(0,w.jsxs)(`label`,{className:`check`,children:[(0,w.jsx)(n,{type:`checkbox`,name:`verified`,required:!0}),`已核实本次金额、实际付款人与凭据一致。`]}):``]})}function ee(a,o=`owner`,s=`客户付款金额`){let c=r.values||{},l=e.payment_account,u=r.paymentMethod??P(l)?.channel,d=e.payments.find(e=>e.id===(c.entry||``).split(`:`)[1]),f=r.action===`correct`?d?.kind===`receipt`&&Y(c.account):u===`信用卡`&&r.action===`receipt`,p=e.credit_card_rate_permille??i.shopSettings?.creditCardRatePermille,m,g;if(f||r.lastCardBasis!==void 0){let t=f?c.amount??(e.balance/100).toFixed(2):r.lastCardBasis,n,i;try{n=C.cents(t)}catch{n=null}if(p!=null)try{i=S.amount(n??0,p)}catch{i=null}i==null?g=`信用卡手续费率未能确认,请重新读取后核对。`:n==null?g=`填写客户付款金额后自动计算`+p+`‰手续费;付款人默认`+T(`owner`)+`,可按实际修改。`:(m=(i/100).toFixed(2),g=s+` ¥`+v(n)+` × `+p+`‰ = ¥`+v(i)+`。计入内部成本,客户付款金额不变;退款不退回已发生的手续费。`)}return(0,w.jsxs)(`div`,{className:`credit-card-preview`,id:a,"data-basis":s,hidden:!f,children:[(0,w.jsxs)(`div`,{className:`credit-card-heading`,children:[(0,w.jsx)(`strong`,{children:`信用卡手续费(内部)`}),(0,w.jsx)(`span`,{className:`small muted`,children:`自动计算 · 客户单据不显示`})]}),(0,w.jsxs)(`div`,{className:`credit-card-fields`,children:[(0,w.jsxs)(`label`,{children:[`手续费(元,自动)`,(0,w.jsx)(n,{type:`number`,min:`0`,step:`0.01`,"data-credit-card-amount":``,readOnly:!0,value:m||``,"aria-label":`信用卡手续费自动金额`})]}),(0,w.jsxs)(`label`,{children:[`手续费付款人`,(0,w.jsx)(t,{name:`credit_card_fee_payer`,defaultValue:o,required:!!f,disabled:!f,children:L(h())})]})]}),(0,w.jsx)(`p`,{className:`small muted`,"data-credit-card-formula":``,"aria-live":`polite`,children:g})]})}function q(e){return e?.system===`credit_card`||String(e?.key||``).startsWith(`card_fee:`)}function J(e=``,t=!1){let n=z(),r=n.map(e=>[e,B(e)]);return e&&!n.includes(e)&&r.push([e,B(e)+(t?`(已停用 · 原货盘)`:`(已停用,请重新选择)`),!0]),r}function Y(e){return typeof S==`object`&&typeof S.isAccount==`function`?S.isAccount(e??``):[`助理信用卡`,`助理1信用卡`,`麦麦信用卡`,`助理2信用卡`].includes(e??``)}let X=()=>e?.member||R();function Z(){let e=x()?X():`assistant`;return F(I(e)?e:`owner`)}function Q(){return typeof S==`object`&&i?.accounts?.includes(`麦麦信用卡`)}function $(e){let n=[`微信`,`支付宝`,`现金`,...Q()?[`信用卡`]:[]];e=M(e||Z()+`微信`);let i=r.paymentMethod?r.paymentMethod===`信用卡`:Y(e),a=P(e),o=a?F(a.member):Z(),s=h(!x()).map(([e,t])=>[F(e),t]);return a&&!I(a.member)&&s.push([o,T(a.member)+`(已停用 · 原记录)`]),(0,w.jsxs)(w.Fragment,{children:[m(`收款方式`,`payment_method`,n,a?.channel||`微信`),(0,w.jsxs)(`label`,{children:[`收款人`,(0,w.jsx)(t,{name:`payment_recipient`,defaultValue:i?`麦麦`:r.recipient||o,"data-non-card-recipient":i?Z():o,"data-card-locked":i,disabled:i,children:L(s)},i?`card`:`standard`),Q()?(0,w.jsxs)(`small`,{className:`small muted payment-account-note`,hidden:!i,children:[`信用卡统一由`,T(`owner`),`收款。`]}):``]})]})}let te=(e=`date`,t)=>g(`业务日期`,e,t||i.today,`date`,{max:i.today,required:!0});function ne(o){let S=e,C=``,M=te(),P=a(o),F=c(o,r.date);if([`return`,`refund`].includes(o)&&l(S))throw Error(`本单已办理售后,请查看售后处理记录,不能重复退货退款。`);if(o===`cancel`)throw Error(`请重新读取订单后,从“取消订单”或“申请取消”核对办理。`);if(S.ownershipPending||u(S))throw Error(`归属申请待店主复核,当前暂停本单其他修改和记账。`);if(S.cancellationPending||d(S))throw Error(`取消申请待店主复核,当前暂停本单修改和退货。`);if(S.changePending||f(S))throw Error(`修改申请待店主复核,当前暂停本单其他记账和取消申请。`);if(S.cancellationApproved&&![`settlement`,`correct`,`review`].includes(o))throw Error(`本单已按录错作废,不能继续登记销售、费用或退款。`);if(o===`complete`&&i.user.role===`assistant`&&S.pendingFees.length)throw Error(`这张旧单还有费用尚未入账,请先申请补记旧单费用,店主同意后再补齐旧单账务。`);if(o===`fees`&&(C=(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`p`,{children:`补齐旧单实际已付费用,没有发生的填0。保存后只记一次实际费用;完成旧单账务后计算完整利润。`}),M,(0,w.jsx)(`div`,{className:`fee-grid`,id:`verify-fees`,children:E.Children.toArray(S.pendingFees.map(e=>(0,w.jsxs)(`div`,{className:`fee-verify-row`,"data-key":e.key,children:[(0,w.jsx)(`h3`,{children:e.note}),p(`实际成本(元)`,`verifiedAmount`,e.amount===null?``:(e.amount/100).toFixed(2)),m(`实际付款人`,`verifiedPayer`,h(!0),e.payer)]})))}),(0,w.jsxs)(`label`,{className:`check`,children:[(0,w.jsx)(n,{type:`checkbox`,name:`verified`,required:!0}),`已核实实际支付,没有发生的费用已填0。`]})]})),[`receipt`,`refund`].includes(o)&&(C=(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`div`,{className:`grid three`,children:[M,p(o===`receipt`?`本次实收金额`:`本次实退金额`,`amount`,((o===`receipt`?S.balance:S.netReceived)/100).toFixed(2)),$(o===`refund`&&S.payments.find(e=>e.kind===`receipt`&&S.payments.filter(t=>t.account===e.account).reduce((e,t)=>e+(t.kind===`receipt`?t.amount:-t.amount),0)>0)?.account||S.payment_account)]}),g(`凭据备注(选填)`,`reference`,``,`text`,{maxLength:100,placeholder:`交易凭据末几位或说明`}),(0,w.jsxs)(`label`,{className:`check`,children:[(0,w.jsx)(n,{type:`checkbox`,name:`verified`,required:!0}),`已在实际账户核实`,o===`receipt`?`到账`:`退款成功`,`,不是仅收到客户截图。`]})]})),o===`expense`&&(C=(0,w.jsxs)(w.Fragment,{children:[S.pendingFees.length?(0,w.jsx)(`div`,{className:`note`,children:`本旧单还有费用尚未入账,请从“补记旧单费用”补齐,或完成旧单账务时一并入账。这里仅记额外发生的费用。`}):``,(0,w.jsx)(`p`,{className:`small muted`,children:`记录额外已支付的费用;已包含在货品成本或已记账费用中的不要重复登记。`}),(0,w.jsxs)(`div`,{className:`grid three`,children:[M,p(`本次费用`,`amount`),m(`实际付款人`,`payer`,h(!0),`assistant`)]}),g(`费用项目与说明`,`note`,``,`text`,{required:!0,maxLength:150})]})),o===`cost`&&(C=(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`div`,{className:`note`,children:`进货料价和克工费按该行克重自动计算;原单合计金额保留,改按克录入时需填写实际单价。没有的成本填0,完成销售记账后锁定。快递和附加费用可从“补记旧单费用”填写。`}),S.lines.map((e,t)=>(0,w.jsx)(N,{line:e,index:t,members:h,fallback:x()?X():`owner`,choice:m,opts:L,grams:_,yuan:v},t))]})),o===`complete`&&(C=(0,w.jsxs)(w.Fragment,{children:[M,E.Children.toArray(S.lines.map((e,t)=>e.unit===`g`&&y(e.pocket)&&e.stockCount==null?b(e.pocket,``,{name:`completeCount-`+t,title:e.name+` · 实际出库数量(对)`,help:``}):``)),(0,w.jsx)(`p`,{children:`补齐这张旧单的销售记账:按填写金额记录实际费用、从原货盘扣减黄金并计入销售与利润。款项未收齐或成本金额有空白时,请先补齐。`}),(0,w.jsxs)(`label`,{className:`check`,children:[(0,w.jsx)(n,{type:`checkbox`,name:`verified`,required:!0}),`已核实全额收款、商品已交付,所填费用为实际已付金额,没有发生的已填0。`]})]})),o===`return`&&(C=(0,w.jsxs)(w.Fragment,{children:[M,g(`退货原因`,`reason`,``,`text`,{required:!0,maxLength:200}),(0,w.jsx)(`div`,{className:`grid two`,children:E.Children.toArray(S.lines.map((e,t)=>(0,w.jsxs)(`div`,{className:`return-stock-item`,children:[m(e.name+` · 实物去向`,`return-`+t,e.unit===`g`?[...e.pocket||e.costMaterial?.mode===`pool`?[]:[[``,`已退供应商,不留店内`]],...J(e.pocket,!0)]:[[``,`按件商品,不记黄金货盘`]],e.pocket||(e.costMaterial?.mode===`pool`?i.pockets[0]:``)),b(r.values?.[`return-`+t]??(e.pocket||(e.costMaterial?.mode===`pool`?i.pockets[0]:``)),e.stockCount,{readOnly:Number.isSafeInteger(e.stockCount),name:`returnCount-`+t,title:`实际退回数量(对)`,help:``})]})))}),(0,w.jsx)(`div`,{className:`note`,children:`本入口办理整单退货,原销售额与货品成本在退货日冲回。已花费的运费等仍保留。换货先退原单,再开新单;部分退货暂未开放。`}),(0,w.jsxs)(`label`,{className:`check`,children:[(0,w.jsx)(n,{type:`checkbox`,name:`verified`,required:!0}),`已核实本单全部商品退回,所选去向与实际一致。`]})]})),o===`settlement`&&x())throw Error(`团队成员往来请在每日对账核对。`);if(o===`settlement`&&(S.materialCostPending||S.settlementDue==null))throw Error(`本批料费尚未补齐,补足采购后再核对实际交款。`);if(o===`settlement`&&(C=(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`div`,{className:`grid three`,children:[M,m(`转款方向`,`direction`,[[`toOwner`,T(`assistant`)+` → `+T(`owner`)],[`toAssistant`,T(`owner`)+` → `+T(`assistant`)]],S.settlementDue<0?`toAssistant`:`toOwner`),m(`本笔归属`,`bucket`,[[`cost`,`货款`],[`profit`,`利润`]],`cost`)]}),(0,w.jsxs)(`div`,{className:`grid two`,children:[p(`实际转账金额`,`amount`),g(`转账凭据/说明`,`note`,``,`text`,{required:!0,maxLength:150})]}),(0,w.jsx)(`p`,{className:`small muted`,children:S.ownerCredit?T(`owner`)+`已直接收到部分客户款,先按实际情况核清归属。`:`货款待结 ¥${v(S.costDue)};利润待结 ¥${v(S.profitDue)}(负数为${T(`owner`)}需转回)。`}),(0,w.jsxs)(`label`,{className:`check`,children:[(0,w.jsx)(n,{type:`checkbox`,name:`verified`,required:!0}),`已核实各人实际转账,不是仅记录计划交款。`]})]})),o===`correct`){let e=e=>!e.price_lock_event_id&&!S.corrections.some(t=>t.target===e.id)&&!String(e.note||e.reference||``).startsWith(`更正冲回:`),i=new Set((S.fee_items||[]).filter(q).map(e=>e.expense_id)),a=[...(S.cancellationApproved||l(S)?[]:S.payments.filter(e)).map(e=>[`payment:`+e.id,e.date+` `+(e.kind===`receipt`?`客户收款`:`客户退款`)+` `+v(e.amount)+`元 `+D(e.account)]),...(S.cancellationApproved||l(S)?[]:S.expenses.filter(t=>e(t)&&!q(t)&&!i.has(t.id))).map(e=>[`expense:`+e.id,e.date+` 直接费用 `+v(e.amount)+`元 `+e.note]),...S.settlements.filter(e).map(e=>[`settlement:`+e.id,e.date+` `+(e.amount<0?T(`owner`)+`返款`:T(`assistant`)+`交款`)+` `+v(Math.abs(e.amount))+`元`])];C=(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`div`,{className:`note`,children:`更正录错的流水,保留原记录。填0表示撤回误记。真实客户退货请用退货入口,不要用更正代替。更正发生在所选日期,不覆盖原日记录。`}),m(`选择原流水`,`entry`,a,a[0]?.[0]),(0,w.jsxs)(`div`,{className:`grid three`,children:[M,p(`更正后金额(元)`,`amount`),(0,w.jsxs)(`label`,{children:[`更正后收退款账户(仅收退款)`,(0,w.jsx)(t,{name:`account`,defaultValue:`助理微信`,children:L(O())}),(0,w.jsxs)(`small`,{className:`small muted correction-card-note`,hidden:!Y(r.values?.account),children:[`信用卡统一由`,T(`owner`),`收款。`]})]}),m(`更正后付款人(仅费用)`,`payer`,h(!0),`assistant`),m(`更正后转款方向(仅交款)`,`direction`,[[`toOwner`,T(`assistant`)+` → `+T(`owner`)],[`toAssistant`,T(`owner`)+` → `+T(`assistant`)]],`toOwner`),m(`更正后款项归属(仅交款)`,`bucket`,[[`cost`,`货款`],[`profit`,`利润`]],`cost`)]}),g(`更正原因`,`reason`,``,`text`,{required:!0,maxLength:200}),(0,w.jsxs)(`label`,{className:`check`,children:[(0,w.jsx)(n,{type:`checkbox`,name:`verified`,required:!0}),`已核实原凭据,这次是修正登记错误。`]})]})}return[`receipt`,`correct`].includes(o)&&(C=(0,w.jsxs)(w.Fragment,{children:[C,ee(`action-credit-card-fee`)]})),o===`review`&&(C=(0,w.jsx)(`p`,{children:`确认已查看商品、克重、成本、收退款与交款凭据。复核后再有变动,会重新提示待复核。`})),(0,w.jsxs)(`form`,{className:`panel`,id:`action-form`,"data-kind":o,...P?{"data-order-change":`true`,"data-order-direct":!F}:{},children:[(0,w.jsx)(`h2`,{children:F?`申请`+k[o]:A[o]}),P?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`fieldset`,{style:{display:`contents`},disabled:!!r.stale||!!r.actionBlocked,children:[C,K(o)]}),(0,w.jsx)(`div`,{id:`order-action-change-error`,"aria-live":`polite`,children:r.actionError&&(0,w.jsxs)(`div`,{className:`error`,children:[r.actionError,r.retryKey&&(0,w.jsx)(s,{type:`submit`,formNoValidate:!0,"data-retry-key":r.retryKey,disabled:!!r.retryBusy,children:`恢复原操作`}),r.stale&&(0,w.jsxs)(w.Fragment,{children:[` `,j(`重新读取订单后申请`,`reload-order-change`)]})]})})]}):C,(0,w.jsxs)(`div`,{className:`form-actions`,children:[(0,w.jsx)(s,{className:`primary`,disabled:!!r.stale||!!r.actionBlocked,...P?{"data-order-action-submit":``}:{},children:F?`提交变更申请`:P?`核实并保存`:`确认保存`}),j(`收起`,`hide-action`,`quiet`)]})]},r.formKey)}return{showAction:ne,actionInput:W,orderActionUsesChangeForm:a,orderActionRequiresApproval:c}}function F({state:e,currentOrder:i,orderChangeDetail:a,orderOwnershipDetail:c,orderCancellationDetail:l,orderChangeListStatus:u,orderOwnershipListStatus:d,orderCancellationListStatus:f},{orderChangeActionLabel:p,orderChangeTime:m,orderChangeActionSummaryHTML:h,orderChangeComparisonHTML:g,button:_,teamMemberEnabled:v,opts:y,orderOwnershipEffectHTML:b,orderOwnershipPairHTML:x,orderOwnershipTime:S,orderCancellationCanDirect:C,orderCancellationTime:T,validateOrderCancellationSummary:D,yuan:O,pocketLabel:k,grams:A,inventoryCountHTML:j,orderCancellationStatus:M,orderChangeMoney:N,orderChangeStatus:P,orderOwnershipStatus:F,validateOrderChangeRequest:I,validateOrderOwnershipRequest:L}){function R(e){return e.direct===!0?`当天直接取消`:M[e.status]}function z(t){let n=e.user.role===`owner`&&t.canApprove;return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`div`,{className:`cancellation-list-tabs`,role:`group`,"aria-label":`取消申请状态`,children:E.Children.toArray([[`pending`,`待复核`],[`approved`,`已取消`],[`rejected`,`已驳回`],[`all`,`全部`]].map(([e,n])=>_(n+(e===`all`?``:`(`+t.counts[e]+`)`),`filter-order-cancellations`,f===e?`primary`:``,{"data-status":e,"aria-pressed":f===e})))}),t.requests.length?(0,w.jsx)(`div`,{className:`table-wrap`,children:(0,w.jsx)(r,{className:`cancellation-list-table`,"aria-label":`全部日期的取消申请`,columns:[{title:`原订单/日期`},{title:`经办/申请人及时间`},{title:`取消原因`},{title:`状态/处理记录`},{title:`查看`}],rows:t.requests.map((e,t)=>({key:t,cellClasses:[void 0,void 0,`cancellation-reason`,void 0,void 0],cells:[(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`strong`,{children:e.order_number}),(0,w.jsx)(`div`,{className:`small muted`,children:e.order_date}),(0,w.jsxs)(`div`,{className:`small`,children:[`原成交 ¥`,O(e.summary.total)]})]}),(0,w.jsxs)(w.Fragment,{children:[e.direct===!0?`经办人:`:``,e.operator_name||e.requester_name,(0,w.jsx)(`div`,{className:`small muted`,children:T(e.executedAt||e.created)})]}),e.reason,(0,w.jsxs)(w.Fragment,{children:[R(e),e.stale&&e.status===`pending`?(0,w.jsx)(`div`,{className:`small danger-text`,children:`原单已有变动,需驳回后重新申请`}):``,e.note?(0,w.jsx)(`div`,{className:`small cancellation-reason`,children:e.note}):``,e.reviewer_name?(0,w.jsxs)(`div`,{className:`small muted`,children:[e.reviewer_name,` · `,T(e.reviewed)]}):``]}),_(n&&e.status===`pending`?`查看并复核`:`查看订单`,`open-cancellation-order`,``,{"data-id":e.order_id})]}))})}):(0,w.jsx)(`p`,{className:`empty`,children:`全部日期均无此状态的取消申请。`})]})}function B(t){let n=e.user.role===`owner`&&t.canApprove;return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`div`,{className:`change-list-tabs`,role:`group`,"aria-label":`归属申请状态`,children:E.Children.toArray([[`pending`,`待复核`],[`approved`,`已修改`],[`rejected`,`已驳回`],[`all`,`全部`]].map(([e,n])=>_(n+(e===`all`?``:`(`+t.counts[e]+`)`),`order-ownership-filter`,d===e?`primary`:``,{"data-status":e,"aria-pressed":d===e})))}),t.requests.length?(0,w.jsx)(`div`,{className:`table-wrap`,children:(0,w.jsx)(r,{className:`change-list-table`,"aria-label":`全部日期的归属申请`,columns:[{title:`订单/日期`},{title:`归属修改`},{title:`申请人/原因`},{title:`复核结果`},{title:`查看`}],rows:t.requests.map((e,t)=>({key:t,cells:[(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`strong`,{className:`order-ownership-list-customer`,children:e.order_customer||`未填客户称呼`}),(0,w.jsxs)(`div`,{className:`small muted`,children:[e.order_number,` · `,e.order_date]})]}),x(e),(0,w.jsxs)(w.Fragment,{children:[e.requester_name,(0,w.jsx)(`div`,{className:`small muted`,children:S(e.created)}),(0,w.jsx)(`p`,{className:`change-reason`,children:e.reason})]}),(0,w.jsxs)(w.Fragment,{children:[F[e.status],e.stale&&e.status===`pending`?(0,w.jsx)(`div`,{className:`small danger-text`,children:`订单已有变动,需驳回后重申`}):``,e.note?(0,w.jsx)(`p`,{className:`small change-reason`,children:e.note}):``,e.reviewer_name?(0,w.jsxs)(`div`,{className:`small muted`,children:[e.reviewer_name,` · `,S(e.reviewed)]}):``]}),_(n&&e.status===`pending`?`查看并复核`:`查看订单`,`order-ownership-open-order`,``,{"data-id":e.order_id})]}))})}):(0,w.jsx)(`p`,{className:`empty`,children:`全部日期均无此状态的归属申请。`})]})}function V(t){let n=e.user.role===`owner`&&t.canApprove;return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`div`,{className:`change-list-tabs`,role:`group`,"aria-label":`变更申请状态`,children:E.Children.toArray([[`pending`,`待复核`],[`approved`,`已同意`],[`rejected`,`已驳回`],[`all`,`全部`]].map(([e,n])=>_(n+(e===`all`?``:`(`+t.counts[e]+`)`),`filter-order-changes`,u===e?`primary`:``,{"data-status":e,"aria-pressed":u===e})))}),t.requests.length?(0,w.jsx)(`div`,{className:`table-wrap`,children:(0,w.jsx)(r,{className:`change-list-table`,"aria-label":`全部日期的变更申请`,columns:[{title:`原订单/日期`},{title:`申请人/申请时间`},{title:`动作/申请原因`},{title:`状态/复核意见`},{title:`查看`}],rows:t.requests.map((e,t)=>({key:t,cellClasses:[void 0,void 0,`change-reason`,void 0,void 0],cells:[(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`strong`,{children:e.order_number}),(0,w.jsx)(`div`,{className:`small muted`,children:e.order_date}),(0,w.jsxs)(`div`,{className:`small`,children:[`原成交 `,N(e.summary.before.total),(0,w.jsx)(`br`,{}),`申请成交 `,N(e.summary.after.total)]})]}),(0,w.jsxs)(w.Fragment,{children:[e.requester_name,(0,w.jsx)(`div`,{className:`small muted`,children:m(e.created)})]}),(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`strong`,{children:p(e)}),(0,w.jsx)(`br`,{}),e.reason]}),(0,w.jsxs)(w.Fragment,{children:[P[e.status],e.stale&&e.status===`pending`?(0,w.jsx)(`div`,{className:`small danger-text`,children:`原单已有变动,需驳回后重新申请`}):``,e.note?(0,w.jsx)(`div`,{className:`small change-reason`,children:e.note}):``,e.reviewer_name?(0,w.jsxs)(`div`,{className:`small muted`,children:[e.reviewer_name,` · `,m(e.reviewed)]}):``]}),_(n&&e.status===`pending`?`查看并复核`:`查看订单`,`open-change-order`,``,{"data-id":e.order_id})]}))})}):(0,w.jsx)(`p`,{className:`empty`,children:`全部日期均无此状态的变更申请。`})]})}function H(e){return e?.requiresLegacyCountVerified?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`div`,{className:`note`,children:e.legacyCountNotice||`这笔历史记录未记录对数,当前对数按实际盘点基准保留。本次旧重量冲回不自动更改当前对数,如实物有变化请另做当天对数调整。`}),(0,w.jsxs)(`label`,{className:`check`,children:[(0,w.jsx)(n,{name:`legacyCountVerified`,type:`checkbox`,required:!0}),`已核对当前对数基准,理解本次更正对历史对数的处理`]})]}):``}function U(e,t=void 0){let n=e?.summary,r=e=>e===null||Number.isSafeInteger(e);if(!e||typeof e.id!=`string`||!e.id||typeof e.order_id!=`string`||t&&e.order_id!==t||!Object.hasOwn(M,e.status)||!Number.isSafeInteger(e.order_revision)||typeof e.reason!=`string`||typeof e.requester_name!=`string`||typeof e.created!=`string`||typeof e.stale!=`boolean`||typeof e.canApprove!=`boolean`||!n||![`total`,`netReceived`,`directCost`].every(e=>Number.isSafeInteger(n[e]))||![`goodsCost`,`profit`,`settlementDue`].every(e=>r(n[e]))||!Array.isArray(n.inventory)||!n.inventory.every(e=>typeof e.date==`string`&&typeof e.pocket==`string`&&Number.isSafeInteger(e.mg)))throw Error(`取消申请资料未完整返回,请重新读取订单后复核。`);return e}function W(e){return G(U(e).summary)}function G(e){let t=D(e),n=e=>e===null?`待补齐`:`¥`+O(e);return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`div`,{className:`note`,children:`本次按“录错作废”撤销本单记账,不是实际退货退款。原单和冲回明细保留,不会向客户付款。`}),(0,w.jsxs)(`dl`,{className:`cancellation-summary`,children:[(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`dt`,{children:`撤销原成交金额`}),(0,w.jsx)(`dd`,{children:n(t.total)})]}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`dt`,{children:`撤销收款净额`}),(0,w.jsx)(`dd`,{children:n(t.netReceived)})]}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`dt`,{children:`撤销货品成本`}),(0,w.jsx)(`dd`,{children:n(t.goodsCost)})]}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`dt`,{children:`撤销已记费用`}),(0,w.jsx)(`dd`,{children:n(t.directCost)})]}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`dt`,{children:`撤销原记账利润`}),(0,w.jsx)(`dd`,{children:n(t.profit)})]}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`dt`,{children:`当前双方待结净额`}),(0,w.jsx)(`dd`,{children:n(t.settlementDue)})]})]}),(0,w.jsx)(`h3`,{children:`库存冲回摘要`}),t.legacyCountNotice?(0,w.jsx)(`p`,{className:`note`,children:t.legacyCountNotice}):``,t.inventory.length?(0,w.jsx)(`div`,{className:`table-wrap`,children:(0,w.jsx)(r,{"aria-label":`取消后库存冲回摘要`,columns:[{title:`原日期`},{title:`货盘`},{title:`恢复/冲回克重`,headerClassName:`number`}],rows:t.inventory.map((e,t)=>({key:t,cellClasses:[void 0,void 0,`number`],cells:[e.date,k(e.pocket),(0,w.jsxs)(w.Fragment,{children:[e.mg>0?`+`:``,A(e.mg),`g`,j(e,{signed:!0})]})]}))})}):(0,w.jsx)(`p`,{className:`small muted`,children:`本单没有需要冲回的库存出入。`}),(0,w.jsx)(`p`,{className:`small muted cancellation-summary-note`,children:`按原日期、原货盘冲回库存。收款与费用撤回后仍能查看原记录和冲回行;双方实际交款保留,不会自动抹掉或转账。日购料真实采购付款保留,本单耗用将释放并重算相关成本与待结金额。`})]})}let K=()=>({order:i,data:l.data});function ee(t){let{order:r,data:i}=K(),a=i.pending;if(t===`request`&&C(r)&&(t=`direct`),[`request`,`direct`].includes(t)&&(!i.eligible||a||![`draft`,`confirmed`,`delivered`].includes(r.status)))throw Error(i.reason||`这张订单当前不能申请取消。`);if(t===`direct`&&!C(r))throw Error(`当前不能直接取消,请重新读取订单。`);if(![`request`,`direct`].includes(t)&&(e.user.role!==`owner`||!i.canApprove||a?.status!==`pending`))throw Error(`取消申请由店主账号复核。`);if(t===`approve`&&(!a.canApprove||a.stale||a.order_revision!==r.revision))throw Error(`订单已有变动,请重新读取后复核;过期申请需驳回后重新申请。`);let c,l,u;if(t===`direct`)l=`取消今天的订单`,u=`核实并取消订单`,c=(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`div`,{className:`note`,id:`order-cancellation-mode`,children:[`这张订单是今天开的,核实后直接按录错作废,无需另行审批。业务日期:`,i.directActionDate,`。本入口不办理真实退货或退款。`]}),(0,w.jsx)(n,{type:`hidden`,name:`date`,defaultValue:i.directActionDate}),G(i.summary),(0,w.jsxs)(`label`,{children:[`取消原因`,(0,w.jsx)(o,{name:`reason`,rows:3,required:!0,maxLength:200,placeholder:`写清这张单录错的原因,例如:同一笔销售重复录入。`})]}),(0,w.jsxs)(`label`,{className:`check`,children:[(0,w.jsx)(n,{type:`checkbox`,name:`verified`,required:!0}),`已核实这是录错作废,并确认撤销上述记账和冲回库存;本次不登记真实退货退款。`]})]});else if(t===`request`)l=`申请取消这张订单`,u=`提交取消申请`,c=(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`p`,{children:`仅用于开错、重复录入等需要整单作废的登记错误。提交后仍按原单计账,店主同意后才取消、恢复库存并撤销本单销售、成本、收款和费用记账。`}),(0,w.jsx)(`p`,{className:`small muted`,children:`真实退货请从“整单退货”办理;这里不会发起真实退款。`}),(0,w.jsxs)(`label`,{children:[`取消原因`,(0,w.jsx)(o,{name:`reason`,rows:3,required:!0,maxLength:200,placeholder:`写清这张单录错的原因,例如:同一笔销售重复录入。`})]})]});else if(t===`approve`)l=`复核并同意取消`,u=`同意取消并作废`,c=(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`p`,{children:[`申请人:`,a.requester_name,` · `,T(a.created)]}),(0,w.jsxs)(`p`,{className:`cancellation-reason`,children:[`取消原因:`,a.reason]}),W(a),(0,w.jsxs)(`label`,{children:[`复核备注(选填)`,(0,w.jsx)(o,{name:`note`,maxLength:200,rows:2})]}),(0,w.jsxs)(`label`,{className:`check`,children:[(0,w.jsx)(n,{type:`checkbox`,name:`verified`,required:!0}),`已核实这是录错作废,并确认撤销上述记账和冲回库存;本次不登记真实退货退款。`]})]});else if(t===`reject`)l=`驳回取消申请`,u=`确认驳回`,c=(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`p`,{className:`cancellation-reason`,children:[`取消原因:`,a.reason]}),(0,w.jsx)(`p`,{className:`small muted`,children:`驳回后原订单继续计账,申请人可核对后重新申请。`}),(0,w.jsxs)(`label`,{children:[`驳回意见`,(0,w.jsx)(o,{name:`note`,rows:3,required:!0,maxLength:200,placeholder:`写清需要补充或重新核对的地方。`})]})]});else throw Error(`取消操作无效,请重新读取订单。`);return t!==`reject`&&(c=(0,w.jsxs)(w.Fragment,{children:[c,H(t===`approve`?a.summary:i.requiresLegacyCountVerified?i:i.summary)]})),(0,w.jsxs)(`form`,{className:`panel order-cancellation-form`,id:`order-cancellation-form`,"data-kind":t,children:[(0,w.jsx)(`h2`,{children:l}),c,(0,w.jsx)(`div`,{id:`order-cancellation-error`,"aria-live":`polite`}),(0,w.jsxs)(`div`,{className:`form-actions`,children:[(0,w.jsx)(s,{type:`submit`,"data-order-cancellation-submit":``,className:[`approve`,`direct`].includes(t)?`danger`:`primary`,children:u}),_(`收起`,`close-order-cancellation-form`,`quiet`)]})]})}let q=()=>({order:i,data:c.data});function J(r=`request`){let{order:i,data:a}=q(),c=a.pending;if(![`request`,`approve`,`reject`].includes(r))throw Error(`归属修改操作无效,请重新读取。`);if(r===`request`&&(!a.eligible||c))throw Error(a.reason||`本单当前不能重复修改归属。`);if(r!==`request`&&(e.user.role!==`owner`||!a.canApprove||c?.status!==`pending`))throw Error(`归属申请由店主账号复核。`);if(r===`approve`&&(!c.canApprove||c.stale||c.order_revision!==i.revision))throw Error(`订单已有变动,请驳回旧申请后按最新订单重新核对。`);let l=r===`request`&&e.user.role===`owner`&&a.canDirect;if(r===`request`&&e.user.role===`owner`&&!l)throw Error(a.reason||`当前不能直接修改归属,请重新读取订单。`);let u,d,f;if(r===`request`){u=l?`修改订单归属`:`申请修改订单归属`,f=l?`确认修改归属`:`提交归属申请`;let e=a.members.find(e=>e.member===a.member),r=a.members.filter(e=>e.member!==a.member&&e.enabled!==!1&&v(e.member));d=(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`div`,{className:`note`,children:l?`店主核对后直接生效。`:`提交后等待店主复核,今天的订单也须审批;批准前继续按原归属计账。`}),(0,w.jsxs)(`div`,{className:`grid two`,children:[(0,w.jsxs)(`label`,{children:[`当前归属`,(0,w.jsx)(n,{defaultValue:e.label,readOnly:!0})]}),(0,w.jsxs)(`label`,{children:[`修改为`,(0,w.jsx)(t,{name:`member`,required:!0,defaultValue:``,children:y([[``,`请选择新归属`],...r.map(e=>[e.member,e.label])])})]})]}),(0,w.jsxs)(`p`,{className:`order-ownership-selection`,id:`order-ownership-selection`,"aria-live":`polite`,children:[e.label,` → 请选择新归属`]}),b(a.member),(0,w.jsxs)(`label`,{children:[`修改原因`,(0,w.jsx)(o,{name:`reason`,required:!0,maxLength:200,rows:3,placeholder:`写清原归属录错的原因及正确归属。`})]}),(0,w.jsxs)(`label`,{className:`check`,children:[(0,w.jsx)(n,{type:`checkbox`,name:`verified`,required:!0}),`已核对原归属、新归属和修改原因,确认本次归属`,l?`更正`:`申请`,`。`]})]})}else u=r===`approve`?`复核并同意修改归属`:`驳回归属申请`,f=r===`approve`?`同意并修改归属`:`确认驳回`,d=(0,w.jsxs)(w.Fragment,{children:[x(c),(0,w.jsxs)(`p`,{children:[`申请人:`,c.requester_name,` · `,S(c.created)]}),(0,w.jsxs)(`p`,{className:`change-reason`,children:[`修改原因:`,c.reason]}),r===`approve`?(0,w.jsxs)(w.Fragment,{children:[b(c.before.member),(0,w.jsxs)(`label`,{children:[`复核备注(选填)`,(0,w.jsx)(o,{name:`note`,maxLength:200,rows:2})]}),(0,w.jsxs)(`label`,{className:`check`,children:[(0,w.jsx)(n,{type:`checkbox`,name:`verified`,required:!0}),`已核对原归属、新归属和原因,同意后按新归属统计,并更新原助理的查看权限。`]})]}):(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`p`,{className:`small muted`,children:`驳回后保留原归属,申请人可核对后重新申请。`}),(0,w.jsxs)(`label`,{children:[`驳回意见`,(0,w.jsx)(o,{name:`note`,required:!0,maxLength:200,rows:3,placeholder:`写清需要重新核对的地方。`})]})]})]});return(0,w.jsxs)(`form`,{id:`order-ownership-form`,className:`panel order-ownership-form`,"data-kind":r,children:[(0,w.jsx)(`h2`,{children:u}),d,(0,w.jsx)(`div`,{id:`order-ownership-error`,"aria-live":`polite`}),(0,w.jsxs)(`div`,{className:`form-actions`,children:[(0,w.jsx)(s,{type:`submit`,className:`primary`,children:f}),_(`收起`,`order-ownership-close-form`,`quiet`)]})]})}let Y=()=>({order:i,data:a.data});function X(t){let{order:r,data:i}=Y(),a=i.pending;if(![`approve`,`reject`].includes(t))throw Error(`修改复核操作无效,请重新读取订单。`);if(e.user.role!==`owner`||!i.canApprove||a?.status!==`pending`)throw Error(`修改申请由店主账号复核。`);if(t===`approve`&&(!a.canApprove||a.stale||a.order_revision!==r.revision))throw Error(`订单已有变动,请重新读取后复核;过期申请需驳回后重新申请。`);let c=(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`p`,{children:(0,w.jsxs)(`strong`,{children:[`本次申请:`,p(a)]})}),(0,w.jsxs)(`p`,{children:[`申请人:`,a.requester_name,` · `,m(a.created)]}),(0,w.jsxs)(`p`,{className:`change-reason`,children:[`申请原因:`,a.reason]})]}),l=t===`approve`?(0,w.jsxs)(w.Fragment,{children:[c,h(a),g(a),(0,w.jsxs)(`label`,{children:[`复核备注(选填)`,(0,w.jsx)(o,{name:`note`,maxLength:200,rows:2})]}),(0,w.jsxs)(`label`,{className:`check`,children:[(0,w.jsx)(n,{type:`checkbox`,name:`verified`,required:!0}),`已核对本次申请动作、金额、日期、账户或付款人、退货去向及库存,确认原值与申请值,以及以上关联订单的本次修改。`]})]}):(0,w.jsxs)(w.Fragment,{children:[c,(0,w.jsx)(`p`,{children:`驳回后原单继续计账,申请人可按最新原单重新申请。`}),(0,w.jsxs)(`label`,{children:[`驳回意见`,(0,w.jsx)(o,{name:`note`,required:!0,maxLength:200,rows:3,placeholder:`写清需要重新核对或补充的地方。`})]})]});return(0,w.jsxs)(`form`,{className:`panel order-change-form`,id:`order-change-form`,"data-kind":t,children:[(0,w.jsx)(`h2`,{children:t===`approve`?`复核并同意变更`:`驳回变更申请`}),l,(0,w.jsx)(`div`,{id:`order-change-error`,"aria-live":`polite`}),(0,w.jsxs)(`div`,{className:`form-actions`,children:[(0,w.jsx)(s,{type:`submit`,className:`primary`,children:t===`approve`?`同意变更并更新原单`:`确认驳回`}),_(`收起`,`close-order-change-form`,`quiet`)]})]})}return{showOrderChangeForm:X,showOrderOwnershipForm:J,showOrderCancellationForm:ee,orderChangeListHTML:V,orderOwnershipListHTML:B,orderCancellationListHTML:z,validateOrderCancellationRequest:U,validateOrderChangeRequest:I,validateOrderOwnershipRequest:L}}function I(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function L(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>0}function R({afterSaleChangesStatus:e,state:a,ui:c={},orderAfterSaleFormEntry:l,currentOrder:u},{button:d,validOrderDate:f,teamMemberKeys:p,field:m,moneyField:h,opts:g,teamMemberOptions:_,currentMember:v,teamMode:y,choice:b,teamMemberName:S,yuan:T,activePaymentAccounts:D,normalizePaymentAccount:O,accountIdentity:k,orderAfterSaleSummaryHTML:A,orderActionCanDirect:j,grams:M,stockCountText:N,pocketCountsEnabled:P,pocketLabel:F,stockCountField:R,activePocketKeys:z,orderChangeUser:B,stockCountValue:V}){function H(e,t){if(!I(e)||e.id!==t||!L(e.revision)||!I(e.record))return!1;let n=e.record,r=e.permissions;return n.id===t&&n.revision===e.revision&&typeof n.actor==`string`&&typeof n.created==`string`&&typeof n.member==`string`&&p().includes(n.member)&&le(n)&&I(r)&&typeof r.canEdit==`boolean`&&typeof r.canDirectEdit==`boolean`&&typeof r.requiresApproval==`boolean`&&typeof r.reason==`string`&&I(e.values)&&typeof e.values.amount==`string`&&Array.isArray(e.history)&&e.history.every(e=>de(e))&&(e.pending===null||!!de(e.pending))}function U(e,t){if(!H(e,t))throw Error(`售后记录资料未完整返回,请重新读取后再修改。`);if(e.pending&&(e.pending.afterSaleId!==t||e.permissions.canEdit))throw Error(`售后修改状态不一致,请重新读取。`);for(let n of e.history)if(n.afterSaleId!==t)throw Error(`售后修改历史不一致,请重新读取。`);return e}function W(e,t){return(0,w.jsxs)(`form`,{id:`after-sale-review-form`,"data-id":t.id,"data-kind":e,children:[(0,w.jsx)(`h3`,{children:e===`approve`?`同意售后修改`:`驳回售后修改`}),(0,w.jsxs)(`label`,{children:[e===`approve`?`复核备注(选填)`:`驳回意见`,(0,w.jsx)(o,{disabled:c.blocked,name:`note`,rows:2,maxLength:200,required:e===`reject`})]}),e===`approve`?(0,w.jsxs)(`label`,{className:`check`,children:[(0,w.jsx)(n,{disabled:c.blocked,type:`checkbox`,name:`verified`,required:!0}),`已核对原值、申请值、日期、金额和付款人。`]}):``,(0,w.jsxs)(`div`,{className:`form-actions`,children:[d(`取消`,`after-sale-review-cancel`,`quiet`,{disabled:c.busy}),(0,w.jsx)(s,{type:`submit`,disabled:c.blocked,className:e===`approve`?`primary`:``,children:e===`approve`?`确认同意修改`:`确认驳回申请`})]})]})}function G(e,t){let n=a.user.role===`owner`&&e.status===`pending`;return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(s,{className:`dialog-close`,"data-action":`after-sale-changes-close`,"aria-label":`关闭售后修改复核`,children:`×`}),(0,w.jsxs)(`h2`,{id:`after-sale-changes-title`,children:[`售后修改`,e.status===`pending`?`复核`:`记录`]}),(0,w.jsx)(`div`,{className:`actions`,children:d(`返回申请列表`,`after-sale-changes-reload`,`quiet`)}),(0,w.jsxs)(`p`,{children:[se(e),` · `,e.requesterName||`申请人未提供`,` · `,ce(e.created)]}),(0,w.jsxs)(`p`,{className:`small muted`,children:[`订单归属:`,S(e.member),`。`,e.status===`pending`?`本次申请尚未生效;店主同意后才更新原售后。`:``]}),e.reason?(0,w.jsxs)(`p`,{className:`change-reason`,children:[`修改说明:`,e.reason]}):``,q(e),e.stale?(0,w.jsx)(`div`,{className:`error`,children:e.staleReason||`原记录已有变动,不能同意这份旧申请。请驳回后按最新记录重新申请。`}):``,e.status===`pending`?``:(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`p`,{className:`small muted`,children:[`复核人:`,e.reviewerName||`未提供`,` · `,ce(e.reviewed)]}),e.note?(0,w.jsxs)(`p`,{className:`change-reason`,children:[e.status===`rejected`?`驳回意见`:`复核备注`,`:`,e.note]}):``]}),(0,w.jsx)(`div`,{id:`after-sale-review-actions`,children:t?W(t,e):n?(0,w.jsxs)(`div`,{className:`actions`,children:[e.canApprove&&!e.stale?d(`同意修改`,`after-sale-review-decision`,`primary`,{"data-kind":`approve`}):``,d(`驳回申请`,`after-sale-review-decision`,``,{"data-kind":`reject`})]}):``}),(0,w.jsx)(`div`,{id:`after-sale-review-error`,"aria-live":`polite`,children:c.feedback})]})}function K(e){return(0,w.jsxs)(`li`,{children:[(0,w.jsx)(`strong`,{children:se(e)}),(0,w.jsxs)(`small`,{children:[e.requesterName||`申请人未提供`,` · `,ce(e.created)]}),e.reason?(0,w.jsxs)(`p`,{className:`change-reason`,children:[`修改说明:`,e.reason]}):``,e.status===`pending`?``:(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`small`,{children:[`复核人:`,e.reviewerName||`未提供`,` · `,ce(e.reviewed)]}),e.note?(0,w.jsxs)(`p`,{className:`change-reason`,children:[e.status===`rejected`?`驳回意见`:`复核备注`,`:`,e.note]}):``]}),(0,w.jsxs)(`details`,{children:[(0,w.jsx)(`summary`,{children:`查看原值与申请值`}),q(e)]})]})}function ee(e){return(0,w.jsx)(`dl`,{className:`after-sale-facts`,children:E.Children.toArray([[`售后日期`,e.date],[`售后项目`,e.project],[`客户`,e.customer],[`金额`,`¥`+T(e.amount)],[`谁支付`,S(e.payer)],[`订单归属`,S(e.member)]].map(([e,t])=>(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`dt`,{children:e}),(0,w.jsx)(`dd`,{children:t})]})))})}function q(e){let t=de(e),n=(e,n,r=e=>e)=>{let i=t.before[n]!==t.after[n];return(0,w.jsxs)(`tr`,{...i?{className:`order-change-modified`}:{},children:[(0,w.jsxs)(`th`,{scope:`row`,children:[e,i?(0,w.jsx)(`span`,{className:`change-mark`,children:`已修改`}):``]}),(0,w.jsx)(`td`,{children:r(t.before[n])}),(0,w.jsx)(`td`,{children:r(t.after[n])})]})};return(0,w.jsx)(`div`,{className:`table-wrap after-sale-comparison`,children:(0,w.jsxs)(i,{className:`order-change-table`,"aria-label":`售后修改原值与申请值对照`,children:[(0,w.jsx)(`thead`,{children:(0,w.jsxs)(`tr`,{children:[(0,w.jsx)(`th`,{children:`核对项目`}),(0,w.jsx)(`th`,{children:`原值(申请时)`}),(0,w.jsx)(`th`,{children:`申请值(同意后)`})]})}),(0,w.jsxs)(`tbody`,{children:[n(`售后日期`,`date`),n(`售后项目`,`project`),n(`客户`,`customer`),n(`金额`,`amount`,e=>`¥`+T(Number(e))),n(`谁支付`,`payer`,S)]})]})})}function J(e){let t=e.record,n=e.pending,r=n?(0,w.jsxs)(`section`,{className:`after-sale-pending`,children:[(0,w.jsx)(`h3`,{children:`待店主审批`}),(0,w.jsx)(`p`,{className:`small muted`,children:`申请尚未生效,当前仍按原记录计账。`}),q(n),n.reason?(0,w.jsxs)(`p`,{className:`change-reason`,children:[`修改说明:`,n.reason]}):``,a.user.role===`owner`?d(`查看并复核`,`after-sale-change-open`,`primary`,{"data-id":n.id}):(0,w.jsx)(`p`,{className:`small muted`,children:`店主同意后才更新这笔记录。`})]}):``;return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(s,{className:`dialog-close`,"data-action":`close-after-sale`,"aria-label":`关闭售后记录`,children:`×`}),(0,w.jsx)(`h2`,{id:`after-sale-title`,children:`修改售后`}),e.permissions.canEdit?(0,w.jsxs)(`form`,{id:`after-sale-edit-form`,"data-id":t.id,"data-approval":String(c.approval),children:[(0,w.jsxs)(`fieldset`,{disabled:c.blocked,style:{display:`contents`},children:[(0,w.jsxs)(`div`,{className:`grid two`,children:[m(`售后日期`,`date`,t.date,`date`,{required:!0,max:a.today}),m(`售后项目`,`project`,t.project,`text`,{required:!0,maxLength:100}),m(`客户`,`customer`,t.customer,`text`,{required:!0,maxLength:60}),h(`金额(元)`,`amount`,(t.amount/100).toFixed(2)),Y(t.member,!0),b(`谁支付`,`payer`,_(),t.payer)]}),(0,w.jsx)(`div`,{className:`note`,id:`after-sale-edit-mode`,"aria-live":`polite`,children:c.approval?`本次修改需店主审批。同意后才更新售后费用和利润;待审批期间仍按原记录计账。`:a.user.role===`owner`?`保存后直接更新这笔售后,费用与利润按修改后的日期重算。`:`原日期与修改后日期均为今天,直接保存;改为其他日期须提交店主审批。`}),(0,w.jsxs)(`label`,{children:[`修改说明(选填)`,(0,w.jsx)(o,{name:`reason`,rows:2,maxLength:200,placeholder:`例如:售后金额或付款人录错。`})]})]}),(0,w.jsx)(`div`,{id:`after-sale-edit-error`,"aria-live":`polite`,children:c.feedback}),(0,w.jsxs)(`div`,{className:`form-actions`,children:[(0,w.jsx)(`span`,{className:`small muted`,children:`金额可填 0。归属沿用原记录。`}),(0,w.jsxs)(`div`,{className:`actions`,children:[d(`取消`,`close-after-sale`,`quiet`,{disabled:c.busy}),(0,w.jsx)(s,{type:`submit`,disabled:c.blocked,className:`primary`,children:c.approval?`提交修改申请`:`直接保存修改`})]})]})]}):(0,w.jsxs)(w.Fragment,{children:[ee(t),n?``:(0,w.jsx)(`p`,{className:`note`,children:e.permissions.reason||`这笔售后当前不可修改。`}),r]}),(0,w.jsx)(`div`,{id:`after-sale-read-error`,"aria-live":`polite`}),e.history.length?(0,w.jsxs)(`details`,{children:[(0,w.jsxs)(`summary`,{children:[`售后修改记录(`,e.history.length,`)`]}),(0,w.jsx)(`ul`,{className:`timeline`,children:E.Children.toArray(e.history.map(K))})]}):``]})}function Y(e=v(),t=!1){if(!y())return``;let r=p().includes(e)?e:v();return a.user.role===`owner`&&!t?b(`订单归属(经营款与业绩)`,`member`,_(),r):(0,w.jsxs)(`label`,{children:[`订单归属(经营款与业绩)`,(0,w.jsx)(n,{defaultValue:S(r),readOnly:!0}),(0,w.jsx)(n,{type:`hidden`,name:`member`,defaultValue:r})]})}function X(){return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(s,{className:`dialog-close`,"data-action":`close-after-sale`,"aria-label":`关闭新增售后`,children:`×`}),(0,w.jsx)(`h2`,{id:`after-sale-title`,children:`新增售后`}),(0,w.jsx)(`p`,{className:`small muted`,children:`售后费用计入所选日期,并扣减当天利润。`}),(0,w.jsxs)(`form`,{id:`after-sale-form`,children:[(0,w.jsxs)(`div`,{className:`grid two`,children:[m(`售后日期`,`date`,a.today,`date`,{required:!0,max:a.today}),m(`售后项目`,`project`,``,`text`,{required:!0,maxLength:100,placeholder:`例如:维修、补寄快递`}),m(`客户`,`customer`,``,`text`,{required:!0,maxLength:60,placeholder:`客户称呼或代号`}),h(`金额(元)`,`amount`,``),Y(),(0,w.jsxs)(`label`,{children:[`谁支付`,(0,w.jsxs)(t,{name:`payer`,required:!0,defaultValue:``,children:[(0,w.jsx)(`option`,{value:``,disabled:!0,children:`请选择`}),g(_())]})]})]}),(0,w.jsx)(`div`,{id:`after-sale-error`,"aria-live":`polite`,children:c.feedback}),(0,w.jsxs)(`div`,{className:`form-actions`,children:[(0,w.jsx)(`span`,{className:`small muted`,children:`金额可填 0,请按实际支出填写。`}),(0,w.jsxs)(`div`,{className:`actions`,children:[d(`取消`,`close-after-sale`,`quiet`),(0,w.jsx)(s,{className:`primary`,type:`submit`,children:`保存售后`})]})]})]})]})}function Z(e){return k(e)?.member||v()}let Q=x.positiveMg;function $(e){let t=u,n=l,r=t=>String(e.querySelector(`[name="${t}"]`)?.value??``).trim();if(!n||!t||n.id!==t?.id||n.user!==B()||n.revision!==t.revision||e.dataset.orderId!==n.id)throw Error(`请重新读取订单后核对售后。`);let i=r(`date`),o=r(`reason`);if(!f(i)||i>a.today||i<(t.delivered_date||t.date))throw Error(`售后日期应为交付当天至今天之间的有效日期。`);if(!o||o.length>200)throw Error(`售后原因请填写1~200字。`);let s=[...e.querySelectorAll(`[data-after-sale-line]`)];if(s.length!==t.lines.length)throw Error(`请核对全部退回商品后再提交。`);let c=s.map((e,n)=>{let r=t=>String(e.querySelector(`[name="${t}"]`)?.value??``).trim(),i=t.lines[n],a=r(`return_quantity`),o=Q(a),s=r(`return_pocket`),c=r(`return_disposition`);if(!o||o>i.quantity)throw Error(`商品 `+(n+1)+`实际退回克重须大于0且不超过原出库克重。`);if(!ne().includes(s))throw Error(`商品 `+(n+1)+`请选择已启用的自有退入货盘。`);if(![`stock`,`scrap`].includes(c))throw Error(`请选择退回后的实物状态。`);if(c===`scrap`&&P(s))throw Error(`旧料不恢复成品对数,请选择不按对计数的旧料货盘。`);let l=c===`stock`&&P(s)?V(r(`return_count`),{title:`商品 `+(n+1)+`实际退回数量(对)`}):null;if(i.stockCount!=null&&l!=null&&Number.isSafeInteger(i.stockCount)&&l>i.stockCount)throw Error(`商品 `+(n+1)+`实际退回对数不能超过原出库对数。`);return{lineIndex:n,quantity:a,pocket:s,disposition:c,stockCount:l}}),d=r(`refund_amount`),m=C.cents(d,`实际退款金额`);if(m>t.netReceived)throw Error(`实际退款不能超过本单尚未退回的净实收金额。`);let h=r(`deduction_reason`);if(h.length>200||t.netReceived-m>0&&!h)throw Error(`有扣留客户款时,请填写1~200字扣留原因。`);let g=O(r(`refund_account`)),_=r(`refund_payer`);if(!g||!p().includes(_))throw Error(`请选择退款账户与实际退款付款人。`);if(_!==Z(g))throw Error(`实际退款付款人须与退款账户一致。`);let v=r(`refund_reference`);if(v.length>100)throw Error(`退款凭据备注最多100字。`);let y=[...e.querySelectorAll(`.order-after-sale-expense`)].map(e=>{let t=t=>String(e.querySelector(`[name="${t}"]`)?.value??``).trim(),n=t(`expense_amount`),r=t(`expense_note`),i=t(`expense_payer`);if(C.cents(n,`新增售后成本`)<=0)throw Error(`新增售后成本须大于0,没有发生请移除此项。`);if(!r||r.length>150||!p().includes(i))throw Error(`请填写新增售后成本项目并选择实际付款人。`);return{amount:n,payer:i,note:r}});if(y.length>30)throw Error(`一次售后最多填写30项新增成本。`);return{date:i,revision:n.revision,reason:o,verified:!0,afterSale:{lines:c,refund:{amount:d,account:g,payer:_,reference:v},deductionReason:h,expenses:y}}}function te(e={}){return(0,w.jsxs)(`div`,{className:`order-after-sale-expense grid four`,children:[m(`售后成本项目`,`expense_note`,e.note||``,`text`,{required:!0,maxLength:150,placeholder:`如寄件费、重新编绳`}),h(`实际成本(元)`,`expense_amount`,e.amount??``),b(`实际付款人`,`expense_payer`,_(),e.payer||v()),d(`移除`,`order-after-sale-remove-expense`,`quiet`)]})}function ne(){return z().filter(e=>a.pocketCatalog?.some(t=>t.key===e&&t.self===!0))}function re(e,t){let n=ne(),r=c.lines?.[t]?.pocket??(n.includes(e.pocket)?e.pocket:n[0]||``),i=c.lines?.[t]?.disposition||`stock`;return(0,w.jsxs)(`article`,{className:`order-after-sale-line`,"data-after-sale-line":t,children:[(0,w.jsxs)(`div`,{className:`panel-title`,children:[(0,w.jsxs)(`h3`,{children:[t+1,` · `,e.name]}),(0,w.jsxs)(`span`,{className:`small muted`,children:[`原出库 `,M(e.quantity),`g`,Number.isSafeInteger(e.stockCount)?` · `+N(e.stockCount):P(e.pocket)?` · 未记录对数`:``]})]}),(0,w.jsxs)(`div`,{className:`grid two`,children:[m(`实际退回克重(g)`,`return_quantity`,M(e.quantity),`number`,{required:!0,min:`0.001`,max:M(e.quantity),step:`0.001`,inputMode:`decimal`}),b(`退回后的状态`,`return_disposition`,[[`stock`,`完好退回现货(保留工费)`],[`scrap`,`退回旧料(工费损失)`]],`stock`),b(`实际退入自有货盘`,`return_pocket`,n.map(e=>[e,F(e)]),r),R(r,String(e.stockCount??``),{name:`return_count`,visible:i===`stock`&&P(r),title:`实际退回数量(对)`,help:`按实际清点填写,不使用计工费件数。`})]}),(0,w.jsx)(`p`,{className:`small muted`,"data-after-sale-line-note":``,children:i===`stock`?`实退材料按原料费回售后日料池;原进货工费保留为这件现货的库存成本,再销售时选择对应退回现货继承,不重复付款。`:`实退材料按原料费回售后日料池;原进货工费计入本单售后损失,不恢复成品对数。`})]})}function ie(e=a.today){return l?.forceApproval||a.user.role===`assistant`&&!j(`return`,e)}function ae(e=a.today){return ie(e)?`本次提交原订单售后申请,店主同意后一次登记退货、退款、费用与利润调整。复核前原账保持原值。`:`核实后一次登记退货、实际退款与售后成本。系统只记账,退款须已在实际账户完成。`}function oe(e){let t=(e.payments?.filter(e=>e.kind===`receipt`)||[]).find(t=>e.payments.filter(e=>e.account===t.account).reduce((e,t)=>e+(t.kind===`receipt`?t.amount:-t.amount),0)>0)?.account||e.payment_account,r=D(O(t));t&&!r.includes(O(t))&&r.push(O(t));let i=k(t)?.member||v();return(0,w.jsxs)(`form`,{id:`order-after-sale-form`,className:`panel order-after-sale-form`,"data-order-id":e.id,children:[(0,w.jsx)(`h2`,{children:`处理售后`}),(0,w.jsx)(`p`,{id:`order-after-sale-mode`,className:`note`,"aria-live":`polite`,children:ae(c.date)}),(0,w.jsxs)(`div`,{className:`grid two`,children:[m(`售后日期`,`date`,a.today,`date`,{required:!0,max:a.today}),(0,w.jsxs)(`label`,{children:[`售后原因`,(0,w.jsx)(o,{name:`reason`,rows:2,maxLength:200,required:!0,placeholder:`填写客户实际退货退款原因。`})]})]}),(0,w.jsxs)(`section`,{className:`order-after-sale-products`,children:[(0,w.jsx)(`h3`,{children:`实物回库`}),E.Children.toArray(e.lines.map(re))]}),(0,w.jsxs)(`section`,{className:`order-after-sale-refund internal`,children:[(0,w.jsx)(`h3`,{children:`实际退款`}),(0,w.jsxs)(`div`,{className:`grid three`,children:[h(`实际退款金额(元,可修改)`,`refund_amount`,(e.netReceived/100).toFixed(2)),b(`退款账户`,`refund_account`,r,O(t)),b(`实际退款付款人`,`refund_payer`,_(),i)]}),m(`退款凭据备注(选填)`,`refund_reference`,``,`text`,{maxLength:100}),(0,w.jsxs)(`div`,{className:`order-after-sale-retained`,children:[(0,w.jsx)(`span`,{children:`本次扣留客户款(系统计算)`}),(0,w.jsx)(`strong`,{id:`order-after-sale-retained`,children:c.retained??`¥0.00`}),(0,w.jsxs)(`small`,{className:`muted`,children:[`原净实收 ¥`,T(e.netReceived),` − 本次实际退款`]})]}),(0,w.jsxs)(`label`,{children:[`扣留款原因`,(0,w.jsx)(o,{name:`deduction_reason`,required:c.reasonRequired,rows:2,maxLength:200,placeholder:`有扣留款时填写,如约定扣除不可退工费或实际损耗。`})]}),(0,w.jsx)(`p`,{className:`small muted`,children:`扣留款与支付渠道手续费分开核对。原单已经发生的支付手续费、邮费等成本继续保留。`})]}),(0,w.jsxs)(`section`,{className:`order-after-sale-expenses internal`,children:[(0,w.jsxs)(`div`,{className:`panel-title`,children:[(0,w.jsx)(`h3`,{children:`新增售后成本(选填)`}),d(`+ 添加售后成本`,`order-after-sale-add-expense`)]}),(0,w.jsx)(`p`,{className:`small muted`,children:`只填这次新发生且实际已付的成本;原单已记费用不要重复填写。`}),(0,w.jsx)(`div`,{id:`order-after-sale-expenses`,children:c.expenses})]}),(0,w.jsxs)(`div`,{className:`form-actions`,children:[(0,w.jsx)(s,{type:`button`,className:`primary`,"data-action":`order-after-sale-preview`,disabled:c.previewLoading,children:`核对售后预览`}),(0,w.jsx)(`span`,{className:`small muted`,id:`order-after-sale-preview-status`,"aria-live":`polite`,children:c.previewStatus||`填好后先预览,核对回库、回料、退款和利润。`})]}),(0,w.jsx)(`div`,{id:`order-after-sale-preview`,"aria-live":`polite`,children:c.preview&&A(c.preview.record,{preview:!0})}),(0,w.jsxs)(`label`,{className:`check`,children:[(0,w.jsx)(n,{type:`checkbox`,name:`verified`,required:!0,disabled:!c.preview}),`已按实际退回商品、退款凭据和新增成本,核对以下预览。`]}),(0,w.jsx)(`div`,{id:`order-after-sale-error`,"aria-live":`polite`,children:c.afterError&&(0,w.jsxs)(`div`,{className:`error`,children:[c.afterError,` `,(0,w.jsx)(s,{type:`button`,"data-action":`reload-order-change`,children:`重新读取订单`})]})}),(0,w.jsxs)(`div`,{className:`form-actions`,children:[(0,w.jsx)(s,{type:`submit`,className:`primary`,"data-order-after-sale-submit":``,disabled:!c.preview,children:ie(c.date)?`提交售后申请`:`确认并保存售后`}),d(`收起`,`order-after-sale-close`,`quiet`)]})]})}function se(e){return{pending:`待店主审批`,approved:`已同意`,rejected:`已驳回`}[e.status]||`状态待确认`}function ce(e){return String(e||`未提供`).replace(`T`,` `).replace(/\.\d{3}Z$/,` UTC`).replace(/Z$/,` UTC`)}function le(e){return I(e)&&f(e.date)&&typeof e.project==`string`&&!!e.project.trim()&&e.project.length<=100&&typeof e.customer==`string`&&!!e.customer.trim()&&e.customer.length<=60&&typeof e.amount==`number`&&Number.isSafeInteger(e.amount)&&e.amount>=0&&typeof e.payer==`string`&&p().includes(e.payer)}function ue(e){return I(e)&&typeof e.id==`string`&&!!e.id&&typeof e.afterSaleId==`string`&&!!e.afterSaleId&&L(e.revision)&&L(e.recordRevision)&&(e.status===`pending`||e.status===`approved`||e.status===`rejected`)&&le(e.before)&&le(e.after)&&typeof e.canApprove==`boolean`&&typeof e.stale==`boolean`&&typeof e.staleReason==`string`&&typeof e.member==`string`&&typeof e.created==`string`&&typeof e.requesterName==`string`&&(e.reviewed==null||typeof e.reviewed==`string`)&&(e.reviewerName==null||typeof e.reviewerName==`string`)&&(e.note==null||typeof e.note==`string`)&&typeof e.reason==`string`}function de(e){if(!ue(e))throw Error(`售后修改申请资料未完整返回,请重新读取。`);return e}function fe(t){if(!Array.isArray(t.requests)||!t.counts||![`pending`,`approved`,`rejected`].every(e=>Number.isSafeInteger(t.counts[e])&&t.counts[e]>=0))throw Error(`售后修改列表未完整返回,请重新读取。`);let n=E.Children.toArray([[`pending`,`待审批`],[`approved`,`已同意`],[`rejected`,`已驳回`],[`all`,`全部`]].map(([n,r])=>d(r+(n===`all`?``:`(`+t.counts[n]+`)`),`after-sale-changes-filter`,n===e?`active`:``,{"data-status":n,"aria-pressed":n===e}))),i=t.requests.map(de);return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`div`,{className:`change-list-tabs`,role:`group`,"aria-label":`售后修改申请状态`,children:n}),i.length?(0,w.jsx)(`div`,{className:`table-wrap`,children:(0,w.jsx)(r,{className:`change-list-table`,columns:[{title:`售后记录`},{title:`修改后日期`},{title:`申请人`},{title:`申请时间`},{title:`状态`},{title:`操作`}],rows:i.map((e,t)=>({key:t,cells:[(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`strong`,{children:e.before.customer}),(0,w.jsxs)(`div`,{className:`small muted`,children:[e.before.date,` · `,e.before.project]})]}),e.after.date,e.requesterName||`未提供`,ce(e.created),(0,w.jsxs)(w.Fragment,{children:[se(e),e.stale?(0,w.jsx)(`div`,{className:`small danger-text`,children:`原记录已有变动`}):``]}),d(a.user.role===`owner`&&e.status===`pending`?`查看并复核`:`查看修改`,`after-sale-change-open`,``,{"data-id":e.id})]}))})}):(0,w.jsx)(`p`,{className:`empty`,children:`没有符合状态的售后修改申请。`})]})}return{afterSaleChangeListHTML:fe,newIndependentSale:X,editIndependentSale:J,independentReview:G,independentReviewForm:W,orderAfterSaleFormHTML:oe,orderAfterSaleExpenseHTML:te,orderAfterSaleInput:$,orderAfterSaleApproval:ie,orderAfterSalePocketKeys:ne,orderAfterSaleAccountPayer:Z,orderAfterSaleModeText:ae,validateAfterSaleDetail:U,validateAfterSaleRequest:de,orderAfterSaleSummaryHTML:A}}function z(e){let t=D(e);return{...t,...O(e,t),...k(e,t),...P(e,t),...F(e,t),...R(e,t)}}var B=e=>typeof e==`object`&&!!e,V=e=>e instanceof Error?e.message:String(e),H=e=>B(e)&&(e.status===403||e.status===404||e.status===409);function U({client:e,state:t,session:n,sale:r,refreshState:i,refreshBook:a,openList:o,close:c,saved:l}){let{message:u}=f.useApp(),[d,p]=(0,E.useState)(r.action===`after-sale-change-open`&&r.id||``),[m,g]=(0,E.useState)(``),[_,v]=(0,E.useState)(``),[y,b]=(0,E.useState)(!1),[x,S]=(0,E.useState)(null),[D,O]=(0,E.useState)(null),[k,A]=(0,E.useState)(``),[j,M]=(0,E.useState)(0),N=(0,E.useRef)(0);(0,E.useEffect)(()=>()=>{N.current++},[]);let P=d||r.id,F=d?`/api/after-sales/changes/`+encodeURIComponent(d):r.id?`/api/after-sales/`+encodeURIComponent(r.id):``,I=z({state:t,session:n}),L=h(async()=>{d||await i();let t=await e.api(F);if(!d)return{kind:`record`,data:I.validateAfterSaleDetail(t,r.id||``)};let n=I.validateAfterSaleRequest(t);if(n.id!==d)throw Error(`申请编号不一致,请重新读取。`);return{kind:`request`,data:n}},F&&t.user.id+`/`+F+`/`+j),R=L.value?.kind===`record`?L.value.data:void 0,U=D??(L.value?.kind===`request`?L.value.data:void 0),W=!!R?.permissions&&(R.permissions.requiresApproval||!R.permissions.canDirectEdit||t.user.role!==`owner`&&(R.record.date!==t.today||(x??R.record.date)!==t.today)),G=!!(y||e.busy||e.pending());function K(){N.current++,g(``),v(``),S(null),O(null),A(``),b(!1),M(e=>e+1)}function ee(){N.current++,c()}function q(e){let t=V(e).replace(`不要重新开单`,P?`不要重复提交售后修改`:`不要重复新增售后`);H(e)&&P&&b(!0),v(t),u.error(t)}async function J(n,r,o,s){if(e.user!==t.user.id)return;let c=B(r)&&typeof r.date==`string`?r.date:void 0,f=()=>N.current===s&&e.user===t.user.id;if(n===`/api/after-sales`){f()?l(c):a(),u.success(`售后已保存,已计入 `+c+` 的费用与利润`),await i();return}let p=n.endsWith(`/update`),m=p&&B(o)&&o.applied===!0,h=p?m?`售后修改已保存`:`售后修改申请已提交,待店主审批`:n.endsWith(`/approve`)?`已同意售后修改`:`已驳回售后修改申请`;f()&&(g(``),v(``),A(h));try{if(await i(),e.user!==t.user.id)return;if(f()&&m)l(B(o.record)&&B(o.record.record)&&typeof o.record.record.date==`string`?o.record.record.date:c);else if(a(),f()&&p&&K(),f()&&!p){let e=I.validateAfterSaleRequest(o);if(e.id!==d)throw Error(`申请编号不一致,请重新读取。`);O(e),A(``)}u.success(h)}catch(e){f()&&v(`结果已保存,刷新失败:`+V(e)+`。请重新读取查看结果。`)}}async function Y(t){let n=t.target instanceof Element&&t.target.closest(`[data-action]`);if(!n)return;t.stopPropagation();let{action:r,id:i,kind:a}=n.dataset;if(r===`close-after-sale`||r===`after-sale-changes-close`)return ee();if(r===`after-sale-changes-reload`)N.current++,o();else if(r===`after-sale-change-open`||r===`after-sale-edit`){if(e.busy)return;r===`after-sale-change-open`&&i&&p(i),K()}else if(r===`after-sale-review-decision`){if(y||U?.status!==`pending`)return q(Error(`请重新读取申请后再复核。`));(a===`approve`||a===`reject`)&&g(a),v(``)}else if(r===`after-sale-review-cancel`)g(``),v(``);else if(r===`retry`){let t=N.current;try{let n=await e.retryPending();n&&await J(n.job.url,n.job.data,n.result,t)}catch(e){t===N.current&&q(e)}}}async function X(n){n.stopPropagation(),n.preventDefault();let r=n.target;if(!(r instanceof HTMLFormElement))return;let i=Object.fromEntries(Array.from(new FormData(r),([e,t])=>[e,String(t)])),a=N.current;try{let n,o;if(d){if(t.user.role!==`owner`)throw Error(`请使用店主账号复核。`);if(G||U?.status!==`pending`||r.dataset.id!==U.id||r.dataset.kind!==m)throw Error(`请重新读取申请后再复核。`);let e=i.note.trim();if(m===`approve`&&(!U.canApprove||U.stale))throw Error(`原记录已有变动,请重新读取并核对。`);if(m===`reject`&&!e)throw Error(`请填写驳回意见。`);if(e.length>200)throw Error(`复核意见最多200字。`);if(m===`approve`&&!i.verified)throw Error(`请核对修改前后内容并勾选确认。`);n=F+`/`+m,o={revision:U.revision,note:e,...m===`approve`?{verified:!0}:{}}}else{if(P&&(G||!R||!R.permissions.canEdit||R.pending||r.dataset.id!==P))throw Error(`请重新读取售后记录后再修改。`);if(o={date:i.date,project:i.project.trim(),customer:i.customer.trim(),amount:i.amount.trim(),payer:i.payer},!I.validOrderDate(o.date)||o.date>t.today)throw Error(`售后日期请选择今天或之前的有效日期。`);if(!o.project||o.project.length>100)throw Error(`售后项目请填写1~100字。`);if(!o.customer||o.customer.length>60)throw Error(`客户请填写1~60字的称呼或代号。`);if(!I.teamMemberKeys().includes(o.payer))throw Error(`请选择这笔售后由谁支付。`);if(C.cents(o.amount,`售后金额`),P&&R){let e=i.reason.trim();if(e.length>200)throw Error(`修改说明最多200字。`);n=F+`/update`,o={revision:R.revision,...o,reason:e}}else n=`/api/after-sales`,I.teamMode()&&Object.assign(o,{member:i.member||I.currentMember()})}v(``);let s=await e.mutate(n,o);await J(n,o,s,a)}catch(e){if(a!==N.current)return;let t=r.elements.namedItem(`verified`);H(e)&&t instanceof HTMLInputElement&&(t.checked=!1),q(e)}}let Z=(0,w.jsx)(s,{type:`button`,disabled:e.busy,"data-action":d?`after-sale-change-open`:`after-sale-edit`,"data-id":P,children:d?`重新读取申请并复核`:`重新读取售后`}),Q=_&&(0,w.jsxs)(`div`,{className:`error`,role:`alert`,children:[_,` `,P&&(e.pending()?(0,w.jsx)(s,{type:`button`,"data-action":`retry`,disabled:e.busy,children:`恢复原操作`}):Z)]}),$=z({state:t,session:n,ui:{approval:W,blocked:G,busy:e.busy,feedback:Q}}),te;return te=k||F&&(d?!U:!R)?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(s,{className:`dialog-close`,"data-action":d?`after-sale-changes-close`:`close-after-sale`,"aria-label":d?`关闭售后修改复核`:`关闭售后记录`,children:`×`}),(0,w.jsx)(`h2`,{children:k||(d?`售后修改复核`:`修改售后`)}),L.error||_?(0,w.jsxs)(`div`,{className:`error`,role:`alert`,children:[L.error||_,` `,Z,d&&(0,w.jsx)(s,{"data-action":`after-sale-changes-reload`,children:`返回申请列表`})]}):(0,w.jsx)(`p`,{role:`status`,children:k?`正在刷新…`:d?`正在读取申请…`:`正在读取售后记录…`})]}):d&&U?$.independentReview(U,m):P&&R?$.editIndependentSale(R):$.newIndependentSale(),(0,w.jsx)(T,{id:d?`after-sale-changes-dialog`:`after-sale-dialog`,ownClose:!0,label:d?`售后修改复核`:`售后记录`,close:ee,children:(0,w.jsx)(`div`,{onClick:Y,onSubmit:X,onChange:e=>{e.target instanceof HTMLInputElement&&e.target.name===`date`&&S(e.target.value)},children:te})})}var W=e=>{e.stopPropagation(),e.preventDefault()},G=e=>Object.fromEntries(new FormData(e));function K({ids:e,id:t,open:n,blocked:r}){if(!e)return null;let i=e.indexOf(t);return(0,w.jsxs)(`div`,{className:`order-detail-navigation-row`,role:`group`,"aria-label":`切换订单`,children:[(0,w.jsx)(s,{"data-action":`order-detail-prev`,disabled:r||i<=0,onClick:()=>n(e[i-1]),children:`← 上一条`}),(0,w.jsxs)(`span`,{"aria-live":`polite`,children:[i+1,` / `,e.length]}),(0,w.jsx)(s,{"data-action":`order-detail-next`,disabled:r||i<0||i>=e.length-1,onClick:()=>n(e[i+1]),children:`下一条 →`}),(0,w.jsx)(`small`,{children:`按当前筛选后的销售订单顺序查看`})]})}function ee({selected:e,client:t,state:n,session:r,refresh:i,refreshState:a,listIds:o,openOrder:c,close:u,onLost:d,printStatuses:f}){let v=`/api/orders/`+encodeURIComponent(e),[b,x]=(0,E.useState)(0),[S,D]=(0,E.useState)(null),[O,k]=(0,E.useState)(``),[A,j]=(0,E.useState)({}),[M,N]=(0,E.useState)([]),P=(0,E.useRef)(0);(0,E.useEffect)(()=>()=>{P.current++},[]);let F=h(async()=>{let[i,a,o,s]=await Promise.allSettled([t.api(v),t.api(v+`/change`),t.api(v+`/ownership`),t.api(v+`/cancellation`)]);if(i.status===`rejected`)throw L.revoke(i.reason),i.reason;let c=g(i.value,e),l=z({state:n,session:r});function u(t,r){let i={id:e,user:n.user.id,revision:c.revision};if(t.status===`rejected`){if(L.revoke(t.reason))throw t.reason;return{...i,error:_(t.reason)}}try{let n=t.value;if(n.revision!==c.revision||!Array.isArray(n.requests))throw Error(`订单已有新记录,请重新读取订单后复核。`);return n.requests.forEach(t=>r(t,e)),{...i,data:n}}catch(e){return{...i,error:_(e)}}}return{order:c,entries:[u(a,l.validateOrderChangeRequest),u(o,l.validateOrderOwnershipRequest),u(s,l.validateOrderCancellationRequest)]}},[e,b,n.user.id].join(`/`)),I=F.value?.order,L=p({client:t,state:n,id:e,watch:!!I,onLost:d}),R=f[I?.printStatus?.id||e],B=I&&R?{...I,printStatus:R}:I,[V,H,U]=F.value?.entries||[],ee=t.pending(),q={state:n,session:r,currentOrder:B,orderChangeDetail:V,orderOwnershipDetail:H,orderCancellationDetail:U,orderAfterSaleFormEntry:B&&{id:e,revision:B.revision,user:n.user.id,forceApproval:A.forceApproval},ui:{...A,actionBlocked:t.busy||!!ee,retryBusy:t.busy,retryKey:ee?.key===A.pendingKey?A.pendingKey:null},navigation:(0,w.jsx)(K,{ids:o,id:e,open:c,blocked:!!S||t.busy||!!t.pending()})},J=z(q);function Y(){P.current++,D(null),k(``),N([]),j({})}let X=h(()=>t.api(v+`/after-sale`),S?.type===`after`&&e+`/`+b),Z,Q=O;try{S?.type===`after`?X.error?Q=X.error:X.value?X.value.orderId!==e||X.value.revision!==B.revision||!X.value.eligible||X.value.record||!J.orderAfterSalePocketKeys().length||B.lines.some(e=>e.unit!==`g`||!e.costParts||e.costParts.material==null||e.costParts.labor==null)?Q=X.value.blockedReason||`请重新核对原单成本、自有货盘与售后资格。`:Z=z({...q,ui:{...A,expenses:M.map(e=>(0,w.jsx)(`div`,{"data-expense-id":e,children:J.orderAfterSaleExpenseHTML()},e))}}).orderAfterSaleFormHTML(B):Z=(0,w.jsx)(`p`,{role:`status`,children:`正在读取售后资料…`}):S?.type===`action`?Z=J.showAction(S.kind):S&&(Z={change:J.showOrderChangeForm,ownership:J.showOrderOwnershipForm,cancellation:J.showOrderCancellationForm}[S.type](S.kind))}catch(e){Q=_(e)}function $(){Y(),x(e=>e+1),i()}async function te(n){if(!(n.target instanceof Element))return;let r=n.target.closest(`[data-action]`);if(!r)return;n.stopPropagation();let{action:i=``,id:a=``}=r.dataset;try{if(i===`close-dialog`||i===`order-detail-prev`||i===`order-detail-next`)return;if(i===`print`)return window.open(`/print/`+encodeURIComponent(e)+`?mode=full`,`_blank`,`noopener`),await t.mutate(v+`/print`,{mode:`full`});if(i===`recovery-print`)return window.open(`/print/recoveries/`+encodeURIComponent(a),`_blank`,`noopener`);if(i===`edit-order`)return l(`order-edit`,{search:`?order=`+encodeURIComponent(e)});if(i===`edit`)return l(`create`,{search:`?draft=`+encodeURIComponent(e)});if(i===`goto-team-funds`)return l(`team-funds`);if(i===`goto-material-pools`)return l(`material-pools`);if(i===`open-price-lock`)return l(`price-locks`,{search:`?lock=`+encodeURIComponent(a)});if(i===`recovery-open`)return l(`recoveries`,{search:`?recovery=`+encodeURIComponent(a)});if(i.includes(`reload`)||i.includes(`retry`))return $();if(i.includes(`close`)||i===`hide-action`)return Y();if(t.busy||t.pending())throw Error(`请先恢复原操作。`);if(i===`order-after-sale-preview`){let n=r.form,i=J.orderAfterSaleInput(n),a=++P.current,o=JSON.stringify(i);n.elements.verified.checked=!1,j(e=>({...e,preview:null,verified:!1,afterError:``,previewLoading:!0,previewStatus:`正在按原单成本核对售后…`}));let s;try{s=await t.api(v+`/after-sale-preview`,i)}catch(e){if(P.current===a)throw e;return}if(P.current!==a)return;if(s.before?.id!==e||s.after?.id!==e||s.before.revision!==B.revision)throw Error(`售后预览与当前订单不一致,请重新读取。`);let c=s.afterSale||s.after.orderAfterSale;J.orderAfterSaleSummaryHTML(c,{preview:!0}),j(e=>({...e,preview:{record:c,signature:o},previewLoading:!1,previewStatus:`预览已更新,请核对后勾选确认。`}));return}if(i===`order-after-sale-add-expense`||i===`order-after-sale-remove-expense`){P.current++;let e=r.form;e?.elements.verified&&(e.elements.verified.checked=!1),j(e=>({...e,preview:null,previewLoading:!1,verified:!1,previewStatus:`资料已修改,请重新核对售后预览。`}));let t=r.closest(`[data-expense-id]`)?.dataset.expenseId;N(e=>i.endsWith(`add-expense`)?[...e,crypto.randomUUID()]:e.filter(e=>e!==t));return}if(Y(),i===`order-after-sale-open`)return D({type:`after`});if(i.startsWith(`order-ownership-`))return D({type:`ownership`,kind:i.slice(16)});if(i.endsWith(`-order-change`))return D({type:`change`,kind:i.split(`-`)[0]});if(i.endsWith(`-order-cancellation`))return D({type:`cancellation`,kind:i.split(`-`)[0]});if(i.startsWith(`show-`)){let e=i.slice(5);if(J.orderActionUsesChangeForm(e)){let t=V?.data;if(!t||V.error)throw Error(`请重新读取订单并核对修改申请。`);let n=t.actions?.[e]||t;if(!n.eligible||t.pending||B.cancellationPending)throw Error(n.reason||`本单暂不能提交变更申请,请重新读取。`)}return j({action:e,formKey:P.current}),D({type:`action`,kind:e})}}catch(e){i===`order-after-sale-preview`?j(t=>({...t,preview:null,previewLoading:!1,verified:!1,stale:[403,404,409].includes(m(e)),afterError:_(e),previewStatus:`预览未完成,请核对提示后重新预览。`})):k(_(e))}}function ne(e){let t=e.target;if(!(t instanceof HTMLInputElement||t instanceof HTMLSelectElement||t instanceof HTMLTextAreaElement))return;let n=t.form;if(!n)return;if(S?.type===`action`){let e=G(n);t.name===`date`&&J.orderActionRequiresApproval(S.kind,A.date)!==J.orderActionRequiresApproval(S.kind,e.date)&&n.elements.verified&&(n.elements.verified.checked=!1);let r=A.paymentMethod===`信用卡`?A.recipient:n.elements.payment_recipient?.value,i=n.elements.credit_card_fee_payer?.disabled===!1;j(t=>({...t,action:S.kind,values:e,date:e.date,paymentMethod:e.payment_method,recipient:r,lastCardBasis:i?e.amount:t.lastCardBasis}));return}if(S?.type!==`after`)return;if(t.name===`verified`){j(e=>({...e,verified:t.checked}));return}P.current++;let r=G(n),i=null;try{i=B.netReceived-C.cents(r.refund_amount)}catch{}t.name===`refund_account`&&(n.elements.refund_payer.value=J.orderAfterSaleAccountPayer(t.value)),n.elements.verified.checked=!1;let a=Array.from(n.querySelectorAll(`[data-after-sale-line]`),e=>({pocket:e.querySelector(`[name=return_pocket]`).value,disposition:e.querySelector(`[name=return_disposition]`).value}));j(e=>({...e,lines:a,preview:null,previewLoading:!1,verified:!1,date:r.date,previewStatus:`资料已修改,请重新核对售后预览。`,reasonRequired:i!==null&&i>0,retained:i===null?`待填写退款金额`:i<0?`退款超出净实收`:`¥`+(i/100).toFixed(2)}))}async function re(e){if(W(e),!S||!(e.target instanceof HTMLFormElement))return;let n=e.target,r=G(n),i=n.dataset.kind,o=!1,s,c=e.nativeEvent.submitter?.dataset.retryKey;try{if(t.busy)return;if(c){let e=t.pending();if(!e||e.key!==c||e.key!==A.pendingKey)return;s=e.key,o=e.url===v+`/`+i,await t.retryPending(),$(),await a();return}if(t.pending())return;let e,l;if(S.type===`after`){let t=J.orderAfterSaleInput(n);if(l=t,A.stale||A.previewLoading||A.preview?.signature!==JSON.stringify(l))throw Error(`请先重新核对本次售后预览。`);if(V?.data?.pending||B.cancellationPending||J.orderAfterSaleRecord(B))throw Error(`本单已变动或有待复核申请,请重新读取。`);if(!A.verified)throw Error(`请核对售后预览,并勾选实物、实际退款和成本确认。`);let r=J.orderAfterSaleApproval(l.date);o=!r,r&&(l={...t,action:`return`}),e=v+(r?`/change`:`/return`)}else if(S.type===`action`){if(l=J.actionInput(n),e=v+`/`+i,J.orderActionUsesChangeForm(i)){if(A.stale||!V?.data)throw Error(`请重新读取订单后核对本次申请。`);let t=J.orderActionRequiresApproval(i,l.date);if(l={...l,...t?{action:i}:{},revision:B.revision,verified:r.verified===`on`,reason:(r.change_reason||r.reason||``).trim()},!l.reason||l.reason.length>200)throw Error((t?`申请原因`:`登记原因`)+`请填写1~200字。`);if(!l.verified)throw Error(`请核实本次金额、付款人或账户、退货去向,并勾选确认。`);o=!t,t&&(e=v+`/change`)}}else{let t={change:V,ownership:H,cancellation:U}[S.type].data,n=t.pending;if(i===`approve`||i===`reject`){if(!n||n.status!==`pending`||!t.canApprove)throw Error(`请重新读取后复核。`);if(i===`approve`&&(!n.canApprove||n.stale||n.order_revision!==B.revision||!r.verified))throw Error(`订单已有变动,请重新读取后复核。`);e=y.find(([e])=>e===S.type)[1]+`/`+encodeURIComponent(n.id)+`/`+i,l={...i===`approve`?{revision:n.order_revision,verified:!0}:{},note:r.note.trim()}}else S.type===`ownership`?(l={member:r.member,revision:B.revision,reason:r.reason.trim(),verified:!0},e=v+`/ownership`):(l={revision:B.revision,reason:r.reason.trim(),...i===`direct`?{date:U.data.directActionDate,verified:!0}:{}},e=v+(i===`direct`?`/canceltoday`:`/cancellation`));r.legacyCountVerified&&(l={...l,legacyCountVerified:!0})}let u=t.mutate(e,l);s=t.pending()?.key,await u,$(),await a()}catch(e){if(await L.checkFailure(e))return;if(S.type===`after`){let r=m(e)===403&&o&&!t.pending(),i=!r&&[403,404,409].includes(m(e));(r||i)&&(n.elements.verified.checked=!1),j(t=>({...t,...r?{forceApproval:!0,verified:!1}:i?{stale:!0,preview:null,verified:!1}:{},afterError:_(e)+(r?` 输入已保留,重新核实后提交店主复核。`:``)}))}else if(S.type===`action`&&J.orderActionUsesChangeForm(i)&&([403,404,409].includes(m(e))||s&&s===t.pending()?.key)){let r=m(e)===403&&o&&!t.pending(),i=[403,404,409].includes(m(e));i&&n.elements.verified&&(n.elements.verified.checked=!1),j(t=>({...t,forceApproval:r,pendingKey:s,stale:!r&&i,actionError:_(e)+(r?` 输入已保留,请重新核实后提交店主审批。`:``)}))}else k(_(e))}}return S?.type===`after`&&(A.stale||t.pending()||t.busy)&&(Z=(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`fieldset`,{disabled:!0,children:Z}),(0,w.jsx)(s,{type:`button`,onClick:$,children:`重新读取订单`}),(0,w.jsx)(s,{type:`button`,onClick:Y,disabled:t.busy,children:`收起`})]})),(0,w.jsx)(T,{id:`order-dialog`,label:`关闭订单`,close:u,children:(0,w.jsx)(`div`,{id:`order-content`,onClick:te,onChange:ne,onSubmit:re,children:F.error?(0,w.jsxs)(`p`,{role:`alert`,children:[F.error,` `,(0,w.jsx)(s,{onClick:$,children:`重新读取`})]}):B?z({...q,detailForm:Z,error:Q}).renderDetail():`正在读取订单…`})})}function q(e){let t={mode:`today`,date:``,from:``,to:``,q:``,status:``,member:``,pocket:``},n=sessionStorage.getItem(`mm-order-book-`+e.user.id);if(!n)return t;let r;try{r=JSON.parse(n)}catch{return t}if(!r||typeof r!=`object`)return t;for(let e of Object.keys(t)){let n=Reflect.get(r,e);typeof n==`string`&&(t[e]=n)}return t}var J=e=>e.map(([e,t])=>(0,w.jsx)(`option`,{value:e,children:t},e));function Y({client:e,state:r,session:i,refreshState:a,saleListStatus:o,setSaleListStatus:c}){let[d,f]=(0,E.useState)(()=>q(r)),p=v(r.user.id),[m,g]=(0,E.useState)(()=>sessionStorage.getItem(p)||``);(0,E.useEffect)(()=>{sessionStorage.removeItem(p);let e=e=>g(t=>t+` `+e.detail);return window.addEventListener(`order-access-refresh-error`,e),()=>window.removeEventListener(`order-access-refresh-error`,e)},[p]);let _=b(e,r.user.id,g);(0,E.useEffect)(()=>{let t=!0,n=!1;async function i(){if(!(document.hidden||n||e.busy)){n=!0;try{let n=await e.api(`/api/state`);t&&n.user.id===r.user.id&&n.today!==r.today&&await a()}catch(e){t&&g(e instanceof Error?e.message:String(e))}finally{n=!1}}}let o=window.setInterval(i,6e4);return document.addEventListener(`visibilitychange`,i),()=>{t=!1,clearInterval(o),document.removeEventListener(`visibilitychange`,i)}},[e,r.user.id,r.today,a]);let[x,S]=(0,E.useState)(0),[C,D]=(0,E.useState)(u(`order`)),[O,k]=(0,E.useState)(null),[A,j]=(0,E.useState)(``),[M,N]=(0,E.useState)(`pending`),P=A===`after-sale`?o:M,[F,I]=(0,E.useState)(()=>u(`afterSale`)?{action:`after-sale-edit`,id:u(`afterSale`)}:null),L=(0,E.useCallback)(()=>S(e=>e+1),[]);function R(e){let t={...d,...e};f(t),sessionStorage.setItem(`mm-order-book-`+r.user.id,JSON.stringify(t))}let B=z({state:r,session:i,orderBookFilters:d,orderChangeListStatus:P,orderOwnershipListStatus:P,orderCancellationListStatus:P,afterSaleChangesStatus:P}),V,H;try{V=B.orderBookRange()}catch(e){H=e instanceof Error?e.message:String(e)}let W=V&&new URLSearchParams({from:V.from,date:V.date,q:d.q.trim(),status:d.status||`all`,...d.pocket?{pocket:d.pocket}:{},...r.user.role===`owner`&&d.member?{member:d.member}:{}}),G=h(async()=>{let t=await e.api(`/api/order-book?`+W);if(t.from!==V.from||t.date!==V.date||(t.pocket??``)!==d.pocket)throw Error(`返回账本与所选日期或货盘不一致,请重新读取。`);return t},W?[r.user.id,W,x].join(`/`):``),K=h(()=>Promise.all(y.map(async([,t])=>{try{return(await e.api(t+`?status=pending`)).counts.pending}catch{return`读取失败`}})),r.user.id+`/`+x),Y=y.find(([e])=>e===A),X=h(async()=>{let t=Y[1]+`?status=`+P;switch(A){case`change`:return B.orderChangeListHTML(await e.api(t));case`ownership`:return B.orderOwnershipListHTML(await e.api(t));case`cancellation`:return B.orderCancellationListHTML(await e.api(t));case`after-sale`:return B.afterSaleChangeListHTML(await e.api(t))}},A&&[A,P,x].join(`/`)),Z=X.value,Q,$=H||G.error;if(G.value)try{let e=e=>e.map(e=>_[e.printStatus?.id||e.id]?{...e,printStatus:_[e.printStatus?.id||e.id]}:e);Q=B.renderOrderBook({...G.value,rows:e(G.value.rows),...G.value.displayRows?{displayRows:e(G.value.displayRows)}:{}},V)}catch(e){$=e instanceof Error?e.message:String(e)}let te=(e,t=!1)=>{j(``),g(``),k(t?[...new Set(G.value.rows.filter(e=>![`afterSale`,`orderAfterSale`].includes(e.kind??``)).map(e=>e.id))]:null),D(e)};function ne(){D(``),u(`order`)&&l(`orders`,{replace:!0,fromPage:!0})}function re(e){k(null),j(``),D(``),g(e),u(`order`)&&(sessionStorage.setItem(p,e),l(`orders`,{replace:!0,fromPage:!0})),L(),a().catch(t=>g(e+` `+(t instanceof Error?t.message:String(t))))}function ie(e){if(!(e.target instanceof Element))return;let t=e.target.closest(`[data-action]`);if(!t||!t.dataset.action||e.defaultPrevented)return;let{action:n=``,id:i=``,period:a,status:o}=t.dataset,s=y.find(e=>e[3]===n);if(s)j(s[0]),s[0]!==`after-sale`&&N(`pending`);else{if([`open-order`,`open-change-order`,`open-cancellation-order`,`order-ownership-open-order`].includes(n))return te(i,n===`open-order`);if(n===`recovery-open`)return l(`recoveries`,{search:`?recovery=`+encodeURIComponent(i)});if(n===`recovery-print`)return window.open(`/print/recoveries/`+encodeURIComponent(i),`_blank`,`noopener`);if(n===`open-price-lock`)return l(`price-locks`,{search:`?lock=`+encodeURIComponent(i)});if(n===`after-sale-edit`||n===`new-after-sale`||n===`after-sale-change-open`)j(``),I({action:n,id:i});else{if(o)return A===`after-sale`?c(o):N(o);if(n===`order-period`)return R({mode:a,...a===`date`&&!d.date?{date:V?.date||r.today}:{},...a===`range`&&!d.from&&!d.to?{from:V?.from||r.today,to:V?.date||r.today}:{}});(n===`refresh`||n.includes(`retry`)||n.includes(`reload`))&&L()}}}let ae=K.value?.every(e=>typeof e==`number`&&Number.isInteger(e))?K.value.reduce((e,t)=>e+t,0):null,oe=(r.members||[]).map(e=>[e.member,B.teamMemberName(e.member)+(e.enabled===!1?`(已停用)`:``)]),se={change:[`order-changes-dialog`,`变更申请与复核`,`关闭变更申请列表`,`全部日期,不受订单页的日期、搜索或状态筛选影响。待批期间仍按原订单计账,包含改单、费用、成本、退款与退货;店主同意后才更新原单。`],ownership:[`order-ownership-dialog`,`订单归属申请与复核`,`关闭归属复核列表`,`全部日期,不受订单页筛选影响。`+B.teamMemberName(`owner`)+`可直接更正归属;助理的归属申请均须店主同意后生效。`],cancellation:[`order-cancellations-dialog`,`取消申请与复核`,`关闭取消申请列表`,`全部日期,不受订单页的日期、搜索或状态筛选影响。申请期间仍按原订单计账;店主同意后才按录错作废。当天直接取消的记录单独标明经办人。`],"after-sale":[`after-sale-changes-dialog`,r.user.role===`owner`?`售后修改复核`:`售后修改申请`,`关闭售后修改复核`,(r.user.role===`owner`?`跨日期查看售后修改,核对原值与申请值后复核。`:`查看自己归属售后的修改申请。`)+`待审批期间仍按原记录计账。`]}[A||`change`];return(0,w.jsxs)(`div`,{className:`business-pages`,onClick:ie,children:[(0,w.jsxs)(`div`,{className:`page-heading`,children:[(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`div`,{className:`eyebrow`,children:`ORDER BOOK`}),(0,w.jsx)(`h1`,{children:`订单`}),(0,w.jsx)(`p`,{className:`muted`,children:`按日期查看销售订单、回收与售后,点击客户查看明细。`})]}),(0,w.jsxs)(`div`,{className:`actions`,children:[(0,w.jsxs)(`details`,{className:`order-review-menu`,children:[(0,w.jsxs)(`summary`,{children:[`申请与复核`,ae===null?` · 待读取`:ae?` · `+ae+` 待处理`:``]}),(0,w.jsx)(`div`,{className:`order-review-options`,children:y.map(([e,,t,n,i],a)=>(0,w.jsxs)(s,{type:`button`,id:i,"data-action":n,children:[t,e===`after-sale`?r.user.role===`owner`?`复核`:`申请`:``,`(`,K.value?.[a]??`…`,`)`]},e))})]}),(0,w.jsx)(s,{type:`button`,"data-action":`new-after-sale`,children:`新增售后费用`}),(0,w.jsx)(s,{type:`button`,"data-action":`refresh`,children:`刷新`})]})]}),(0,w.jsxs)(`div`,{className:`order-book-dates`,children:[(0,w.jsx)(`div`,{className:`order-period-buttons`,role:`group`,"aria-label":`订单日期`,children:B.orderBookPeriodOptions.map(([e,t])=>(0,w.jsx)(s,{type:`button`,"data-action":`order-period`,"data-period":e,"aria-pressed":e===d.mode,children:t},e))}),(0,w.jsxs)(`label`,{id:`order-single-date`,hidden:d.mode!==`date`,children:[`指定日期`,(0,w.jsx)(n,{type:`date`,id:`order-date`,value:d.mode===`date`?d.date:V?.date||r.today,min:`2000-01-01`,max:r.today,"aria-label":`指定订单日期`,onChange:e=>R({date:e.target.value})})]}),(0,w.jsx)(`div`,{id:`order-range-fields`,hidden:d.mode!==`range`,children:[`from`,`to`].map((e,t)=>(0,w.jsxs)(`label`,{children:[t?`结束`:`开始`,`日期`,(0,w.jsx)(n,{type:`date`,id:`order-`+e,value:d[e],min:`2000-01-01`,max:r.today,"aria-label":`订单`+(t?`结束`:`开始`)+`日期`,onChange:t=>R({[e]:t.target.value})})]},e))}),(0,w.jsx)(`span`,{children:V?.from===V?.date?V?.date:V&&V.from+` 至 `+V.date})]}),(0,w.jsxs)(`details`,{className:`order-book-overview`,children:[(0,w.jsx)(`summary`,{children:`查看收款、成本与利润汇总`}),(0,w.jsx)(`div`,{className:`cards order-book-cards`,children:Q?.cards}),G.value&&B.priceLockActivityHTML(G.value.priceLockActivity),(0,w.jsx)(`p`,{children:B.orderBookScope()})]}),(0,w.jsxs)(`section`,{className:`panel order-book-panel`,children:[(0,w.jsxs)(`div`,{className:`filters order-book-filters`,children:[(0,w.jsx)(n,{id:`order-search`,"aria-label":`搜索订单(单号、客户、商品或克重)`,value:d.q,placeholder:`单号、客户、商品或克重,如1.38克`,maxLength:100,onChange:e=>R({q:e.target.value})}),(0,w.jsx)(t,{id:`order-filter`,"aria-label":`筛选状态`,value:d.status,onChange:e=>R({status:e.target.value}),children:J(B.orderBookStatusOptions)}),(0,w.jsxs)(`label`,{children:[`出货货盘`,(0,w.jsx)(t,{id:`order-pocket-filter`,"aria-label":`出货货盘`,value:d.pocket,onChange:e=>R({pocket:e.target.value}),children:J(B.orderBookPocketOptions())})]}),r.user.role===`owner`&&oe.length>0&&(0,w.jsxs)(`label`,{children:[`订单归属`,(0,w.jsx)(t,{id:`order-member-filter`,value:d.member,onChange:e=>R({member:e.target.value}),children:J([[``,`全部成员`],...oe])})]}),(0,w.jsx)(`span`,{id:`order-book-count`,children:Q?.count})]}),d.status===`price_lock`&&(0,w.jsx)(`p`,{children:`锁价仅显示已生成的销售单;未交付的锁价单请到「待交付」查看。`}),d.pocket&&(0,w.jsx)(`p`,{children:`包含所选货盘的订单,金额按整单汇总。锁价实际收付区仍按日期显示。`}),(0,w.jsx)(`div`,{id:`order-list`,"aria-live":`polite`,children:$?(0,w.jsxs)(`p`,{role:`alert`,children:[$,` `,(0,w.jsx)(s,{onClick:L,children:`重新读取`})]}):Q?.list??`正在读取订单…`}),(0,w.jsx)(`p`,{className:`small muted`,children:`销售按原记账日保留,订单售后调整和独立售后费用按售后日期计入利润。已取消订单不计汇总,原收退款、费用和作废冲回明细保留在每日对账。销售克重合计不含银饰和直接回收,单行仍显示实际克重;件数照常合计。旧草稿报价不计入合计。`})]}),m&&(0,w.jsx)(`p`,{role:`alert`,children:m}),A&&(0,w.jsxs)(T,{id:se[0],close:()=>j(``),label:se[2],children:[(0,w.jsx)(`h2`,{children:se[1]}),(0,w.jsx)(`p`,{className:`small muted`,children:se[3]}),X.error?(0,w.jsxs)(`p`,{children:[X.error,` `,(0,w.jsx)(s,{onClick:L,children:`重新读取`})]}):Z||`正在读取…`]}),C&&(0,w.jsx)(ee,{client:e,state:r,session:i,refresh:L,refreshState:a,listIds:O,selected:C,openOrder:D,close:ne,onLost:re,printStatuses:_},C),F&&(0,w.jsx)(U,{client:e,state:r,session:i,sale:F,refreshState:a,refreshBook:L,openList:()=>{I(null),j(`after-sale`)},close:()=>I(null),saved:e=>{I(null),e&&R({mode:`date`,date:e,q:``,status:``,pocket:``}),L()}})]})}export{Y as OrdersPage}; |