<template>
  <ai-list v-if="!isShowDetail">
    <template slot="title">
      <ai-title title="居民群管理" :isShowBottomBorder="false"></ai-title>
    </template>
    <template slot="tabs">
      <el-tabs v-model="currIndex">
        <el-tab-pane v-for="(tab,i) in tabs" :key="i" :label="tab.label">
          <component :ref="String(i)" v-if="currIndex == i" :is="tab.comp" @change="onChange" lazy :instance="instance" :dict="dict" :permissions="permissions"/>
        </el-tab-pane>
      </el-tabs>
    </template>
  </ai-list>
  <Detail v-else-if="componentName === 'Detail'" :params="params" :instance="instance" :dict="dict" :permissions="permissions" @change="onChange"></Detail>
</template>

<script>
  import List from './components/List.vue'
  import Statistics from './components/Statistics'
  import Tags from './components/Tags'
  import Detail from './components/Detail'
  import { mapState } from 'vuex'

  export default {
    name: 'AppResidentGroupManage',
    label: '居民群管理',

    components: {
      List,
      Tags,
      Detail,
      Statistics
    },

    props: {
      instance: Function,
      dict: Object,
      permissions: Function
    },

    computed: {
      ...mapState(['user']),

      tabs () {
        const tabList = [
          {label: '居民群列表', name: 'List', comp: List, permission: ''},
          {label: '居民群统计', name: 'Statistics', comp: Statistics, permission: ''},
          {label: '居民群标签', name: 'Tags', comp: Tags, permission: ''}
        ].filter(item => {
          return true
        })

        return tabList
      }
    },

    data () {
      return {
        activeName: 'JoinEvent',
        currIndex: '0',
        componentName: '',
        params: {},
        isShowDetail: false
      }
    },

    created () {
    },

    methods: {
      onChange (data) {
        if (data.type === 'list') {
          this.componentName = 'List'
          this.isShowDetail = false
          this.params = data.params
        }

        if (data.type === 'detail') {
          this.componentName = 'Detail'
          this.isShowDetail = true
          this.params = data.params
        }
      }
    }
  }
</script>

<style lang="scss" scoped>
</style>
