<template>
  <div class="AppTaskAi">
    <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 AnnounceList from './components/AnnounceList'
import Add from './components/Add'
import Detail from './components/Detail'
import TaskList from './components/TaskList'
import TaskAdd from './components/TaskAdd'
import TaskDetail from './components/TaskDetail'

export default {
  name: "AppTaskAi",
  label: "任务管理",
  props: {
    instance: Function,
    dict: Object,
  },
  data() {
    return {
      component: "List",
      params: {},
      include: [],

    };
  },
  components: {
    List,
    AnnounceList,
    Add,
    Detail,
    TaskList,
    TaskDetail,
    TaskAdd
  },
  mounted() {
    if (this.$route.params.id) {
      this.component = 'Detail'
      this.params = {
        id: this.$route.params.id
      }
    }
  },
  methods: {
    onChange(data) {
      if (data.type === "List") {
        this.component = "List";
        this.params = data.params;

        this.$nextTick(() => {
          if (data.isRefresh) {
            this.$refs.component.getTableData();
          }
        });
      }
      if (data.type === 'Add') {
        this.component = 'Add'
        this.params = data.params
      }

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

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

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

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

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

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

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

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