Files
weiguang-jewelry-ledger/新账系统/web/dist/assets/PrivateOperationsPage-DbK9f-5_.js
T

1 line
14 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{Vt as t,a as n,b as r,i,jt as a,lt as o,nr as s,o as c,s as l,w as u}from"./index-BvkDlq1y.js";import{t as d}from"./typography-DUlVOiLU.js";import{o as f}from"./shared-D0Ng0yPd.js";var p=e(s(),1),m=r();function h({client:e,state:t,members:r,initial:i,close:s,saved:l,recover:u}){let[d,h]=(0,p.useState)(i),g=(0,p.useRef)(null);(0,p.useLayoutEffect)(()=>{let e=g.current;return e.showModal(),()=>{e.close()}},[]);let _=t.user.role===`owner`,v=(0,p.useCallback)(async()=>{let t=await e.api(n+`?`+new URLSearchParams({member:d.member,date:d.date}));if(t.member!==d.member||t.date!==d.date||!Number.isSafeInteger(t.revision))throw Error(`记录未完整返回`);return t},[e,d]),y=c(v),[b,x]=(0,p.useState)(null),[S,C]=(0,p.useState)(null),w=y&&`data`in y?y.data:null,T=b?.value??String(w?.total_count??``);function E(e){h(e),x(null),C(null)}function D(){E({...d})}async function O(t){if(t.preventDefault(),w){C(null);try{await e.mutate(n,{date:w.date,member:w.member,total_count:T,revision:w.revision}),l()}catch(e){C(e)}}}return(0,m.jsxs)(`dialog`,{ref:g,"aria-labelledby":`private-people-title`,className:`private-people-modal`,id:`private-people-dialog`,onCancel:t=>{t.preventDefault(),e.busy||s()},children:[(0,m.jsxs)(`div`,{className:`ops-heading`,children:[(0,m.jsx)(`h2`,{id:`private-people-title`,children:`记录人数`}),(0,m.jsx)(o,{"aria-label":`关闭`,"data-action":`private-people-close`,disabled:e.busy,onClick:s,children:`×`})]}),(0,m.jsxs)(`form`,{id:`private-people-form`,className:`ops-form`,onSubmit:O,children:[(0,m.jsxs)(`div`,{className:`ops-fields`,children:[(0,m.jsxs)(`label`,{children:[`日期`,(0,m.jsx)(`input`,{type:`date`,name:`date`,required:!0,max:t.today,value:d.date,onChange:e=>E({...d,date:e.target.value})})]}),_?(0,m.jsxs)(`label`,{children:[`员工`,(0,m.jsx)(`select`,{name:`member`,value:d.member,onChange:e=>E({...d,member:e.target.value}),children:r.map(e=>(0,m.jsxs)(`option`,{value:e.member,children:[e.label,e.enabled===!1&&`(已停用)`]},e.member))})]}):(0,m.jsxs)(`div`,{children:[(0,m.jsx)(`span`,{className:`muted`,children:`员工`}),(0,m.jsx)(`p`,{children:f.memberName(t,d.member)}),(0,m.jsx)(`input`,{type:`hidden`,name:`member`,value:d.member})]})]}),(0,m.jsxs)(`div`,{id:`private-people-fields`,children:[!y&&(0,m.jsx)(`p`,{className:`muted`,children:`正在读取记录…`}),y&&`error`in y&&(0,m.jsx)(a,{type:`error`,showIcon:!0,message:y.error,action:(0,m.jsx)(o,{"data-action":`private-people-retry`,onClick:D,children:`重新读取`})}),w&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`p`,{className:`muted`,children:w.previous?`上次记录:`+w.previous.date+`,总人数 `+w.previous.total+`。`:`还没有更早的总人数记录,本次可作为基准。`}),(0,m.jsxs)(`div`,{className:`ops-fields`,children:[(0,m.jsxs)(`label`,{children:[`当天总人数(必填)`,(0,m.jsx)(`input`,{type:`number`,name:`total_count`,required:!0,min:`0`,max:`1000000`,step:`1`,inputMode:`numeric`,placeholder:`填写微信总人数`,value:T,onChange:e=>x({value:e.target.value,valid:e.target.validity.valid})})]}),(0,m.jsxs)(`div`,{children:[(0,m.jsx)(`span`,{className:`muted`,children:`今日新增人数(自动计算)`}),(0,m.jsx)(`p`,{id:`private-people-delta`,"aria-live":`polite`,children:w.previous?T?b?.valid===!1?`请填写有效的总人数`:Number(T)-w.previous.total+` 人`:`填写总人数后自动计算`:`首次记录,作为基准`})]})]}),(0,m.jsx)(`p`,{className:`muted`,children:`前一天没记录时,对比上一次有记录的日期。首次登记作为基准;补记或修改历史总人数后,后续增量会自动重算。人数减少时如实显示负数。`}),(0,m.jsxs)(`div`,{className:`ops-actions`,children:[(0,m.jsx)(o,{"data-action":`private-people-close`,disabled:e.busy,onClick:s,children:`取消`}),(0,m.jsx)(o,{type:`primary`,htmlType:`submit`,disabled:e.busy,children:`保存人数`})]})]})]}),(0,m.jsxs)(`div`,{"aria-live":`polite`,id:`private-people-error`,children:[S&&(0,m.jsx)(a,{type:`error`,showIcon:!0,message:S.message,action:S.status===409&&(0,m.jsx)(o,{"data-action":`private-people-retry`,onClick:D,children:`重新读取后核对`})}),e.pending()?.url===`/api/private-operations/people`&&!e.busy&&(0,m.jsx)(o,{"data-action":`retry`,onClick:()=>void u(),children:`恢复原操作`})]})]})]})}function g({data:e,open:t}){let n=e.rows.filter(e=>e.total!==null),r=new Set(n.map(e=>e.member)),a=e.members.filter(e=>r.has(e.member)),s=[...new Set(n.map(e=>e.date))].sort(),c=new Map(n.map(e=>[e.date+`|`+e.member,e]));return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsxs)(`section`,{className:`ops-panel`,children:[(0,m.jsxs)(`div`,{className:`ops-heading`,children:[(0,m.jsx)(`h2`,{children:`员工运营汇总`}),(0,m.jsxs)(`span`,{className:`muted`,children:[e.from,` ~ `,e.date]})]}),(0,m.jsx)(`div`,{className:`ops-scroll`,tabIndex:0,role:`region`,"aria-label":`员工运营汇总表`,children:(0,m.jsxs)(`table`,{className:`private-ops-summary`,children:[(0,m.jsx)(`thead`,{children:(0,m.jsx)(`tr`,{children:[`员工`,`最近总人数`,`新增人数`,`成交订单`,`新客订单`,`老客订单`,`未标记订单`,`新客转化参考`,`退款订单`,`操作`].map(e=>(0,m.jsx)(`th`,{scope:`col`,children:e},e))})}),(0,m.jsxs)(`tbody`,{children:[e.summaries.map(n=>(0,m.jsxs)(`tr`,{children:[(0,m.jsxs)(`th`,{scope:`row`,children:[n.label,n.enabled===!1&&(0,m.jsx)(`small`,{children:`已停用`})]}),(0,m.jsxs)(`td`,{children:[i(n.total),n.totalDate&&(0,m.jsx)(`small`,{children:n.totalDate})]}),(0,m.jsxs)(`td`,{children:[(0,m.jsx)(`strong`,{children:i(n.newPeople)}),(0,m.jsxs)(`small`,{children:[n.recordedDays,`/`,e.days,` 天可算增量`]})]}),(0,m.jsx)(`td`,{children:(0,m.jsx)(`strong`,{children:n.orders})}),(0,m.jsx)(`td`,{children:n.newOrders}),(0,m.jsx)(`td`,{children:n.returningOrders}),(0,m.jsx)(`td`,{children:n.unknownOrders}),(0,m.jsx)(`td`,{children:n.conversion===null?`—`:(n.conversion*100).toFixed(1)+`%`}),(0,m.jsx)(`td`,{children:n.refundOrders}),(0,m.jsx)(`td`,{children:(0,m.jsx)(o,{size:`small`,"data-action":`private-people-open`,"data-member":n.member,"data-date":e.date,onClick:()=>t({member:n.member,date:e.date}),children:`记人数`})})]},n.member)),!e.summaries.length&&(0,m.jsx)(`tr`,{children:(0,m.jsx)(`td`,{colSpan:10,children:`没有符合筛选条件的员工。`})})]})]})}),(0,m.jsx)(`p`,{className:`muted`,children:`新增人数=当天总人数-上次记录的总人数。新客转化参考=新客订单数÷新增人数。按订单数统计,可能包含之前加的客户或同一客户多次下单;不是同批客户的准确转化率。人数缺记、分母不大于0或订单未标记时不显示比率;区间比率按合计计算。`})]}),(0,m.jsxs)(`section`,{className:`ops-panel`,id:`private-people-history-panel`,children:[(0,m.jsxs)(`div`,{className:`ops-heading`,children:[(0,m.jsx)(`h2`,{children:`每日人数记录`}),(0,m.jsx)(o,{"data-action":`private-people-open`,onClick:()=>t(),children:`记录人数`})]}),(0,m.jsxs)(`p`,{className:`muted`,children:[e.from,` ~ `,e.date,` · 已记录 `,s.length,` 天。点击人数可修改对应员工当天的记录。`]}),s.length?(0,m.jsx)(`div`,{className:`ops-scroll`,tabIndex:0,role:`region`,"aria-label":`每日人数记录`,children:(0,m.jsxs)(`table`,{className:`private-people-history`,children:[(0,m.jsxs)(`thead`,{children:[(0,m.jsxs)(`tr`,{children:[(0,m.jsx)(`th`,{rowSpan:2,scope:`col`,children:`日期`}),a.map(e=>(0,m.jsx)(`th`,{colSpan:2,scope:`colgroup`,children:e.label},e.member))]}),(0,m.jsx)(`tr`,{children:a.map(e=>(0,m.jsxs)(p.Fragment,{children:[(0,m.jsx)(`th`,{scope:`col`,children:`当日总人数`}),(0,m.jsx)(`th`,{scope:`col`,children:`较上次新增`})]},e.member))})]}),(0,m.jsx)(`tbody`,{children:s.map(e=>(0,m.jsxs)(`tr`,{children:[(0,m.jsx)(`th`,{scope:`row`,children:e}),a.map(({member:n,label:r})=>{let a=c.get(e+`|`+n);return(0,m.jsxs)(p.Fragment,{children:[(0,m.jsx)(`td`,{children:a?(0,m.jsxs)(o,{type:`link`,"data-action":`private-people-open`,"data-date":e,"data-member":n,"aria-label":`修改`+r+` `+e+`人数`,onClick:()=>t({date:e,member:n}),children:[i(a.total),` 人`]}):`未记录`}),(0,m.jsx)(`td`,{children:a?a.netChange===null?`首次记录`:(0,m.jsxs)(m.Fragment,{children:[a.netChange<0?`减少 `+Math.abs(a.netChange):`新增 `+a.netChange,` 人`,a.previousDate&&(0,m.jsxs)(`small`,{children:[`对比 `,a.previousDate]})]}):`—`})]},n)})]},e))})]})}):(0,m.jsx)(`p`,{className:`muted`,children:`所选日期暂无人数记录。`}),(0,m.jsx)(`p`,{className:`muted`,children:`新增人数与上一次有记录的总人数比较,漏记日期自动跳过;没有人数记录的日期不显示,0人也作为有效记录。`})]})]})}var _=new WeakMap;function v({client:e,state:n}){l(e);let{message:r}=u.useApp(),i=n.user.role===`owner`,s=n.members?.length?n.members:n.shopSettings?.members?.length?n.shopSettings.members:f.memberKeys(n).map(e=>({member:e,label:f.memberName(n,e),enabled:!0})),[c,g]=(0,p.useState)(()=>{let t=_.get(e);return t?.user===n.user.id?t.filters:{from:n.today,date:n.today,member:``}}),[v,x]=(0,p.useState)(c),[S,C]=(0,p.useState)(0),[w,T]=(0,p.useState)(null),E=(0,p.useRef)(!1);(0,p.useEffect)(()=>(E.current=!0,()=>{E.current=!1}),[]);function D(t){x(t),g(t),_.set(e,{user:n.user.id,filters:t}),C(e=>e+1)}function O(e){e.preventDefault(),D(v)}function k(e){D({...c,from:e?n.today.slice(0,7)+`-01`:n.today,date:n.today})}function A(e){T(e??{member:i?c.member||s.find(e=>e.member!==`owner`)?.member||`owner`:f.currentMember(n),date:i?c.date:n.today})}function j(t){E.current&&e.user===n.user.id&&(T(null),i?D(v):C(e=>e+1),r.success(t))}async function M(){try{await e.retryPending()&&j(`原人数操作已确认`)}catch(e){E.current&&r.error(e.message)}}return(0,m.jsx)(t,{button:{autoInsertSpace:!1},children:(0,m.jsxs)(`div`,{className:`private-ops-page`,children:[(0,m.jsxs)(`div`,{className:`page-heading`,children:[(0,m.jsxs)(`div`,{children:[(0,m.jsx)(`div`,{className:`eyebrow`,children:i?`PRIVATE OPERATIONS`:`PEOPLE`}),(0,m.jsx)(d.Title,{level:1,children:i?`私域运营概况`:`登记人数`}),(0,m.jsx)(d.Paragraph,{type:`secondary`,children:i?`仅超级管理员可查看统计;员工可自行登记本人人数。成交按订单归属人统计。`:`填写自己的当天微信总人数,系统自动与上次记录对比。`})]}),(0,m.jsx)(o,{type:`primary`,"data-action":`private-people-open`,onClick:()=>A(),children:`记录人数`})]}),!w&&e.pending()?.url===`/api/private-operations/people`&&!e.busy&&(0,m.jsx)(a,{type:`warning`,showIcon:!0,message:`上次提交结果尚未确认,请先恢复原操作。重试会使用同一个操作号。`,action:(0,m.jsx)(o,{"data-action":`retry`,onClick:()=>void M(),children:`恢复原操作`})}),i?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`section`,{className:`ops-panel`,children:(0,m.jsxs)(`form`,{id:`private-ops-filter`,className:`ops-form ops-filter`,onSubmit:O,children:[(0,m.jsxs)(`label`,{children:[`开始日期`,(0,m.jsx)(`input`,{type:`date`,name:`from`,required:!0,max:n.today,value:v.from,onChange:e=>x({...v,from:e.target.value})})]}),(0,m.jsxs)(`label`,{children:[`结束日期`,(0,m.jsx)(`input`,{type:`date`,name:`date`,required:!0,max:n.today,value:v.date,onChange:e=>x({...v,date:e.target.value})})]}),(0,m.jsxs)(`label`,{children:[`员工`,(0,m.jsxs)(`select`,{name:`member`,value:v.member,onChange:e=>x({...v,member:e.target.value}),children:[(0,m.jsx)(`option`,{value:``,children:`全部员工`}),s.map(e=>(0,m.jsxs)(`option`,{value:e.member,children:[e.label,e.enabled===!1&&`(已停用)`]},e.member))]})]}),(0,m.jsxs)(`div`,{className:`ops-actions`,children:[(0,m.jsx)(o,{type:`primary`,htmlType:`submit`,children:`查询`}),(0,m.jsx)(o,{"data-action":`private-ops-period`,"data-period":`today`,onClick:()=>k(!1),children:`今天`}),(0,m.jsx)(o,{"data-action":`private-ops-period`,"data-period":`month`,onClick:()=>k(!0),children:`本月`})]})]})}),(0,m.jsx)(y,{client:e,query:c,open:A,retry:()=>D(v)},S)]}):(0,m.jsx)(b,{client:e,edit:e=>A({date:e,member:f.currentMember(n)}),retry:()=>C(e=>e+1)},S),w&&(0,m.jsx)(h,{client:e,state:n,members:s,initial:w,close:()=>T(null),saved:()=>j(`人数已保存`),recover:M})]})})}function y({client:e,query:t,open:n,retry:r}){let i=(0,p.useCallback)(async()=>{let n=await e.api(`/api/private-operations?`+new URLSearchParams({...t}));if(n.from!==t.from||n.date!==t.date||!Array.isArray(n.members)||!Array.isArray(n.summaries)||!Array.isArray(n.rows))throw Error(`运营资料未完整返回,请重新查询`);return n},[e,t]),s=c(i);return(0,m.jsx)(`div`,{id:`private-ops-result`,"aria-live":`polite`,children:s?`data`in s?(0,m.jsx)(g,{data:s.data,open:n}):(0,m.jsx)(a,{type:`error`,showIcon:!0,message:s.error,action:(0,m.jsx)(o,{onClick:r,"data-action":`private-ops-retry`,children:`重新读取`})}):(0,m.jsx)(`p`,{className:`muted`,children:`正在读取运营数据…`})})}function b({client:e,edit:t,retry:r}){let s=(0,p.useCallback)(async()=>{let t=await e.api(n+`-history`);if(!Array.isArray(t.rows))throw Error(`人数记录未完整返回,请重新读取`);return t.rows},[e]),l=c(s);return(0,m.jsx)(`section`,{className:`ops-panel`,id:`people-entry-history`,children:l?`error`in l?(0,m.jsx)(a,{type:`error`,showIcon:!0,message:l.error,action:(0,m.jsx)(o,{"data-action":`private-people-history-retry`,onClick:r,children:`重新读取`})}):(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`h2`,{children:`我的人数记录`}),(0,m.jsx)(`div`,{className:`ops-scroll`,children:(0,m.jsxs)(`table`,{children:[(0,m.jsx)(`thead`,{children:(0,m.jsxs)(`tr`,{children:[(0,m.jsx)(`th`,{children:`日期`}),(0,m.jsx)(`th`,{children:`总人数`}),(0,m.jsx)(`th`,{children:`新增人数`}),(0,m.jsx)(`th`,{children:`操作`})]})}),(0,m.jsxs)(`tbody`,{children:[l.data.map(e=>(0,m.jsxs)(`tr`,{children:[(0,m.jsx)(`td`,{children:e.date}),(0,m.jsx)(`td`,{children:i(e.total)}),(0,m.jsxs)(`td`,{children:[e.newPeople===null?`首次记录`:e.newPeople+` 人`,e.previousDate&&(0,m.jsxs)(`small`,{children:[`对比 `,e.previousDate]})]}),(0,m.jsx)(`td`,{children:(0,m.jsx)(o,{size:`small`,"data-action":`private-people-open`,"data-date":e.date,onClick:()=>t(e.date),children:`修改`})})]},e.date)),!l.data.length&&(0,m.jsx)(`tr`,{children:(0,m.jsx)(`td`,{colSpan:4,children:`还没有人数记录。`})})]})]})})]}):(0,m.jsx)(`p`,{className:`muted`,children:`正在读取本人人数…`})})}export{v as PrivateOperationsPage};