<template>
<div>
  <el-tabs v-model="editableTabsValue2" type="card" @tab-click="handleClick">
    <el-tab-pane v-for="(item, index) in tabNameList" :key="item.name" :label="item.title" :name="item.name">
      <div v-if="item.name == 'wd_orgId'">
        <assign-org-dimension ref="wd_orgId" :object-id="item.objectId" :dimension-wd-code="item.dimensionWdCode"/>
      </div>
      <div v-else>
        <assign-list-dimension ref="otherDimension" :object-id="item.objectId" :dimension-wd-code="item.dimensionWdCode"/>
      </div>
    </el-tab-pane>
  </el-tabs>
</div>
</template>
<script>
import AssignOrgDimension from "./AssignOrgDimension.vue";
import AssignListDimension from "./AssignListDimension.vue";
export default{
  name: 'AssignDimension',
  components:{
    'AssignOrgDimension': AssignOrgDimension,
    'AssignListDimension': AssignListDimension
  },
  props:{
    objectId:{
      type: String,
      default(){
        return '';
      }
    },
    orgModal:{
      type: Boolean,
      default(){
        return false;
      }
    }
  },
  data(){
    return{
        dimensionWdCode: '',
        objectId: '',
        editableTabsValue2: this.$t("module.dimension.orgManage"),
        tabNameList: [],
        editableTabs2: [],
    }
  },
  computed:{

  },
  created:function(){
    this.init();
    this.$emit('SetTitle', this.$t("module.dimension.dimensionManage"));
    this.$emit('SetPageSize', 650);
    this.$emit('SetPageActions', [
      {
        text: this.$t("common.save"),
        theme: "primary",
        handle: () => {
          this.onOk();
        }
      }
    ])
  },
  beforeMount:function(){

  },
  mounted:function(){

  },
  beforeDestroy:function(){

  },
  destroyed:function(){

  },
  methods:{
    init() {
      $store.dispatch("QueryDimensionList",{}).then((response) => {
        for(const key in response.recordList){
            this.tabNameList.push({
            title: response.recordList[key].wdName,
            name: response.recordList[key].wdCode,
            dimensionWdCode: response.recordList[key].wdCode,
            objectId: this.objectId,
          });
           this.editableTabsValue2 =  this.tabNameList[0].name;
        } 
      })
      },
      handleClick(tab, event) {
        console.log(tab, event);
     },
     onOk(){
       if(this.$refs.wd_orgId){
         this.$refs.wd_orgId[0].onOk();
       }
       if( this.$refs.otherDimension){
         for(var key = 0; key < this.$refs.otherDimension.length; key++){
           this.$refs.otherDimension[key].onOk();
         }
       }
        this.$emit("Close")
     }
  },
  destroyed:function(){

  },
  watch:{

  },
  directives:{

  }
}
</script>
