<template>
  <ai-list v-if="!isShowDetail">
    <template slot="title">
      <ai-title title="专题活动" :isShowBottomBorder="false" :instance="instance" :isShowArea="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)" :is="tab.comp" v-if="currIndex === String(i)" @change="onChange" :instance="instance" :dict="dict" :permissions="permissions"/>
        </el-tab-pane>
      </el-tabs>
    </template>
  </ai-list>
  <component v-else :is="componentName" @change="onChange" :params="params" :instance="instance" :dict="dict" :permissions="permissions"></component>
</template>

<script>
  import Event from './components/Event'
  import Comments from './components/Comments'
  import Add from './components/Add'
  import Detail from './components/Detail'
  import { mapState } from 'vuex'

  export default {
    name: 'AppProjectActivities',
    label: '专题活动',

    components: {
      Add,
      Detail,
      Event,
      Comments
    },

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

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

      tabs () {
        const tabList = [
          {label: '内容管理', name: 'Event', comp: Event, permission: 'app_appvillageinfo'},
          {label: '评论管理', name: 'Comments', comp: Comments, permission: 'app_appvillageinfocomment'}
        ].filter(item => {
          return this.permissions(item.permission)
        })

        return tabList
      }
    },

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

    created () {
    },

    methods: {
      areaChange () {
        console.log(this.$refs[this.currIndex])
        this.$refs[this.currIndex][0].getList()
      },

      onChange (data) {
        if (data.type === 'detail') {
          this.componentName = 'Detail'
          this.isShowDetail = true
          this.params = data.params
        }

        if (data.type === 'add') {
          this.componentName = 'Add'
          this.isShowDetail = true
          this.params = data.params
        }

        if (data.type === 'list') {
          this.isShowDetail = false

          this.$nextTick(() => {
            if (data.isRefresh) {
              // this.$refs[this.currIndex].getList()
            }
          })
        }
      }
    }
  }
</script>

<style lang="scss" scoped>
  .no-permission__wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    height: 100%;
    padding-bottom: 100px;
    font-size: 16px;
    color: #333;

    h2 {
      font-size: 16px;
      color: #333;
    }

    i {
      font-style: normal;
      color: #2771ff;
    }

    .no-permission {
      width: 120px;
      margin-top: 0;
    }
  }
</style>
