<template>
  <el-tabs v-model="activeName" @tab-click="handleClick">
    <el-tab-pane :label="item.label" :name="item.name" v-for="(item,index) in tabs" >
      <component :is="item.tableComp" :ref="item.ref" :height="height" :queryParam="queryParam" :list="tabsData[item.name]"/>
    </el-tab-pane>
  </el-tabs>
</template>

<script>
import First from "@/views/jhzx/components/sygdpc/First";
import Sygdjh from "@/views/jhzx/components/sygdpc/Sygdjh";
import Second from "@/views/jhzx/components/sygdpc/Second";
import Third from "@/views/jhzx/components/sygdpc/Third";
import Fourth from "@/views/jhzx/components/sygdpc/Fourth";
import Bcxq from "@/views/jhzx/components/sygdpc/Bcxq";
import SygdjhDetail from "@/views/jhzx/components/sygdpc/SygdjhDetail";
export default {
  name:"MyTabs",
  components:{First,Sygdjh,Second,Third,Bcxq,Fourth,SygdjhDetail},
  props:{
    queryParam:Object,
    height:{
      type:Number,
      default:500,
    }
  },
  data(){
    return{
      activeName:'first',
      tabs:[
        {name:'first',label:'前方三月需求计划',tableComp:'First',ref:'firstRef'},
        {name:'sygdjh',label:'三月滚动计划编制',tableComp:'Sygdjh',ref:'sygdjhRef'},
        {name:'sygdjhDetail',label:'三月滚动计划明细',tableComp:'SygdjhDetail',ref:'sygdjhDetailRef'},
        {name:'second',label:'线表信息',tableComp:'Second',ref:'secondRef'},
        {name:'third',label:'批量信息',tableComp:'Third',ref:'thirdRef'},
        {name:'bcxq',label:'板材需求',tableComp:'Bcxq',ref:'bcxqRef'},
        {name:'fourth',label:'跨位信息',tableComp:'Fourth',ref:'fourthRef'},
      ],
      tabsData:{
        first:[],
        sygdjh:[],
        sygdjhDetail:[],
        second:[],
        third:[],
        bcxq:[],
        fourth:[],
      }
    }
  },
  methods:{
    initData(name,list){
      this.tabsData[name]=list
    },
    initTabData(){
      this.$emit('initTabData',this.activeName);
    },
    getSelectData(){
      return this.$refs['sygdjhDetail'].getSelectData();
    },
    handleClick(){
      Object.keys(this.tabsData).forEach(key=>{
        if (key!==this.activeName){
          this.tabsData[key]=null;
        }
      })
      this.initTabData();
    },
  }
}
</script>
