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