import{_ as N,j as E}from"./index.76a66f15.js";/* empty css *//* empty css */import{a$ as y,C as _,D as v,aJ as l,b2 as d,E as b,aV as u,G as S,b5 as w,b1 as U,b3 as $,bo as D,bs as O,ct as A,c4 as B,bE as z,cu as J,bm as P,bn as q,bv as F,bV as G,bL as W}from"./arco.f3c60d68.js";import"./chart.a626c034.js";import"./vue.7d1f2b31.js";const j={components:{imgChange:E},data(){return{loading:!1,categoryList:[],originalData:[],tempId:-1}},mounted(){this.getCategoryList()},methods:{getCategoryList(){this.loading=!0,this.$request.post("admin/app/physical/category/index",{}).then(n=>{const t=n.data.rows||[];this.categoryList=this.buildTreeWithLevel(t),this.originalData=JSON.parse(JSON.stringify(this.categoryList)),this.loading=!1}).catch(()=>{this.loading=!1})},buildTreeWithLevel(n){const t=[],o={},a=[...n].sort((e,s)=>(e.weigh||0)-(s.weigh||0));return a.forEach(e=>{o[e.id]={...e,children:[],level:-1,status:String(e.status)}}),a.forEach(e=>{if(e.parent_id===0){const s=o[e.id];s.level=0,t.push(s)}}),a.forEach(e=>{const s=o[e.id];if(s.level===-1&&e.parent_id!==0){const r=o[e.parent_id];r&&r.level===0&&(s.level=1,r.children.push(s))}}),a.forEach(e=>{const s=o[e.id];if(s.level===-1&&e.parent_id!==0){const r=o[e.parent_id];r&&r.level===1&&(s.level=2,r.children.push(s))}}),this.flattenTree(t)},flattenTree(n){const t=[];return n.forEach(o=>{const{children:a,...e}=o;t.push({...e}),a&&a.length>0&&t.push(...this.flattenTree(a))}),t},getPlaceholder(n){return["\u4E00\u7EA7","\u4E8C\u7EA7","\u4E09\u7EA7"][n.level]+"\u5206\u7C7B\u540D\u79F0"},getStyle(n){return["first","second_style1","third_style1"][n]||"first"},addCategory(n,t=0){const o={id:this.tempId--,parent_id:n,name:"",image:"",description:"",weigh:0,status:"1",style:this.getStyle(t),level:t,isNew:!0};if(n===0)this.categoryList.push(o),this.$nextTick(()=>{window.scrollTo({top:document.body.scrollHeight,behavior:"smooth"})});else{const a=this.categoryList.findIndex(e=>e.id===n);if(a>-1){const e=this.categoryList[a].level;let s=a+1;for(;s!t.includes(o.id)),this.$message.success(`\u5DF2\u5220\u9664${t.length}\u4E2A\u5206\u7C7B`)},getAllChildrenIds(n){const t=[],o=a=>{this.categoryList.forEach(e=>{e.parent_id===a&&(t.push(e.id),o(e.id))})};return o(n),t},resetForm(){this.getCategoryList(),this.$message.success("\u5DF2\u91CD\u7F6E")},async saveAll(){for(const a of this.categoryList)if(!a.name||a.name.trim()===""){this.$message.error("\u8BF7\u586B\u5199\u6240\u6709\u5206\u7C7B\u540D\u79F0");return}const n=a=>a.map((e,s)=>{const r={id:e.id,name:e.name,parent_id:e.parent_id,style:e.style||this.getStyle(e.level),image:e.image,description:e.description,status:e.status,weigh:e.weigh||s,level:e.level};return e.children&&e.children.length>0&&(r.children=n(e.children)),r}),t=this.buildTree(this.categoryList),o={original_ids:this.originalData.map(a=>a.id),categories:n(t)};this.loading=!0;try{await this.$request.post("admin/app/physical/category/save",o),this.$message.success("\u6210\u529F\u4FDD\u5B58"),this.getCategoryList()}catch(a){this.$message.error(a.msg||"\u4FDD\u5B58\u5931\u8D25")}finally{this.loading=!1}},buildTree(n){const t=[],o={},a=[...n].sort((e,s)=>(e.weigh||0)-(s.weigh||0));return a.forEach(e=>{o[e.id]={...e,children:[]}}),a.forEach(e=>{const s=o[e.id];e.parent_id===0?t.push(s):o[e.parent_id]&&o[e.parent_id].children.push(s)}),t}}},H={class:"container"},K={class:"table-toolbar"},M={key:0,class:"level-indent"};function Q(n,t,o,a,e,s){const r=y("icon-plus"),p=D,g=O,m=A,L=B,f=z,h=J,C=y("img-change"),V=P,k=q,x=F,T=G,I=W;return _(),v("div",H,[l(I,{class:"content-card",bordered:!1},{default:d(()=>[l(L,{"offset-top":80},{default:d(()=>[b("div",K,[l(g,null,{default:d(()=>[l(p,{type:"dashed",onClick:t[0]||(t[0]=i=>s.addCategory(0))},{icon:d(()=>[l(r)]),default:d(()=>[t[1]||(t[1]=u(" \u6DFB\u52A0\u5206\u7C7B ",-1))]),_:1}),l(p,{type:"text",onClick:n.openGuide},{default:d(()=>[...t[2]||(t[2]=[u("\u64CD\u4F5C\u6307\u5F15",-1)])]),_:1},8,["onClick"])]),_:1}),l(g,null,{default:d(()=>[l(m,{content:"\u786E\u5B9A\u8981\u91CD\u7F6E\u5417\uFF1F\u5C06\u6062\u590D\u4E3A\u4FDD\u5B58\u524D\u7684\u6570\u636E",type:"warning",onOk:s.resetForm},{default:d(()=>[l(p,null,{default:d(()=>[...t[3]||(t[3]=[u("\u91CD\u7F6E",-1)])]),_:1})]),_:1},8,["onOk"]),l(p,{type:"primary",onClick:s.saveAll},{default:d(()=>[...t[4]||(t[4]=[u("\u4FDD\u5B58",-1)])]),_:1},8,["onClick"])]),_:1})])]),_:1}),l(T,{data:e.categoryList,loading:e.loading,pagination:!1,bordered:!1,"row-key":"id"},{columns:d(()=>[l(h,{title:"\u5206\u7C7B\u540D\u79F0",width:"300"},{cell:d(({record:i})=>[b("div",{class:"category-name-cell",style:S({paddingLeft:i.level*40+"px"})},[i.level>0?(_(),v("span",M,"\u2514")):w("",!0),l(f,{modelValue:i.name,"onUpdate:modelValue":c=>i.name=c,placeholder:s.getPlaceholder(i),style:{width:"180px"}},null,8,["modelValue","onUpdate:modelValue","placeholder"]),i.level<2?(_(),U(p,{key:1,type:"dashed",size:"mini",onClick:c=>s.addCategory(i.id,i.level+1),style:{"margin-left":"8px"}},{default:d(()=>[l(r),u(" \u6DFB\u52A0"+$(i.level===0?"\u4E8C\u7EA7":"\u4E09\u7EA7")+"\u5206\u7C7B ",1)]),_:2},1032,["onClick"])):w("",!0)],4)]),_:1}),l(h,{title:"\u5206\u7C7B\u56FE\u7247",width:"200"},{cell:d(({record:i})=>[l(C,{modelValue:i.image,"onUpdate:modelValue":c=>i.image=c,width:150,height:150},null,8,["modelValue","onUpdate:modelValue"])]),_:1}),l(h,{title:"\u63CF\u8FF0",width:"200"},{cell:d(({record:i})=>[l(f,{modelValue:i.description,"onUpdate:modelValue":c=>i.description=c,placeholder:"\u63CF\u8FF0"},null,8,["modelValue","onUpdate:modelValue"])]),_:1}),l(h,{title:"\u6392\u5E8F",width:"100"},{cell:d(({record:i})=>[l(V,{modelValue:i.weigh,"onUpdate:modelValue":c=>i.weigh=c,min:0,style:{width:"80px"}},null,8,["modelValue","onUpdate:modelValue"])]),_:1}),l(h,{title:"\u72B6\u6001",width:"60",fixed:"right"},{cell:d(({record:i})=>[l(k,{modelValue:i.status,"onUpdate:modelValue":c=>i.status=c,"checked-value":"1","unchecked-value":"0","checked-text":"\u663E\u793A","unchecked-text":"\u9690\u85CF",size:"small"},null,8,["modelValue","onUpdate:modelValue"])]),_:1}),l(h,{title:"\u64CD\u4F5C",width:"120",fixed:"right"},{cell:d(({record:i})=>[l(g,null,{default:d(()=>[l(m,{content:"\u786E\u5B9A\u8981\u5220\u9664\u8BE5\u5206\u7C7B\u5417\uFF1F\u5C06\u540C\u65F6\u5220\u9664\u6240\u6709\u5B50\u5206\u7C7B",type:"warning",onOk:c=>s.deleteCategory(i)},{default:d(()=>[l(x,{status:"danger"},{default:d(()=>[...t[5]||(t[5]=[u("\u5220\u9664",-1)])]),_:1})]),_:1},8,["onOk"])]),_:2},1024)]),_:1})]),_:1},8,["data","loading"])]),_:1})])}const se=N(j,[["render",Q],["__scopeId","data-v-e0bc0657"]]);export{se as default};