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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

1 line
35 KiB
JavaScript
Raw Normal View History

import{n as e}from"./rolldown-runtime-Dl_DZoUm.js";import{b as t,nr as n,s as r}from"./index-BvkDlq1y.js";import{i,n as a,r as o,t as s}from"./controls-Dkdh_TtG.js";import{i as c,n as l,r as u,t as d}from"./settingsModel-DuLjBEgM.js";import{c as f,i as p,t as m}from"./shared-D0Ng0yPd.js";import{i as h,n as g,o as _,t as v}from"./BusinessControls-DBHpCgMH.js";var y=e(n(),1),b=t();function x(e){let{name:t,amount:n,payer:r,enabled:i,byQuantity:a}=c(e);return{name:t,amount:n,payer:r,enabled:i===`true`,byQuantity:a===`true`}}function S({shop:e,client:t,members:n,team:r,busy:c,onBusy:l,dirty:f,onDirty:_,onSaved:S,notice:C}){let w=p.presetCatalog(e.costPresets),[T,E]=(0,y.useState)(``),[D,O]=(0,y.useState)(null),[k,A]=(0,y.useState)(!1),[j,M]=(0,y.useState)(``);function N(){k||f&&!window.confirm(`成本修改尚未保存,放弃修改?`)||(O(null),_(!1),M(``))}function P(n,r=``){if(c||t.busy||t.pending())return;let i=w[r]||{name:``,amount:`0`,payer:`order`,enabled:!0,byQuantity:!1};O({action:n,kind:r||`custom_`+crypto.randomUUID(),original:i,revision:e.revision}),_(!1),M(``)}async function F(e){if(e.preventDefault(),!D||k)return;let n=!1;try{if(c||t.busy||t.pending())throw Error(`请先确认当前操作,再保存成本`);let r=D.action===`delete`?null:x(e.currentTarget);if(r){if(r.name=r.name.trim(),!r.name||r.name.length>40)throw Error(`成本名称请填写1~40字`);if(m.cents(r.amount,`成本`)>1e8)throw Error(`成本最多1000000元`)}A(!0),l(!0),M(``);let i=await t.mutate(`/api/shop-settings`,{revision:D.revision,costPresets:{[D.kind]:r}});n=!0,O(null),_(!1),await S(i.shopSettings),C(D.action===`delete`?`成本项目已删除`:`成本项目已保存`)}catch(e){let t=n?`成本已经保存,请刷新页面核对`:d(e);M(t),C(t,!0)}finally{A(!1),l(!1)}}let I=Object.entries(w).filter(([,e])=>e.name.toLocaleLowerCase().includes(T.trim().toLocaleLowerCase()));return(0,b.jsxs)(`section`,{id:`shop-cost-manager`,className:`shop-cost-manager`,children:[(0,b.jsxs)(`div`,{className:`panel-title`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`h3`,{children:`勾选成本管理`}),(0,b.jsx)(`p`,{className:`small muted`,children:`自行添加需要的项目。删除后不再用于新单,历史订单成本保留。`})]}),(0,b.jsx)(s,{action:`shop-cost-add`,className:`primary`,onClick:()=>P(`add`),children:`+ 新增成本`})]}),(0,b.jsxs)(`label`,{className:`shop-cost-search`,children:[`搜索成本`,(0,b.jsx)(h,{type:`search`,id:`shop-cost-search`,placeholder:`输入成本名称`,autoComplete:`off`,value:T,onChange:e=>E(e.target.value)})]}),(0,b.jsx)(`div`,{id:`shop-cost-list`,children:I.length?(0,b.jsx)(`div`,{className:`table-wrap`,children:(0,b.jsx)(g,{className:`shop-cost-table`,columns:[{title:`成本名称`},{title:`金额/单价`},{title:`付款人`},{title:`计费方式`},{title:`状态`},{title:`操作`}],rows:I.map(([e,t])=>({key:e,attributes:{"data-cost-row":e},cells:[(0,b.jsx)(b.Fragment,{children:(0,b.jsx)(`strong`,{children:t.name})}),(0,b.jsxs)(b.Fragment,{children:[`¥`,t.amount]}),t.payer===`order`?`订单归属人`:n.find(e=>e.member===t.payer)?.label||`待确认`,t.byQuantity?`单价 × 数量`:`每单一次`,t.enabled?`启用`:`停用`,(0,b.jsx)(b.Fragment,{children:(0,b.jsxs)(`div`,{className:`actions`,children:[(0,b.jsx)(s,{action:`shop-cost-edit`,className:`quiet`,"data-kind":e,onClick:()=>P(`edit`,e),children:`编辑`}),(0,b.jsx)(s,{action:`shop-cost-delete`,className:`danger`,"data-kind":e,onClick:()=>P(`delete`,e),children:`删除`})]})})]}))})}):(0,b.jsx)(`p`,{className:`empty`,children:Object.keys(w).length?`没有匹配的成本项目。`:`还没有勾选成本,点击“新增成本”添加。`})}),D&&(0,b.jsxs)(o,{id:`shop-cost-dialog`,close:N,children:[(0,b.jsx)(s,{className:`dialog-close`,action:`shop-cost-close`,"aria-label":`关闭成本编辑`,onClick:N,children:`×`}),(0,b.jsx)(`h2`,{children:{add:`新增成本`,delete:`删除成本`,edit:`编辑成本`}[D.action]}),(0,b.jsxs)(`form`,{id:`shop-cost-form`,onSubmit:F,onChange:e=>{let t=x(e.currentTarget);_(Object.keys(t).some(e=>t[e]!=