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

13 lines
178 KiB
JavaScript
Raw Blame History

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