import{_ as S,j as T}from"./index.76a66f15.js";/* empty css *//* empty css */import{S as D}from"./share.46fc03c1.js";import{a$ as p,C as _,D as y,aJ as a,b2 as i,E as v,aV as h,G as U,b5 as C,b1 as O,b3 as $,bo as z,bs as A,ct as B,c4 as M,bE as J,cu as G,bm as P,bn as W,bv as q,bV as F,bL as H}from"./arco.f3c60d68.js";import"./chart.a626c034.js";import"./vue.7d1f2b31.js";import"./qrcode.vue.esm.aee0cddc.js";const Y={components:{shareModal:D,imgChange:T},data(){return{loading:!1,categoryList:[],originalData:[],tempId:-1,shareId:null,modal:{share:!1},maxLevel:4}},mounted(){this.getCategoryList()},methods:{openGuide(){window.open("https://wood-soft.feishu.cn/wiki/EVY8wdCJgiE7EZkSHCVc5gYSnpb","_blank")},getCategoryList(){this.loading=!0,this.$request.post("admin/course/group/tree",{}).then(s=>{const e=s.data||[];this.categoryList=this.flattenTreeWithLevel(e),this.originalData=JSON.parse(JSON.stringify(this.categoryList)),this.loading=!1}).catch(()=>{this.loading=!1})},flattenTreeWithLevel(s,e=0){const l=[];return s.forEach(d=>{const{children:o,...t}=d;l.push({...t,level:e,status:String(d.status)}),o&&o.length>0&&e{window.scrollTo({top:document.body.scrollHeight,behavior:"smooth"})});else{const d=this.categoryList.findIndex(o=>o.id===s);if(d>-1){const o=this.categoryList[d].level;let t=d+1;for(;t!e.includes(l.id)),this.$message.success(`\u5DF2\u5220\u9664${e.length}\u4E2A\u5206\u7C7B`)},getAllChildrenIds(s){const e=[],l=d=>{this.categoryList.forEach(o=>{o.parent_id===d&&(e.push(o.id),l(o.id))})};return l(s),e},detail(s){this.$router.push({name:"course.group.detail",params:{id:s}})},share(s){this.shareId=s.id,this.showModal("share")},showModal(s){this.modal[s]=!this.modal[s]},resetForm(){this.getCategoryList(),this.$message.success("\u5DF2\u91CD\u7F6E")},async saveAll(){for(const l of this.categoryList)if(!l.name||l.name.trim()===""){this.$message.error("\u8BF7\u586B\u5199\u6240\u6709\u5206\u7C7B\u540D\u79F0");return}const s=this.buildTree(this.categoryList),e={original_ids:this.originalData.map(l=>l.id),groups:s};this.loading=!0;try{await this.$request.post("admin/course/group/save",e),this.$message.success("\u6210\u529F\u4FDD\u5B58"),this.getCategoryList()}catch(l){this.$message.error(l.msg||"\u4FDD\u5B58\u5931\u8D25")}finally{this.loading=!1}},buildTree(s){const e=[],l={},d=[...s].sort((t,r)=>(t.sort||0)-(r.sort||0));d.forEach(t=>{l[t.id]={id:t.id,name:t.name,image:t.image||"",parent_id:t.parent_id,status:parseInt(t.status),sort:t.sort||0,children:[]}}),d.forEach(t=>{const r=l[t.id];t.parent_id===0?e.push(r):l[t.parent_id]&&l[t.parent_id].children.push(r)});const o=t=>{t.forEach(r=>{r.children&&r.children.length===0?delete r.children:r.children&&r.children.length>0&&o(r.children)})};return o(e),e}}},j={class:"container"},Z={class:"table-toolbar"},K={key:0,class:"level-indent"};function Q(s,e,l,d,o,t){const r=p("icon-plus"),u=z,g=A,f=B,b=M,L=J,m=G,k=p("img-change"),w=P,x=W,V=q,I=F,N=H,E=p("share-modal");return _(),y("div",j,[a(N,{class:"content-card",bordered:!1},{default:i(()=>[a(b,{"offset-top":80},{default:i(()=>[v("div",Z,[a(g,null,{default:i(()=>[a(u,{type:"dashed",onClick:e[0]||(e[0]=n=>t.addCategory(0))},{icon:i(()=>[a(r)]),default:i(()=>[e[2]||(e[2]=h(" \u6DFB\u52A0\u5206\u7C7B ",-1))]),_:1}),a(u,{type:"text",onClick:t.openGuide},{default:i(()=>[...e[3]||(e[3]=[h("\u67E5\u770B\u6307\u5F15",-1)])]),_:1},8,["onClick"])]),_:1}),a(g,null,{default:i(()=>[a(f,{content:"\u786E\u5B9A\u8981\u91CD\u7F6E\u5417\uFF1F\u5C06\u6062\u590D\u4E3A\u4FDD\u5B58\u524D\u7684\u6570\u636E",type:"warning",onOk:t.resetForm},{default:i(()=>[a(u,null,{default:i(()=>[...e[4]||(e[4]=[h("\u91CD\u7F6E",-1)])]),_:1})]),_:1},8,["onOk"]),a(u,{type:"primary",onClick:t.saveAll},{default:i(()=>[...e[5]||(e[5]=[h("\u4FDD\u5B58",-1)])]),_:1},8,["onClick"])]),_:1})])]),_:1}),a(I,{data:o.categoryList,loading:o.loading,pagination:!1,bordered:!1,"row-key":"id"},{columns:i(()=>[a(m,{title:"\u5206\u7C7B\u540D\u79F0",width:"300"},{cell:i(({record:n})=>[v("div",{class:"category-name-cell",style:U({paddingLeft:n.level*40+"px"})},[n.level>0?(_(),y("span",K,"\u2514")):C("",!0),a(L,{modelValue:n.name,"onUpdate:modelValue":c=>n.name=c,placeholder:t.getPlaceholder(n),style:{width:"180px"}},null,8,["modelValue","onUpdate:modelValue","placeholder"]),n.levelt.addCategory(n.id,n.level+1),style:{"margin-left":"8px"}},{default:i(()=>[a(r),h(" \u6DFB\u52A0"+$(t.getLevelName(n.level+1))+"\u5206\u7C7B ",1)]),_:2},1032,["onClick"])):C("",!0)],4)]),_:1}),a(m,{title:"\u5206\u7C7B\u56FE\u7247",width:"200"},{cell:i(({record:n})=>[a(k,{modelValue:n.image,"onUpdate:modelValue":c=>n.image=c,width:150,height:150},null,8,["modelValue","onUpdate:modelValue"])]),_:1}),a(m,{title:"\u6392\u5E8F",width:"100"},{cell:i(({record:n})=>[a(w,{modelValue:n.sort,"onUpdate:modelValue":c=>n.sort=c,min:0,style:{width:"80px"}},null,8,["modelValue","onUpdate:modelValue"])]),_:1}),a(m,{title:"\u72B6\u6001",width:"60",fixed:"right"},{cell:i(({record:n})=>[a(x,{modelValue:n.status,"onUpdate:modelValue":c=>n.status=c,"checked-value":"1","unchecked-value":"0","checked-text":"\u663E\u793A","unchecked-text":"\u9690\u85CF",size:"small"},null,8,["modelValue","onUpdate:modelValue"])]),_:1}),a(m,{title:"\u64CD\u4F5C",width:"220",fixed:"right",align:"right"},{cell:i(({record:n})=>[a(g,null,{default:i(()=>[a(u,{style:{padding:"0"},type:"text",size:"small",onClick:c=>t.detail(n.id)},{default:i(()=>[...e[6]||(e[6]=[h(" \u8BFE\u7A0B\u7BA1\u7406 ",-1)])]),_:1},8,["onClick"]),a(u,{style:{padding:"0"},type:"text",size:"small",onClick:c=>t.share(n)},{default:i(()=>[...e[7]||(e[7]=[h(" \u5206\u4EAB ",-1)])]),_:1},8,["onClick"]),a(f,{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=>t.deleteCategory(n)},{default:i(()=>[a(V,{status:"danger"},{default:i(()=>[...e[8]||(e[8]=[h("\u5220\u9664",-1)])]),_:1})]),_:1},8,["onOk"])]),_:2},1024)]),_:1})]),_:1},8,["data","loading"])]),_:1}),a(E,{visible:o.modal.share,type:"group",id:o.shareId,onCancel:e[1]||(e[1]=n=>t.showModal("share"))},null,8,["visible","id"])])}const ie=S(Y,[["render",Q],["__scopeId","data-v-be551fe5"]]);export{ie as default};