第7项:按路由加载页面并核验登录和开单冷启动预算

This commit is contained in:
黄健铭 committed 2026-12-05 08:25:22 -08:00
1 parent c6ad648d7e
commit f9cd68c569
71 files changed
+1250 -454

No files matched your search

@@ -0,0 +1 @@
import{n as e}from"./rolldown-runtime-Dl_DZoUm.js";import{s as t,tr as n,v as r}from"./index-D422TGjj.js";import{o as i}from"./shared-Da74NgmJ.js";import{t as a}from"./format-u4LYCVYL.js";import{a as o,c as s,i as c,l,n as u,o as d,r as f,s as p,t as m,u as h}from"./data-Cu-7m_75.js";import{a as g,i as _,n as v,o as y,r as b,s as x,t as S}from"./BusinessControls-B3wlV0Qu.js";var C=e(n(),1);function w(e,t,n){let r=new FormData(e),a=e=>String(r.get(e)||``),s=a(`kind`),c=a(`pocket`),l=a(`grams`).trim(),u=a(`to`),d=s===`adjustment`,p=i.activePocketKeys(t);if(!Object.hasOwn(o,s)||!p.includes(c)&&c!==n?.pocket)throw Error(`请选择库存动作和货盘。`);if(d&&t.user.role!==`owner`)throw Error(`对数调整由店主操作。`);if(!(n&&d?/^-?\d+(?:\.\d{1,3})?$/:/^\d+(?:\.\d{1,3})?$/).test(l)||!d&&Number(l)<=0)throw Error(n?`克重请填写有效数字,最多保留3位小数。`:`数量请填写大于0的数字,最多保留3位小数。`);if(s===`transfer`&&(u===c||!p.includes(u)&&u!==n?.to))throw Error(`平移请选择两个不同的货盘。`);if(d&&n?.kind!==`adjustment`&&(!i.pocketCountsEnabled(t,c)||Number(l)!==0))throw Error(`只调整对数请选择已启用对数的货盘,克重保留0。`);let m=i.pocketCountsEnabled(t,c)||s===`transfer`&&i.pocketCountsEnabled(t,u),h=!!n&&n.stockCount==null&&c===n.pocket&&(s!==`transfer`||u===n.to)&&Number(l)!==0;return{kind:s,date:a(`date`),pocket:c,grams:l,note:n?a(`note`).trim():a(`note`),...n?{reason:a(`reason`).trim()}:{},...s===`transfer`?{to:u}:{},...m?{stockCount:f(a(`stockCount`),d,h)}:{}}}var T=r();function E({state:e,original:t,onDate:n}){let r=i.activePocketKeys(e),[a,s]=(0,C.useState)(t?.kind||`increase`),[c,l]=(0,C.useState)(t?.pocket||(r.includes(`现货`)?`现货`:r[0])||``),u=t?t.to||r.find(e=>e!==c):r.includes(`金料`)?`金料`:r[0],[d,f]=(0,C.useState)(u||``),[p,m]=(0,C.useState)(t?.grams||``),h=a===`transfer`,v=a===`adjustment`,y=v&&(t?.kind!==`adjustment`||Number(t.grams)===0),b=i.pocketCountsEnabled(e,c)||h&&i.pocketCountsEnabled(e,d),x=!!t&&t.stockCount==null&&t.pocket===c&&(!h||t.to===d),w=n=>i.pocketOptions(e,n,!!t).filter(([e])=>e!==``).map(([e,t,n])=>(0,T.jsx)(`option`,{value:e,disabled:n,children:t},e)),E=(0,T.jsxs)(`label`,{children:[`业务日期`,(0,T.jsx)(_,{name:`date`,type:`date`,defaultValue:t?.date||e.today,max:e.today,required:!0,onChange:e=>n?.(e.target.value)})]});return(0,T.jsxs)(T.Fragment,{children:[(0,T.jsxs)(`div`,{className:`stock-entry-fields`,children:[t&&E,(0,T.jsxs)(`label`,{children:[t?`类型`:`动作`,(0,T.jsx)(g,{name:`kind`,value:a,onChange:e=>s(e.target.value),children:Object.entries(o).filter(([n])=>n!==`adjustment`||e.user.role===`owner`||t?.kind===n).map(([e,n])=>(0,T.jsx)(`option`,{value:e,children:e===`adjustment`&&!t?`只调整对数`:n},e))})]}),(0,T.jsxs)(`label`,{children:[(0,T.jsx)(`span`,{"data-stock-pocket-label":!0,children:h?`从哪移出`:`货盘`}),(0,T.jsx)(g,{name:`pocket`,value:c,onChange:e=>l(e.target.value),children:w(t?.pocket)})]}),(0,T.jsxs)(`label`,{"data-stock-to":!0,hidden:!h,children:[`移到哪`,(0,T.jsx)(g,{name:`to`,value:d,disabled:!h,required:h,onChange:e=>f(e.target.value),children:w(t?.to)})]}),(0,T.jsxs)(`label`,{children:[t?`克重(g)`:`数量(g)`,(0,T.jsx)(_,{name:`grams`,type:`number`,required:!0,min:y?`0`:v?`-100000000`:`0.001`,step:`0.001`,inputMode:`decimal`,placeholder:t?void 0:`填写正数`,value:y?`0`:p,readOnly:y,onChange:e=>m(e.target.value)})]}),(0,T.jsxs)(`label`,{"data-stock-count-field":!0,hidden:!b,children:[`库存数量(对)`,(0,T.jsx)(_,{name:`stockCount`,type:`number`,defaultValue:t?.stockCount??``,min:v?`-1000000000`:`1`,max:`1000000000`,step:`1`,inputMode:`numeric`,disabled:!b,required:b&&!x,placeholder:v?`增加填正数,减少填负数`:`一对填1`}),t&&t.stockCount==null&&(0,T.jsx)(`small`,{children:`历史未记录对数,可保留空白。`})]}),!t&&E]}),!t&&(0,T.jsx)(`p`,{"data-stock-count-note":!0,hidden:!b||!h&&!v,children:v?`只修正已盘点的对数,不改变克重。增加填正整数,减少填负整数。`:`平移涉及对数货盘时填写本次实际对数;两边都记录对数时同步增减相同数量。`}),(0,T.jsxs)(`label`,{children:[`备注(选填)`,(0,T.jsx)(_,{name:`note`,type:`text`,maxLength:200,defaultValue:t?.note||``,placeholder:t?void 0:`可填写来源或原因`})]}),!t&&(0,T.jsx)(S,{className:`primary`,id:`stock-submit`,disabled:!r.length,children:v?`保存对数调整`:`登记`+o[a]})]})}function D({client:e,state:t,blocked:n,reload:r}){let[i,a]=(0,C.useState)(``);async function o(n){n.preventDefault();try{let i=w(n.currentTarget,t);await e.mutate(`/api/stock`,i),r()}catch(e){a(e.message)}}return(0,T.jsxs)(`section`,{className:`panel stock-entry`,children:[(0,T.jsx)(`h2`,{children:`登记库存变动`}),(0,T.jsx)(`p`,{children:`销售与退货会随订单自动记账,无需重复登记。启用对数的货盘同时记录克重与对数。`}),(0,T.jsxs)(`form`,{id:`stock-form`,onSubmit:o,oLine truncated