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