Files
xin-procurement/public/assets/goods-DD5elziV.js
T
2026-08-20 16:54:34 +08:00

1 line
11 KiB
JavaScript

import{i as e}from"./rolldown-runtime-BgaNhQyE.js";import{Dr as t,t as n}from"./jsx-runtime-CRBytmvs.js";import{t as r}from"./typography-DRFhazK9.js";import{L as i,V as a,c as o,y as s}from"./lodash-DzOfPy0f.js";import{t as c}from"./alert-DuXzwpQC.js";import{n as ee,t as te}from"./table-BXi9q3AE.js";import{t as l}from"./space-Cu4QVMgQ.js";import{t as u}from"./button-BILozH6U.js";import{l as ne}from"./XinForm-BPDYdeax.js";import{t as re}from"./card-DU2T2-YW.js";import{t as ie}from"./modal-g8Q5gNCx.js";import{t as ae}from"./image-CTRBNpBE.js";import{t as oe}from"./input-CHcsaDtX.js";import{r as d}from"./PictureOutlined-CB8Pr7jP.js";import{t as f}from"./tag-DBV1bHre.js";import{t as se}from"./upload-oMV5VJeJ.js";import{t as ce}from"./DownloadOutlined-DJY9Mu8c.js";import{t as p}from"./UploadOutlined-NadwXvrl.js";import{t as le}from"./XinTable-BS9orhKm.js";import{t as m}from"./AuthButton-DvrpreK4.js";import{n as ue}from"./category-MmrJkdbs.js";import{i as de,n as fe,o as pe,r as h,s as g,t as _}from"./goods-D5BPswzh.js";var v=e(t(),1),y={0:{text:`下架`,color:`default`},1:{text:`上架`,color:`success`}},b=n(),{Title:me,Text:x}=r,S=e=>Math.round(e*100)/100,C=e=>e.map(e=>({...e,disabled:!!e.children?.length,children:e.children?.length?C(e.children):e.children})),w=e=>e.map(e=>({...e,selectable:!e.children?.length,children:e.children?.length?w(e.children):e.children})),T=()=>{let[e,t]=(0,v.useState)([]),[n,r]=(0,v.useState)([]),T=(0,v.useMemo)(()=>C(n),[n]),he=(0,v.useMemo)(()=>w(n),[n]),[E,D]=(0,v.useState)(void 0),O=(0,v.useRef)(null);(0,v.useEffect)(()=>{O.current?.reset()},[E]);let[k,A]=(0,v.useState)(!1),[j,M]=(0,v.useState)(!1),[N,P]=(0,v.useState)(!1),[F,I]=(0,v.useState)([]),[L,R]=(0,v.useState)(1),[z,B]=(0,v.useState)(20),[ge,V]=(0,v.useState)(0),[H,_e]=(0,v.useState)([]),[U,ve]=(0,v.useState)(``),[W,ye]=(0,v.useState)(void 0),G=(0,v.useRef)({}),[be,K]=(0,v.useState)(!1),[xe,q]=(0,v.useState)(!1),[J,Y]=(0,v.useState)(null),[Se,X]=(0,v.useState)(!1),[Z,Q]=(0,v.useState)([]),Ce=async()=>{K(!0);try{await h(E?{category_id:E}:{})}finally{K(!1)}},we=async()=>{if(J){X(!0),Q([]);try{await pe(J),q(!1),Y(null),O.current?.reset()}catch(e){let t=e?.data?.data?.errors;Array.isArray(t)&&Q(t)}finally{X(!1)}}};(0,v.useEffect)(()=>{g().then(e=>t(e.data.data??[])),ue().then(e=>r(e.data.data??[]))},[]);let $=async(e=U,t=W,n=L,r=z)=>{M(!0);try{let i=await de({keyword:e||void 0,category_id:t,page:n,pageSize:r}),a=i.data.data?.rows??[],o=i.data.data?.levels??[],s=a.map(e=>{let t=G.current[e.id];if(t===void 0)return e;let n={...e,cost_price:t},r=Number(t??0);return o.forEach(e=>{e.id!=null&&(n[`price_${e.id}`]=r>0?S(r*(1+Number(e.percent??0)/100)):null)}),n});I(s),V(i.data.data?.total??0),_e(o)}finally{M(!1)}},Te=()=>{A(!0),R(1),B(20),$(``,void 0,1,20)},Ee=(e,t)=>{G.current[e]=t,I(n=>n.map(n=>{if(n.id!==e)return n;let r={...n,cost_price:t},i=Number(t??0);return H.forEach(e=>{e.id!=null&&(r[`price_${e.id}`]=i>0?S(i*(1+Number(e.percent??0)/100)):null)}),r}))},De=async()=>{let e=[];if(Object.entries(G.current).forEach(([t,n])=>{n!=null&&e.push({product_id:Number(t),cost_price:n})}),e.length===0){d.info(`没有需要保存的价格调整`);return}P(!0);try{await _(e),d.success(`已更新 ${e.length} 件商品成本价,各等级售价已按上浮比例联动,受影响门店将收到通知`),G.current={},await $()}finally{P(!1)}},Oe=[{title:`商品`,dataIndex:`name`,fixed:`left`,width:160,render:(e,t)=>(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`div`,{className:`font-medium`,children:e}),(0,b.jsxs)(x,{type:`secondary`,className:`text-xs`,children:[t.spec,t.unit?` / ${t.unit}`:``]})]})},{title:`成本价`,key:`cost_price`,fixed:`left`,width:130,render:(e,t)=>(0,b.jsx)(a,{size:`small`,min:0,precision:2,prefix:`¥`,value:t.cost_price,onChange:e=>Ee(t.id,e),className:`w-32`})},...H.map(e=>({title:e.name,key:`price_${e.id}`,width:150,render:(t,n)=>{let r=n[`price_${e.id}`];return(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`div`,{children:r==null?(0,b.jsx)(x,{type:`secondary`,children:`未设成本价`}):${r}`}),(0,b.jsxs)(`div`,{className:`text-xs text-gray-400`,children:[`成本上浮 `,Number(e.percent??0),`%`]})]})}}))],ke={api:`/product/goods`,columns:[{title:`ID`,dataIndex:`id`,hideInForm:!0,hideInSearch:!0,width:70,align:`center`},{title:`商品图片`,dataIndex:`image_ids`,valueType:`image`,fieldProps:{action:`/product/goods/upload`,maxWidth:3e3,maxHeight:3e3,maxSize:10,mode:`multiple`,maxCount:5,changeType:`id`},render:(e,t)=>!t.images_arr||t.images_arr?.length<=0?`-`:(0,b.jsx)(l,{wrap:!1,children:t.images_arr.map(e=>(0,b.jsx)(ae,{src:e.preview_url,width:60,height:60,style:{objectFit:`cover`,borderRadius:4}},e.id))}),align:`center`,hideInSearch:!0,colProps:{span:24}},{title:`商品名称`,dataIndex:`name`,valueType:`text`,colProps:{span:24},required:!0,render:(e,t)=>(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`div`,{className:`mb-1.5`,children:t.name}),(0,b.jsx)(`div`,{className:`text-[#999] text-[12px]`,children:t.remark})]}),rules:[{required:!0,message:`请输入商品名称`}]},{title:`商品描述`,dataIndex:`remark`,valueType:`text`,hideInSearch:!0,hideInTable:!0,colProps:{span:24}},{title:`成本价`,dataIndex:`cost_price`,valueType:`digit`,hideInSearch:!0,align:`center`,tooltip:`各等级售价 = 成本价 × (100 + 等级上浮比例) / 100`,fieldProps:{min:0,precision:2,prefix:`¥`},render:(e,t)=>Number(t.cost_price??0)>0?${t.cost_price}`:(0,b.jsx)(x,{type:`secondary`,children:`未设置`})},{title:`规格/包规`,dataIndex:`spec`,valueType:`text`,hideInSearch:!0,align:`center`},{title:`单位`,dataIndex:`unit`,valueType:`text`,hideInSearch:!0,initialValue:`斤`,align:`center`},{title:`排序`,dataIndex:`sort`,valueType:`digit`,hideInSearch:!0,fieldProps:{min:0},align:`center`},{title:`分类`,dataIndex:`category_id`,valueType:`treeSelect`,required:!0,align:`center`,rules:[{required:!0,message:`请选择分类`}],fieldProps:{treeData:T,fieldNames:{label:`name`,value:`id`,children:`children`},treeDefaultExpandAll:!0,showSearch:!0,treeNodeFilterProp:`name`,placeholder:`选择末级分类`},hideInSearch:!0,render:(e,t)=>t.category?(0,b.jsx)(f,{color:`cyan`,children:t.category.name}):`-`},{title:`供应商`,dataIndex:`supplier_id`,valueType:`select`,hideInSearch:!0,align:`center`,fieldProps:{options:e.map(e=>({label:e.name,value:e.id})),showSearch:!0,optionFilterProp:`label`,allowClear:!0,placeholder:`默认供应商(可选)`},render:(e,t)=>t.supplier?.name??`-`},{title:`市场`,dataIndex:`market`,valueType:`text`,align:`center`,fieldProps:{placeholder:`市场名称,如:新发地`,maxLength:50,allowClear:!0},render:(e,t)=>t.market||`-`},{title:`状态`,dataIndex:`status`,valueType:`radioButton`,initialValue:1,fieldProps:{options:[{value:1,label:`上架`},{value:0,label:`下架`}]},render:(e,t)=>{let n=y[t.status??1];return(0,b.jsx)(f,{color:n?.color,children:n?.text})},align:`center`},{title:`图文详情`,dataIndex:`content`,valueType:`richText`,hideInSearch:!0,hideInTable:!0,colProps:{span:24},fieldProps:{height:400,groupId:11,placeholder:`输入商品图文详情,支持插入图片`}},{title:`等级价格`,dataIndex:`prices`,hideInForm:!0,hideInSearch:!0,width:420,align:`center`,render:(e,t)=>(0,b.jsx)(l,{wrap:!0,children:t.prices?.length?t.prices.map(e=>(0,b.jsxs)(f,{color:`geekblue`,title:`按成本价上浮 ${e.percent??0}%`,children:[e.level?.name??`等级${e.level_id}`,(0,b.jsxs)(`span`,{style:{color:`red`,marginLeft:5},children:[`¥`,e.price??`未设定`]})]},e.level_id)):`-`})},{title:`创建时间`,dataIndex:`created_at`,hideInForm:!0,hideInSearch:!0,align:`center`}],rowKey:`id`,accessName:`product.goods`,tableRef:O,scroll:{x:1200},actionBarRender:e=>[e.add,e.search,(0,b.jsx)(u,{icon:(0,b.jsx)(o,{}),onClick:Te,children:`价格矩阵`},`matrix`),(0,b.jsx)(m,{auth:`product.goods.export`,children:(0,b.jsx)(u,{icon:(0,b.jsx)(ce,{}),loading:be,onClick:Ce,children:`导出`})},`export`),(0,b.jsx)(m,{auth:`product.goods.import`,children:(0,b.jsx)(u,{icon:(0,b.jsx)(p,{}),onClick:()=>q(!0),children:`导入`})},`import`),e.keywordSearch],formProps:{grid:!0,colProps:{span:12},rowProps:{gutter:20},layout:`vertical`},requestParams:e=>({...e,category_id:E}),modalProps:{width:800,centered:!0,classNames:{body:`overflow-y-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden h-[80vh]`}}};return(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)(`div`,{className:`mb-5`,children:[(0,b.jsx)(me,{level:3,children:`商品列表`}),(0,b.jsx)(x,{type:`secondary`,children:`商品售价按客户等级上浮比例自动换算(成本价 × (100 + 上浮比例) / 100);「价格矩阵」支持批量调整成本价,调价后自动通知受影响门店。`})]}),(0,b.jsxs)(`div`,{className:`flex items-start gap-4`,children:[(0,b.jsxs)(re,{style:{width:200},title:`商品分类`,children:[(0,b.jsx)(`div`,{className:`cursor-pointer rounded-2xl mb-2 px-2 h-6 leading-6 ${E===void 0?`bg-blue-50`:`hover:bg-gray-50`}`,onClick:()=>{D(void 0)},children:`全部商品`}),(0,b.jsx)(ee,{showLine:!0,blockNode:!0,onSelect:e=>D(Number(e[0])),treeData:he,selectedKeys:E?[E]:void 0,fieldNames:{title:`name`,key:`id`,children:`children`}})]}),(0,b.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,b.jsx)(le,{...ke})})]}),(0,b.jsxs)(ie,{title:`导入商品`,open:xe,onCancel:()=>q(!1),onOk:we,okText:`开始导入`,okButtonProps:{disabled:!J},confirmLoading:Se,destroyOnHidden:!0,width:560,children:[(0,b.jsxs)(`div`,{className:`mb-3`,children:[(0,b.jsx)(x,{type:`secondary`,children:`列格式:品名*、分类*(末级分类,支持「父分类/子分类」路径)、供应商(不存在自动创建)、市场、 规格/包规、单位(默认斤)、成本价、排序、库存、保质期、状态(上架/下架)、备注。 导入一律新增商品;整表校验,任何一行有错则全部不导入。`}),(0,b.jsx)(u,{type:`link`,className:`px-0`,onClick:fe,children:`下载导入模板`})]}),(0,b.jsxs)(se.Dragger,{accept:`.xlsx,.xls`,maxCount:1,beforeUpload:e=>(Y(e),Q([]),!1),onRemove:()=>{Y(null),Q([])},children:[(0,b.jsx)(`p`,{className:`ant-upload-drag-icon`,children:(0,b.jsx)(s,{})}),(0,b.jsx)(`p`,{className:`ant-upload-text`,children:`点击或拖拽 Excel 文件到此区域`}),(0,b.jsx)(`p`,{className:`ant-upload-hint`,children:`仅支持 .xlsx / .xls,单次最多 1000 行`})]}),Z.length>0&&(0,b.jsx)(c,{className:`mt-3`,type:`error`,showIcon:!0,message:`共 ${Z.length} 处错误,修正后请重新导入`,description:(0,b.jsx)(`ul`,{className:`max-h-48 overflow-y-auto pl-4 mb-0 list-disc`,children:Z.map((e,t)=>(0,b.jsxs)(`li`,{children:[`第 `,e.row,` 行:`,e.message]},t))})})]}),(0,b.jsxs)(i,{title:`价格矩阵 · 批量调价`,open:k,onClose:()=>A(!1),size:1200,extra:(0,b.jsxs)(l,{children:[(0,b.jsx)(u,{onClick:()=>$(),children:`刷新`}),(0,b.jsx)(u,{type:`primary`,loading:N,onClick:De,children:`保存调价`})]}),children:[(0,b.jsxs)(l,{className:`mb-4`,wrap:!0,children:[(0,b.jsx)(ne,{style:{width:180},placeholder:`按分类筛选`,allowClear:!0,treeDefaultExpandAll:!0,fieldNames:{label:`name`,value:`id`,children:`children`},treeData:n,value:W,onChange:e=>{ye(e),R(1),$(U,e,1,z)}}),(0,b.jsx)(oe.Search,{style:{width:240},placeholder:`搜索品名/规格`,allowClear:!0,value:U,onChange:e=>ve(e.target.value),onSearch:e=>{R(1),$(e,W,1,z)}}),(0,b.jsx)(x,{type:`secondary`,children:`等级列按上浮比例自动换算,仅成本价可编辑`})]}),(0,b.jsx)(te,{rowKey:`id`,size:`small`,loading:j,columns:Oe,dataSource:F,pagination:{current:L,pageSize:z,total:ge,showSizeChanger:!0,pageSizeOptions:[20,50,100],showTotal:e=>`共 ${e} 件商品`,onChange:(e,t)=>{R(e),B(t),$(U,W,e,t)}},scroll:{x:H.length*150+290}})]})]})};export{T as default};