<template>
  <div class="AppCarousel">
    <keep-alive :include="['List']">
      <component ref="component" :is="component" @change="onChange" :params="params" :instance="instance" :dict="dict"></component>
    </keep-alive>
  </div>
</template>

<script>
  import List from './components/List'
  import Detail from './components/Detail'
  import Add from './components/Add'

  export default {
    name: 'AppCarousel',
    label: '轮播图片',

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

    data () {
      return {
        component: 'List',
        params: {},
        include: []
      }
    },

    components: {
      Detail,
      List,
      Add
    },

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

        if (data.type === 'Add') {
          this.component = 'Add'
          this.params = data.params
        }

        if (data.type === 'List') {
          this.component = 'List'
          this.params = data.params

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

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