<template>
  <PageWrapper  contentFullHeight="true" contentClass="flex" style="height:100%;overflow: none;">
      <a-row :gutter="12" style="background:#d9d9d9;padding:10px">
          <a-col :span="6">
            <a-card style="margin:0px"> 
              <div style="font-size:15px;overflow-y: auto;height:calc(90vh - 0px);">
                  <a-directory-tree :showLine="showLine" :tree-data="systemCategoryData"
                      v-model:expandedKeys="expandedKeys"
                      v-model:selectedKeys="selectedKeys"
                      @select="onTreeSelect"
                      >
                  </a-directory-tree>
              </div>
            </a-card>  
          </a-col>
          <a-col :span="18" style="height: calc(90vh - 0px);background:#d9d9d9">
            <a-card  style="margin:0px">
              <div style="font-size:15px;overflow-y: auto;height:calc(90vh - 0px);">
                <WbSurveyCfgList  ref="registerWbSurveyCfgList"></WbSurveyCfgList>
              </div>
            </a-card>
          </a-col>
      </a-row>   
      
  </PageWrapper>    

</template>
<script lang="ts" setup>
  import {ref} from 'vue';
  import { loadTreeData,getChildList} from '../../system/category/category.api';

  import WbSurveyCfgList from './WbSurveyCfgList.vue';

  const emit = defineEmits(['register','success']);

  const rightActiveKey = ref('base');
  const pageTitle = ref("创建或修改指标")
  const systemCategoryData = ref([]);

  const curSelNode = ref({})
  const showLine = ref(false)
  const expandedKeys = ref([]);
  const selectedKeys = ref([]);
  const registerWbSurveyCfgList = ref();
  const isUpdate = ref();

  const rightTabChange = (type: string) => {
    rightActiveKey.value = type;
  };


  function onTreeSelect(selectedKeys, e:{selected: Boolean, selectedNodes,node,event}) {
    if(e.selected) {
      if(e.node.leaf){
        let domainName = e.node.title
        let domainCode = e.node.code
        registerWbSurveyCfgList.value.setDomain(domainCode,domainName)
      } 
    }     
  }


  async function setDomainData(pcode) {
      let list =  expandedKeys.value =  []
      systemCategoryData.value =list=  await loadTreeData({'async': false,'pcode':pcode});
      if(!list||list.length==0) return;
      let isLeaf = false;
      do {
        if(!list[0].leaf) {
          let childs = list[0].children;
          if(childs.length>0) {
            expandedKeys.value.push(list[0].key)
            list = childs
            isLeaf = false;
          } 
        } else {
          selectedKeys.value.push(list[0].key)
          isLeaf = true;
          let domainName = list[0].title
          let domainCode = list[0].code
          registerWbSurveyCfgList.value.setDomain(domainCode,domainName)

        }

      } while(!isLeaf)

  }


  setDomainData("B06")

</script>

<style scope>
.underline-input {
border-left:none;
border-top:none;
border-right:none;
width: 100%;
}
</style>