1 line
5.4 KiB
JavaScript
1 line
5.4 KiB
JavaScript
import{n as e}from"./rolldown-runtime-Dl_DZoUm.js";import{i as t,t as n}from"./react-1o5M9n0k.js";import{a as r,z as i}from"./index-D-ox0wtk.js";import{y as a}from"./skeleton-B4Z0R3jQ.js";import{n as o,t as s}from"./input-BnsACfRy.js";import{n as c,t as l}from"./ReloadOutlined-BW5sy5GM.js";import{t as u}from"./typography-xRg_3Gco.js";import{o as d}from"./shared-DZLPF0cC.js";var f=e(t(),1),p=e=>typeof e==`number`&&Number.isSafeInteger(e),m=e=>p(e)&&e>=0,h=e=>typeof e==`object`&&!!e;function g(e,t){return/^\d{4}-(0[1-9]|1[0-2])$/.test(e)&&e>=`2000-01`&&e<=t.slice(0,7)}function _(){throw Error(`月度利润未完整返回,请重新读取。`)}function v(e,t,n){if(!h(e)||e.basis!==`orderDate`||e.month!==t||e.from!==t+`-01`||typeof e.date!=`string`||!/^\d{4}-\d{2}-\d{2}$/.test(e.date)||!e.date.startsWith(t)||e.date<e.from||e.date>n.today||!Array.isArray(e.rows))return _();let r=new Date(e.date+`T12:00:00Z`);if(Number.isNaN(r.getTime())||r.toISOString().slice(0,10)!==e.date)return _();let i=new Set(d.memberKeys(n).filter(e=>e!==`owner`)),a=e.rows.map(e=>{if(!h(e))return _();let{member:t,name:n,recordCount:r,orderCount:a,afterSaleCount:o,draftCount:s,unknownCostCount:c,unknownProfitCount:l,sales:u,knownTotalCost:d,knownProfit:f,profit:g,incomplete:v,shareRate:y,estimatedShare:b}=e;if(typeof t!=`string`||!i.delete(t)||typeof n!=`string`||!n||!m(r)||!m(a)||!m(o)||!m(s)||!m(c)||!m(l)||r!==a+o||!p(u)||!p(d)||!p(f)||typeof v!=`boolean`||!p(y)||y<0||y>100)return _();if(g===null){if(!v||b!==null)return _()}else{if(g!==f||v||!p(b))return _();let e=(BigInt(Math.abs(f))*BigInt(y)+50n)/100n;if(b!==Number(f<0?-e:e))return _()}return{member:t,profit:g,knownProfit:f,unknownProfitCount:l,shareRate:y,estimatedShare:b}});return i.size?_():{from:e.from,date:e.date,rows:a}}var y=n(),b=new WeakMap;function x({client:e,state:t}){return t.user.role===`owner`?(0,y.jsx)(S,{client:e,state:t},t.user.id):(0,y.jsx)(i,{type:`error`,showIcon:!0,message:`团队账目仅店主账号可查看。`})}function S({client:e,state:t}){let[n,p]=(0,f.useState)(()=>{let n=b.get(e);return{month:n?.user===t.user.id?n.month:t.today.slice(0,7)}}),[m,h]=(0,f.useState)(n.month),[_,x]=(0,f.useState)(null);(0,f.useEffect)(()=>{let r=!0;async function i(){try{if(!g(n.month,t.today))throw Error(`请选择2000年1月至本月之间的有效月份。`);let i=await e.api(`/api/team-profits?`+new URLSearchParams({month:n.month}));r&&x({request:n,report:v(i,n.month,t)})}catch(e){let t=e;r&&x({request:n,error:t.name===`AbortError`?`读取超时,请重试。`:t.message})}}return i(),()=>{r=!1}},[e,n,t]);let S=()=>p({month:n.month}),C=_&&`report`in _?_.report:null;return(0,y.jsxs)(`div`,{className:`team-profits-page`,children:[(0,y.jsxs)(`div`,{className:`page-heading`,children:[(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`div`,{className:`eyebrow`,children:`TEAM PROFITS`}),(0,y.jsx)(u.Title,{level:1,children:`团队账目`}),(0,y.jsx)(u.Paragraph,{type:`secondary`,children:`按月核对助理净利润与预计分成。`})]}),(0,y.jsx)(a,{icon:(0,y.jsx)(l,{"aria-hidden":`true`}),"data-action":`team-funds-refresh`,onClick:S,children:`刷新`})]}),(0,y.jsx)(o,{className:`panel`,children:(0,y.jsx)(`form`,{id:`team-funds-filter`,onSubmit:n=>{n.preventDefault(),b.set(e,{user:t.user.id,month:m}),p({month:m})},children:(0,y.jsxs)(c,{align:`end`,wrap:!0,children:[(0,y.jsxs)(`label`,{className:`team-month-field`,children:[`月份`,(0,y.jsx)(s,{type:`month`,name:`month`,value:m,required:!0,min:`2000-01`,max:t.today.slice(0,7),onChange:e=>h(e.target.value)})]}),(0,y.jsx)(a,{type:`primary`,htmlType:`submit`,autoInsertSpace:!1,children:`查询`})]})})}),(0,y.jsx)(u.Paragraph,{type:`secondary`,children:`订单按开单日期、售后按记录日期计入;锁价单交付后计入利润。本月统计截至今天,成本或费用未补齐时显示待核算。`}),(0,y.jsxs)(`div`,{id:`team-funds-content`,"aria-live":`polite`,"aria-busy":_?.request!==n,children:[!_&&(0,y.jsx)(`p`,{children:`正在读取月度利润…`}),_&&`error`in _&&(0,y.jsx)(i,{type:`error`,showIcon:!0,message:_.error,action:(0,y.jsx)(a,{size:`small`,"data-action":`team-funds-refresh`,onClick:S,children:`重新读取`})}),C&&(0,y.jsxs)(o,{className:`panel`,title:(0,y.jsx)(`h2`,{children:`助理月度利润`}),extra:(0,y.jsxs)(`span`,{className:`muted`,children:[C.from,` 至 `,C.date]}),children:[(0,y.jsx)(`div`,{className:`team-profit-table`,children:(0,y.jsxs)(`table`,{children:[(0,y.jsx)(`thead`,{children:(0,y.jsxs)(`tr`,{children:[(0,y.jsx)(`th`,{scope:`col`,children:`成员`}),(0,y.jsx)(`th`,{scope:`col`,children:`月度净利润`}),(0,y.jsx)(`th`,{scope:`col`,children:`分成比例`}),(0,y.jsx)(`th`,{scope:`col`,children:`预计分成`})]})}),(0,y.jsx)(`tbody`,{children:C.rows.map(e=>(0,y.jsxs)(`tr`,{children:[(0,y.jsx)(`td`,{children:(0,y.jsx)(`strong`,{children:d.memberName(t,e.member)})}),(0,y.jsx)(`td`,{children:e.profit===null?(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(`strong`,{children:`待核算`}),(0,y.jsxs)(`div`,{className:`small muted`,children:[`已核算部分 ¥`,r(e.knownProfit),e.unknownProfitCount>0&&` · `+e.unknownProfitCount+` 笔待补齐`]})]}):`¥`+r(e.profit)}),(0,y.jsxs)(`td`,{children:[e.shareRate,`%`]}),(0,y.jsx)(`td`,{children:e.estimatedShare===null?`待核算`:`¥`+r(e.estimatedShare)})]},e.member))})]})}),(0,y.jsx)(`p`,{className:`small muted`,children:`预计分成=月度净利润 × 该月份生效比例,四舍五入到分;负数保留公式计算结果。`})]})]})]})}export{x as TeamFundsPage}; |