<template>
  <div class="resource">
    <div v-if="dialogfrom=='index'" class="index_search">
     <el-row>
        <span>行政区划：</span>
        <div class="index_search_list">
          <div class="item" :class="item.checked?'active':''" v-for="(item,index) in AreaDict" @click="choseArea2(item.code,index,'resource')">{{item.label}}</div>
        </div>
      </el-row>
       <el-row>
        <span>专项场景：</span>
        <div class="index_search_list">
          <div class="item" :class="item.checked?'active':''" v-for="(item,index) in dc_data.NOTICE_SCENE" @click="choseScene2(item.value,index,'resource')">{{item.label}}</div>
        </div>
      </el-row>
    </div>
    <el-tabs v-model="activeName"  :stretch="false" v-if="dialogfrom!='scheme'">
      <el-tab-pane label="应急仓库" name="first"><warehouse v-if="activeName=='first'" :allarea="search.areaList" :allscene="search.senceList" :selectID_warehouse="selectID_warehouse" :dialogfrom="dialogfrom" @resetFun4="resetFun4" @getSelection="getSelection"></warehouse></el-tab-pane>
      <el-tab-pane label="应急物资" name="second"><goods v-if="activeName=='second'" :allarea="search.areaList" :allscene="search.senceList" :dialogfrom="dialogfrom" :selectID_goods="selectID_goods" @resetFun4="resetFun4" @getSelection="getSelection"></goods></el-tab-pane>
      <el-tab-pane label="避难场所" name="third"><refuge v-if="activeName=='third'" :allarea="search.areaList" :allscene="search.senceList" :dialogfrom="dialogfrom" :selectID_refuge="selectID_refuge" @resetFun4="resetFun4" @getSelection="getSelection"></refuge></el-tab-pane>
      <el-tab-pane v-if="dialogfrom=='index'||dialogfrom=='scheme'" label="应急专家" name="fourth"><expert v-if="activeName=='fourth'" :allarea="search.areaList" :selectID_expert="selectID_expert"  :dialogfrom="dialogfrom" @resetFun4="resetFun4" @getSelection="getSelection"></expert></el-tab-pane>
      <el-tab-pane label="医疗机构" name="five"><institution v-if="activeName=='five'" :allarea="search.areaList" :dialogfrom="dialogfrom" :selectID_institution="selectID_institution" @resetFun4="resetFun4" @getSelection="getSelection"></institution></el-tab-pane>
      <el-tab-pane label="救援队伍" name="six"><rescue v-if="activeName=='six'" :allarea="search.areaList" :dialogfrom="dialogfrom" :selectID_rescue="selectID_rescue" @resetFun4="resetFun4" @getSelection="getSelection"></rescue></el-tab-pane>
      <el-tab-pane v-if="dialogfrom=='index'" label="重大危险源" name="seven"><dangerous v-if="activeName=='seven'" :allarea="search.areaList"  :dialogfrom="dialogfrom" @resetFun4="resetFun4"></dangerous></el-tab-pane>
      <el-tab-pane v-if="dialogfrom=='scheme'" label="事件档案库" name="eight"><event v-if="activeName=='eight'"   :dialogfrom="dialogfrom" :selectID_event="selectID_event" @getSelection="getSelection" ></event></el-tab-pane>
    </el-tabs>
     <el-tabs v-model="activeName"  :stretch="false" v-if="dialogfrom=='scheme'">
      <el-tab-pane label="应急仓库" name="first" v-if="showTabList[0]"><warehouse v-if="activeName=='first'" :allarea="search.areaList" :allscene="search.senceList" :selectID_warehouse="selectID_warehouse" :dialogfrom="dialogfrom" @resetFun4="resetFun4" @getSelection="getSelection"></warehouse></el-tab-pane>
      <el-tab-pane label="应急物资" name="second" v-if="showTabList[1]"><goods v-if="activeName=='second'" :allarea="search.areaList" :allscene="search.senceList" :dialogfrom="dialogfrom" :selectID_goods="selectID_goods" @resetFun4="resetFun4" @getSelection="getSelection"></goods></el-tab-pane>
      <el-tab-pane label="避难场所" name="third" v-if="showTabList[2]"><refuge v-if="activeName=='third'" :allarea="search.areaList" :allscene="search.senceList" :dialogfrom="dialogfrom" :selectID_refuge="selectID_refuge" @resetFun4="resetFun4" @getSelection="getSelection"></refuge></el-tab-pane>
      <el-tab-pane  v-if="showTabList[3]" label="应急专家" name="fourth"><expert v-if="activeName=='fourth'" :allarea="search.areaList" :selectID_expert="selectID_expert"  :dialogfrom="dialogfrom" @resetFun4="resetFun4" @getSelection="getSelection"></expert></el-tab-pane>
      <el-tab-pane label="医疗机构" name="five"  v-if="showTabList[4]"><institution v-if="activeName=='five'" :allarea="search.areaList" :dialogfrom="dialogfrom" :selectID_institution="selectID_institution" @resetFun4="resetFun4" @getSelection="getSelection"></institution></el-tab-pane>
      <el-tab-pane label="救援队伍" name="six" v-if="showTabList[5]"><rescue v-if="activeName=='six'" :allarea="search.areaList" :dialogfrom="dialogfrom" :selectID_rescue="selectID_rescue" @resetFun4="resetFun4" @getSelection="getSelection"></rescue></el-tab-pane>
      <el-tab-pane  v-if="showTabList[6]" label="事件档案库" name="eight"><event v-if="activeName=='eight'"   :dialogfrom="dialogfrom" :selectID_event="selectID_event" @getSelection="getSelection" ></event></el-tab-pane>
    </el-tabs>
  </div>
</template>
<script>
import warehouse from '@/views/emergency/warehouse.vue'
import goods from '@/views/emergency/goods.vue'
import refuge from '@/views/emergency/refuge.vue'
import institution from '@/views/emergency/institution.vue'
import rescue from '@/views/emergency/rescue.vue'
import expert from '@/views/emergency/expert.vue'
import dangerous from '@/views/emergency/dangerous.vue'
import event from '@/views/archives/event.vue'
import Base from '@/views/base/base'

export default {
    name: 'Notice',
    components: {
      warehouse,goods,refuge,institution,rescue,expert,dangerous,event
    },
    props: ['dialogfrom','openPage','openType','selectID_warehouse','selectID_goods','selectID_refuge','selectID_expert','selectID_institution','selectID_rescue','selectID_event','allType'],
    mixins: [Base],
    data() {
        return {
            activeName: 'first',
            dc_key:['NOTICE_SCENE'],
            areaList:[],
            senceList:[],
            search:{areaList:'',senceList:''},
            showTabList:[false,false,false,false,false,false,false],
        }
    },
    mounted() {
      console.log(this.dialogfrom)
        this.initDict(this.dc_key).then((res) => {
        this.initArea().then(()=>{

          })
        })
      switch(this.openPage){
        case 'warehouse':
          this.activeName='first'
          break;
        case 'goods':
          this.activeName='second'
          break;
        case 'refuge':
          this.activeName='third'
          break;
        case 'expert':
          this.activeName='fourth'
          break;
        case 'institution':
          this.activeName='five'
          break;
        case 'rescue':
          this.activeName='six'
          break;
        case 'event':
          this.activeName='eight'
          break;
      }
      if(this.allType){
        var result = this.allType
        for(var i=0;i<result.length;i++){
          var index=Number(result[i])
          this.$set(this.showTabList, index, true)
        }
        var C=['first','second','third','fourth','five','six','eight']
        this.activeName=C[Number(result[0])]
        console.log(this.showTabList)
      }
    },
    methods: {
        getSelection(data){
          this.$emit('getSelection',data)
        },
        resetFun4(){
          this.areaList=[]
          this.senceList=[]
          for(var i=0;i<this.AreaDict.length;i++){
            this.$set(this.AreaDict[i], 'checked', false);
          }
          for(var i=0;i<this.dc_data.NOTICE_SCENE.length;i++){
            this.$set(this.dc_data.NOTICE_SCENE[i], 'checked', false);
          }
        },
        choseArea2(code,index){
          if(this.areaList.length==0){
            this.areaList.push(code)
            this.AreaDict[index].checked=true
          }else{
            var is=false
            for(var i=0;i<this.areaList.length;i++){
              if(this.areaList[i]==code){
                this.areaList.splice(i,1)
                this.AreaDict[index].checked=false
                is=true
              }
            }
            if(!is){
              this.areaList.push(code)
              this.AreaDict[index].checked=true
            }
          }
          if(this.areaList.length==0){
            this.search.areaList=''
          }else{
          this.search.areaList=this.areaList.join(',')
          }
        },
        choseScene2(val,index){
          if(this.senceList.length==0){
            this.senceList.push(val)
            this.dc_data.NOTICE_SCENE[index].checked=true
          }else{
            var is=false
            for(var i=0;i<this.dc_data.NOTICE_SCENE.length;i++){
              if(this.senceList[i]==val){
                this.senceList.splice(i,1)
                this.dc_data.NOTICE_SCENE[index].checked=false
                is=true
              }
            }
            if(!is){
              this.senceList.push(val)
              this.dc_data.NOTICE_SCENE[index].checked=true
            }
          }
          if(this.senceList.length==0){
            this.search.senceList=''
          }else{
          this.search.senceList=this.senceList.join(',')
          }
        },

    }
}
</script>

<style scoped lang="scss">
  
</style>
<style lang="scss">
.resource{
  .el-tabs__item{
    width: 150px;
    text-align: center;
    padding: 0;
  }
  .el-tabs__active-bar{
   width: 150px!important;
  }
}
</style>
