<template>
  <section class="AppOrganizationChange">
    <keep-alive :include="['List']">
      <component ref="component" :is="component" :instance="instance" :selected.sync="selected" :params="params" :dict="dict" @change="onChange"/>
    </keep-alive>
  </section>
</template>

<script>
import addChange from "./components/addChange.vue";
import List from "./components/List.vue";
import organizationSetting from "./components/organizationSetting.vue";

export default {
  name: "AppOrganizationChange",
  label: "组织换届",
  props: {
    instance: Function,
    dict: Object,
  },
  components: {
    List, 
    addChange,
    organizationSetting,
  },
  data() {
    return {
      component: "List",
      params: {},
      include: [],
      selected: {},
    }
  },
  methods: {
    onChange(data) {
      if (data.type === "List") {
        this.component = "List";
        this.params = data.params;
      }

      if (data.type === "organizationSetting") {
        this.component = "organizationSetting";
        this.params = data.params;
      }

      if (data.type === "addChange") {
        this.component = "addChange";
        this.params = data.params;

        this.$nextTick(() => {
          if (data.isRefresh) {
            this.$refs.component.getList();
          }
        });
      }
    },
  },
  created() {
    let {organizationId: id, organizationName: name} = this.user.info
    this.selected = {id, name}
  }
}
</script>

<style lang="scss" scoped>
.AppOrganizationChange {
  height: 100%;
}
</style>
