

<script>
/* eslint-disable */
// sd-skip-auto-import
import FormService from"../form-service";import components from"./_import-components/sd-form-template-catetree-import";var _render=function e(){var t=this,a=t._self._c;return a("a-card",{class:t.$style.treewrap},[a("a-input-search",{attrs:{"allow-clear":""},on:{change:t.onSearchChange},model:{value:t.searchStr,callback:function(e){t.searchStr=e},expression:"searchStr"}}),t.spinning?a("a-spin",{class:t.$style.spin,attrs:{spinning:t.spinning}}):[t.treeData.length>0?a("a-tree",{attrs:{"block-node":true,"tree-data":t.treeData,"replace-fields":t.replaceFields,"selected-keys":t.selectedKeys,"expanded-keys":t.expandedKeys},on:{select:t.treeSelect,expand:t.onExpand},scopedSlots:t._u([{key:"title",fn:function({text:e}){return[e.indexOf(t.searchValue)>-1?a("span",[t._v(" "+t._s(e.substr(0,e.indexOf(t.searchValue)))),a("span",{class:t.$style.active},[t._v(t._s(t.searchValue))]),t._v(t._s(e.substr(e.indexOf(t.searchValue)+t.searchValue.length)))]):a("span",[t._v(t._s(e))])]}}],null,false,3102584899)}):a("a-empty")]],2)};var staticRenderFns=[];_render._withStripped=true;export default{name:"SdFormTemplateCatetree",components:components,props:{rootSelected:{type:Boolean,default:false},rootType:{type:String,default:"TEMP_CLASS_MANAGE"}},data(){return{searchStr:"",spinning:true,replaceFields:{title:"text",key:"id"},treeData:[],dataList:[],expandedKeys:["LOCAL_ROOT",global?"GLOBAL_ROOT":""],autoExpandParent:false,selectedKeys:[],searchValue:""}},created(){this.initTreeData()},methods:{initTreeData(e){this.spinning=true;FormService.getTepmlateTootNode(this.rootType).then((t=>{this.treeData=t.data;Promise.all(this.treeData.map((e=>FormService.getTemplateCateTree(e.id,"true")))).then((t=>{t.forEach(((e,t)=>{this.treeData[t].children=e.data}));this.treeData=this.transformData(this.treeData);this.generateList(this.treeData);if(!e){this.selectedKeys=[this.treeData[0].id];this.$emit("treeSelect",{id:this.treeData[0].id,name:this.treeData[0].text})}})).finally((()=>{this.spinning=false}))}))},onSearchChange(e){const t=e.target.value;const a=this.dataList.map((e=>{if(e.title.indexOf(t)>-1)return this.getParentKey(e.key,this.treeData);return null})).filter(((e,t,a)=>e&&a.indexOf(e)===t));a.unshift(this.treeData?.[0].id);Object.assign(this,{expandedKeys:a,searchValue:t,autoExpandParent:true})},getParentKey(e,t){let a;for(let r=0;r<t.length;r++){const s=t[r];if(s.children)if(s.children.some((t=>t.id===e)))a=s.id;else if(this.getParentKey(e,s.children))a=this.getParentKey(e,s.children)}return a},transformData(e){return e.map((e=>{const{children:t,...a}=e;const r={...a,scopedSlots:{title:"title"},title:e.text};if(t)r.children=this.transformData(t);r.isLeaf=!(t&&t.length>0);return r}))},generateList(e){for(let t=0;t<e.length;t++){const a=e[t];const r=a.id;const s=a.text;const n=a.props;this.dataList.push({key:r,id:r,title:s,props:n});if(a.children)this.generateList(a.children)}},onExpand(e){this.expandedKeys=e;this.autoExpandParent=false},treeSelect(e,t){if(e[0]&&e[0]!==this.selectedKeys[0]){this.selectedKeys=e;this.$emit("treeSelect",{id:t.node.dataRef.id,name:t.node.dataRef.text,edit:"true"===t.node.dataRef.props?.edit})}},refresh(){this.initTreeData(true)}},render:_render,staticRenderFns:staticRenderFns};</script>

<style module lang="scss">
@use '@/common/design' as *;
.spin {
  width: 100%;
  line-height: 10;
}
.treewrap {
  :global(.ant-input-search) {
    overflow: hidden;
  }
  :global(.ant-tree) {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  :global(.ant-card-body) {
    background: $white;
  }
  .active {
    color: $primary-color;
  }
}
</style>
