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

<script>
import electionList from "./components/electionList.vue";
import electionAdd from "./components/electionAdd.vue";
import Statistics from "./components/Statistics.vue";

export default {
  name: "AppGeneralElection",
  label: "换届选举",
  props: {
    instance: Function,
    dict: Object,
  },
  components: {electionAdd, electionList,Statistics},
  data() {
    return {
      component: "electionList",
      params: {},
      include: [],
    }
  },
  methods: {
    onChange(data) {
      if (data.type === "electionAdd") {
        this.component = "electionAdd";
        this.params = data.params;
      }

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

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

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

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