<template>
  <ai-list>
    <template slot="title">
      <ai-title title="居民积分" :isShowArea="currIndex === '0'" :hideLevel="$store.state.user.info.areaList.length - 1" v-model="areaId" :instance="instance" @change="search.current = 1, getList()"></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 :areaId="areaId" :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>
</template>

<script>
  import List from './components/List'
  import Rule from './components/Rule'

  export default {
    name: 'AppResidentCredits',
    label: '居民积分',

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

    data () {
      return {
        component: 'List',
        params: {},
        currIndex: '0',
        areaId: ''
      }
    },

    components: {
      List,
      Rule
    },

    computed: {
      tabs () {
        return [
          {label: '居民积分', name: 'List', comp: List, permission: ''},
          {label: `积分规则`, name: 'Rule', comp: Rule, permission: ''}
        ].filter(item => {
          return true
        })
      }
    },

    created () {
      this.areaId = this.$store.state.user.info.areaId
    },

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

        if (data.type === 'Rule') {
          this.component = 'Rule'
          this.params = data.params
        }
      }
    }
  }
</script>

<style lang="scss">
  .doc-circulation {
    height: 100%;
    background: #F3F6F9;
    overflow: auto;
  }
</style>
