<template>
  <div class="container">
    <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
      <el-tab-pane v-if="hasPerm('/busConfig/liquidConfig/list')" label="液位监测仪" name="liquid">
        <list-liquid-config ref="liquidConfig"/>
      </el-tab-pane>
      <el-tab-pane v-if="hasPerm('/busConfig/gasConfig/list')" label="燃气智能监测终端" name="gas">
        <list-gas-config ref="gasConfig"/>
      </el-tab-pane>
      <el-tab-pane v-if="hasPerm('/busConfig/harmfulConfig/list')" label="有害气体监测仪" name="harmful">
        <list-harmful-config ref="harmfulConfig"/>
      </el-tab-pane>
      <el-tab-pane v-if="hasPerm('/busConfig/tempConfig/list')" label="温湿度监测仪" name="temphumidity">
        <list-temp-config ref="tempConfig"/>
      </el-tab-pane>
      <el-tab-pane v-if="hasPerm('/busConfig/digConfig/list')" label="开挖监测仪" name="dig">
        <list-dig-config ref="digConfig"/>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import ListLiquidConfig from './components/listLiquidConfig'
import ListGasConfig from './components/listGasConfig'
import ListHarmfulConfig from './components/listHarmfulConfig'
import ListTempConfig from './components/listTempConfig'
import ListDigConfig from './components/listDigConfig'
import { hasPermission } from '@/utils/permission'
export default {
  name: 'DeviceConfig',
  components: { ListDigConfig, ListTempConfig, ListHarmfulConfig, ListGasConfig, ListLiquidConfig },
  data() {
    return {
      activeName: 'liquid'
    }
  },
  created() {
    this.caclActive()
  },
  methods: {
    handleClick(tab, event) {
      if (tab.name === 'liquid') {
        this.$refs.liquidConfig.fetchData()
      } else if (tab.name === 'harmful') {
        this.$refs.harmfulConfig.fetchData()
      } else if (tab.name === 'gas') {
        this.$refs.gasConfig.fetchData()
      } else if (tab.name === 'temp') {
        this.$refs.tempConfig.fetchData()
      } else if (tab.name === 'dig') {
        this.$refs.digConfig.fetchData()
      }
    },
    // 计算那个是当前第一个tab
    caclActive() {
      if (hasPermission('/busConfig/liquidConfig/list')) {
        this.activeName = 'liquid'
      } else if (hasPermission('/busConfig/gasConfig/list')) {
        this.activeName = 'gas'
      } else if (hasPermission('/busConfig/harmfulConfig/list')) {
        this.activeName = 'harmful'
      } else if (hasPermission('/busConfig/tempConfig/list')) {
        this.activeName = 'temp'
      } else if (hasPermission('/busConfig/digConfig/list')) {
        this.activeName = 'dig'
      }
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .container{
    padding: 5px;
  }
</style>
